From 2977e4275b0e3cfab63c0976a492fe6a9161aeed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Bed=C5=99ich?= Date: Wed, 21 Jun 2023 19:24:39 +0200 Subject: [PATCH] fix: Fix EZSP group binding (#721) Koenkk/zigbee2mqtt#18065 --- src/adapter/ezsp/adapter/ezspAdapter.ts | 26 +++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/adapter/ezsp/adapter/ezspAdapter.ts b/src/adapter/ezsp/adapter/ezspAdapter.ts index 271c310072..f04dde9efe 100644 --- a/src/adapter/ezsp/adapter/ezspAdapter.ts +++ b/src/adapter/ezsp/adapter/ezspAdapter.ts @@ -529,10 +529,15 @@ class EZSPAdapter extends Adapter { return this.driver.queue.execute(async () => { this.checkInterpanLock(); const ieee = new EmberEUI64(sourceIeeeAddress); - const addrmode = (type === 'group') ? 1 : 3; - const ieeeDst = (type === 'group') ? destinationAddressOrGroup : - new EmberEUI64(destinationAddressOrGroup as string); - if (type !== 'group') { + let addrmode, ieeeDst; + if (type === 'group') { + // 0x01 = 16-bit group address for DstAddr and DstEndpoint not present + addrmode = 0x01; + ieeeDst = uint16_t.serialize(uint16_t, destinationAddressOrGroup as number); + } else { + // 0x03 = 64-bit extended address for DstAddr and DstEndpoint present + addrmode = 0x03; + ieeeDst = new EmberEUI64(destinationAddressOrGroup as string); this.driver.setNode(destinationNetworkAddress, ieeeDst as EmberEUI64); } await this.driver.zdoRequest( @@ -551,10 +556,15 @@ class EZSPAdapter extends Adapter { return this.driver.queue.execute(async () => { this.checkInterpanLock(); const ieee = new EmberEUI64(sourceIeeeAddress); - const addrmode = (type === 'group') ? 1 : 3; - const ieeeDst = (type === 'group') ? destinationAddressOrGroup : - new EmberEUI64(destinationAddressOrGroup as string); - if (type !== 'group') { + let addrmode, ieeeDst; + if (type === 'group') { + // 0x01 = 16-bit group address for DstAddr and DstEndpoint not present + addrmode = 0x01; + ieeeDst = uint16_t.serialize(uint16_t, destinationAddressOrGroup as number); + } else { + // 0x03 = 64-bit extended address for DstAddr and DstEndpoint present + addrmode = 0x03; + ieeeDst = new EmberEUI64(destinationAddressOrGroup as string); this.driver.setNode(destinationNetworkAddress, ieeeDst as EmberEUI64); } await this.driver.zdoRequest(