Skip to content

Commit

Permalink
added workaround for LUMI devices
Browse files Browse the repository at this point in the history
  • Loading branch information
captainLettuce authored and captainLettuce committed Mar 8, 2025
1 parent 13b3038 commit 37718f9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/adapter/const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Zcl } from "src";

/**
* Workaround for devices that require a specific manufacturer code to be reported by coordinator while interviewing...
* - Lumi/Aqara devices do not work properly otherwise (missing features): https://github.com/Koenkk/zigbee2mqtt/issues/9274
*/
export const WORKAROUND_JOIN_MANUF_IEEE_PREFIX_TO_CODE: {[ieeePrefix: string]: Zcl.ManufacturerCode} = {
// NOTE: Lumi has a new prefix registered since 2021, in case they start using that one with new devices, it might need to be added here too...
// "0x18c23c" https://maclookup.app/vendors/lumi-united-technology-co-ltd
'0x54ef44': Zcl.ManufacturerCode.LUMI_UNITED_TECHOLOGY_LTD_SHENZHEN,
};
23 changes: 23 additions & 0 deletions src/adapter/zboss/adapter/zbossAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {ZclPayload} from '../../events';
import {ZBOSSDriver} from '../driver';
import {CommandId, DeviceUpdateStatus} from '../enums';
import {FrameType, ZBOSSFrame} from '../frame';
import {WORKAROUND_JOIN_MANUF_IEEE_PREFIX_TO_CODE} from "../../const";

const NS = 'zh:zboss';

Expand All @@ -29,6 +30,7 @@ export class ZBOSSAdapter extends Adapter {
private queue: Queue;
private readonly driver: ZBOSSDriver;
private waitress: Waitress<ZclPayload, WaitressMatcher>;
private currentManufacturerCode: Zcl.ManufacturerCode

constructor(
networkOptions: TsType.NetworkOptions,
Expand All @@ -39,6 +41,7 @@ export class ZBOSSAdapter extends Adapter {
super(networkOptions, serialPortOptions, backupPath, adapterOptions);
this.hasZdoMessageOverhead = false;
this.manufacturerID = Zcl.ManufacturerCode.NORDIC_SEMICONDUCTOR_ASA;
this.currentManufacturerCode = Zcl.ManufacturerCode.NORDIC_SEMICONDUCTOR_ASA;
const concurrent = adapterOptions && adapterOptions.concurrent ? adapterOptions.concurrent : 8;
logger.debug(`Adapter concurrent: ${concurrent}`, NS);
this.queue = new Queue(concurrent);
Expand Down Expand Up @@ -248,6 +251,18 @@ export class ZBOSSAdapter extends Adapter {
payload = prefixedPayload;
break;
}
case Zdo.ClusterId.NODE_DESCRIPTOR_REQUEST: {
// set workaround manuf code if necessary, or revert to default if previous joined device required workaround and new one does not
const joinManufCode = WORKAROUND_JOIN_MANUF_IEEE_PREFIX_TO_CODE[ieeeAddress.substring(0, 8)] ?? this.manufacturerID;

if (this.currentManufacturerCode !== joinManufCode) {
logger.debug(`[WORKAROUND] Setting coordinator manufacturer code to ${Zcl.ManufacturerCode[joinManufCode]}.`, NS);

await this.driver.execCommand(CommandId.ZDO_SET_NODE_DESC_MANUF_CODE, {manufacturerCode: joinManufCode});

this.currentManufacturerCode = joinManufCode;
}
}
}
switch (clusterId) {
case Zdo.ClusterId.BIND_REQUEST:
Expand All @@ -267,6 +282,14 @@ export class ZBOSSAdapter extends Adapter {
if (!disableResponse && zdoResponseClusterId !== undefined) {
assert(frame, `ZDO ${Zdo.ClusterId[clusterId]} expected response ${Zdo.ClusterId[zdoResponseClusterId]}.`);

if (this.currentManufacturerCode !== this.manufacturerID) {
logger.debug(`[WORKAROUND] Resetting coordinator manufacturer code to ${Zcl.ManufacturerCode[this.manufacturerID]}.`, NS);

await this.driver.execCommand(CommandId.ZDO_SET_NODE_DESC_MANUF_CODE, {manufacturerCode: this.manufacturerID});

this.currentManufacturerCode = this.manufacturerID;
}

return frame.payload.zdo as ZdoTypes.RequestToResponseMap[K];
}
}, networkAddress);
Expand Down
2 changes: 0 additions & 2 deletions src/adapter/zboss/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {KeyValue} from '../../controller/tstype';
import {Queue, Waitress} from '../../utils';
import {logger} from '../../utils/logger';
import * as ZSpec from '../../zspec';
import {ManufacturerCode} from '../../zspec/zcl';
import * as Zdo from '../../zspec/zdo';
import {ZDO_REQ_CLUSTER_ID_TO_ZBOSS_COMMAND_ID} from './commands';
import {CommandId, DeviceType, PolicyType, ResetOptions, StatusCodeGeneric} from './enums';
Expand Down Expand Up @@ -120,7 +119,6 @@ export class ZBOSSDriver extends EventEmitter {
await this.execCommand(CommandId.SET_TC_POLICY, {type: PolicyType.IGNORE_TC_REJOIN, value: 0});
await this.execCommand(CommandId.SET_TC_POLICY, {type: PolicyType.APS_INSECURE_JOIN, value: 0});
await this.execCommand(CommandId.SET_TC_POLICY, {type: PolicyType.DISABLE_NWK_MGMT_CHANNEL_UPDATE, value: 0});
await this.execCommand(CommandId.ZDO_SET_NODE_DESC_MANUF_CODE, {manufacturerCode: ManufacturerCode.LUMI_UNITED_TECHOLOGY_LTD_SHENZHEN});

await this.addEndpoint(
1,
Expand Down

0 comments on commit 37718f9

Please sign in to comment.