#7571 Add filtered_optimistic device option (#7633)

* Add filtered_optimistic device option

* Add test to cover filtered_optimistic
This commit is contained in:
Jorge Schrauwen authored and GitHub committed 2021-05-30 13:03:55 +02:00
1 parent c6e2e875d5
commit 15a7bab5f3
3 files changed
+26

No files matched your search

+5
View File
@@ -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);
}
+9
View File
@@ -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": {
+12
View File
@@ -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'}));