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.
Files changed (252) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/package.json +9 -3
  3. package/.github/ISSUE_TEMPLATE/config.yml +0 -5
  4. package/.github/dependabot.yml +0 -22
  5. package/.github/workflows/ci.yml +0 -69
  6. package/.github/workflows/release-please.yml +0 -18
  7. package/.github/workflows/stale.yml +0 -20
  8. package/.github/workflows/typedoc.yaml +0 -47
  9. package/.release-please-manifest.json +0 -3
  10. package/.vscode/extensions.json +0 -3
  11. package/.vscode/settings.json +0 -11
  12. package/biome.json +0 -98
  13. package/examples/join-and-log.js +0 -24
  14. package/release-please-config.json +0 -9
  15. package/src/adapter/adapter.ts +0 -189
  16. package/src/adapter/adapterDiscovery.ts +0 -666
  17. package/src/adapter/const.ts +0 -12
  18. package/src/adapter/deconz/adapter/deconzAdapter.ts +0 -877
  19. package/src/adapter/deconz/driver/constants.ts +0 -246
  20. package/src/adapter/deconz/driver/driver.ts +0 -1540
  21. package/src/adapter/deconz/driver/frame.ts +0 -11
  22. package/src/adapter/deconz/driver/frameParser.ts +0 -753
  23. package/src/adapter/deconz/driver/parser.ts +0 -45
  24. package/src/adapter/deconz/driver/writer.ts +0 -22
  25. package/src/adapter/deconz/types.d.ts +0 -13
  26. package/src/adapter/ember/adapter/emberAdapter.ts +0 -2265
  27. package/src/adapter/ember/adapter/endpoints.ts +0 -86
  28. package/src/adapter/ember/adapter/oneWaitress.ts +0 -324
  29. package/src/adapter/ember/adapter/tokensManager.ts +0 -782
  30. package/src/adapter/ember/consts.ts +0 -178
  31. package/src/adapter/ember/enums.ts +0 -1746
  32. package/src/adapter/ember/ezsp/buffalo.ts +0 -1392
  33. package/src/adapter/ember/ezsp/consts.ts +0 -148
  34. package/src/adapter/ember/ezsp/enums.ts +0 -1114
  35. package/src/adapter/ember/ezsp/ezsp.ts +0 -9061
  36. package/src/adapter/ember/ezspError.ts +0 -10
  37. package/src/adapter/ember/types.ts +0 -866
  38. package/src/adapter/ember/uart/ash.ts +0 -1960
  39. package/src/adapter/ember/uart/consts.ts +0 -109
  40. package/src/adapter/ember/uart/enums.ts +0 -192
  41. package/src/adapter/ember/uart/parser.ts +0 -48
  42. package/src/adapter/ember/uart/queues.ts +0 -247
  43. package/src/adapter/ember/uart/writer.ts +0 -53
  44. package/src/adapter/ember/utils/initters.ts +0 -58
  45. package/src/adapter/ember/utils/math.ts +0 -73
  46. package/src/adapter/events.ts +0 -21
  47. package/src/adapter/ezsp/adapter/backup.ts +0 -109
  48. package/src/adapter/ezsp/adapter/ezspAdapter.ts +0 -614
  49. package/src/adapter/ezsp/driver/commands.ts +0 -2497
  50. package/src/adapter/ezsp/driver/consts.ts +0 -11
  51. package/src/adapter/ezsp/driver/driver.ts +0 -1002
  52. package/src/adapter/ezsp/driver/ezsp.ts +0 -802
  53. package/src/adapter/ezsp/driver/frame.ts +0 -101
  54. package/src/adapter/ezsp/driver/index.ts +0 -4
  55. package/src/adapter/ezsp/driver/multicast.ts +0 -78
  56. package/src/adapter/ezsp/driver/parser.ts +0 -81
  57. package/src/adapter/ezsp/driver/types/basic.ts +0 -201
  58. package/src/adapter/ezsp/driver/types/index.ts +0 -239
  59. package/src/adapter/ezsp/driver/types/named.ts +0 -2330
  60. package/src/adapter/ezsp/driver/types/struct.ts +0 -844
  61. package/src/adapter/ezsp/driver/uart.ts +0 -460
  62. package/src/adapter/ezsp/driver/utils/crc16ccitt.ts +0 -44
  63. package/src/adapter/ezsp/driver/utils/index.ts +0 -32
  64. package/src/adapter/ezsp/driver/writer.ts +0 -64
  65. package/src/adapter/index.ts +0 -3
  66. package/src/adapter/serialPort.ts +0 -58
  67. package/src/adapter/socketPortUtils.ts +0 -16
  68. package/src/adapter/tstype.ts +0 -78
  69. package/src/adapter/z-stack/adapter/adapter-backup.ts +0 -519
  70. package/src/adapter/z-stack/adapter/adapter-nv-memory.ts +0 -457
  71. package/src/adapter/z-stack/adapter/endpoints.ts +0 -57
  72. package/src/adapter/z-stack/adapter/manager.ts +0 -543
  73. package/src/adapter/z-stack/adapter/tstype.ts +0 -6
  74. package/src/adapter/z-stack/adapter/zStackAdapter.ts +0 -1190
  75. package/src/adapter/z-stack/constants/af.ts +0 -27
  76. package/src/adapter/z-stack/constants/common.ts +0 -285
  77. package/src/adapter/z-stack/constants/dbg.ts +0 -23
  78. package/src/adapter/z-stack/constants/index.ts +0 -11
  79. package/src/adapter/z-stack/constants/mac.ts +0 -128
  80. package/src/adapter/z-stack/constants/sapi.ts +0 -25
  81. package/src/adapter/z-stack/constants/sys.ts +0 -72
  82. package/src/adapter/z-stack/constants/util.ts +0 -82
  83. package/src/adapter/z-stack/constants/utils.ts +0 -14
  84. package/src/adapter/z-stack/constants/zdo.ts +0 -103
  85. package/src/adapter/z-stack/models/startup-options.ts +0 -13
  86. package/src/adapter/z-stack/structs/entries/address-manager-entry.ts +0 -44
  87. package/src/adapter/z-stack/structs/entries/address-manager-table.ts +0 -19
  88. package/src/adapter/z-stack/structs/entries/aps-link-key-data-entry.ts +0 -12
  89. package/src/adapter/z-stack/structs/entries/aps-link-key-data-table.ts +0 -21
  90. package/src/adapter/z-stack/structs/entries/aps-tc-link-key-entry.ts +0 -19
  91. package/src/adapter/z-stack/structs/entries/aps-tc-link-key-table.ts +0 -21
  92. package/src/adapter/z-stack/structs/entries/channel-list.ts +0 -8
  93. package/src/adapter/z-stack/structs/entries/has-configured.ts +0 -16
  94. package/src/adapter/z-stack/structs/entries/index.ts +0 -16
  95. package/src/adapter/z-stack/structs/entries/nib.ts +0 -66
  96. package/src/adapter/z-stack/structs/entries/nwk-key-descriptor.ts +0 -15
  97. package/src/adapter/z-stack/structs/entries/nwk-key.ts +0 -13
  98. package/src/adapter/z-stack/structs/entries/nwk-pan-id.ts +0 -8
  99. package/src/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-entry.ts +0 -20
  100. package/src/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-table.ts +0 -19
  101. package/src/adapter/z-stack/structs/entries/security-manager-entry.ts +0 -33
  102. package/src/adapter/z-stack/structs/entries/security-manager-table.ts +0 -22
  103. package/src/adapter/z-stack/structs/index.ts +0 -4
  104. package/src/adapter/z-stack/structs/serializable-memory-object.ts +0 -14
  105. package/src/adapter/z-stack/structs/struct.ts +0 -367
  106. package/src/adapter/z-stack/structs/table.ts +0 -198
  107. package/src/adapter/z-stack/unpi/constants.ts +0 -33
  108. package/src/adapter/z-stack/unpi/frame.ts +0 -62
  109. package/src/adapter/z-stack/unpi/index.ts +0 -4
  110. package/src/adapter/z-stack/unpi/parser.ts +0 -56
  111. package/src/adapter/z-stack/unpi/writer.ts +0 -21
  112. package/src/adapter/z-stack/utils/channel-list.ts +0 -40
  113. package/src/adapter/z-stack/utils/index.ts +0 -2
  114. package/src/adapter/z-stack/utils/network-options.ts +0 -26
  115. package/src/adapter/z-stack/znp/buffaloZnp.ts +0 -175
  116. package/src/adapter/z-stack/znp/definition.ts +0 -2713
  117. package/src/adapter/z-stack/znp/index.ts +0 -2
  118. package/src/adapter/z-stack/znp/parameterType.ts +0 -22
  119. package/src/adapter/z-stack/znp/tstype.ts +0 -44
  120. package/src/adapter/z-stack/znp/utils.ts +0 -10
  121. package/src/adapter/z-stack/znp/znp.ts +0 -342
  122. package/src/adapter/z-stack/znp/zpiObject.ts +0 -148
  123. package/src/adapter/zboss/adapter/zbossAdapter.ts +0 -526
  124. package/src/adapter/zboss/commands.ts +0 -1184
  125. package/src/adapter/zboss/consts.ts +0 -9
  126. package/src/adapter/zboss/driver.ts +0 -422
  127. package/src/adapter/zboss/enums.ts +0 -360
  128. package/src/adapter/zboss/frame.ts +0 -227
  129. package/src/adapter/zboss/reader.ts +0 -65
  130. package/src/adapter/zboss/types.ts +0 -0
  131. package/src/adapter/zboss/uart.ts +0 -428
  132. package/src/adapter/zboss/utils.ts +0 -58
  133. package/src/adapter/zboss/writer.ts +0 -49
  134. package/src/adapter/zigate/adapter/patchZdoBuffaloBE.ts +0 -27
  135. package/src/adapter/zigate/adapter/zigateAdapter.ts +0 -618
  136. package/src/adapter/zigate/driver/LICENSE +0 -17
  137. package/src/adapter/zigate/driver/buffaloZiGate.ts +0 -212
  138. package/src/adapter/zigate/driver/commandType.ts +0 -418
  139. package/src/adapter/zigate/driver/constants.ts +0 -150
  140. package/src/adapter/zigate/driver/frame.ts +0 -197
  141. package/src/adapter/zigate/driver/messageType.ts +0 -287
  142. package/src/adapter/zigate/driver/parameterType.ts +0 -32
  143. package/src/adapter/zigate/driver/ziGateObject.ts +0 -146
  144. package/src/adapter/zigate/driver/zigate.ts +0 -423
  145. package/src/adapter/zoh/adapter/utils.ts +0 -27
  146. package/src/adapter/zoh/adapter/zohAdapter.ts +0 -838
  147. package/src/buffalo/buffalo.ts +0 -342
  148. package/src/buffalo/index.ts +0 -1
  149. package/src/controller/controller.ts +0 -1022
  150. package/src/controller/database.ts +0 -124
  151. package/src/controller/events.ts +0 -52
  152. package/src/controller/greenPower.ts +0 -603
  153. package/src/controller/helpers/index.ts +0 -1
  154. package/src/controller/helpers/installCodes.ts +0 -107
  155. package/src/controller/helpers/request.ts +0 -96
  156. package/src/controller/helpers/requestQueue.ts +0 -125
  157. package/src/controller/helpers/zclFrameConverter.ts +0 -47
  158. package/src/controller/helpers/zclTransactionSequenceNumber.ts +0 -19
  159. package/src/controller/index.ts +0 -6
  160. package/src/controller/model/device.ts +0 -1249
  161. package/src/controller/model/endpoint.ts +0 -1105
  162. package/src/controller/model/entity.ts +0 -23
  163. package/src/controller/model/group.ts +0 -424
  164. package/src/controller/model/index.ts +0 -5
  165. package/src/controller/model/zigbeeEntity.ts +0 -30
  166. package/src/controller/touchlink.ts +0 -189
  167. package/src/controller/tstype.ts +0 -274
  168. package/src/index.ts +0 -12
  169. package/src/models/backup-storage-legacy.ts +0 -48
  170. package/src/models/backup-storage-unified.ts +0 -47
  171. package/src/models/backup.ts +0 -37
  172. package/src/models/index.ts +0 -5
  173. package/src/models/network-options.ts +0 -11
  174. package/src/utils/backup.ts +0 -152
  175. package/src/utils/index.ts +0 -5
  176. package/src/utils/logger.ts +0 -20
  177. package/src/utils/patchBigIntSerialization.ts +0 -8
  178. package/src/utils/queue.ts +0 -76
  179. package/src/utils/types.d.ts +0 -3
  180. package/src/utils/utils.ts +0 -19
  181. package/src/utils/wait.ts +0 -5
  182. package/src/utils/waitress.ts +0 -96
  183. package/src/zspec/consts.ts +0 -84
  184. package/src/zspec/enums.ts +0 -22
  185. package/src/zspec/index.ts +0 -3
  186. package/src/zspec/tstypes.ts +0 -18
  187. package/src/zspec/utils.ts +0 -247
  188. package/src/zspec/zcl/buffaloZcl.ts +0 -1220
  189. package/src/zspec/zcl/definition/cluster.ts +0 -5915
  190. package/src/zspec/zcl/definition/clusters-typegen.ts +0 -588
  191. package/src/zspec/zcl/definition/clusters-types.ts +0 -7331
  192. package/src/zspec/zcl/definition/consts.ts +0 -24
  193. package/src/zspec/zcl/definition/enums.ts +0 -203
  194. package/src/zspec/zcl/definition/foundation.ts +0 -329
  195. package/src/zspec/zcl/definition/manufacturerCode.ts +0 -729
  196. package/src/zspec/zcl/definition/status.ts +0 -69
  197. package/src/zspec/zcl/definition/tstype.ts +0 -377
  198. package/src/zspec/zcl/index.ts +0 -11
  199. package/src/zspec/zcl/utils.ts +0 -321
  200. package/src/zspec/zcl/zclFrame.ts +0 -356
  201. package/src/zspec/zcl/zclHeader.ts +0 -102
  202. package/src/zspec/zcl/zclStatusError.ts +0 -10
  203. package/src/zspec/zdo/buffaloZdo.ts +0 -2336
  204. package/src/zspec/zdo/definition/clusters.ts +0 -722
  205. package/src/zspec/zdo/definition/consts.ts +0 -16
  206. package/src/zspec/zdo/definition/enums.ts +0 -99
  207. package/src/zspec/zdo/definition/status.ts +0 -105
  208. package/src/zspec/zdo/definition/tstypes.ts +0 -1062
  209. package/src/zspec/zdo/index.ts +0 -7
  210. package/src/zspec/zdo/utils.ts +0 -76
  211. package/src/zspec/zdo/zdoStatusError.ts +0 -10
  212. package/test/adapter/adapter.test.ts +0 -1062
  213. package/test/adapter/ember/ash.test.ts +0 -337
  214. package/test/adapter/ember/consts.ts +0 -131
  215. package/test/adapter/ember/emberAdapter.test.ts +0 -3449
  216. package/test/adapter/ember/ezsp.test.ts +0 -385
  217. package/test/adapter/ember/ezspBuffalo.test.ts +0 -93
  218. package/test/adapter/ember/ezspError.test.ts +0 -12
  219. package/test/adapter/ember/math.test.ts +0 -206
  220. package/test/adapter/ezsp/frame.test.ts +0 -30
  221. package/test/adapter/ezsp/uart.test.ts +0 -181
  222. package/test/adapter/z-stack/adapter.test.ts +0 -3984
  223. package/test/adapter/z-stack/constants.test.ts +0 -33
  224. package/test/adapter/z-stack/structs.test.ts +0 -115
  225. package/test/adapter/z-stack/unpi.test.ts +0 -213
  226. package/test/adapter/z-stack/znp.test.ts +0 -1284
  227. package/test/adapter/zboss/fixZdoResponse.test.ts +0 -179
  228. package/test/adapter/zigate/patchZdoBuffaloBE.test.ts +0 -81
  229. package/test/adapter/zigate/zdo.test.ts +0 -187
  230. package/test/adapter/zoh/utils.test.ts +0 -36
  231. package/test/adapter/zoh/zohAdapter.test.ts +0 -1307
  232. package/test/benchOptions.ts +0 -14
  233. package/test/buffalo.test.ts +0 -431
  234. package/test/controller.bench.ts +0 -214
  235. package/test/controller.test.ts +0 -8702
  236. package/test/greenpower.test.ts +0 -1408
  237. package/test/mockAdapters.ts +0 -65
  238. package/test/mockDevices.ts +0 -598
  239. package/test/requests.bench.ts +0 -229
  240. package/test/testUtils.ts +0 -20
  241. package/test/tsconfig.json +0 -9
  242. package/test/utils/math.ts +0 -19
  243. package/test/utils.test.ts +0 -279
  244. package/test/vitest.config.mts +0 -26
  245. package/test/zcl.test.ts +0 -2831
  246. package/test/zspec/utils.test.ts +0 -68
  247. package/test/zspec/zcl/buffalo.test.ts +0 -1374
  248. package/test/zspec/zcl/frame.test.ts +0 -960
  249. package/test/zspec/zcl/utils.test.ts +0 -273
  250. package/test/zspec/zdo/buffalo.test.ts +0 -1850
  251. package/test/zspec/zdo/utils.test.ts +0 -241
  252. package/tsconfig.json +0 -24
