Fix turn off and dim commands

This commit is contained in:
Victor Hagelbäck 2021-02-20 10:49:00 +01:00
parent 70059da094
commit e528e2be1f
3 changed files with 18 additions and 6 deletions

View file

@ -142,7 +142,6 @@ class PlejBLEHandler extends EventEmitter {
deviceId, deviceId,
BLE_CMD_DIM2_CHANGE, BLE_CMD_DIM2_CHANGE,
`01${brightnessVal.toString(16).padStart(4, '0')}`, `01${brightnessVal.toString(16).padStart(4, '0')}`,
`Dim ${data}`,
); );
break; break;
default: default:
@ -799,7 +798,9 @@ class PlejBLEHandler extends EventEmitter {
try { try {
this.write(payload); this.write(payload);
} catch (err) { } 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) { } else if (deviceId !== BLE_BROADCAST_DEVICE_ID) {

View file

@ -88,12 +88,21 @@ class PlejdDeviceCommunication extends EventEmitter {
}); });
} else if (command === COMMANDS.TURN_ON) { } else if (command === COMMANDS.TURN_ON) {
this.plejdDevices[deviceId] = { this.plejdDevices[deviceId] = {
state: data.state, state: 1,
dim: 0, dim: 0,
}; };
logger.silly(`All states: ${JSON.stringify(this.plejdDevices, null, 2)}`); logger.silly(`All states: ${JSON.stringify(this.plejdDevices, null, 2)}`);
this.emit(PlejdDeviceCommunication.EVENTS.stateChanged, deviceId, { 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) { } else if (command === COMMANDS.TRIGGER_SCENE) {
this.emit(PlejdDeviceCommunication.EVENTS.sceneTriggered, deviceId, data.sceneId); this.emit(PlejdDeviceCommunication.EVENTS.sceneTriggered, deviceId, data.sceneId);
@ -237,7 +246,9 @@ class PlejdDeviceCommunication extends EventEmitter {
logger.debug( logger.debug(
`Write queue: Processing ${deviceName} (${queueItem.deviceId}). Command ${ `Write queue: Processing ${deviceName} (${queueItem.deviceId}). Command ${
queueItem.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)) { if (this.writeQueue.some((item) => item.deviceId === queueItem.deviceId)) {