mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-10-23 14:22:38 +00:00
* Add filtered_optimistic device option * Add test to cover filtered_optimistic
This commit is contained in:
1 parent
c6e2e875d5
commit
15a7bab5f3
3 files changed
+26
No files matched your search
@@ -237,6 +237,11 @@ class EntityPublish extends Extension {
|
||||
}
|
||||
}
|
||||
|
||||
// filter out attribute listed in filtered_optimistic
|
||||
if (options.hasOwnProperty('filtered_optimistic')) {
|
||||
options.filtered_optimistic.forEach((a) => delete msg[a]);
|
||||
}
|
||||
|
||||
this.publishEntityState(resolvedEntity.settings.ID, msg);
|
||||
}
|
||||
|
||||
|
||||
@@ -701,6 +701,15 @@
|
||||
"description": "Publish optimistic state after set",
|
||||
"default": true
|
||||
},
|
||||
"filtered_optimistic": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"examples": ["color_mode", "color_temp", "color"],
|
||||
"title": "Filtered attributes",
|
||||
"description": "Skip optimistic state after set for certain attributes, this has no effect if optimistic is set to false."
|
||||
},
|
||||
"filtered_attributes": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
|
||||
@@ -422,6 +422,18 @@ describe('Publish', () => {
|
||||
expect(MQTT.publish).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
it('Shouldnt publish new brightness state when filtered_optimistic is used', async () => {
|
||||
const device = zigbeeHerdsman.devices.bulb_color;
|
||||
const endpoint = device.getEndpoint(1);
|
||||
settings.set(['devices', device.ieeeAddr, 'filtered_optimistic'], ["brightness"]);
|
||||
await MQTT.events.message('zigbee2mqtt/bulb_color/set', stringify({brightness: '200'}));
|
||||
await flushPromises();
|
||||
expect(endpoint.command).toHaveBeenCalledTimes(1);
|
||||
expect(endpoint.command).toHaveBeenCalledWith("genLevelCtrl", "moveToLevelWithOnOff", {"level": 200, "transtime": 0}, {});
|
||||
expect(MQTT.publish).toHaveBeenCalledTimes(1);
|
||||
expect(JSON.parse(MQTT.publish.mock.calls[0][1])).toStrictEqual({state: 'ON'});
|
||||
});
|
||||
|
||||
it('Shouldnt publish new state when optimistic = false for group', async () => {
|
||||
settings.set(['groups', '2', 'optimistic'], false);
|
||||
await MQTT.events.message('zigbee2mqtt/group_2/set', stringify({brightness: '200'}));
|
||||
|
||||
Reference in new issue
Block a user