Fix "Cannot read property 'ID' of undefined". https://github.com/Koenkk/zigbee2mqtt/issues/6981

This commit is contained in:
Koen Kanters
2021-04-07 18:39:54 +02:00
parent ab0ae8ce91
commit 30efb3e824
2 changed files with 8 additions and 2 deletions
+7 -2
View File
@@ -188,6 +188,11 @@ class Zigbee extends events.EventEmitter {
`Wrong type '${typeof key}'`,
);
const getEndpointName = (endpointNames, endpoint) => {
return endpoint ?
utils.getKey(endpointNames, endpoint.ID, null, ((v) => v === 'default' ? null : v)) : null;
};
const deviceOptions = settings.get().device_options;
if (typeof key === 'string' || typeof key === 'number') {
if (typeof key === 'number') {
@@ -247,7 +252,7 @@ class Zigbee extends events.EventEmitter {
return {
type: 'device', device, endpoint, settings: {...deviceOptions, ...entity},
name: entity.friendlyName, definition,
endpointName: utils.getKey(endpointNames, endpoint.ID, null, ((v) => v === 'default' ? null : v)),
endpointName: getEndpointName(endpointNames, endpoint),
};
} else {
let group = this.getGroupByID(entity.ID);
@@ -269,7 +274,7 @@ class Zigbee extends events.EventEmitter {
return {
type: 'device', definition, name, device, endpoint, settings: {...deviceOptions, ...(setting || {})},
endpointName: utils.getKey(endpointNames, endpoint.ID, null, ((v) => v === 'default' ? null : v)),
endpointName: getEndpointName(endpointNames, endpoint),
};
} else { // Group
const setting = settings.getEntity(key.groupID);