diff --git a/lib/zigbee.js b/lib/zigbee.js index b2eb1f4f..ab443126 100644 --- a/lib/zigbee.js +++ b/lib/zigbee.js @@ -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); diff --git a/test/stub/zigbeeHerdsman.js b/test/stub/zigbeeHerdsman.js index ad6f550f..0be5b3a4 100644 --- a/test/stub/zigbeeHerdsman.js +++ b/test/stub/zigbeeHerdsman.js @@ -189,6 +189,7 @@ const devices = { 'TS0601_thermostat': TS0601_thermostat, 'external_converter_device': new Device('EndDevice', '0x0017880104e45511', 1114, 'external', [new Endpoint(1, [], [], '0x0017880104e45511')], false, null, 'external_converter_device' ), 'QS_Zigbee_D02_TRIAC_2C_LN':new Device('Router', '0x0017882194e45543', 6549,4151, [new Endpoint(1, [0], [], '0x0017882194e45543'), new Endpoint(2, [0, 6], [], '0x0017882194e45543')], true, "Mains (single phase)", 'TS110F', false, '_TYZB01_v8gtiaed'), + 'unknown': new Device('Router', '0x0017980134e45545', 6540,4151, [], true, "Mains (single phase)"), } const mock = {