Skip to content

Commit

Permalink
fix: fixed error states in sendCommand
Browse files Browse the repository at this point in the history
During my testing I frequently got in an connection error state.
The first error state this commit fixes is when sending a command to a bulb while it is still connecting (e.g. startup or reconnect) it will emit an 'error' event on the socket (Error: Connection to device broken) but would not attempt to reconnect to the device
Secondly, when sending multiple commands the ceiling light commands did frequently take more than 3000 milliseconds to execute triggering the 'Error sending command' error. However, most of the time this command would still come through indicating the connection was not broken. Therefore I increased the timeout which triggers this error to 6000 seconds.
  • Loading branch information
BasKiers committed Jun 30, 2018
1 parent c13fc44 commit 990c2ac
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/yeelights/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,9 @@ class YeelightDevice extends Homey.Device {

/* send commands to devices using their socket connection */
sendCommand(id, command) {
if (yeelights[id].connected === false && yeelights[id].socket !== null) {
if(yeelights[id].connecting && yeelights[id].connected === false){
this.log('Unable to send command because socket is still connecting');
} else if (yeelights[id].connected === false && yeelights[id].socket !== null) {
yeelights[id].socket.emit('error', new Error('Connection to device broken'));
} else if (yeelights[id].socket === null) {
this.log('Unable to send command because socket is not available');
Expand All @@ -269,7 +271,7 @@ class YeelightDevice extends Homey.Device {
if (yeelights[id].connected === true && yeelights[id].socket !== null) {
yeelights[id].socket.emit('error', new Error('Error sending command'));
}
}, 3000);
}, 6000);
}
}

Expand Down

0 comments on commit 990c2ac

Please sign in to comment.