zigbee-herdsman 6.0.2 → 6.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/package.json +9 -3
- package/.github/ISSUE_TEMPLATE/config.yml +0 -5
- package/.github/dependabot.yml +0 -22
- package/.github/workflows/ci.yml +0 -69
- package/.github/workflows/release-please.yml +0 -18
- package/.github/workflows/stale.yml +0 -20
- package/.github/workflows/typedoc.yaml +0 -47
- package/.release-please-manifest.json +0 -3
- package/.vscode/extensions.json +0 -3
- package/.vscode/settings.json +0 -11
- package/biome.json +0 -98
- package/examples/join-and-log.js +0 -24
- package/release-please-config.json +0 -9
- package/src/adapter/adapter.ts +0 -189
- package/src/adapter/adapterDiscovery.ts +0 -666
- package/src/adapter/const.ts +0 -12
- package/src/adapter/deconz/adapter/deconzAdapter.ts +0 -877
- package/src/adapter/deconz/driver/constants.ts +0 -246
- package/src/adapter/deconz/driver/driver.ts +0 -1540
- package/src/adapter/deconz/driver/frame.ts +0 -11
- package/src/adapter/deconz/driver/frameParser.ts +0 -753
- package/src/adapter/deconz/driver/parser.ts +0 -45
- package/src/adapter/deconz/driver/writer.ts +0 -22
- package/src/adapter/deconz/types.d.ts +0 -13
- package/src/adapter/ember/adapter/emberAdapter.ts +0 -2265
- package/src/adapter/ember/adapter/endpoints.ts +0 -86
- package/src/adapter/ember/adapter/oneWaitress.ts +0 -324
- package/src/adapter/ember/adapter/tokensManager.ts +0 -782
- package/src/adapter/ember/consts.ts +0 -178
- package/src/adapter/ember/enums.ts +0 -1746
- package/src/adapter/ember/ezsp/buffalo.ts +0 -1392
- package/src/adapter/ember/ezsp/consts.ts +0 -148
- package/src/adapter/ember/ezsp/enums.ts +0 -1114
- package/src/adapter/ember/ezsp/ezsp.ts +0 -9061
- package/src/adapter/ember/ezspError.ts +0 -10
- package/src/adapter/ember/types.ts +0 -866
- package/src/adapter/ember/uart/ash.ts +0 -1960
- package/src/adapter/ember/uart/consts.ts +0 -109
- package/src/adapter/ember/uart/enums.ts +0 -192
- package/src/adapter/ember/uart/parser.ts +0 -48
- package/src/adapter/ember/uart/queues.ts +0 -247
- package/src/adapter/ember/uart/writer.ts +0 -53
- package/src/adapter/ember/utils/initters.ts +0 -58
- package/src/adapter/ember/utils/math.ts +0 -73
- package/src/adapter/events.ts +0 -21
- package/src/adapter/ezsp/adapter/backup.ts +0 -109
- package/src/adapter/ezsp/adapter/ezspAdapter.ts +0 -614
- package/src/adapter/ezsp/driver/commands.ts +0 -2497
- package/src/adapter/ezsp/driver/consts.ts +0 -11
- package/src/adapter/ezsp/driver/driver.ts +0 -1002
- package/src/adapter/ezsp/driver/ezsp.ts +0 -802
- package/src/adapter/ezsp/driver/frame.ts +0 -101
- package/src/adapter/ezsp/driver/index.ts +0 -4
- package/src/adapter/ezsp/driver/multicast.ts +0 -78
- package/src/adapter/ezsp/driver/parser.ts +0 -81
- package/src/adapter/ezsp/driver/types/basic.ts +0 -201
- package/src/adapter/ezsp/driver/types/index.ts +0 -239
- package/src/adapter/ezsp/driver/types/named.ts +0 -2330
- package/src/adapter/ezsp/driver/types/struct.ts +0 -844
- package/src/adapter/ezsp/driver/uart.ts +0 -460
- package/src/adapter/ezsp/driver/utils/crc16ccitt.ts +0 -44
- package/src/adapter/ezsp/driver/utils/index.ts +0 -32
- package/src/adapter/ezsp/driver/writer.ts +0 -64
- package/src/adapter/index.ts +0 -3
- package/src/adapter/serialPort.ts +0 -58
- package/src/adapter/socketPortUtils.ts +0 -16
- package/src/adapter/tstype.ts +0 -78
- package/src/adapter/z-stack/adapter/adapter-backup.ts +0 -519
- package/src/adapter/z-stack/adapter/adapter-nv-memory.ts +0 -457
- package/src/adapter/z-stack/adapter/endpoints.ts +0 -57
- package/src/adapter/z-stack/adapter/manager.ts +0 -543
- package/src/adapter/z-stack/adapter/tstype.ts +0 -6
- package/src/adapter/z-stack/adapter/zStackAdapter.ts +0 -1190
- package/src/adapter/z-stack/constants/af.ts +0 -27
- package/src/adapter/z-stack/constants/common.ts +0 -285
- package/src/adapter/z-stack/constants/dbg.ts +0 -23
- package/src/adapter/z-stack/constants/index.ts +0 -11
- package/src/adapter/z-stack/constants/mac.ts +0 -128
- package/src/adapter/z-stack/constants/sapi.ts +0 -25
- package/src/adapter/z-stack/constants/sys.ts +0 -72
- package/src/adapter/z-stack/constants/util.ts +0 -82
- package/src/adapter/z-stack/constants/utils.ts +0 -14
- package/src/adapter/z-stack/constants/zdo.ts +0 -103
- package/src/adapter/z-stack/models/startup-options.ts +0 -13
- package/src/adapter/z-stack/structs/entries/address-manager-entry.ts +0 -44
- package/src/adapter/z-stack/structs/entries/address-manager-table.ts +0 -19
- package/src/adapter/z-stack/structs/entries/aps-link-key-data-entry.ts +0 -12
- package/src/adapter/z-stack/structs/entries/aps-link-key-data-table.ts +0 -21
- package/src/adapter/z-stack/structs/entries/aps-tc-link-key-entry.ts +0 -19
- package/src/adapter/z-stack/structs/entries/aps-tc-link-key-table.ts +0 -21
- package/src/adapter/z-stack/structs/entries/channel-list.ts +0 -8
- package/src/adapter/z-stack/structs/entries/has-configured.ts +0 -16
- package/src/adapter/z-stack/structs/entries/index.ts +0 -16
- package/src/adapter/z-stack/structs/entries/nib.ts +0 -66
- package/src/adapter/z-stack/structs/entries/nwk-key-descriptor.ts +0 -15
- package/src/adapter/z-stack/structs/entries/nwk-key.ts +0 -13
- package/src/adapter/z-stack/structs/entries/nwk-pan-id.ts +0 -8
- package/src/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-entry.ts +0 -20
- package/src/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-table.ts +0 -19
- package/src/adapter/z-stack/structs/entries/security-manager-entry.ts +0 -33
- package/src/adapter/z-stack/structs/entries/security-manager-table.ts +0 -22
- package/src/adapter/z-stack/structs/index.ts +0 -4
- package/src/adapter/z-stack/structs/serializable-memory-object.ts +0 -14
- package/src/adapter/z-stack/structs/struct.ts +0 -367
- package/src/adapter/z-stack/structs/table.ts +0 -198
- package/src/adapter/z-stack/unpi/constants.ts +0 -33
- package/src/adapter/z-stack/unpi/frame.ts +0 -62
- package/src/adapter/z-stack/unpi/index.ts +0 -4
- package/src/adapter/z-stack/unpi/parser.ts +0 -56
- package/src/adapter/z-stack/unpi/writer.ts +0 -21
- package/src/adapter/z-stack/utils/channel-list.ts +0 -40
- package/src/adapter/z-stack/utils/index.ts +0 -2
- package/src/adapter/z-stack/utils/network-options.ts +0 -26
- package/src/adapter/z-stack/znp/buffaloZnp.ts +0 -175
- package/src/adapter/z-stack/znp/definition.ts +0 -2713
- package/src/adapter/z-stack/znp/index.ts +0 -2
- package/src/adapter/z-stack/znp/parameterType.ts +0 -22
- package/src/adapter/z-stack/znp/tstype.ts +0 -44
- package/src/adapter/z-stack/znp/utils.ts +0 -10
- package/src/adapter/z-stack/znp/znp.ts +0 -342
- package/src/adapter/z-stack/znp/zpiObject.ts +0 -148
- package/src/adapter/zboss/adapter/zbossAdapter.ts +0 -526
- package/src/adapter/zboss/commands.ts +0 -1184
- package/src/adapter/zboss/consts.ts +0 -9
- package/src/adapter/zboss/driver.ts +0 -422
- package/src/adapter/zboss/enums.ts +0 -360
- package/src/adapter/zboss/frame.ts +0 -227
- package/src/adapter/zboss/reader.ts +0 -65
- package/src/adapter/zboss/types.ts +0 -0
- package/src/adapter/zboss/uart.ts +0 -428
- package/src/adapter/zboss/utils.ts +0 -58
- package/src/adapter/zboss/writer.ts +0 -49
- package/src/adapter/zigate/adapter/patchZdoBuffaloBE.ts +0 -27
- package/src/adapter/zigate/adapter/zigateAdapter.ts +0 -618
- package/src/adapter/zigate/driver/LICENSE +0 -17
- package/src/adapter/zigate/driver/buffaloZiGate.ts +0 -212
- package/src/adapter/zigate/driver/commandType.ts +0 -418
- package/src/adapter/zigate/driver/constants.ts +0 -150
- package/src/adapter/zigate/driver/frame.ts +0 -197
- package/src/adapter/zigate/driver/messageType.ts +0 -287
- package/src/adapter/zigate/driver/parameterType.ts +0 -32
- package/src/adapter/zigate/driver/ziGateObject.ts +0 -146
- package/src/adapter/zigate/driver/zigate.ts +0 -423
- package/src/adapter/zoh/adapter/utils.ts +0 -27
- package/src/adapter/zoh/adapter/zohAdapter.ts +0 -838
- package/src/buffalo/buffalo.ts +0 -342
- package/src/buffalo/index.ts +0 -1
- package/src/controller/controller.ts +0 -1022
- package/src/controller/database.ts +0 -124
- package/src/controller/events.ts +0 -52
- package/src/controller/greenPower.ts +0 -603
- package/src/controller/helpers/index.ts +0 -1
- package/src/controller/helpers/installCodes.ts +0 -107
- package/src/controller/helpers/request.ts +0 -96
- package/src/controller/helpers/requestQueue.ts +0 -125
- package/src/controller/helpers/zclFrameConverter.ts +0 -47
- package/src/controller/helpers/zclTransactionSequenceNumber.ts +0 -19
- package/src/controller/index.ts +0 -6
- package/src/controller/model/device.ts +0 -1249
- package/src/controller/model/endpoint.ts +0 -1105
- package/src/controller/model/entity.ts +0 -23
- package/src/controller/model/group.ts +0 -424
- package/src/controller/model/index.ts +0 -5
- package/src/controller/model/zigbeeEntity.ts +0 -30
- package/src/controller/touchlink.ts +0 -189
- package/src/controller/tstype.ts +0 -274
- package/src/index.ts +0 -12
- package/src/models/backup-storage-legacy.ts +0 -48
- package/src/models/backup-storage-unified.ts +0 -47
- package/src/models/backup.ts +0 -37
- package/src/models/index.ts +0 -5
- package/src/models/network-options.ts +0 -11
- package/src/utils/backup.ts +0 -152
- package/src/utils/index.ts +0 -5
- package/src/utils/logger.ts +0 -20
- package/src/utils/patchBigIntSerialization.ts +0 -8
- package/src/utils/queue.ts +0 -76
- package/src/utils/types.d.ts +0 -3
- package/src/utils/utils.ts +0 -19
- package/src/utils/wait.ts +0 -5
- package/src/utils/waitress.ts +0 -96
- package/src/zspec/consts.ts +0 -84
- package/src/zspec/enums.ts +0 -22
- package/src/zspec/index.ts +0 -3
- package/src/zspec/tstypes.ts +0 -18
- package/src/zspec/utils.ts +0 -247
- package/src/zspec/zcl/buffaloZcl.ts +0 -1220
- package/src/zspec/zcl/definition/cluster.ts +0 -5915
- package/src/zspec/zcl/definition/clusters-typegen.ts +0 -588
- package/src/zspec/zcl/definition/clusters-types.ts +0 -7331
- package/src/zspec/zcl/definition/consts.ts +0 -24
- package/src/zspec/zcl/definition/enums.ts +0 -203
- package/src/zspec/zcl/definition/foundation.ts +0 -329
- package/src/zspec/zcl/definition/manufacturerCode.ts +0 -729
- package/src/zspec/zcl/definition/status.ts +0 -69
- package/src/zspec/zcl/definition/tstype.ts +0 -377
- package/src/zspec/zcl/index.ts +0 -11
- package/src/zspec/zcl/utils.ts +0 -321
- package/src/zspec/zcl/zclFrame.ts +0 -356
- package/src/zspec/zcl/zclHeader.ts +0 -102
- package/src/zspec/zcl/zclStatusError.ts +0 -10
- package/src/zspec/zdo/buffaloZdo.ts +0 -2336
- package/src/zspec/zdo/definition/clusters.ts +0 -722
- package/src/zspec/zdo/definition/consts.ts +0 -16
- package/src/zspec/zdo/definition/enums.ts +0 -99
- package/src/zspec/zdo/definition/status.ts +0 -105
- package/src/zspec/zdo/definition/tstypes.ts +0 -1062
- package/src/zspec/zdo/index.ts +0 -7
- package/src/zspec/zdo/utils.ts +0 -76
- package/src/zspec/zdo/zdoStatusError.ts +0 -10
- package/test/adapter/adapter.test.ts +0 -1062
- package/test/adapter/ember/ash.test.ts +0 -337
- package/test/adapter/ember/consts.ts +0 -131
- package/test/adapter/ember/emberAdapter.test.ts +0 -3449
- package/test/adapter/ember/ezsp.test.ts +0 -385
- package/test/adapter/ember/ezspBuffalo.test.ts +0 -93
- package/test/adapter/ember/ezspError.test.ts +0 -12
- package/test/adapter/ember/math.test.ts +0 -206
- package/test/adapter/ezsp/frame.test.ts +0 -30
- package/test/adapter/ezsp/uart.test.ts +0 -181
- package/test/adapter/z-stack/adapter.test.ts +0 -3984
- package/test/adapter/z-stack/constants.test.ts +0 -33
- package/test/adapter/z-stack/structs.test.ts +0 -115
- package/test/adapter/z-stack/unpi.test.ts +0 -213
- package/test/adapter/z-stack/znp.test.ts +0 -1284
- package/test/adapter/zboss/fixZdoResponse.test.ts +0 -179
- package/test/adapter/zigate/patchZdoBuffaloBE.test.ts +0 -81
- package/test/adapter/zigate/zdo.test.ts +0 -187
- package/test/adapter/zoh/utils.test.ts +0 -36
- package/test/adapter/zoh/zohAdapter.test.ts +0 -1307
- package/test/benchOptions.ts +0 -14
- package/test/buffalo.test.ts +0 -431
- package/test/controller.bench.ts +0 -214
- package/test/controller.test.ts +0 -8702
- package/test/greenpower.test.ts +0 -1408
- package/test/mockAdapters.ts +0 -65
- package/test/mockDevices.ts +0 -598
- package/test/requests.bench.ts +0 -229
- package/test/testUtils.ts +0 -20
- package/test/tsconfig.json +0 -9
- package/test/utils/math.ts +0 -19
- package/test/utils.test.ts +0 -279
- package/test/vitest.config.mts +0 -26
- package/test/zcl.test.ts +0 -2831
- package/test/zspec/utils.test.ts +0 -68
- package/test/zspec/zcl/buffalo.test.ts +0 -1374
- package/test/zspec/zcl/frame.test.ts +0 -960
- package/test/zspec/zcl/utils.test.ts +0 -273
- package/test/zspec/zdo/buffalo.test.ts +0 -1850
- package/test/zspec/zdo/utils.test.ts +0 -241
- package/tsconfig.json +0 -24
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import events from "node:events";
|
|
2
|
-
|
|
3
|
-
import type {Adapter} from "../../adapter";
|
|
4
|
-
import type Database from "../database";
|
|
5
|
-
|
|
6
|
-
// biome-ignore lint/suspicious/noExplicitAny: API
|
|
7
|
-
type EventMap<T> = Record<keyof T, any[]> | DefaultEventMap;
|
|
8
|
-
type DefaultEventMap = [never];
|
|
9
|
-
|
|
10
|
-
export abstract class Entity<T extends EventMap<T> = DefaultEventMap> extends events.EventEmitter<T> {
|
|
11
|
-
protected static database: Database;
|
|
12
|
-
protected static adapter: Adapter;
|
|
13
|
-
|
|
14
|
-
public static injectDatabase(database: Database): void {
|
|
15
|
-
Entity.database = database;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
public static injectAdapter(adapter: Adapter): void {
|
|
19
|
-
Entity.adapter = adapter;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export default Entity;
|
|
@@ -1,424 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert";
|
|
2
|
-
import {logger} from "../../utils/logger";
|
|
3
|
-
import * as Zcl from "../../zspec/zcl";
|
|
4
|
-
import type {TFoundation} from "../../zspec/zcl/definition/clusters-types";
|
|
5
|
-
import type {CustomClusters} from "../../zspec/zcl/definition/tstype";
|
|
6
|
-
import zclTransactionSequenceNumber from "../helpers/zclTransactionSequenceNumber";
|
|
7
|
-
import type {
|
|
8
|
-
ClusterOrRawAttributeKeys,
|
|
9
|
-
ClusterOrRawPayload,
|
|
10
|
-
DatabaseEntry,
|
|
11
|
-
KeyValue,
|
|
12
|
-
PartialClusterOrRawWriteAttributes,
|
|
13
|
-
TCustomCluster,
|
|
14
|
-
} from "../tstype";
|
|
15
|
-
import Device from "./device";
|
|
16
|
-
import type Endpoint from "./endpoint";
|
|
17
|
-
import Entity from "./entity";
|
|
18
|
-
import {ZigbeeEntity} from "./zigbeeEntity";
|
|
19
|
-
|
|
20
|
-
const NS = "zh:controller:group";
|
|
21
|
-
|
|
22
|
-
interface Options {
|
|
23
|
-
manufacturerCode?: number;
|
|
24
|
-
direction?: Zcl.Direction;
|
|
25
|
-
srcEndpoint?: number;
|
|
26
|
-
reservedBits?: number;
|
|
27
|
-
transactionSequenceNumber?: number;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
interface OptionsWithDefaults extends Options {
|
|
31
|
-
direction: Zcl.Direction;
|
|
32
|
-
reservedBits: number;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export class Group extends ZigbeeEntity {
|
|
36
|
-
private databaseID: number;
|
|
37
|
-
public readonly groupID: number;
|
|
38
|
-
private readonly _members: Endpoint[];
|
|
39
|
-
#customClusters: [input: CustomClusters, output: CustomClusters];
|
|
40
|
-
// Can be used by applications to store data.
|
|
41
|
-
public readonly meta: KeyValue;
|
|
42
|
-
|
|
43
|
-
// This lookup contains all groups that are queried from the database, this is to ensure that always
|
|
44
|
-
// the same instance is returned.
|
|
45
|
-
private static readonly groups: Map<number /* groupID */, Group> = new Map();
|
|
46
|
-
private static loadedFromDatabase = false;
|
|
47
|
-
|
|
48
|
-
/** Member endpoints with valid devices (not unknown/deleted) */
|
|
49
|
-
get members(): Endpoint[] {
|
|
50
|
-
return this._members.filter((e) => e.getDevice() !== undefined);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** List of server / client custom clusters common to all devices in the group */
|
|
54
|
-
get customClusters(): [input: CustomClusters, output: CustomClusters] {
|
|
55
|
-
return this.#customClusters;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
private constructor(databaseID: number, groupID: number, members: Endpoint[], meta: KeyValue) {
|
|
59
|
-
super();
|
|
60
|
-
this.databaseID = databaseID;
|
|
61
|
-
this.groupID = groupID;
|
|
62
|
-
this._members = members;
|
|
63
|
-
this.meta = meta;
|
|
64
|
-
this.#customClusters = this.#identifyCustomClusters();
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/*
|
|
68
|
-
* CRUD
|
|
69
|
-
*/
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Reset runtime lookups.
|
|
73
|
-
*/
|
|
74
|
-
public static resetCache(): void {
|
|
75
|
-
Group.groups.clear();
|
|
76
|
-
Group.loadedFromDatabase = false;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
private static fromDatabaseEntry(entry: DatabaseEntry): Group {
|
|
80
|
-
// db is expected to never contain duplicate, so no need for explicit check
|
|
81
|
-
const members: Endpoint[] = [];
|
|
82
|
-
|
|
83
|
-
for (const member of entry.members) {
|
|
84
|
-
const device = Device.byIeeeAddr(member.deviceIeeeAddr);
|
|
85
|
-
|
|
86
|
-
if (device) {
|
|
87
|
-
const endpoint = device.getEndpoint(member.endpointID);
|
|
88
|
-
|
|
89
|
-
if (endpoint) {
|
|
90
|
-
members.push(endpoint);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return new Group(entry.id, entry.groupID, members, entry.meta);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
private toDatabaseRecord(): DatabaseEntry {
|
|
99
|
-
const members: DatabaseEntry["members"] = [];
|
|
100
|
-
|
|
101
|
-
for (const member of this._members) {
|
|
102
|
-
const device = member.getDevice();
|
|
103
|
-
|
|
104
|
-
if (device) {
|
|
105
|
-
members.push({deviceIeeeAddr: device.ieeeAddr, endpointID: member.ID});
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return {id: this.databaseID, type: "Group", groupID: this.groupID, members, meta: this.meta};
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
private static loadFromDatabaseIfNecessary(): void {
|
|
113
|
-
if (!Group.loadedFromDatabase) {
|
|
114
|
-
for (const entry of Entity.database.getEntriesIterator(["Group"])) {
|
|
115
|
-
const group = Group.fromDatabaseEntry(entry);
|
|
116
|
-
Group.groups.set(group.groupID, group);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
Group.loadedFromDatabase = true;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
public static byGroupID(groupID: number): Group | undefined {
|
|
124
|
-
Group.loadFromDatabaseIfNecessary();
|
|
125
|
-
return Group.groups.get(groupID);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* @deprecated use allIterator()
|
|
130
|
-
*/
|
|
131
|
-
public static all(): Group[] {
|
|
132
|
-
Group.loadFromDatabaseIfNecessary();
|
|
133
|
-
return Array.from(Group.groups.values());
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
public static *allIterator(predicate?: (value: Group) => boolean): Generator<Group> {
|
|
137
|
-
Group.loadFromDatabaseIfNecessary();
|
|
138
|
-
|
|
139
|
-
for (const group of Group.groups.values()) {
|
|
140
|
-
if (!predicate || predicate(group)) {
|
|
141
|
-
yield group;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
public static create(groupID: number): Group {
|
|
147
|
-
assert(typeof groupID === "number", "GroupID must be a number");
|
|
148
|
-
// Don't allow groupID 0, from the spec:
|
|
149
|
-
// "Scene identifier 0x00, along with group identifier 0x0000, is reserved for the global scene used by the OnOff cluster"
|
|
150
|
-
assert(groupID >= 1, "GroupID must be at least 1");
|
|
151
|
-
|
|
152
|
-
Group.loadFromDatabaseIfNecessary();
|
|
153
|
-
|
|
154
|
-
if (Group.groups.has(groupID)) {
|
|
155
|
-
throw new Error(`Group with groupID '${groupID}' already exists`);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const databaseID = Entity.database.newID();
|
|
159
|
-
const group = new Group(databaseID, groupID, [], {});
|
|
160
|
-
Entity.database.insert(group.toDatabaseRecord());
|
|
161
|
-
|
|
162
|
-
Group.groups.set(group.groupID, group);
|
|
163
|
-
return group;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
public async removeFromNetwork(): Promise<void> {
|
|
167
|
-
for (const endpoint of this._members) {
|
|
168
|
-
await endpoint.removeFromGroup(this);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
this.removeFromDatabase();
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
public removeFromDatabase(): void {
|
|
175
|
-
Group.loadFromDatabaseIfNecessary();
|
|
176
|
-
|
|
177
|
-
if (Entity.database.has(this.databaseID)) {
|
|
178
|
-
Entity.database.remove(this.databaseID);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
Group.groups.delete(this.groupID);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
public save(writeDatabase = true): void {
|
|
185
|
-
Entity.database.update(this.toDatabaseRecord(), writeDatabase);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
public addMember(endpoint: Endpoint): void {
|
|
189
|
-
if (!this._members.includes(endpoint)) {
|
|
190
|
-
this._members.push(endpoint);
|
|
191
|
-
this.save();
|
|
192
|
-
|
|
193
|
-
this.#customClusters = this.#identifyCustomClusters();
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
public removeMember(endpoint: Endpoint): void {
|
|
198
|
-
const i = this._members.indexOf(endpoint);
|
|
199
|
-
|
|
200
|
-
if (i > -1) {
|
|
201
|
-
this._members.splice(i, 1);
|
|
202
|
-
this.save();
|
|
203
|
-
|
|
204
|
-
this.#customClusters = this.#identifyCustomClusters();
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
public hasMember(endpoint: Endpoint): boolean {
|
|
209
|
-
return this._members.includes(endpoint);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
#identifyCustomClusters(): [input: CustomClusters, output: CustomClusters] {
|
|
213
|
-
const members = this.members;
|
|
214
|
-
|
|
215
|
-
if (members.length > 0) {
|
|
216
|
-
const customClusters = members[0].getDevice().customClusters;
|
|
217
|
-
const inputClusters: CustomClusters = {};
|
|
218
|
-
const outputClusters: CustomClusters = {};
|
|
219
|
-
|
|
220
|
-
for (const clusterName in customClusters) {
|
|
221
|
-
const customCluster = customClusters[clusterName];
|
|
222
|
-
let hasInput = true;
|
|
223
|
-
let hasOutput = true;
|
|
224
|
-
|
|
225
|
-
for (const member of members) {
|
|
226
|
-
if (clusterName in member.getDevice().customClusters) {
|
|
227
|
-
hasInput = member.inputClusters.includes(customCluster.ID);
|
|
228
|
-
hasOutput = member.outputClusters.includes(customCluster.ID);
|
|
229
|
-
|
|
230
|
-
if (!hasInput && !hasOutput) {
|
|
231
|
-
break;
|
|
232
|
-
}
|
|
233
|
-
} else {
|
|
234
|
-
hasInput = false;
|
|
235
|
-
hasOutput = false;
|
|
236
|
-
|
|
237
|
-
break;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
if (hasInput) {
|
|
242
|
-
inputClusters[clusterName] = customCluster;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
if (hasOutput) {
|
|
246
|
-
outputClusters[clusterName] = customCluster;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
return [inputClusters, outputClusters];
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
return [{}, {}];
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/*
|
|
257
|
-
* Zigbee functions
|
|
258
|
-
*/
|
|
259
|
-
|
|
260
|
-
public async write<Cl extends number | string, Custom extends TCustomCluster | undefined = undefined>(
|
|
261
|
-
clusterKey: Cl,
|
|
262
|
-
attributes: PartialClusterOrRawWriteAttributes<Cl, Custom>,
|
|
263
|
-
options?: Options,
|
|
264
|
-
): Promise<void> {
|
|
265
|
-
const customClusters = this.#customClusters[options?.direction === Zcl.Direction.SERVER_TO_CLIENT ? 1 : 0 /* default to CLIENT_TO_SERVER */];
|
|
266
|
-
const cluster = Zcl.Utils.getCluster(clusterKey, options?.manufacturerCode, customClusters);
|
|
267
|
-
const optionsWithDefaults = this.getOptionsWithDefaults(options, Zcl.Direction.CLIENT_TO_SERVER, cluster.manufacturerCode);
|
|
268
|
-
const payload: TFoundation["write"] = [];
|
|
269
|
-
|
|
270
|
-
for (const nameOrID in attributes) {
|
|
271
|
-
const attribute = cluster.getAttribute(nameOrID);
|
|
272
|
-
|
|
273
|
-
if (attribute) {
|
|
274
|
-
payload.push({attrId: attribute.ID, attrData: attributes[nameOrID], dataType: attribute.type});
|
|
275
|
-
} else if (!Number.isNaN(Number(nameOrID))) {
|
|
276
|
-
const value = attributes[nameOrID];
|
|
277
|
-
|
|
278
|
-
payload.push({attrId: Number(nameOrID), attrData: value.value, dataType: value.type});
|
|
279
|
-
} else {
|
|
280
|
-
throw new Error(`Unknown attribute '${nameOrID}', specify either an existing attribute or a number`);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
const createLogMessage = (): string =>
|
|
285
|
-
`Write ${this.groupID} ${cluster.name}(${JSON.stringify(attributes)}, ${JSON.stringify(optionsWithDefaults)})`;
|
|
286
|
-
logger.debug(createLogMessage, NS);
|
|
287
|
-
|
|
288
|
-
try {
|
|
289
|
-
const frame = Zcl.Frame.create(
|
|
290
|
-
Zcl.FrameType.GLOBAL,
|
|
291
|
-
optionsWithDefaults.direction,
|
|
292
|
-
true,
|
|
293
|
-
optionsWithDefaults.manufacturerCode,
|
|
294
|
-
optionsWithDefaults.transactionSequenceNumber ?? zclTransactionSequenceNumber.next(),
|
|
295
|
-
"write",
|
|
296
|
-
cluster,
|
|
297
|
-
payload,
|
|
298
|
-
customClusters,
|
|
299
|
-
optionsWithDefaults.reservedBits,
|
|
300
|
-
);
|
|
301
|
-
|
|
302
|
-
await Entity.adapter.sendZclFrameToGroup(this.groupID, frame, optionsWithDefaults.srcEndpoint);
|
|
303
|
-
} catch (error) {
|
|
304
|
-
const err = error as Error;
|
|
305
|
-
err.message = `${createLogMessage()} failed (${err.message})`;
|
|
306
|
-
// biome-ignore lint/style/noNonNullAssertion: ignored using `--suppress`
|
|
307
|
-
logger.debug(err.stack!, NS);
|
|
308
|
-
|
|
309
|
-
throw error;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
public async read<Cl extends number | string, Custom extends TCustomCluster | undefined = undefined>(
|
|
314
|
-
clusterKey: Cl,
|
|
315
|
-
attributes: ClusterOrRawAttributeKeys<Cl, Custom>,
|
|
316
|
-
options?: Options,
|
|
317
|
-
): Promise<undefined> {
|
|
318
|
-
const customClusters = this.#customClusters[options?.direction === Zcl.Direction.SERVER_TO_CLIENT ? 1 : 0 /* default to CLIENT_TO_SERVER */];
|
|
319
|
-
const cluster = Zcl.Utils.getCluster(clusterKey, options?.manufacturerCode, customClusters);
|
|
320
|
-
const optionsWithDefaults = this.getOptionsWithDefaults(options, Zcl.Direction.CLIENT_TO_SERVER, cluster.manufacturerCode);
|
|
321
|
-
const payload: TFoundation["read"] = [];
|
|
322
|
-
|
|
323
|
-
for (const attribute of attributes) {
|
|
324
|
-
if (typeof attribute === "number") {
|
|
325
|
-
payload.push({attrId: attribute});
|
|
326
|
-
} else {
|
|
327
|
-
const attr = cluster.getAttribute(attribute);
|
|
328
|
-
|
|
329
|
-
if (attr) {
|
|
330
|
-
payload.push({attrId: attr.ID});
|
|
331
|
-
} else {
|
|
332
|
-
logger.warning(`Ignoring unknown attribute ${attribute} in cluster ${cluster.name}`, NS);
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
const frame = Zcl.Frame.create(
|
|
338
|
-
Zcl.FrameType.GLOBAL,
|
|
339
|
-
optionsWithDefaults.direction,
|
|
340
|
-
true,
|
|
341
|
-
optionsWithDefaults.manufacturerCode,
|
|
342
|
-
optionsWithDefaults.transactionSequenceNumber ?? zclTransactionSequenceNumber.next(),
|
|
343
|
-
"read",
|
|
344
|
-
cluster,
|
|
345
|
-
payload,
|
|
346
|
-
customClusters,
|
|
347
|
-
optionsWithDefaults.reservedBits,
|
|
348
|
-
);
|
|
349
|
-
|
|
350
|
-
const createLogMessage = (): string =>
|
|
351
|
-
`Read ${this.groupID} ${cluster.name}(${JSON.stringify(attributes)}, ${JSON.stringify(optionsWithDefaults)})`;
|
|
352
|
-
logger.debug(createLogMessage, NS);
|
|
353
|
-
|
|
354
|
-
try {
|
|
355
|
-
await Entity.adapter.sendZclFrameToGroup(this.groupID, frame, optionsWithDefaults.srcEndpoint);
|
|
356
|
-
} catch (error) {
|
|
357
|
-
const err = error as Error;
|
|
358
|
-
err.message = `${createLogMessage()} failed (${err.message})`;
|
|
359
|
-
// biome-ignore lint/style/noNonNullAssertion: ignored using `--suppress`
|
|
360
|
-
logger.debug(err.stack!, NS);
|
|
361
|
-
|
|
362
|
-
throw error;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
public async command<Cl extends number | string, Co extends number | string, Custom extends TCustomCluster | undefined = undefined>(
|
|
367
|
-
clusterKey: Cl,
|
|
368
|
-
commandKey: Co,
|
|
369
|
-
payload: ClusterOrRawPayload<Cl, Co, Custom>,
|
|
370
|
-
options?: Options,
|
|
371
|
-
): Promise<undefined> {
|
|
372
|
-
const customClusters = this.#customClusters[options?.direction === Zcl.Direction.SERVER_TO_CLIENT ? 1 : 0 /* default to CLIENT_TO_SERVER */];
|
|
373
|
-
const cluster = Zcl.Utils.getCluster(clusterKey, options?.manufacturerCode, customClusters);
|
|
374
|
-
const optionsWithDefaults = this.getOptionsWithDefaults(options, Zcl.Direction.CLIENT_TO_SERVER, cluster.manufacturerCode);
|
|
375
|
-
const command =
|
|
376
|
-
optionsWithDefaults.direction === Zcl.Direction.CLIENT_TO_SERVER
|
|
377
|
-
? cluster.getCommand(commandKey)
|
|
378
|
-
: cluster.getCommandResponse(commandKey);
|
|
379
|
-
|
|
380
|
-
const createLogMessage = (): string => `Command ${this.groupID} ${cluster.name}.${command.name}(${JSON.stringify(payload)})`;
|
|
381
|
-
logger.debug(createLogMessage, NS);
|
|
382
|
-
|
|
383
|
-
try {
|
|
384
|
-
const frame = Zcl.Frame.create(
|
|
385
|
-
Zcl.FrameType.SPECIFIC,
|
|
386
|
-
optionsWithDefaults.direction,
|
|
387
|
-
true,
|
|
388
|
-
optionsWithDefaults.manufacturerCode,
|
|
389
|
-
optionsWithDefaults.transactionSequenceNumber || zclTransactionSequenceNumber.next(),
|
|
390
|
-
command,
|
|
391
|
-
cluster,
|
|
392
|
-
payload,
|
|
393
|
-
customClusters,
|
|
394
|
-
optionsWithDefaults.reservedBits,
|
|
395
|
-
);
|
|
396
|
-
|
|
397
|
-
await Entity.adapter.sendZclFrameToGroup(this.groupID, frame, optionsWithDefaults.srcEndpoint);
|
|
398
|
-
} catch (error) {
|
|
399
|
-
const err = error as Error;
|
|
400
|
-
err.message = `${createLogMessage()} failed (${err.message})`;
|
|
401
|
-
// biome-ignore lint/style/noNonNullAssertion: ignored using `--suppress`
|
|
402
|
-
logger.debug(err.stack!, NS);
|
|
403
|
-
|
|
404
|
-
throw error;
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
private getOptionsWithDefaults(
|
|
409
|
-
options: Options | undefined,
|
|
410
|
-
direction: Zcl.Direction,
|
|
411
|
-
manufacturerCode: number | undefined,
|
|
412
|
-
): OptionsWithDefaults {
|
|
413
|
-
return {
|
|
414
|
-
direction,
|
|
415
|
-
srcEndpoint: undefined,
|
|
416
|
-
reservedBits: 0,
|
|
417
|
-
manufacturerCode,
|
|
418
|
-
transactionSequenceNumber: undefined,
|
|
419
|
-
...(options || {}),
|
|
420
|
-
};
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
export default Group;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ClusterOrRawAttributeKeys,
|
|
3
|
-
ClusterOrRawAttributes,
|
|
4
|
-
ClusterOrRawPayload,
|
|
5
|
-
KeyValue,
|
|
6
|
-
PartialClusterOrRawWriteAttributes,
|
|
7
|
-
TCustomCluster,
|
|
8
|
-
} from "../tstype";
|
|
9
|
-
import Entity from "./entity";
|
|
10
|
-
|
|
11
|
-
export abstract class ZigbeeEntity extends Entity {
|
|
12
|
-
public abstract read<Cl extends number | string, Custom extends TCustomCluster | undefined = undefined>(
|
|
13
|
-
clusterKey: Cl,
|
|
14
|
-
attributes: ClusterOrRawAttributeKeys<Cl, Custom>,
|
|
15
|
-
options?: KeyValue,
|
|
16
|
-
): Promise<ClusterOrRawAttributes<Cl, Custom> | undefined>;
|
|
17
|
-
|
|
18
|
-
public abstract write<Cl extends number | string, Custom extends TCustomCluster | undefined = undefined>(
|
|
19
|
-
clusterKey: Cl,
|
|
20
|
-
attributes: PartialClusterOrRawWriteAttributes<Cl, Custom>,
|
|
21
|
-
options?: KeyValue,
|
|
22
|
-
): Promise<void>;
|
|
23
|
-
|
|
24
|
-
public abstract command<Cl extends number | string, Co extends number | string, Custom extends TCustomCluster | undefined = undefined>(
|
|
25
|
-
clusterKey: Cl,
|
|
26
|
-
commandKey: Co,
|
|
27
|
-
payload: ClusterOrRawPayload<Cl, Co, Custom>,
|
|
28
|
-
options?: KeyValue,
|
|
29
|
-
): Promise<undefined | KeyValue>;
|
|
30
|
-
}
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import type {Adapter} from "../adapter";
|
|
2
|
-
import {wait} from "../utils";
|
|
3
|
-
import {logger} from "../utils/logger";
|
|
4
|
-
import {assertString} from "../utils/utils";
|
|
5
|
-
import * as Zcl from "../zspec/zcl";
|
|
6
|
-
|
|
7
|
-
const NS = "zh:controller:touchlink";
|
|
8
|
-
const scanChannels = [11, 15, 20, 25, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24, 26];
|
|
9
|
-
|
|
10
|
-
export class Touchlink {
|
|
11
|
-
private adapter: Adapter;
|
|
12
|
-
private locked: boolean;
|
|
13
|
-
|
|
14
|
-
public constructor(adapter: Adapter) {
|
|
15
|
-
this.adapter = adapter;
|
|
16
|
-
this.locked = false;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
private lock(lock: boolean): void {
|
|
20
|
-
if (lock && this.locked) {
|
|
21
|
-
throw new Error("Touchlink operation already in progress");
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
this.locked = lock;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
private transactionNumber(): number {
|
|
28
|
-
return Math.floor(Math.random() * 0xffffffff);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public async scan(): Promise<{ieeeAddr: string; channel: number}[]> {
|
|
32
|
-
this.lock(true);
|
|
33
|
-
const result = [];
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
for (const channel of scanChannels) {
|
|
37
|
-
logger.info(`Set InterPAN channel to '${channel}'`, NS);
|
|
38
|
-
await this.adapter.setChannelInterPAN(channel);
|
|
39
|
-
|
|
40
|
-
try {
|
|
41
|
-
// TODO: multiple responses are not handled yet.
|
|
42
|
-
const response = await this.adapter.sendZclFrameInterPANBroadcast(this.createScanRequestFrame(this.transactionNumber()), 500);
|
|
43
|
-
logger.debug(`Got scan response on channel '${channel}' of '${response.address}'`, NS);
|
|
44
|
-
assertString(response.address);
|
|
45
|
-
result.push({ieeeAddr: response.address, channel});
|
|
46
|
-
} catch (error) {
|
|
47
|
-
logger.warning(`Scan request failed or was not answered: '${error}'`, NS);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
} finally {
|
|
51
|
-
logger.info("Restore InterPAN channel", NS);
|
|
52
|
-
await this.adapter.restoreChannelInterPAN();
|
|
53
|
-
this.lock(false);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
public async identify(ieeeAddr: string, channel: number): Promise<void> {
|
|
60
|
-
this.lock(true);
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
const transaction = this.transactionNumber();
|
|
64
|
-
|
|
65
|
-
logger.info(`Set InterPAN channel to '${channel}'`, NS);
|
|
66
|
-
await this.adapter.setChannelInterPAN(channel);
|
|
67
|
-
|
|
68
|
-
await this.adapter.sendZclFrameInterPANBroadcast(this.createScanRequestFrame(transaction), 500);
|
|
69
|
-
logger.debug(`Got scan response on channel '${channel}'`, NS);
|
|
70
|
-
|
|
71
|
-
logger.debug(`Identifying '${ieeeAddr}'`, NS);
|
|
72
|
-
await this.adapter.sendZclFrameInterPANToIeeeAddr(this.createIdentifyRequestFrame(transaction), ieeeAddr);
|
|
73
|
-
} finally {
|
|
74
|
-
logger.info("Restore InterPAN channel", NS);
|
|
75
|
-
await this.adapter.restoreChannelInterPAN();
|
|
76
|
-
this.lock(false);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public async factoryReset(ieeeAddr: string, channel: number): Promise<boolean> {
|
|
81
|
-
this.lock(true);
|
|
82
|
-
try {
|
|
83
|
-
const transaction = this.transactionNumber();
|
|
84
|
-
|
|
85
|
-
logger.info(`Set InterPAN channel to '${channel}'`, NS);
|
|
86
|
-
await this.adapter.setChannelInterPAN(channel);
|
|
87
|
-
|
|
88
|
-
await this.adapter.sendZclFrameInterPANBroadcast(this.createScanRequestFrame(transaction), 500);
|
|
89
|
-
logger.debug(`Got scan response on channel '${channel}'`, NS);
|
|
90
|
-
|
|
91
|
-
logger.debug(`Identifying '${ieeeAddr}'`, NS);
|
|
92
|
-
await this.adapter.sendZclFrameInterPANToIeeeAddr(this.createIdentifyRequestFrame(transaction), ieeeAddr);
|
|
93
|
-
await wait(2000);
|
|
94
|
-
|
|
95
|
-
logger.debug(`Reset to factory new '${ieeeAddr}'`, NS);
|
|
96
|
-
await this.adapter.sendZclFrameInterPANToIeeeAddr(this.createResetFactoryNewRequestFrame(transaction), ieeeAddr);
|
|
97
|
-
} finally {
|
|
98
|
-
logger.info("Restore InterPAN channel", NS);
|
|
99
|
-
await this.adapter.restoreChannelInterPAN();
|
|
100
|
-
this.lock(false);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return true;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
public async factoryResetFirst(): Promise<boolean> {
|
|
107
|
-
this.lock(true);
|
|
108
|
-
let done = false;
|
|
109
|
-
|
|
110
|
-
try {
|
|
111
|
-
for (const channel of scanChannels) {
|
|
112
|
-
logger.info(`Set InterPAN channel to '${channel}'`, NS);
|
|
113
|
-
await this.adapter.setChannelInterPAN(channel);
|
|
114
|
-
|
|
115
|
-
try {
|
|
116
|
-
const transaction = this.transactionNumber();
|
|
117
|
-
|
|
118
|
-
const response = await this.adapter.sendZclFrameInterPANBroadcast(this.createScanRequestFrame(transaction), 500);
|
|
119
|
-
logger.debug(`Got scan response on channel '${channel}'`, NS);
|
|
120
|
-
assertString(response.address);
|
|
121
|
-
|
|
122
|
-
// Device answered (if not it will fall in the catch below),
|
|
123
|
-
// identify it (this will make e.g. the bulb flash)
|
|
124
|
-
logger.debug("Identifying", NS);
|
|
125
|
-
await this.adapter.sendZclFrameInterPANToIeeeAddr(this.createIdentifyRequestFrame(transaction), response.address);
|
|
126
|
-
await wait(2000);
|
|
127
|
-
|
|
128
|
-
logger.debug("Reset to factory new", NS);
|
|
129
|
-
await this.adapter.sendZclFrameInterPANToIeeeAddr(this.createResetFactoryNewRequestFrame(transaction), response.address);
|
|
130
|
-
done = true;
|
|
131
|
-
} catch (error) {
|
|
132
|
-
logger.warning(`Scan request failed or was not answered: '${error}'`, NS);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (done) break;
|
|
136
|
-
}
|
|
137
|
-
} finally {
|
|
138
|
-
logger.info("Restore InterPAN channel", NS);
|
|
139
|
-
await this.adapter.restoreChannelInterPAN();
|
|
140
|
-
this.lock(false);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return done;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
private createScanRequestFrame(transaction: number): Zcl.Frame {
|
|
147
|
-
return Zcl.Frame.create(
|
|
148
|
-
Zcl.FrameType.SPECIFIC,
|
|
149
|
-
Zcl.Direction.CLIENT_TO_SERVER,
|
|
150
|
-
true,
|
|
151
|
-
undefined,
|
|
152
|
-
0,
|
|
153
|
-
"scanRequest",
|
|
154
|
-
Zcl.Clusters.touchlink.ID,
|
|
155
|
-
{transactionID: transaction, zigbeeInformation: 4, touchlinkInformation: 18},
|
|
156
|
-
{},
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
private createIdentifyRequestFrame(transaction: number): Zcl.Frame {
|
|
161
|
-
return Zcl.Frame.create(
|
|
162
|
-
Zcl.FrameType.SPECIFIC,
|
|
163
|
-
Zcl.Direction.CLIENT_TO_SERVER,
|
|
164
|
-
true,
|
|
165
|
-
undefined,
|
|
166
|
-
0,
|
|
167
|
-
"identifyRequest",
|
|
168
|
-
Zcl.Clusters.touchlink.ID,
|
|
169
|
-
{transactionID: transaction, duration: 65535},
|
|
170
|
-
{},
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
private createResetFactoryNewRequestFrame(transaction: number): Zcl.Frame {
|
|
175
|
-
return Zcl.Frame.create(
|
|
176
|
-
Zcl.FrameType.SPECIFIC,
|
|
177
|
-
Zcl.Direction.CLIENT_TO_SERVER,
|
|
178
|
-
true,
|
|
179
|
-
undefined,
|
|
180
|
-
0,
|
|
181
|
-
"resetToFactoryNew",
|
|
182
|
-
Zcl.Clusters.touchlink.ID,
|
|
183
|
-
{transactionID: transaction},
|
|
184
|
-
{},
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export default Touchlink;
|