Fix device configuring with endpoint ID not working. https://github.com/nurikk/zigbee2mqtt-frontend/issues/874

This commit is contained in:
Koen Kanters
2021-09-29 22:00:01 +02:00
parent 06d30d1036
commit 8d9f14e30b
3 changed files with 6 additions and 4 deletions
+3 -1
View File
@@ -42,7 +42,9 @@ export default class Device {
let endpoint: ZHEndpoint;
if (key == null) key = 'default';
if (this.definition?.endpoint) {
if (!isNaN(Number(key))) {
endpoint = this.device.getEndpoint(Number(key));
} else if (this.definition?.endpoint) {
const ID = this.definition?.endpoint?.(this.device)[key];
if (ID) endpoint = this.device.getEndpoint(ID);
else if (key === 'default') endpoint = this.device.endpoints[0];
+1 -1
View File
@@ -313,7 +313,7 @@ export function isIkeaTradfriDevice(device: ZHDevice): boolean {
return [4476].includes(device.manufacturerID);
}
const entityIDRegex = new RegExp(`^(.+?)(?:/(${endpointNames.join('|')}))?$`);
const entityIDRegex = new RegExp(`^(.+?)(?:/(${endpointNames.join('|')}|\\d+))?$`);
export function parseEntityID(ID: string): {ID: string, endpoint: string} {
const match = ID.match(entityIDRegex);
return match && {ID: match[1], endpoint: match[2]};
+2 -2
View File
@@ -958,7 +958,7 @@ describe('Bridge', () => {
endpoint.configureReporting.mockClear();
zigbeeHerdsman.permitJoin.mockClear();
MQTT.publish.mockClear();
MQTT.events.message('zigbee2mqtt/bridge/request/device/configure_reporting', stringify({id: 'bulb', cluster: 'genLevelCtrl', attribute: 'currentLevel', maximum_report_interval: 10, minimum_report_interval: 1, reportable_change: 1}));
MQTT.events.message('zigbee2mqtt/bridge/request/device/configure_reporting', stringify({id: '0x000b57fffec6a5b2/1', cluster: 'genLevelCtrl', attribute: 'currentLevel', maximum_report_interval: 10, minimum_report_interval: 1, reportable_change: 1}));
await flushPromises();
expect(endpoint.bind).toHaveBeenCalledTimes(1);
expect(endpoint.bind).toHaveBeenCalledWith('genLevelCtrl', coordinator.endpoints[0]);
@@ -966,7 +966,7 @@ describe('Bridge', () => {
expect(endpoint.configureReporting).toHaveBeenCalledWith('genLevelCtrl', [{"attribute": "currentLevel", "maximumReportInterval": 10, "minimumReportInterval": 1, "reportableChange": 1}]);
expect(MQTT.publish).toHaveBeenCalledWith(
'zigbee2mqtt/bridge/response/device/configure_reporting',
stringify({"data":{id: 'bulb', cluster: 'genLevelCtrl', attribute: 'currentLevel', maximum_report_interval: 10, minimum_report_interval: 1, reportable_change: 1},"status":"ok"}),
stringify({"data":{id: '0x000b57fffec6a5b2/1', cluster: 'genLevelCtrl', attribute: 'currentLevel', maximum_report_interval: 10, minimum_report_interval: 1, reportable_change: 1},"status":"ok"}),
{retain: false, qos: 0}, expect.any(Function)
);
expect(MQTT.publish).toHaveBeenCalledWith(