Fix turn off and dim commands
This commit is contained in:
parent
70059da094
commit
e528e2be1f
3 changed files with 18 additions and 6 deletions
|
|
@ -133,7 +133,7 @@ class MqttClient extends EventEmitter {
|
||||||
// Guess that id that got state command without dim value belongs to Scene, not Device
|
// 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...
|
// This guess could very well be wrong depending on the installation...
|
||||||
logger.warn(
|
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.',
|
+ 'OFF commands still sent to device.',
|
||||||
);
|
);
|
||||||
device = this.deviceRegistry.getScene(decodedTopic.id);
|
device = this.deviceRegistry.getScene(decodedTopic.id);
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
||||||
|
|
|
||||||
|
|
@ -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)) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue