Fix not able to read state from multiple endpoints at once. https://github.com/Koenkk/zigbee-herdsman-converters/issues/1252

This commit is contained in:
Koen Kanters
2020-05-22 18:16:53 +02:00
parent 83215c3290
commit 94dbf9c505
2 changed files with 17 additions and 3 deletions
+5 -3
View File
@@ -143,7 +143,7 @@ class EntityPublish extends Extension {
entries.sort((a, b) => (['state', 'brightness', 'brightness_percent'].includes(a[0]) ? sorter : sorter * -1));
// For each attribute call the corresponding converter
const usedConverters = [];
const usedConverters = {};
for (let [key, value] of entries) {
let endpointName = topic.endpointName;
let actualTarget = target;
@@ -160,9 +160,11 @@ class EntityPublish extends Extension {
}
}
const endpointOrGroupID = actualTarget.constructor.name == 'Group' ? actualTarget.groupID : actualTarget.ID;
if (!usedConverters.hasOwnProperty(endpointOrGroupID)) usedConverters[endpointOrGroupID] = [];
const converter = converters.find((c) => c.key.includes(key));
if (usedConverters.includes(converter)) {
if (usedConverters[endpointOrGroupID].includes(converter)) {
// Use a converter only once (e.g. light_onoff_brightness converters can convert state and brightness)
continue;
}
@@ -238,7 +240,7 @@ class EntityPublish extends Extension {
}
}
usedConverters.push(converter);
usedConverters[endpointOrGroupID].push(converter);
}
return true;
+12
View File
@@ -414,6 +414,18 @@ describe('Publish', () => {
expect(endpoint.read).toHaveBeenCalledWith('genOnOff', ['onOff']);
});
it('Should handle get with multiple endpoints', async () => {
const device = zigbeeHerdsman.devices.QBKG03LM;
const endpoint2 = device.getEndpoint(2);
const endpoint3 = device.getEndpoint(3);
await MQTT.events.message('zigbee2mqtt/0x0017880104e45542/get', JSON.stringify({state_left: '', state_right: ''}));
await flushPromises();
expect(endpoint2.read).toHaveBeenCalledTimes(1);
expect(endpoint2.read).toHaveBeenCalledWith('genOnOff', ['onOff']);
expect(endpoint3.read).toHaveBeenCalledTimes(1);
expect(endpoint3.read).toHaveBeenCalledWith('genOnOff', ['onOff']);
});
it('Should not respond to bridge/config/devices/get', async () => {
await MQTT.events.message('zigbee2mqtt/bridge/config/devices/get', JSON.stringify({state: 'ON'}));
await flushPromises();