@@ -1,1062 +0,0 @@
1
- import type {BrowserConfig, Service} from "bonjour-service";
2
- import type {MockInstance} from "vitest";
3
-
4
- import {afterAll, beforeAll, beforeEach, describe, expect, it, vi} from "vitest";
5
- import {Adapter, type TsType} from "../../src/adapter";
6
- import {findAllDevices} from "../../src/adapter/adapterDiscovery";
7
- import {DeconzAdapter} from "../../src/adapter/deconz/adapter/deconzAdapter";
8
- import {EmberAdapter} from "../../src/adapter/ember/adapter/emberAdapter";
9
- import {EZSPAdapter} from "../../src/adapter/ezsp/adapter/ezspAdapter";
10
- import {SerialPort} from "../../src/adapter/serialPort";
11
- import {ZStackAdapter} from "../../src/adapter/z-stack/adapter/zStackAdapter";
12
- import {ZBOSSAdapter} from "../../src/adapter/zboss/adapter/zbossAdapter";
13
- import {ZiGateAdapter} from "../../src/adapter/zigate/adapter/zigateAdapter";
14
- import {ZoHAdapter} from "../../src/adapter/zoh/adapter/zohAdapter";
15
- import {
16
- DECONZ_CONBEE_II,
17
- EMBER_SKYCONNECT,
18
- EMBER_ZBDONGLE_E,
19
- EMBER_ZBDONGLE_E_CP,
20
- ZBOSS_NORDIC,
21
- ZIGATE_PLUSV2,
22
- ZSTACK_CC2538,
23
- ZSTACK_SMLIGHT_SLZB_06P10,
24
- ZSTACK_SMLIGHT_SLZB_07,
25
- ZSTACK_ZBDONGLE_P,
26
- } from "../mockAdapters";
27
-
28
- const mockPlatform = vi.fn(() => "linux");
29
-
30
- vi.mock("node:os", () => ({
31
- platform: vi.fn(() => mockPlatform()),
32
- }));
33
-
34
- const mockBonjourResult = vi.fn().mockImplementation((type) => ({
35
- name: "Mock Adapter",
36
- type: `${type}_mdns`,
37
- port: "1122",
38
- host: "mock_adapter.local",
39
- addresses: ["192.168.1.123"],
40
- txt: {
41
- radio_type: `${type}`,
42
- },
43
- }));
44
- const mockBonjourFind = vi.fn((_opts: BrowserConfig | null, onup?: (service: Service) => void) => {
45
- if (onup) {
46
- onup(mockBonjourResult("zstack"));
47
- onup(mockBonjourResult("ezsp")); // expected as `ember` Adapter
48
- onup(mockBonjourResult("znp")); // expected as `zstack` Adapter
49
- }
50
-
51
- return {start: vi.fn(), stop: vi.fn()};
52
- });
53
- const mockBonjourFindOne = vi.fn((opts: BrowserConfig | null, _timeout: number, callback?: (service: Service) => void) => {
54
- if (callback) {
55
- callback(mockBonjourResult(opts?.type));
56
- }
57
- });
58
- const mockBonjourDestroy = vi.fn();
59
-
60
- vi.mock("bonjour-service", () => ({
61
- Bonjour: vi.fn(() => ({
62
- find: mockBonjourFind,
63
- findOne: mockBonjourFindOne,
64
- destroy: mockBonjourDestroy,
65
- })),
66
- }));
67
-
68
- describe("Adapter", () => {
69
- beforeAll(() => {
70
- vi.useFakeTimers();
71
- });
72
-
73
- afterAll(() => {
74
- vi.useRealTimers();
75
- });
76
-
77
- beforeEach(() => {
78
- mockPlatform.mockClear();
79
- mockBonjourResult.mockClear();
80
- mockBonjourFind.mockClear();
81
- mockBonjourFindOne.mockClear();
82
- mockBonjourDestroy.mockClear();
83
- });
84
-
85
- it.each([
86
- ["deconz", DeconzAdapter],
87
- ["ember", EmberAdapter],
88
- ["ezsp", EZSPAdapter],
89
- ["zstack", ZStackAdapter],
90
- ["zboss", ZBOSSAdapter],
91
- ["zigate", ZiGateAdapter],
92
- ["zoh", ZoHAdapter],
93
- ])("Calls adapter contructor for %s", async (name, cls) => {
94
- const adapter = await Adapter.create(
95
- {
96
- panID: 0x1a62,
97
- channelList: [11],
98
- extendedPanID: [0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd],
99
- networkKey: [1, 3, 5, 7, 9, 11, 13, 15, 0, 2, 4, 6, 8, 10, 12, 13],
100
- },
101
- {path: "/dev/ttyUSB0", adapter: name as TsType.Adapter},
102
- "test.db.backup",
103
- {disableLED: false},
104
- );
105
-
106
- expect(adapter).toBeInstanceOf(cls);
107
- });
108
-
109
- it("finds all devices", async () => {
110
- vi.spyOn(SerialPort, "list").mockResolvedValueOnce([
111
- Object.assign({pnpId: "deconz conbee ii", serialNumber: "", locationId: ""}, DECONZ_CONBEE_II),
112
- Object.assign({pnpId: "zbdongle-e", serialNumber: "", locationId: ""}, EMBER_ZBDONGLE_E),
113
- Object.assign({pnpId: "cc2538", serialNumber: "", locationId: ""}, ZSTACK_CC2538),
114
- Object.assign({pnpId: "nordic", serialNumber: "", locationId: ""}, ZBOSS_NORDIC),
115
- Object.assign({pnpId: "zigate-plus-v2", serialNumber: "", locationId: "", manufacturer: ""}, ZIGATE_PLUSV2),
116
- ]);
117
-
118
- const p = findAllDevices();
119
-
120
- await vi.advanceTimersByTimeAsync(2500);
121
-
122
- await expect(p).resolves.toStrictEqual([
123
- {
124
- name: "zigate-plus-v2 ()",
125
- path: "/dev/serial/by-id/usb-FTDI_ZiGate_ZIGATE+-if00-port0",
126
- adapter: "zigate",
127
- },
128
- {
129
- name: "zbdongle-e (ITEAD)",
130
- path: "/dev/serial/by-id/usb-ITEAD_SONOFF_Zigbee_3.0_USB_Dongle_Plus_V2_20240122184111-if00",
131
- adapter: "ember",
132
- },
133
- {
134
- name: "cc2538 (Texas Instruments)",
135
- path: "/dev/serial/by-id/usb-Texas_Instruments_CC2538_USB_CDC-if00",
136
- adapter: "zstack",
137
- },
138
- {
139
- name: "nordic (ZEPHYR)",
140
- path: "/dev/serial/by-id/usb-ZEPHYR_Zigbee_NCP_54ACCFAFA6DADC49-if00",
141
- adapter: "zboss",
142
- },
143
- {
144
- name: "deconz conbee ii (dresden elektronik ingenieurtechnik GmbH)",
145
- path: "/dev/serial/by-id/usb-dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2132111-if00",
146
- adapter: "deconz",
147
- },
148
- {
149
- name: "Mock Adapter (tcp://192.168.1.123:1122)",
150
- path: "tcp://192.168.1.123:1122",
151
- adapter: "zstack",
152
- },
153
- {
154
- name: "Mock Adapter (tcp://192.168.1.123:1122)",
155
- path: "tcp://192.168.1.123:1122",
156
- adapter: "ember",
157
- },
158
- {
159
- name: "Mock Adapter (tcp://192.168.1.123:1122)",
160
- path: "tcp://192.168.1.123:1122",
161
- adapter: "zstack",
162
- },
163
- ]);
164
- expect(mockBonjourDestroy).toHaveBeenCalledTimes(1);
165
- });
166
-
167
- it("finds all devices with quirks", async () => {
168
- // on Windows
169
- mockPlatform.mockReturnValueOnce("win32");
170
- vi.spyOn(SerialPort, "list").mockResolvedValueOnce([
171
- Object.assign({pnpId: "zbdongle-e", serialNumber: "", locationId: "", friendlyName: "silicon labs cp210x"}, EMBER_ZBDONGLE_E_CP),
172
- ]);
173
- // `name` in `txt`, no `addresses`
174
- mockBonjourResult.mockImplementationOnce((type) => ({
175
- type: `${type}_mdns`,
176
- port: "1122",
177
- host: "mock_adapter.local",
178
- txt: {
179
- name: "Mock Adapter",
180
- radio_type: `${type}`,
181
- },
182
- }));
183
- // no name
184
- mockBonjourResult.mockImplementationOnce((type) => ({
185
- type: `${type}_mdns`,
186
- port: "1122",
187
- host: "mock_adapter.local",
188
- addresses: ["192.168.1.123"],
189
- txt: {
190
- radio_type: `${type}`,
191
- },
192
- }));
193
-
194
- const p = findAllDevices();
195
-
196
- await vi.advanceTimersByTimeAsync(2500);
197
- await expect(p).resolves.toStrictEqual([
198
- {
199
- name: "silicon labs cp210x (ITEAD)",
200
- path: EMBER_ZBDONGLE_E_CP.path,
201
- adapter: undefined,
202
- },
203
- {
204
- name: "Mock Adapter (tcp://mock_adapter.local:1122)",
205
- path: "tcp://mock_adapter.local:1122",
206
- adapter: "zstack",
207
- },
208
- {
209
- name: "Unknown (tcp://192.168.1.123:1122)",
210
- path: "tcp://192.168.1.123:1122",
211
- adapter: "ember",
212
- },
213
- {
214
- name: "Mock Adapter (tcp://192.168.1.123:1122)",
215
- path: "tcp://192.168.1.123:1122",
216
- adapter: "zstack",
217
- },
218
- ]);
219
- expect(mockBonjourDestroy).toHaveBeenCalledTimes(1);
220
- });
221
-
222
- describe("mDNS discovery", () => {
223
- it.each([
224
- ["deconz", DeconzAdapter],
225
- ["ember", EmberAdapter],
226
- ["ezsp", EmberAdapter], // `ezsp` radio_type uses `ember` Adapter
227
- ["zstack", ZStackAdapter],
228
- ["zboss", ZBOSSAdapter],
229
- ["zigate", ZiGateAdapter],
230
- ])("for %s", async (name, adapterCls) => {
231
- const adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {path: `mdns://${name}`}, "test.db.backup", {disableLED: false});
232
-
233
- expect(adapter).toBeInstanceOf(adapterCls);
234
- // @ts-expect-error protected
235
- expect(adapter.serialPortOptions).toStrictEqual({
236
- path: "tcp://192.168.1.123:1122",
237
- adapter: name === "ezsp" ? "ember" : name,
238
- });
239
- });
240
-
241
- it("for zstack as znp", async () => {
242
- const adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {path: "mdns://znp"}, "test.db.backup", {disableLED: false});
243
-
244
- expect(adapter).toBeInstanceOf(ZStackAdapter);
245
- // @ts-expect-error protected
246
- expect(adapter.serialPortOptions).toStrictEqual({
247
- path: "tcp://192.168.1.123:1122",
248
- adapter: "zstack",
249
- });
250
- });
251
-
252
- it("falls back to host if no addresses", async () => {
253
- mockBonjourResult.mockReturnValueOnce({
254
- name: "Mock Adapter",
255
- type: "my_adapter_mdns",
256
- port: "1122",
257
- host: "mock_adapter.local",
258
- txt: {
259
- radio_type: "zstack",
260
- },
261
- });
262
- const adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {path: "mdns://zstack"}, "test.db.backup", {disableLED: false});
263
-
264
- expect(adapter).toBeInstanceOf(ZStackAdapter);
265
- // @ts-expect-error protected
266
- expect(adapter.serialPortOptions).toStrictEqual({
267
- path: "tcp://mock_adapter.local:1122",
268
- adapter: "zstack",
269
- });
270
- });
271
-
272
- it("times out", async () => {
273
- mockBonjourResult.mockReturnValueOnce(null);
274
- const fakeAdapterName = "mdns_test_device";
275
-
276
- await expect(
277
- Adapter.create({panID: 0, channelList: []}, {path: `mdns://${fakeAdapterName}`}, "test.db", {disableLED: false}),
278
- ).rejects.toThrow(`Coordinator [${fakeAdapterName}] not found after timeout of 2000ms!`);
279
- });
280
-
281
- it("given invalid path", async () => {
282
- await expect(Adapter.create({panID: 0, channelList: []}, {path: "mdns://"}, "test.db", {disableLED: false})).rejects.toThrow(
283
- "No mdns device specified. You must specify the coordinator mdns service type after mdns://, e.g. mdns://my-adapter",
284
- );
285
- });
286
-
287
- it("returns invalid format", async () => {
288
- mockBonjourResult.mockReturnValueOnce({
289
- name: "Mock Adapter",
290
- type: "my_adapter_mdns",
291
- port: "1122",
292
- host: "my_adapter.local",
293
- addresses: ["192.168.1.123"],
294
- txt: {
295
- radio_type: undefined,
296
- },
297
- });
298
-
299
- await expect(Adapter.create({panID: 0, channelList: []}, {path: "mdns://my_adapter"}, "test.db", {disableLED: false})).rejects.toThrow(
300
- "Coordinator returned wrong Zeroconf format! The following values are expected:\n" +
301
- "txt.radio_type, got: undefined\n" +
302
- "port, got: 1122",
303
- );
304
- });
305
- });
306
-
307
- describe("TCP discovery", () => {
308
- it("returns config with tcp path", async () => {
309
- const adapter = await Adapter.create(
310
- {panID: 0x1a62, channelList: [11]},
311
- {path: "tcp://192.168.1.321:3456", adapter: "zstack"},
312
- "test.db.backup",
313
- {disableLED: false},
314
- );
315
-
316
- // @ts-expect-error protected
317
- expect(adapter.serialPortOptions).toStrictEqual({
318
- path: "tcp://192.168.1.321:3456",
319
- adapter: "zstack",
320
- });
321
- });
322
-
323
- it("returns config with socket path", async () => {
324
- const adapter = await Adapter.create(
325
- {panID: 0x1a62, channelList: [11]},
326
- {path: "socket://192.168.1.321:3456", adapter: "zstack"},
327
- "test.db.backup",
328
- {disableLED: false},
329
- );
330
-
331
- // @ts-expect-error protected
332
- expect(adapter.serialPortOptions).toStrictEqual({
333
- path: "tcp://192.168.1.321:3456",
334
- adapter: "zstack",
335
- });
336
- });
337
-
338
- it("returns config with hostname path", async () => {
339
- const adapter = await Adapter.create(
340
- {panID: 0x1a62, channelList: [11]},
341
- {path: "tcp://my-super-host:3456", adapter: "zstack"},
342
- "test.db.backup",
343
- {disableLED: false},
344
- );
345
-
346
- // @ts-expect-error protected
347
- expect(adapter.serialPortOptions).toStrictEqual({
348
- path: "tcp://my-super-host:3456",
349
- adapter: "zstack",
350
- });
351
- });
352
-
353
- it.each(["tcp://192168.1.321", "tcp://192168.1.321:INVALID"])("invalid path", async (path) => {
354
- await expect(
355
- Adapter.create({panID: 0x1a62, channelList: [11]}, {path, adapter: "zstack"}, "test.db.backup", {
356
- disableLED: false,
357
- }),
358
- ).rejects.toThrow("Invalid TCP path, expected format: tcp://<host>:<port>");
359
- });
360
-
361
- it("invalid adapter", async () => {
362
- await expect(
363
- Adapter.create({panID: 0x1a62, channelList: [11]}, {path: "tcp://192.168.1.321:3456"}, "test.db.backup", {
364
- disableLED: false,
365
- }),
366
- ).rejects.toThrow(`Cannot discover TCP adapters at this time. Specify valid 'adapter' and 'port' in your configuration.`);
367
- });
368
- });
369
-
370
- describe("USB discovery", () => {
371
- let listSpy: MockInstance;
372
-
373
- beforeAll(() => {
374
- listSpy = vi.spyOn(SerialPort, "list");
375
- listSpy.mockReturnValue([DECONZ_CONBEE_II, EMBER_ZBDONGLE_E, ZSTACK_CC2538, ZBOSS_NORDIC, ZIGATE_PLUSV2]);
376
- });
377
-
378
- describe("without config", () => {
379
- it("detects each adapter", async () => {
380
- listSpy.mockReturnValueOnce([DECONZ_CONBEE_II]);
381
-
382
- let adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {baudRate: 57600}, "test.db.backup", {disableLED: false});
383
-
384
- expect(adapter).toBeInstanceOf(DeconzAdapter);
385
- // @ts-expect-error protected
386
- expect(adapter.serialPortOptions).toStrictEqual({
387
- path: DECONZ_CONBEE_II.path,
388
- adapter: "deconz",
389
- baudRate: 57600,
390
- });
391
-
392
- listSpy.mockReturnValueOnce([EMBER_ZBDONGLE_E]);
393
-
394
- adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {baudRate: 115200}, "test.db.backup", {disableLED: false});
395
-
396
- expect(adapter).toBeInstanceOf(EmberAdapter);
397
- // @ts-expect-error protected
398
- expect(adapter.serialPortOptions).toStrictEqual({
399
- path: EMBER_ZBDONGLE_E.path,
400
- adapter: "ember",
401
- baudRate: 115200,
402
- });
403
-
404
- listSpy.mockReturnValueOnce([ZSTACK_CC2538]);
405
-
406
- adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {}, "test.db.backup", {disableLED: false});
407
-
408
- expect(adapter).toBeInstanceOf(ZStackAdapter);
409
- // @ts-expect-error protected
410
- expect(adapter.serialPortOptions).toStrictEqual({
411
- path: ZSTACK_CC2538.path,
412
- adapter: "zstack",
413
- });
414
-
415
- listSpy.mockReturnValueOnce([ZBOSS_NORDIC]);
416
-
417
- adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {}, "test.db.backup", {disableLED: false});
418
-
419
- expect(adapter).toBeInstanceOf(ZBOSSAdapter);
420
- // @ts-expect-error protected
421
- expect(adapter.serialPortOptions).toStrictEqual({
422
- path: ZBOSS_NORDIC.path,
423
- adapter: "zboss",
424
- });
425
-
426
- listSpy.mockReturnValueOnce([ZIGATE_PLUSV2]);
427
-
428
- adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {}, "test.db.backup", {disableLED: false});
429
-
430
- expect(adapter).toBeInstanceOf(ZiGateAdapter);
431
- // @ts-expect-error protected
432
- expect(adapter.serialPortOptions).toStrictEqual({
433
- path: ZIGATE_PLUSV2.path,
434
- adapter: "zigate",
435
- });
436
- });
437
-
438
- it("detects on Windows with manufacturer present", async () => {
439
- mockPlatform.mockReturnValueOnce("win32");
440
- listSpy.mockReturnValueOnce([
441
- {
442
- // Windows sample - Sonoff Dongle-E
443
- path: "COM3",
444
- manufacturer: "ITEAD",
445
- serialNumber: "54DD002111",
446
- pnpId: "USB\\VID_1A86&PID_55D4\\54DD002111",
447
- locationId: "Port_#0005.Hub_#0001",
448
- friendlyName: "USB-Enhanced-SERIAL CH9102 (COM3)",
449
- vendorId: "1A86",
450
- productId: "55D4",
451
- },
452
- ]);
453
-
454
- const adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {}, "test.db.backup", {disableLED: false});
455
-
456
- expect(adapter).toBeInstanceOf(EmberAdapter);
457
- // @ts-expect-error protected
458
- expect(adapter.serialPortOptions).toStrictEqual({
459
- path: "COM3",
460
- adapter: "ember",
461
- });
462
- });
463
-
464
- it("detects on Windows without manufacturer present", async () => {
465
- // Note: this is the least-accurate possible match
466
- mockPlatform.mockReturnValueOnce("win32");
467
- listSpy.mockReturnValueOnce([
468
- {
469
- // Windows sample - Sonoff Dongle-E
470
- path: "COM3",
471
- manufacturer: "wch.cn",
472
- serialNumber: "54DD002111",
473
- pnpId: "USB\\VID_1A86&PID_55D4\\54DD002111",
474
- locationId: "Port_#0005.Hub_#0001",
475
- friendlyName: "USB-Enhanced-SERIAL CH9102 (COM3)",
476
- vendorId: "1A86",
477
- productId: "55D4",
478
- },
479
- ]);
480
-
481
- const adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {}, "test.db.backup", {disableLED: false});
482
-
483
- expect(adapter).toBeInstanceOf(EmberAdapter);
484
- // @ts-expect-error protected
485
- expect(adapter.serialPortOptions).toStrictEqual({
486
- path: "COM3",
487
- adapter: "ember",
488
- });
489
- });
490
-
491
- it("detects with pnpId instead of path", async () => {
492
- listSpy.mockReturnValueOnce([{...ZBOSS_NORDIC, path: "/dev/ttyUSB0", pnpId: "usb-ZEPHYR_Zigbee_NCP_54ACCFAFA6DADC49-if00"}]);
493
-
494
- const adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {}, "test.db.backup", {disableLED: false});
495
-
496
- expect(adapter).toBeInstanceOf(ZBOSSAdapter);
497
- // @ts-expect-error protected
498
- expect(adapter.serialPortOptions).toStrictEqual({
499
- path: "/dev/ttyUSB0",
500
- adapter: "zboss",
501
- });
502
- });
503
-
504
- it("detects with conflict vendor+product IDs", async () => {
505
- listSpy.mockReturnValueOnce([{...EMBER_SKYCONNECT, manufacturer: undefined}]);
506
-
507
- let adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {}, "test.db.backup", {disableLED: false});
508
-
509
- expect(adapter).toBeInstanceOf(EmberAdapter);
510
- // @ts-expect-error protected
511
- expect(adapter.serialPortOptions).toStrictEqual({
512
- path: EMBER_SKYCONNECT.path,
513
- adapter: "ember",
514
- });
515
-
516
- listSpy.mockReturnValueOnce([{...ZSTACK_ZBDONGLE_P, path: "/dev/ttyACM0"}]);
517
-
518
- await expect(Adapter.create({panID: 0x1a62, channelList: [11]}, {}, "test.db.backup", {disableLED: false})).rejects.toThrow(
519
- `USB adapter discovery error (No valid USB adapter found). Specify valid 'adapter' and 'port' in your configuration.`,
520
- );
521
-
522
- listSpy.mockReturnValueOnce([
523
- {...ZSTACK_ZBDONGLE_P, path: "/dev/ttyACM0", pnpId: ZSTACK_ZBDONGLE_P.path.replace("/dev/serial/by-id/", "")},
524
- ]);
525
-
526
- adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {}, "test.db.backup", {disableLED: false});
527
-
528
- expect(adapter).toBeInstanceOf(ZStackAdapter);
529
- // @ts-expect-error protected
530
- expect(adapter.serialPortOptions).toStrictEqual({
531
- path: "/dev/ttyACM0",
532
- adapter: "zstack",
533
- });
534
-
535
- listSpy.mockReturnValueOnce([ZSTACK_ZBDONGLE_P]);
536
-
537
- adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {}, "test.db.backup", {disableLED: false});
538
-
539
- expect(adapter).toBeInstanceOf(ZStackAdapter);
540
- // @ts-expect-error protected
541
- expect(adapter.serialPortOptions).toStrictEqual({
542
- path: ZSTACK_ZBDONGLE_P.path,
543
- adapter: "zstack",
544
- });
545
-
546
- listSpy.mockReturnValueOnce([EMBER_ZBDONGLE_E_CP]);
547
-
548
- adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {}, "test.db.backup", {disableLED: false});
549
-
550
- expect(adapter).toBeInstanceOf(EmberAdapter);
551
- // @ts-expect-error protected
552
- expect(adapter.serialPortOptions).toStrictEqual({
553
- path: EMBER_ZBDONGLE_E_CP.path,
554
- adapter: "ember",
555
- });
556
-
557
- listSpy.mockReturnValueOnce([ZSTACK_SMLIGHT_SLZB_06P10]);
558
-
559
- adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {}, "test.db.backup", {disableLED: false});
560
-
561
- expect(adapter).toBeInstanceOf(ZStackAdapter);
562
- // @ts-expect-error protected
563
- expect(adapter.serialPortOptions).toStrictEqual({
564
- path: ZSTACK_SMLIGHT_SLZB_06P10.path,
565
- adapter: "zstack",
566
- });
567
-
568
- listSpy.mockReturnValueOnce([ZSTACK_SMLIGHT_SLZB_07]);
569
-
570
- adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {}, "test.db.backup", {disableLED: false});
571
-
572
- expect(adapter).toBeInstanceOf(EmberAdapter);
573
- // @ts-expect-error protected
574
- expect(adapter.serialPortOptions).toStrictEqual({
575
- path: ZSTACK_SMLIGHT_SLZB_07.path,
576
- adapter: "ember",
577
- });
578
- });
579
-
580
- it("returns first from list with multiple adapters - nothing to match against", async () => {
581
- // NOTE: list is currently sorted
582
- // const sortedPaths = [DECONZ_CONBEE_II.path, ZSTACK_CC2538.path, EMBER_ZBDONGLE_E.path].sort();
583
- // console.log(sortedPaths[0]);
584
- listSpy.mockReturnValueOnce([DECONZ_CONBEE_II, ZSTACK_CC2538, EMBER_ZBDONGLE_E]);
585
-
586
- const adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {}, "test.db.backup", {disableLED: false});
587
-
588
- expect(adapter).toBeInstanceOf(EmberAdapter);
589
- // @ts-expect-error protected
590
- expect(adapter.serialPortOptions).toStrictEqual({
591
- path: EMBER_ZBDONGLE_E.path,
592
- adapter: "ember",
593
- });
594
- });
595
-
596
- it("throws on failure to get SerialPort.list", async () => {
597
- listSpy.mockRejectedValueOnce(new Error("spawn udevadm ENOENT"));
598
-
599
- await expect(Adapter.create({panID: 0x1a62, channelList: [11]}, {}, "test.db.backup", {disableLED: false})).rejects.toThrow(
600
- `USB adapter discovery error (spawn udevadm ENOENT). Specify valid 'adapter' and 'port' in your configuration.`,
601
- );
602
- });
603
-
604
- it("throws on failure to detect with conflict vendor+product IDs", async () => {
605
- listSpy.mockReturnValueOnce([{...EMBER_SKYCONNECT, path: "/dev/ttyACM0", manufacturer: undefined}]);
606
-
607
- await expect(Adapter.create({panID: 0x1a62, channelList: [11]}, {}, "test.db.backup", {disableLED: false})).rejects.toThrow(
608
- `USB adapter discovery error (No valid USB adapter found). Specify valid 'adapter' and 'port' in your configuration.`,
609
- );
610
- });
611
- });
612
-
613
- describe("with adapter+path config", () => {
614
- it("detects each adapter", async () => {
615
- listSpy.mockReturnValueOnce([DECONZ_CONBEE_II]);
616
-
617
- let adapter = await Adapter.create(
618
- {panID: 0x1a62, channelList: [11]},
619
- {adapter: "deconz", path: DECONZ_CONBEE_II.path},
620
- "test.db.backup",
621
- {disableLED: false},
622
- );
623
-
624
- expect(adapter).toBeInstanceOf(DeconzAdapter);
625
- // @ts-expect-error protected
626
- expect(adapter.serialPortOptions).toStrictEqual({
627
- path: DECONZ_CONBEE_II.path,
628
- adapter: "deconz",
629
- });
630
-
631
- listSpy.mockReturnValueOnce([EMBER_ZBDONGLE_E]);
632
-
633
- adapter = await Adapter.create(
634
- {panID: 0x1a62, channelList: [11]},
635
- {adapter: "ember", path: EMBER_ZBDONGLE_E.path},
636
- "test.db.backup",
637
- {disableLED: false},
638
- );
639
-
640
- expect(adapter).toBeInstanceOf(EmberAdapter);
641
- // @ts-expect-error protected
642
- expect(adapter.serialPortOptions).toStrictEqual({
643
- path: EMBER_ZBDONGLE_E.path,
644
- adapter: "ember",
645
- });
646
-
647
- listSpy.mockReturnValueOnce([EMBER_ZBDONGLE_E]);
648
-
649
- adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {adapter: "ezsp", path: EMBER_ZBDONGLE_E.path}, "test.db.backup", {
650
- disableLED: false,
651
- });
652
-
653
- expect(adapter).toBeInstanceOf(EZSPAdapter);
654
- // @ts-expect-error protected
655
- expect(adapter.serialPortOptions).toStrictEqual({
656
- path: EMBER_ZBDONGLE_E.path,
657
- adapter: "ezsp",
658
- });
659
-
660
- listSpy.mockReturnValueOnce([ZSTACK_CC2538]);
661
-
662
- adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {adapter: "zstack", path: ZSTACK_CC2538.path}, "test.db.backup", {
663
- disableLED: false,
664
- });
665
-
666
- expect(adapter).toBeInstanceOf(ZStackAdapter);
667
- // @ts-expect-error protected
668
- expect(adapter.serialPortOptions).toStrictEqual({
669
- path: ZSTACK_CC2538.path,
670
- adapter: "zstack",
671
- });
672
-
673
- listSpy.mockReturnValueOnce([ZBOSS_NORDIC]);
674
-
675
- adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {adapter: "zboss", path: ZBOSS_NORDIC.path}, "test.db.backup", {
676
- disableLED: false,
677
- });
678
-
679
- expect(adapter).toBeInstanceOf(ZBOSSAdapter);
680
- // @ts-expect-error protected
681
- expect(adapter.serialPortOptions).toStrictEqual({
682
- path: ZBOSS_NORDIC.path,
683
- adapter: "zboss",
684
- });
685
-
686
- listSpy.mockReturnValueOnce([ZIGATE_PLUSV2]);
687
-
688
- adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {adapter: "zigate", path: ZIGATE_PLUSV2.path}, "test.db.backup", {
689
- disableLED: false,
690
- });
691
-
692
- expect(adapter).toBeInstanceOf(ZiGateAdapter);
693
- // @ts-expect-error protected
694
- expect(adapter.serialPortOptions).toStrictEqual({
695
- path: ZIGATE_PLUSV2.path,
696
- adapter: "zigate",
697
- });
698
- });
699
-
700
- it("detects with multiple adapters connected", async () => {
701
- listSpy.mockReturnValueOnce([DECONZ_CONBEE_II, ZSTACK_CC2538, EMBER_ZBDONGLE_E]);
702
-
703
- const adapter = await Adapter.create(
704
- {panID: 0x1a62, channelList: [11]},
705
- {adapter: "zstack", path: ZSTACK_CC2538.path},
706
- "test.db.backup",
707
- {disableLED: false},
708
- );
709
-
710
- expect(adapter).toBeInstanceOf(ZStackAdapter);
711
- // @ts-expect-error protected
712
- expect(adapter.serialPortOptions).toStrictEqual({
713
- path: ZSTACK_CC2538.path,
714
- adapter: "zstack",
715
- });
716
- });
717
-
718
- it("detects with pnpId instead of path", async () => {
719
- listSpy.mockReturnValueOnce([{...ZBOSS_NORDIC, path: "/dev/ttyUSB0", pnpId: "usb-ZEPHYR_Zigbee_NCP_54ACCFAFA6DADC49-if00"}]);
720
-
721
- const adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {adapter: "zboss", path: "/dev/ttyUSB0"}, "test.db.backup", {
722
- disableLED: false,
723
- });
724
-
725
- expect(adapter).toBeInstanceOf(ZBOSSAdapter);
726
- // @ts-expect-error protected
727
- expect(adapter.serialPortOptions).toStrictEqual({
728
- path: "/dev/ttyUSB0",
729
- adapter: "zboss",
730
- });
731
- });
732
-
733
- it("detects with conflict vendor+product IDs", async () => {
734
- listSpy.mockReturnValueOnce([{...EMBER_SKYCONNECT, manufacturer: undefined}]);
735
-
736
- let adapter = await Adapter.create(
737
- {panID: 0x1a62, channelList: [11]},
738
- {adapter: "ember", path: EMBER_SKYCONNECT.path},
739
- "test.db.backup",
740
- {disableLED: false},
741
- );
742
-
743
- expect(adapter).toBeInstanceOf(EmberAdapter);
744
- // @ts-expect-error protected
745
- expect(adapter.serialPortOptions).toStrictEqual({
746
- path: EMBER_SKYCONNECT.path,
747
- adapter: "ember",
748
- });
749
-
750
- listSpy.mockReturnValueOnce([{...ZSTACK_ZBDONGLE_P, path: "/dev/ttyACM0"}]);
751
-
752
- adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {adapter: "zstack", path: "/dev/ttyACM0"}, "test.db.backup", {
753
- disableLED: false,
754
- });
755
-
756
- expect(adapter).toBeInstanceOf(ZStackAdapter);
757
- // @ts-expect-error protected
758
- expect(adapter.serialPortOptions).toStrictEqual({
759
- path: "/dev/ttyACM0",
760
- adapter: "zstack",
761
- });
762
- });
763
-
764
- it("returns instance anyway on failure to match", async () => {
765
- listSpy.mockReturnValueOnce([]);
766
- const adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {adapter: "zstack", path: "dev/ttyUSB0"}, "test.db.backup", {
767
- disableLED: false,
768
- });
769
-
770
- expect(adapter).toBeInstanceOf(ZStackAdapter);
771
- // @ts-expect-error protected
772
- expect(adapter.serialPortOptions).toStrictEqual({
773
- path: "dev/ttyUSB0",
774
- adapter: "zstack",
775
- });
776
- });
777
-
778
- it("returns instance anyway on failure to match with different path", async () => {
779
- listSpy.mockReturnValueOnce([DECONZ_CONBEE_II]);
780
-
781
- const adapter = await Adapter.create(
782
- {panID: 0x1a62, channelList: [11]},
783
- {adapter: "deconz", path: "/dev/ttyUSB0"},
784
- "test.db.backup",
785
- {
786
- disableLED: false,
787
- },
788
- );
789
-
790
- expect(adapter).toBeInstanceOf(DeconzAdapter);
791
- // @ts-expect-error protected
792
- expect(adapter.serialPortOptions).toStrictEqual({
793
- path: "/dev/ttyUSB0",
794
- adapter: "deconz",
795
- });
796
- });
797
-
798
- it("returns instance anyway on failure to get SerialPort.list", async () => {
799
- listSpy.mockRejectedValueOnce(new Error("spawn udevadm ENOENT"));
800
-
801
- const adapter = await Adapter.create(
802
- {panID: 0x1a62, channelList: [11]},
803
- {adapter: "zstack", path: ZSTACK_CC2538.path},
804
- "test.db.backup",
805
- {disableLED: false},
806
- );
807
-
808
- expect(adapter).toBeInstanceOf(ZStackAdapter);
809
- // @ts-expect-error protected
810
- expect(adapter.serialPortOptions).toStrictEqual({
811
- path: ZSTACK_CC2538.path,
812
- adapter: "zstack",
813
- });
814
- });
815
-
816
- it("throws on failure to match invalid adapter", async () => {
817
- listSpy.mockReturnValueOnce([]);
818
-
819
- await expect(
820
- Adapter.create(
821
- {panID: 0x1a62, channelList: [11]},
822
- // @ts-expect-error invalid on purpose
823
- {adapter: "invalid", path: "dev/ttyUSB0"},
824
- "test.db.backup",
825
- {disableLED: false},
826
- ),
827
- ).rejects.toThrow(`Adapter 'invalid' does not exists, possible options: zstack, ember, deconz, zigate, zboss, zoh, ezsp`);
828
- });
829
- });
830
-
831
- describe("with adapter only config", () => {
832
- it("detects each adapter", async () => {
833
- listSpy.mockReturnValueOnce([DECONZ_CONBEE_II]);
834
-
835
- let adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {adapter: "deconz"}, "test.db.backup", {disableLED: false});
836
-
837
- expect(adapter).toBeInstanceOf(DeconzAdapter);
838
- // @ts-expect-error protected
839
- expect(adapter.serialPortOptions).toStrictEqual({
840
- path: DECONZ_CONBEE_II.path,
841
- adapter: "deconz",
842
- });
843
-
844
- listSpy.mockReturnValueOnce([EMBER_ZBDONGLE_E]);
845
-
846
- adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {adapter: "ember"}, "test.db.backup", {disableLED: false});
847
-
848
- expect(adapter).toBeInstanceOf(EmberAdapter);
849
- // @ts-expect-error protected
850
- expect(adapter.serialPortOptions).toStrictEqual({
851
- path: EMBER_ZBDONGLE_E.path,
852
- adapter: "ember",
853
- });
854
-
855
- listSpy.mockReturnValueOnce([EMBER_ZBDONGLE_E]);
856
-
857
- adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {adapter: "ezsp"}, "test.db.backup", {disableLED: false});
858
-
859
- expect(adapter).toBeInstanceOf(EZSPAdapter);
860
- // @ts-expect-error protected
861
- expect(adapter.serialPortOptions).toStrictEqual({
862
- path: EMBER_ZBDONGLE_E.path,
863
- adapter: "ezsp",
864
- });
865
-
866
- listSpy.mockReturnValueOnce([ZSTACK_CC2538]);
867
-
868
- adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {adapter: "zstack"}, "test.db.backup", {disableLED: false});
869
-
870
- expect(adapter).toBeInstanceOf(ZStackAdapter);
871
- // @ts-expect-error protected
872
- expect(adapter.serialPortOptions).toStrictEqual({
873
- path: ZSTACK_CC2538.path,
874
- adapter: "zstack",
875
- });
876
-
877
- listSpy.mockReturnValueOnce([ZBOSS_NORDIC]);
878
-
879
- adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {adapter: "zboss"}, "test.db.backup", {disableLED: false});
880
-
881
- expect(adapter).toBeInstanceOf(ZBOSSAdapter);
882
- // @ts-expect-error protected
883
- expect(adapter.serialPortOptions).toStrictEqual({
884
- path: ZBOSS_NORDIC.path,
885
- adapter: "zboss",
886
- });
887
-
888
- listSpy.mockReturnValueOnce([ZIGATE_PLUSV2]);
889
-
890
- adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {adapter: "zigate"}, "test.db.backup", {disableLED: false});
891
-
892
- expect(adapter).toBeInstanceOf(ZiGateAdapter);
893
- // @ts-expect-error protected
894
- expect(adapter.serialPortOptions).toStrictEqual({
895
- path: ZIGATE_PLUSV2.path,
896
- adapter: "zigate",
897
- });
898
- });
899
-
900
- it("detects with multiple adapters connected", async () => {
901
- listSpy.mockReturnValueOnce([DECONZ_CONBEE_II, ZSTACK_CC2538, EMBER_ZBDONGLE_E]);
902
-
903
- const adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {adapter: "zstack"}, "test.db.backup", {disableLED: false});
904
-
905
- expect(adapter).toBeInstanceOf(ZStackAdapter);
906
- // @ts-expect-error protected
907
- expect(adapter.serialPortOptions).toStrictEqual({
908
- path: ZSTACK_CC2538.path,
909
- adapter: "zstack",
910
- });
911
- });
912
-
913
- it("detects with pnpId instead of path", async () => {
914
- listSpy.mockReturnValueOnce([{...ZBOSS_NORDIC, path: "/dev/ttyUSB0", pnpId: "usb-ZEPHYR_Zigbee_NCP_54ACCFAFA6DADC49-if00"}]);
915
-
916
- const adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {adapter: "zboss"}, "test.db.backup", {
917
- disableLED: false,
918
- });
919
-
920
- expect(adapter).toBeInstanceOf(ZBOSSAdapter);
921
- // @ts-expect-error protected
922
- expect(adapter.serialPortOptions).toStrictEqual({
923
- path: "/dev/ttyUSB0",
924
- adapter: "zboss",
925
- });
926
- });
927
-
928
- it("throws on failure to detect with conflict vendor+product IDs", async () => {
929
- listSpy.mockReturnValueOnce([{...EMBER_SKYCONNECT, path: "/dev/ttyACM0", manufacturer: undefined}]);
930
-
931
- await expect(
932
- Adapter.create({panID: 0x1a62, channelList: [11]}, {adapter: "zstack"}, "test.db.backup", {disableLED: false}),
933
- ).rejects.toThrow(
934
- `USB adapter discovery error (No valid USB adapter found). Specify valid 'adapter' and 'port' in your configuration.`,
935
- );
936
- });
937
- });
938
-
939
- describe("with path only config", () => {
940
- it("detects each adapter", async () => {
941
- listSpy.mockReturnValueOnce([DECONZ_CONBEE_II]);
942
-
943
- let adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {path: DECONZ_CONBEE_II.path}, "test.db.backup", {
944
- disableLED: false,
945
- });
946
-
947
- expect(adapter).toBeInstanceOf(DeconzAdapter);
948
- // @ts-expect-error protected
949
- expect(adapter.serialPortOptions).toStrictEqual({
950
- path: DECONZ_CONBEE_II.path,
951
- adapter: "deconz",
952
- });
953
-
954
- listSpy.mockReturnValueOnce([EMBER_ZBDONGLE_E]);
955
-
956
- adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {path: EMBER_ZBDONGLE_E.path}, "test.db.backup", {
957
- disableLED: false,
958
- });
959
-
960
- expect(adapter).toBeInstanceOf(EmberAdapter);
961
- // @ts-expect-error protected
962
- expect(adapter.serialPortOptions).toStrictEqual({
963
- path: EMBER_ZBDONGLE_E.path,
964
- adapter: "ember",
965
- });
966
-
967
- listSpy.mockReturnValueOnce([ZSTACK_CC2538]);
968
-
969
- adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {path: ZSTACK_CC2538.path}, "test.db.backup", {
970
- disableLED: false,
971
- });
972
-
973
- expect(adapter).toBeInstanceOf(ZStackAdapter);
974
- // @ts-expect-error protected
975
- expect(adapter.serialPortOptions).toStrictEqual({
976
- path: ZSTACK_CC2538.path,
977
- adapter: "zstack",
978
- });
979
-
980
- listSpy.mockReturnValueOnce([ZBOSS_NORDIC]);
981
-
982
- adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {path: ZBOSS_NORDIC.path}, "test.db.backup", {
983
- disableLED: false,
984
- });
985
-
986
- expect(adapter).toBeInstanceOf(ZBOSSAdapter);
987
- // @ts-expect-error protected
988
- expect(adapter.serialPortOptions).toStrictEqual({
989
- path: ZBOSS_NORDIC.path,
990
- adapter: "zboss",
991
- });
992
-
993
- listSpy.mockReturnValueOnce([ZIGATE_PLUSV2]);
994
-
995
- adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {path: ZIGATE_PLUSV2.path}, "test.db.backup", {
996
- disableLED: false,
997
- });
998
-
999
- expect(adapter).toBeInstanceOf(ZiGateAdapter);
1000
- // @ts-expect-error protected
1001
- expect(adapter.serialPortOptions).toStrictEqual({
1002
- path: ZIGATE_PLUSV2.path,
1003
- adapter: "zigate",
1004
- });
1005
- });
1006
-
1007
- it("detects with multiple adapters connected", async () => {
1008
- listSpy.mockReturnValueOnce([DECONZ_CONBEE_II, ZSTACK_CC2538, EMBER_ZBDONGLE_E]);
1009
-
1010
- const adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {path: ZSTACK_CC2538.path}, "test.db.backup", {
1011
- disableLED: false,
1012
- });
1013
-
1014
- expect(adapter).toBeInstanceOf(ZStackAdapter);
1015
- // @ts-expect-error protected
1016
- expect(adapter.serialPortOptions).toStrictEqual({
1017
- path: ZSTACK_CC2538.path,
1018
- adapter: "zstack",
1019
- });
1020
- });
1021
-
1022
- it("detects with pnpId instead of path", async () => {
1023
- listSpy.mockReturnValueOnce([{...ZBOSS_NORDIC, path: "/dev/ttyUSB0", pnpId: "usb-ZEPHYR_Zigbee_NCP_54ACCFAFA6DADC49-if00"}]);
1024
-
1025
- const adapter = await Adapter.create({panID: 0x1a62, channelList: [11]}, {path: "/dev/ttyUSB0"}, "test.db.backup", {
1026
- disableLED: false,
1027
- });
1028
-
1029
- expect(adapter).toBeInstanceOf(ZBOSSAdapter);
1030
- // @ts-expect-error protected
1031
- expect(adapter.serialPortOptions).toStrictEqual({
1032
- path: "/dev/ttyUSB0",
1033
- adapter: "zboss",
1034
- });
1035
- });
1036
-
1037
- it("throws on failure to match with different path", async () => {
1038
- listSpy.mockReturnValueOnce([DECONZ_CONBEE_II]);
1039
-
1040
- await expect(
1041
- Adapter.create({panID: 0x1a62, channelList: [11]}, {path: "/dev/ttyUSB0"}, "test.db.backup", {disableLED: false}),
1042
- ).rejects.toThrow(
1043
- `USB adapter discovery error (No valid USB adapter found). Specify valid 'adapter' and 'port' in your configuration.`,
1044
- );
1045
- });
1046
- });
1047
-
1048
- it("throws on failure to match when port info too limited", async () => {
1049
- listSpy.mockReturnValueOnce([{...DECONZ_CONBEE_II, vendorId: undefined}]);
1050
-
1051
- await expect(Adapter.create({panID: 0x1a62, channelList: [11]}, {}, "test.db.backup", {disableLED: false})).rejects.toThrow(
1052
- `USB adapter discovery error (No valid USB adapter found). Specify valid 'adapter' and 'port' in your configuration.`,
1053
- );
1054
-
1055
- listSpy.mockReturnValueOnce([{...DECONZ_CONBEE_II, productId: undefined}]);
1056
-
1057
- await expect(Adapter.create({panID: 0x1a62, channelList: [11]}, {}, "test.db.backup", {disableLED: false})).rejects.toThrow(
1058
- `USB adapter discovery error (No valid USB adapter found). Specify valid 'adapter' and 'port' in your configuration.`,
1059
- );
1060
- });
1061
- });
1062
- });