mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-10-22 22:11:22 +00:00
Set state of stateless properties to ‘idle’ after publish. #959
This commit is contained in:
1 parent
7642b295e1
commit
0826db07d0
2 files changed
+21
-8
No files matched your search
@@ -1,7 +1,7 @@
|
||||
const settings = require('../util/settings');
|
||||
const logger = require('../util/logger');
|
||||
|
||||
const dontCacheProperties = ['action', 'button', 'button_left', 'button_right', 'click', 'forgotten', 'keyerror'];
|
||||
const statelessProperties = ['action', 'button', 'button_left', 'button_right', 'click', 'forgotten', 'keyerror'];
|
||||
|
||||
/**
|
||||
* This extensions handles messages received from devices.
|
||||
@@ -100,11 +100,18 @@ class DeviceReceive {
|
||||
// - If NO payload is returned do nothing. This is for non-standard behaviour
|
||||
// for e.g. click switches where we need to count number of clicks and detect long presses.
|
||||
const publish = (payload) => {
|
||||
// Don't cache messages with following properties:
|
||||
// Don't cache messages with stateless properties.
|
||||
// After a stateless property is send we need to clear it.
|
||||
// Otherwise the state of the device is incorrect.
|
||||
// E.g. when a button is pressed a payload like {"click": "single"}
|
||||
// is produced, afterwards we want to clear this with {"click": "idle"}
|
||||
// https://github.com/Koenkk/zigbee2mqtt/issues/959
|
||||
let cache = true;
|
||||
dontCacheProperties.forEach((property) => {
|
||||
const clearStatePayload = {};
|
||||
statelessProperties.forEach((property) => {
|
||||
if (payload.hasOwnProperty(property)) {
|
||||
cache = false;
|
||||
clearStatePayload[property] = 'idle';
|
||||
}
|
||||
});
|
||||
|
||||
@@ -133,6 +140,9 @@ class DeviceReceive {
|
||||
}
|
||||
|
||||
this.publishEntityState(device.ieeeAddr, payload, cache);
|
||||
if (Object.keys(clearStatePayload).length > 0) {
|
||||
this.publishEntityState(device.ieeeAddr, clearStatePayload, false);
|
||||
}
|
||||
};
|
||||
|
||||
let payload = {};
|
||||
|
||||
Reference in new issue
Block a user