diff --git a/plejd/MqttClient.js b/plejd/MqttClient.js index 5c89ee9..797a96a 100644 --- a/plejd/MqttClient.js +++ b/plejd/MqttClient.js @@ -133,7 +133,7 @@ class MqttClient extends EventEmitter { // Guess that id that got state command without dim value belongs to Scene, not Device // This guess could very well be wrong depending on the installation... logger.warn( - `Device id ${decodedTopic.id} belongs to both scene and device, guessing Scene is what should be set to ON.` + `Device id ${decodedTopic.id} belongs to both scene and device, guessing Scene is what should be set to ON. ` + 'OFF commands still sent to device.', ); device = this.deviceRegistry.getScene(decodedTopic.id); diff --git a/plejd/PlejdBLEHandler.js b/plejd/PlejdBLEHandler.js index 1748ca2..cd3abd7 100644 --- a/plejd/PlejdBLEHandler.js +++ b/plejd/PlejdBLEHandler.js @@ -142,7 +142,6 @@ class PlejBLEHandler extends EventEmitter { deviceId, BLE_CMD_DIM2_CHANGE, `01${brightnessVal.toString(16).padStart(4, '0')}`, - `Dim ${data}`, ); break; default: @@ -799,7 +798,9 @@ class PlejBLEHandler extends EventEmitter { try { this.write(payload); } catch (err) { - logger.error('Failed writing new time to Plejd. Will try again in one hour or at restart.'); + logger.error( + 'Failed writing new time to Plejd. Will try again in one hour or at restart.', + ); } } } else if (deviceId !== BLE_BROADCAST_DEVICE_ID) { diff --git a/plejd/PlejdDeviceCommunication.js b/plejd/PlejdDeviceCommunication.js index 86ed5f8..888f4cb 100644 --- a/plejd/PlejdDeviceCommunication.js +++ b/plejd/PlejdDeviceCommunication.js @@ -88,12 +88,21 @@ class PlejdDeviceCommunication extends EventEmitter { }); } else if (command === COMMANDS.TURN_ON) { this.plejdDevices[deviceId] = { - state: data.state, + state: 1, dim: 0, }; logger.silly(`All states: ${JSON.stringify(this.plejdDevices, null, 2)}`); this.emit(PlejdDeviceCommunication.EVENTS.stateChanged, deviceId, { - state: data.state, + state: 1, + }); + } else if (command === COMMANDS.TURN_OFF) { + this.plejdDevices[deviceId] = { + state: 0, + dim: 0, + }; + logger.silly(`All states: ${JSON.stringify(this.plejdDevices, null, 2)}`); + this.emit(PlejdDeviceCommunication.EVENTS.stateChanged, deviceId, { + state: 0, }); } else if (command === COMMANDS.TRIGGER_SCENE) { this.emit(PlejdDeviceCommunication.EVENTS.sceneTriggered, deviceId, data.sceneId); @@ -237,7 +246,9 @@ class PlejdDeviceCommunication extends EventEmitter { logger.debug( `Write queue: Processing ${deviceName} (${queueItem.deviceId}). Command ${ queueItem.command - }${queueItem.data ? ` ${queueItem.data}` : ''}. Total queue length: ${this.writeQueue.length}`, + }${queueItem.data ? ` ${queueItem.data}` : ''}. Total queue length: ${ + this.writeQueue.length + }`, ); if (this.writeQueue.some((item) => item.deviceId === queueItem.deviceId)) {