From 01dbe1868537e3637c16682d587f8d37871ab739 Mon Sep 17 00:00:00 2001 From: Nerivec <62446222+Nerivec@users.noreply.github.com> Date: Sun, 25 Feb 2024 09:59:24 +0100 Subject: [PATCH] fix: Ember: fixed OTA response matching (#928) --- src/adapter/ember/adapter/emberAdapter.ts | 13 ++++++++----- src/adapter/ember/adapter/oneWaitress.ts | 8 ++++++-- src/adapter/ember/ezsp/ezsp.ts | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/adapter/ember/adapter/emberAdapter.ts b/src/adapter/ember/adapter/emberAdapter.ts index 1f05497f90..9ee9fe9099 100644 --- a/src/adapter/ember/adapter/emberAdapter.ts +++ b/src/adapter/ember/adapter/emberAdapter.ts @@ -148,7 +148,6 @@ import { GP_ENDPOINT, EMBER_ALL_802_15_4_CHANNELS_MASK, ZIGBEE_PROFILE_INTEROPERABILITY_LINK_KEY, - HA_PROFILE_ID, } from "../consts"; import {EmberRequestQueue} from "./requestQueue"; import {FIXED_ENDPOINTS} from "./endpoints"; @@ -2995,19 +2994,21 @@ export class EmberAdapter extends Adapter { /** WARNING: Adapter impl. Starts timer immediately upon returning */ public waitFor(networkAddress: number, endpoint: number, frameType: FrameType, direction: Direction, transactionSequenceNumber: number, clusterID: number, commandIdentifier: number, timeout: number): {promise: Promise; cancel: () => void;} { + const sourceEndpointInfo = FIXED_ENDPOINTS[0]; const waiter = this.oneWaitress.waitFor({ target: networkAddress, apsFrame: { clusterId: clusterID, - profileId: HA_PROFILE_ID,// XXX: ok? only used by OTA upstream + profileId: sourceEndpointInfo.profileId,// XXX: only used by OTA upstream sequence: 0,// set by stack - sourceEndpoint: endpoint, - destinationEndpoint: 0, + sourceEndpoint: sourceEndpointInfo.endpoint, + destinationEndpoint: endpoint, groupId: 0, options: EmberApsOption.NONE, }, zclSequence: transactionSequenceNumber, - }, timeout || DEFAULT_ZCL_REQUEST_TIMEOUT * 3);// XXX: since this is used by OTA..? + commandIdentifier, + }, timeout || DEFAULT_ZCL_REQUEST_TIMEOUT * 3);// XXX: since this is used by OTA... return { cancel: (): void => this.oneWaitress.remove(waiter.id), @@ -3652,6 +3653,7 @@ export class EmberAdapter extends Adapter { target: networkAddress, apsFrame, zclSequence: zclFrame.Header.transactionSequenceNumber, + commandIdentifier: commandResponseId, }, timeout || DEFAULT_ZCL_REQUEST_TIMEOUT)); resolve(result); @@ -3903,6 +3905,7 @@ export class EmberAdapter extends Adapter { target: null, apsFrame: apsFrame, zclSequence: zclFrame.Header.transactionSequenceNumber, + commandIdentifier: command.response, }, timeout || DEFAULT_ZCL_REQUEST_TIMEOUT * 2));// XXX: touchlink timeout? resolve(result); diff --git a/src/adapter/ember/adapter/oneWaitress.ts b/src/adapter/ember/adapter/oneWaitress.ts index f95f2d7ed5..ce6c4a19fd 100644 --- a/src/adapter/ember/adapter/oneWaitress.ts +++ b/src/adapter/ember/adapter/oneWaitress.ts @@ -13,9 +13,12 @@ type OneWaitressMatcher = { */ target?: EmberNodeId, apsFrame: EmberApsFrame, - /** Cluster ID for when the response doesn't match the request. Takes priority over apsFrame.clusterId. */ + /** Cluster ID for when the response doesn't match the request. Takes priority over apsFrame.clusterId. Should be mostly for ZDO requests. */ responseClusterId?: number, - zclSequence?: number; + /** ZCL frame transaction sequence number */ + zclSequence?: number, + /** Expected command ID for ZCL commands */ + commandIdentifier?: number, }; type OneWaitressEventMatcher = { @@ -142,6 +145,7 @@ export class EmberOneWaitress { // no target in touchlink, also no APS sequence, but use the ZCL one instead if (((waiter.matcher.apsFrame.profileId === TOUCHLINK_PROFILE_ID) || (payload.address === waiter.matcher.target)) && (!waiter.matcher.zclSequence || (payload.frame.Header.transactionSequenceNumber === waiter.matcher.zclSequence)) + && (!waiter.matcher.commandIdentifier || (payload.frame.Header.commandIdentifier === waiter.matcher.commandIdentifier)) && (payload.frame.Cluster.ID === waiter.matcher.apsFrame.clusterId) && (payload.endpoint === waiter.matcher.apsFrame.destinationEndpoint)) { clearTimeout(waiter.timer); diff --git a/src/adapter/ember/ezsp/ezsp.ts b/src/adapter/ember/ezsp/ezsp.ts index 9f30a0a0fd..bfe70b2500 100644 --- a/src/adapter/ember/ezsp/ezsp.ts +++ b/src/adapter/ember/ezsp/ezsp.ts @@ -4554,7 +4554,7 @@ export class Ezsp extends EventEmitter { break; } default: { - console.log(`<=== [ZDO clusterId=${apsFrame.clusterId}] Support not implemented`); + console.log(`<=== [ZDO clusterId=${apsFrame.clusterId}] Support not implemented upstream.`); break; } }