Skip to content

Commit

Permalink
fix websocket errors
Browse files Browse the repository at this point in the history
fixes #304 #303
  • Loading branch information
Garfonso committed Jun 12, 2023
1 parent 2178838 commit 0f466a4
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/lib/WebSocketDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,20 @@ export class WebSocketDevice extends Device {
await super.onInterval();
// if not ready -> communication did fail, will be retried on next poll.
if (this.ready) {
if (this.numSockets > 1) {
const states = await this.client.state(-1) as Array<boolean>; //get all socket states.
for (let index = 1; index <= this.numSockets; index += 1) {
const id = this.id + Suffixes.state + '_' + index;
const val = states[index - 1];
await this.adapter.setStateChangedAsync(id, val, true);
try {
if (this.numSockets > 1) {
const states = await this.client.state(-1) as Array<boolean>; //get all socket states.
for (let index = 1; index <= this.numSockets; index += 1) {
const id = this.id + Suffixes.state + '_' + index;
const val = states[index - 1];
await this.adapter.setStateChangedAsync(id, val, true);
}
} else {
const val = await this.client.state(0) as boolean;
await this.adapter.setStateChangedAsync(this.id + Suffixes.state, val, true);
}
} else {
const val = await this.client.state(0) as boolean;
await this.adapter.setStateChangedAsync(this.id + Suffixes.state, val, true);
} catch (e) {
await this.handleNetworkError(e);
}
}
}
Expand Down Expand Up @@ -140,7 +144,7 @@ export class WebSocketDevice extends Device {
}

/**
* process a state change. Device will just try to switch plug. Childs will have to overwrite this behaviour.
* process a state change. Device will just try to switch plug. Children will have to overwrite this behaviour.
* @param id
* @param state
*/
Expand Down Expand Up @@ -170,7 +174,7 @@ export class WebSocketDevice extends Device {
}
}

async getModelInfoForSentry() {
async getModelInfoForSentry() : Promise<any> {
const url = `http://${this.ip}/login?username=Admin&password=${this.pinDecrypted}`;
const result = await axios.get(url);
return result.data;
Expand Down

0 comments on commit 0f466a4

Please sign in to comment.