Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting zboss adapter to always use LUMI manufacturer code #1331

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/adapter/const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as Zcl from '../zspec/zcl';

/**
* 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,
'0x04cf8c': Zcl.ManufacturerCode.LUMI_UNITED_TECHOLOGY_LTD_SHENZHEN,
};
10 changes: 1 addition & 9 deletions src/adapter/ember/adapter/emberAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {EUI64, ExtendedPanId, NodeId, PanId} from '../../../zspec/tstypes';
import * as Zcl from '../../../zspec/zcl';
import * as Zdo from '../../../zspec/zdo';
import * as ZdoTypes from '../../../zspec/zdo/definition/tstypes';
import {WORKAROUND_JOIN_MANUF_IEEE_PREFIX_TO_CODE} from '../../const';
import {DeviceJoinedPayload, DeviceLeavePayload, ZclPayload} from '../../events';
import {
EMBER_HIGH_RAM_CONCENTRATOR,
Expand Down Expand Up @@ -216,15 +217,6 @@ const DEFAULT_NETWORK_REQUEST_TIMEOUT = 10000; // nothing on the network to both
const WATCHDOG_COUNTERS_FEED_INTERVAL = 3600000; // every hour...
/** Default manufacturer code reported by coordinator. */
const DEFAULT_MANUFACTURER_CODE = Zcl.ManufacturerCode.SILICON_LABORATORIES;
/**
* 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
*/
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,
};

/**
* Relay calls between Z2M and EZSP-layer and handle any error that might occur via queue & waitress.
Expand Down
21 changes: 21 additions & 0 deletions src/adapter/zboss/adapter/zbossAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as ZSpec from '../../../zspec';
import * as Zcl from '../../../zspec/zcl';
import * as Zdo from '../../../zspec/zdo';
import * as ZdoTypes from '../../../zspec/zdo/definition/tstypes';
import {WORKAROUND_JOIN_MANUF_IEEE_PREFIX_TO_CODE} from '../../const';
import {ZclPayload} from '../../events';
import {ZBOSSDriver} from '../driver';
import {CommandId, DeviceUpdateStatus} from '../enums';
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 All @@ -64,6 +67,16 @@ export class ZBOSSAdapter extends Adapter {
ieeeAddr: frame.payload.ieee,
});
} else {
// 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[frame.payload.ieee.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;
}
// SECURE_REJOIN, UNSECURE_JOIN, TC_REJOIN
this.emit('deviceJoined', {
networkAddress: frame.payload.nwk,
Expand Down Expand Up @@ -179,6 +192,14 @@ export class ZBOSSAdapter extends Adapter {

public async permitJoin(seconds: number, networkAddress?: number): Promise<void> {
if (this.driver.isInitialized()) {
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;
}

const clusterId = Zdo.ClusterId.PERMIT_JOINING_REQUEST;
// `authentication`: TC significance always 1 (zb specs)
const zdoPayload = Zdo.Buffalo.buildRequest(this.hasZdoMessageOverhead, clusterId, seconds, 1, []);
Expand Down