zigbee-herdsman 10.0.2 → 10.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 (46) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/controller/controller.d.ts.map +1 -1
  3. package/dist/controller/controller.js +6 -1
  4. package/dist/controller/controller.js.map +1 -1
  5. package/dist/controller/model/device.d.ts +1 -1
  6. package/dist/controller/model/device.d.ts.map +1 -1
  7. package/dist/controller/model/device.js +76 -60
  8. package/dist/controller/model/device.js.map +1 -1
  9. package/dist/controller/model/endpoint.d.ts +3 -2
  10. package/dist/controller/model/endpoint.d.ts.map +1 -1
  11. package/dist/controller/model/endpoint.js.map +1 -1
  12. package/dist/zspec/zcl/buffaloZcl.d.ts +3 -3
  13. package/dist/zspec/zcl/buffaloZcl.d.ts.map +1 -1
  14. package/dist/zspec/zcl/buffaloZcl.js.map +1 -1
  15. package/dist/zspec/zcl/definition/cluster.d.ts.map +1 -1
  16. package/dist/zspec/zcl/definition/cluster.js +0 -656
  17. package/dist/zspec/zcl/definition/cluster.js.map +1 -1
  18. package/dist/zspec/zcl/definition/clusters-types.d.ts +25 -412
  19. package/dist/zspec/zcl/definition/clusters-types.d.ts.map +1 -1
  20. package/dist/zspec/zcl/definition/enums.d.ts +0 -1
  21. package/dist/zspec/zcl/definition/enums.d.ts.map +1 -1
  22. package/dist/zspec/zcl/definition/enums.js +0 -1
  23. package/dist/zspec/zcl/definition/enums.js.map +1 -1
  24. package/dist/zspec/zcl/definition/foundation.d.ts +306 -7
  25. package/dist/zspec/zcl/definition/foundation.d.ts.map +1 -1
  26. package/dist/zspec/zcl/definition/foundation.js +552 -207
  27. package/dist/zspec/zcl/definition/foundation.js.map +1 -1
  28. package/dist/zspec/zcl/definition/status.d.ts +21 -10
  29. package/dist/zspec/zcl/definition/status.d.ts.map +1 -1
  30. package/dist/zspec/zcl/definition/status.js +11 -0
  31. package/dist/zspec/zcl/definition/status.js.map +1 -1
  32. package/dist/zspec/zcl/definition/tstype.d.ts +2 -5
  33. package/dist/zspec/zcl/definition/tstype.d.ts.map +1 -1
  34. package/dist/zspec/zcl/utils.d.ts +4 -4
  35. package/dist/zspec/zcl/utils.d.ts.map +1 -1
  36. package/dist/zspec/zcl/utils.js +54 -104
  37. package/dist/zspec/zcl/utils.js.map +1 -1
  38. package/dist/zspec/zcl/zclFrame.d.ts +4 -4
  39. package/dist/zspec/zcl/zclFrame.d.ts.map +1 -1
  40. package/dist/zspec/zcl/zclFrame.js +11 -95
  41. package/dist/zspec/zcl/zclFrame.js.map +1 -1
  42. package/dist/zspec/zcl/zclStatusError.d.ts +1 -1
  43. package/dist/zspec/zcl/zclStatusError.d.ts.map +1 -1
  44. package/dist/zspec/zcl/zclStatusError.js +2 -2
  45. package/dist/zspec/zcl/zclStatusError.js.map +1 -1
  46. package/package.json +1 -1
@@ -1,312 +1,657 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Foundation = void 0;
4
+ const utils_1 = require("../utils");
5
+ const zclStatusError_1 = require("../zclStatusError");
4
6
  const enums_1 = require("./enums");
5
7
  const status_1 = require("./status");
6
8
  exports.Foundation = {
7
9
  /** Read Attributes */
8
10
  read: {
11
+ name: "read",
9
12
  ID: 0x00,
10
- parseStrategy: "repetitive",
11
- parameters: [{ name: "attrId", type: enums_1.DataType.DATA16 }],
12
13
  response: 0x01, // readRsp
14
+ parse(buffalo) {
15
+ const payload = [];
16
+ do {
17
+ const attrId = buffalo.readUInt16();
18
+ payload.push({ attrId });
19
+ } while (buffalo.isMore());
20
+ return payload;
21
+ },
22
+ write(buffalo, payload) {
23
+ if (!Array.isArray(payload)) {
24
+ throw new zclStatusError_1.ZclStatusError(status_1.Status.MALFORMED_COMMAND);
25
+ }
26
+ for (const entry of payload) {
27
+ buffalo.writeUInt16(entry.attrId);
28
+ }
29
+ },
13
30
  },
14
31
  /** Read Attributes Response */
15
32
  readRsp: {
33
+ name: "readRsp",
16
34
  ID: 0x01,
17
- parseStrategy: "repetitive",
18
- parameters: [
19
- { name: "attrId", type: enums_1.DataType.DATA16 },
20
- { name: "status", type: enums_1.DataType.DATA8 },
21
- { name: "dataType", type: enums_1.DataType.DATA8, conditions: [{ type: enums_1.ParameterCondition.FIELD_EQUAL, field: "status", value: status_1.Status.SUCCESS }] },
22
- {
23
- name: "attrData",
24
- type: enums_1.BuffaloZclDataType.USE_DATA_TYPE,
25
- conditions: [{ type: enums_1.ParameterCondition.FIELD_EQUAL, field: "status", value: status_1.Status.SUCCESS }],
26
- },
27
- ],
35
+ parse(buffalo) {
36
+ const payload = [];
37
+ do {
38
+ const attrId = buffalo.readUInt16();
39
+ const status = buffalo.readUInt8();
40
+ const rec = { attrId, status };
41
+ if (status === status_1.Status.SUCCESS) {
42
+ const dataType = buffalo.readUInt8();
43
+ rec.dataType = dataType;
44
+ // [workaround] parse char str as Xiaomi struct for attribute 0xff01 (65281)
45
+ rec.attrData = buffalo.read(attrId === 0xff01 && dataType === enums_1.DataType.CHAR_STR ? enums_1.BuffaloZclDataType.MI_STRUCT : dataType, {});
46
+ }
47
+ payload.push(rec);
48
+ } while (buffalo.isMore());
49
+ return payload;
50
+ },
51
+ write(buffalo, payload) {
52
+ if (!Array.isArray(payload)) {
53
+ throw new zclStatusError_1.ZclStatusError(status_1.Status.MALFORMED_COMMAND);
54
+ }
55
+ for (const entry of payload) {
56
+ buffalo.writeUInt16(entry.attrId);
57
+ buffalo.writeUInt8(entry.status);
58
+ if (entry.status === status_1.Status.SUCCESS) {
59
+ buffalo.writeUInt8(entry.dataType);
60
+ buffalo.write(entry.dataType, entry.attrData, {});
61
+ }
62
+ }
63
+ },
28
64
  },
29
65
  /** Write Attributes */
30
66
  write: {
67
+ name: "write",
31
68
  ID: 0x02,
32
- parseStrategy: "repetitive",
33
- parameters: [
34
- { name: "attrId", type: enums_1.DataType.DATA16 },
35
- { name: "dataType", type: enums_1.DataType.DATA8 },
36
- { name: "attrData", type: enums_1.BuffaloZclDataType.USE_DATA_TYPE },
37
- ],
38
69
  response: 0x04, // writeRsp
70
+ parse(buffalo) {
71
+ const payload = [];
72
+ do {
73
+ const attrId = buffalo.readUInt16();
74
+ const dataType = buffalo.readUInt8();
75
+ const attrData = buffalo.read(dataType, {});
76
+ payload.push({ attrId, dataType, attrData });
77
+ } while (buffalo.isMore());
78
+ return payload;
79
+ },
80
+ write(buffalo, payload) {
81
+ if (!Array.isArray(payload)) {
82
+ throw new zclStatusError_1.ZclStatusError(status_1.Status.MALFORMED_COMMAND);
83
+ }
84
+ for (const entry of payload) {
85
+ buffalo.writeUInt16(entry.attrId);
86
+ buffalo.writeUInt8(entry.dataType);
87
+ buffalo.write(entry.dataType, entry.attrData, {});
88
+ }
89
+ },
39
90
  },
40
91
  /** Write Attributes Undivided */
41
92
  writeUndiv: {
93
+ name: "writeUndiv",
42
94
  ID: 0x03,
43
- parseStrategy: "repetitive",
44
- parameters: [
45
- { name: "attrId", type: enums_1.DataType.DATA16 },
46
- { name: "dataType", type: enums_1.DataType.DATA8 },
47
- { name: "attrData", type: enums_1.BuffaloZclDataType.USE_DATA_TYPE },
48
- ],
95
+ parse(buffalo) {
96
+ const payload = [];
97
+ do {
98
+ const attrId = buffalo.readUInt16();
99
+ const dataType = buffalo.readUInt8();
100
+ const attrData = buffalo.read(dataType, {});
101
+ payload.push({ attrId, dataType, attrData });
102
+ } while (buffalo.isMore());
103
+ return payload;
104
+ },
105
+ write(buffalo, payload) {
106
+ if (!Array.isArray(payload)) {
107
+ throw new zclStatusError_1.ZclStatusError(status_1.Status.MALFORMED_COMMAND);
108
+ }
109
+ for (const entry of payload) {
110
+ buffalo.writeUInt16(entry.attrId);
111
+ buffalo.writeUInt8(entry.dataType);
112
+ buffalo.write(entry.dataType, entry.attrData, {});
113
+ }
114
+ },
49
115
  },
50
116
  /** Write Attributes Response */
51
117
  writeRsp: {
118
+ name: "writeRsp",
52
119
  ID: 0x04,
53
- parseStrategy: "repetitive",
54
- parameters: [
55
- { name: "status", type: enums_1.DataType.ENUM8 },
56
- {
57
- name: "attrId",
58
- type: enums_1.DataType.DATA16,
59
- conditions: [{ type: enums_1.ParameterCondition.FIELD_EQUAL, field: "status", reversed: true, value: status_1.Status.SUCCESS }],
60
- },
61
- ],
120
+ /**
121
+ * Note that write attribute status records are not included for successfully written attributes, to save bandwidth.
122
+ * In the case of successful writing of all attributes, only a single write attribute status record SHALL be included in the command,
123
+ * with the status field set to SUCCESS and the attribute identifier field omitted.
124
+ */
125
+ parse(buffalo) {
126
+ const firstStatus = buffalo.readUInt8();
127
+ if (firstStatus === status_1.Status.SUCCESS) {
128
+ return [{ status: firstStatus }];
129
+ }
130
+ const payload = [];
131
+ const attrId = buffalo.readUInt16();
132
+ payload.push({ status: firstStatus, attrId });
133
+ while (buffalo.isMore()) {
134
+ const status = buffalo.readUInt8();
135
+ const attrId = buffalo.readUInt16();
136
+ payload.push({ status, attrId });
137
+ }
138
+ return payload;
139
+ },
140
+ write(buffalo, payload) {
141
+ if (!Array.isArray(payload)) {
142
+ throw new zclStatusError_1.ZclStatusError(status_1.Status.MALFORMED_COMMAND);
143
+ }
144
+ const nonSuccessPayload = payload.filter((entry) => entry.status !== status_1.Status.SUCCESS);
145
+ if (nonSuccessPayload.length === 0) {
146
+ buffalo.writeUInt8(status_1.Status.SUCCESS);
147
+ }
148
+ else {
149
+ for (const entry of nonSuccessPayload) {
150
+ buffalo.writeUInt8(entry.status);
151
+ buffalo.writeUInt16(entry.attrId);
152
+ }
153
+ }
154
+ },
62
155
  },
63
156
  /** Write Attributes No Response */
64
157
  writeNoRsp: {
158
+ name: "writeNoRsp",
65
159
  ID: 0x05,
66
- parseStrategy: "repetitive",
67
- parameters: [
68
- { name: "attrId", type: enums_1.DataType.DATA16 },
69
- { name: "dataType", type: enums_1.DataType.DATA8 },
70
- { name: "attrData", type: enums_1.BuffaloZclDataType.USE_DATA_TYPE },
71
- ],
160
+ parse(buffalo) {
161
+ const payload = [];
162
+ do {
163
+ const attrId = buffalo.readUInt16();
164
+ const dataType = buffalo.readUInt8();
165
+ const attrData = buffalo.read(dataType, {});
166
+ payload.push({ attrId, dataType, attrData });
167
+ } while (buffalo.isMore());
168
+ return payload;
169
+ },
170
+ write(buffalo, payload) {
171
+ if (!Array.isArray(payload)) {
172
+ throw new zclStatusError_1.ZclStatusError(status_1.Status.MALFORMED_COMMAND);
173
+ }
174
+ for (const entry of payload) {
175
+ buffalo.writeUInt16(entry.attrId);
176
+ buffalo.writeUInt8(entry.dataType);
177
+ buffalo.write(entry.dataType, entry.attrData, {});
178
+ }
179
+ },
72
180
  },
73
181
  /** Configure Reporting */
74
182
  configReport: {
183
+ name: "configReport",
75
184
  ID: 0x06,
76
- parseStrategy: "repetitive",
77
- parameters: [
78
- { name: "direction", type: enums_1.DataType.DATA8 },
79
- { name: "attrId", type: enums_1.DataType.DATA16 },
80
- {
81
- name: "dataType",
82
- type: enums_1.DataType.DATA8,
83
- conditions: [{ type: enums_1.ParameterCondition.FIELD_EQUAL, field: "direction", value: enums_1.Direction.CLIENT_TO_SERVER }],
84
- },
85
- {
86
- name: "minRepIntval",
87
- type: enums_1.DataType.DATA16,
88
- conditions: [{ type: enums_1.ParameterCondition.FIELD_EQUAL, field: "direction", value: enums_1.Direction.CLIENT_TO_SERVER }],
89
- },
90
- {
91
- name: "maxRepIntval",
92
- type: enums_1.DataType.DATA16,
93
- conditions: [{ type: enums_1.ParameterCondition.FIELD_EQUAL, field: "direction", value: enums_1.Direction.CLIENT_TO_SERVER }],
94
- },
95
- {
96
- name: "repChange",
97
- type: enums_1.BuffaloZclDataType.USE_DATA_TYPE,
98
- conditions: [
99
- { type: enums_1.ParameterCondition.FIELD_EQUAL, field: "direction", value: enums_1.Direction.CLIENT_TO_SERVER },
100
- { type: enums_1.ParameterCondition.DATA_TYPE_CLASS_EQUAL, value: enums_1.DataTypeClass.ANALOG },
101
- ],
102
- },
103
- {
104
- name: "timeout",
105
- type: enums_1.DataType.DATA16,
106
- conditions: [{ type: enums_1.ParameterCondition.FIELD_EQUAL, field: "direction", value: enums_1.Direction.SERVER_TO_CLIENT }],
107
- },
108
- ],
109
185
  response: 0x07, // configReportRsp
186
+ parse(buffalo) {
187
+ const payload = [];
188
+ do {
189
+ const direction = buffalo.readUInt8();
190
+ const attrId = buffalo.readUInt16();
191
+ const rec = { direction, attrId };
192
+ if (direction === enums_1.Direction.CLIENT_TO_SERVER) {
193
+ const dataType = buffalo.readUInt8();
194
+ rec.dataType = dataType;
195
+ rec.minRepIntval = buffalo.readUInt16();
196
+ rec.maxRepIntval = buffalo.readUInt16();
197
+ if ((0, utils_1.isAnalogDataType)(dataType)) {
198
+ rec.repChange = buffalo.read(dataType, {});
199
+ }
200
+ }
201
+ else if (direction === enums_1.Direction.SERVER_TO_CLIENT) {
202
+ rec.timeout = buffalo.readUInt16();
203
+ }
204
+ payload.push(rec);
205
+ } while (buffalo.isMore());
206
+ return payload;
207
+ },
208
+ write(buffalo, payload) {
209
+ if (!Array.isArray(payload)) {
210
+ throw new zclStatusError_1.ZclStatusError(status_1.Status.MALFORMED_COMMAND);
211
+ }
212
+ for (const entry of payload) {
213
+ buffalo.writeUInt8(entry.direction);
214
+ buffalo.writeUInt16(entry.attrId);
215
+ if (entry.direction === enums_1.Direction.CLIENT_TO_SERVER) {
216
+ buffalo.writeUInt8(entry.dataType);
217
+ buffalo.writeUInt16(entry.minRepIntval);
218
+ buffalo.writeUInt16(entry.maxRepIntval);
219
+ if ((0, utils_1.isAnalogDataType)(entry.dataType)) {
220
+ buffalo.write(entry.dataType, entry.repChange, {});
221
+ }
222
+ }
223
+ else if (entry.direction === enums_1.Direction.SERVER_TO_CLIENT) {
224
+ buffalo.writeUInt16(entry.timeout);
225
+ }
226
+ }
227
+ },
110
228
  },
111
229
  /** Configure Reporting Response */
112
230
  configReportRsp: {
231
+ name: "configReportRsp",
113
232
  ID: 0x07,
114
- parseStrategy: "repetitive",
115
- parameters: [
116
- { name: "status", type: enums_1.DataType.ENUM8 },
117
- // minimumRemainingBufferBytes: if direction is present, attrId is also present
118
- // https://github.com/Koenkk/zigbee-herdsman/pull/115
119
- { name: "direction", type: enums_1.DataType.DATA8, conditions: [{ type: enums_1.ParameterCondition.MINIMUM_REMAINING_BUFFER_BYTES, value: 3 }] },
120
- { name: "attrId", type: enums_1.DataType.DATA16, conditions: [{ type: enums_1.ParameterCondition.MINIMUM_REMAINING_BUFFER_BYTES, value: 2 }] },
121
- ],
233
+ /**
234
+ * Note that attribute status records are not included for successfully configured attributes, to save bandwidth.
235
+ * In the case of successful configuration of all attributes, only a single attribute status record SHALL be included in the command,
236
+ * with the status field set to SUCCESS and the direction and attribute identifier fields omitted.
237
+ */
238
+ parse(buffalo) {
239
+ const firstStatus = buffalo.readUInt8();
240
+ if (firstStatus === status_1.Status.SUCCESS) {
241
+ return [{ status: firstStatus }];
242
+ }
243
+ const payload = [];
244
+ const direction = buffalo.readUInt8();
245
+ const attrId = buffalo.readUInt16();
246
+ payload.push({ status: firstStatus, direction, attrId });
247
+ while (buffalo.isMore()) {
248
+ const status = buffalo.readUInt8();
249
+ const direction = buffalo.readUInt8();
250
+ const attrId = buffalo.readUInt16();
251
+ payload.push({ status, direction, attrId });
252
+ }
253
+ return payload;
254
+ },
255
+ write(buffalo, payload) {
256
+ if (!Array.isArray(payload)) {
257
+ throw new zclStatusError_1.ZclStatusError(status_1.Status.MALFORMED_COMMAND);
258
+ }
259
+ const nonSuccessPayload = payload.filter((entry) => entry.status !== status_1.Status.SUCCESS);
260
+ if (nonSuccessPayload.length === 0) {
261
+ buffalo.writeUInt8(status_1.Status.SUCCESS);
262
+ }
263
+ else {
264
+ for (const entry of nonSuccessPayload) {
265
+ buffalo.writeUInt8(entry.status);
266
+ buffalo.writeUInt8(entry.direction);
267
+ buffalo.writeUInt16(entry.attrId);
268
+ }
269
+ }
270
+ },
122
271
  },
123
272
  /** Read Reporting Configuration */
124
273
  readReportConfig: {
274
+ name: "readReportConfig",
125
275
  ID: 0x08,
126
- parseStrategy: "repetitive",
127
- parameters: [
128
- { name: "direction", type: enums_1.DataType.DATA8 },
129
- { name: "attrId", type: enums_1.DataType.DATA16 },
130
- ],
131
276
  response: 0x09, // readReportConfigRsp
277
+ parse(buffalo) {
278
+ const payload = [];
279
+ do {
280
+ const direction = buffalo.readUInt8();
281
+ const attrId = buffalo.readUInt16();
282
+ payload.push({ direction, attrId });
283
+ } while (buffalo.isMore());
284
+ return payload;
285
+ },
286
+ write(buffalo, payload) {
287
+ if (!Array.isArray(payload)) {
288
+ throw new zclStatusError_1.ZclStatusError(status_1.Status.MALFORMED_COMMAND);
289
+ }
290
+ for (const entry of payload) {
291
+ buffalo.writeUInt8(entry.direction);
292
+ buffalo.writeUInt16(entry.attrId);
293
+ }
294
+ },
132
295
  },
133
296
  /** Read Reporting Configuration Response */
134
297
  readReportConfigRsp: {
298
+ name: "readReportConfigRsp",
135
299
  ID: 0x09,
136
- parseStrategy: "repetitive",
137
- parameters: [
138
- { name: "status", type: enums_1.DataType.ENUM8 },
139
- { name: "direction", type: enums_1.DataType.DATA8 },
140
- { name: "attrId", type: enums_1.DataType.DATA16 },
141
- {
142
- name: "dataType",
143
- type: enums_1.DataType.DATA8,
144
- conditions: [
145
- { type: enums_1.ParameterCondition.FIELD_EQUAL, field: "status", value: status_1.Status.SUCCESS },
146
- { type: enums_1.ParameterCondition.FIELD_EQUAL, field: "direction", value: enums_1.Direction.CLIENT_TO_SERVER },
147
- ],
148
- },
149
- {
150
- name: "minRepIntval",
151
- type: enums_1.DataType.DATA16,
152
- conditions: [
153
- { type: enums_1.ParameterCondition.FIELD_EQUAL, field: "status", value: status_1.Status.SUCCESS },
154
- { type: enums_1.ParameterCondition.FIELD_EQUAL, field: "direction", value: enums_1.Direction.CLIENT_TO_SERVER },
155
- ],
156
- },
157
- {
158
- name: "maxRepIntval",
159
- type: enums_1.DataType.DATA16,
160
- conditions: [
161
- { type: enums_1.ParameterCondition.FIELD_EQUAL, field: "status", value: status_1.Status.SUCCESS },
162
- { type: enums_1.ParameterCondition.FIELD_EQUAL, field: "direction", value: enums_1.Direction.CLIENT_TO_SERVER },
163
- ],
164
- },
165
- {
166
- name: "repChange",
167
- type: enums_1.BuffaloZclDataType.USE_DATA_TYPE,
168
- conditions: [
169
- { type: enums_1.ParameterCondition.FIELD_EQUAL, field: "status", value: status_1.Status.SUCCESS },
170
- { type: enums_1.ParameterCondition.FIELD_EQUAL, field: "direction", value: enums_1.Direction.CLIENT_TO_SERVER },
171
- { type: enums_1.ParameterCondition.DATA_TYPE_CLASS_EQUAL, value: enums_1.DataTypeClass.ANALOG },
172
- ],
173
- },
174
- {
175
- name: "timeout",
176
- type: enums_1.DataType.DATA16,
177
- conditions: [
178
- { type: enums_1.ParameterCondition.FIELD_EQUAL, field: "status", value: status_1.Status.SUCCESS },
179
- { type: enums_1.ParameterCondition.FIELD_EQUAL, field: "direction", value: enums_1.Direction.SERVER_TO_CLIENT },
180
- ],
181
- },
182
- ],
300
+ parse(buffalo) {
301
+ const payload = [];
302
+ do {
303
+ const status = buffalo.readUInt8();
304
+ const direction = buffalo.readUInt8();
305
+ const attrId = buffalo.readUInt16();
306
+ const rec = { status, direction, attrId };
307
+ if (status === status_1.Status.SUCCESS) {
308
+ if (direction === enums_1.Direction.CLIENT_TO_SERVER) {
309
+ const dataType = buffalo.readUInt8();
310
+ rec.dataType = dataType;
311
+ rec.minRepIntval = buffalo.readUInt16();
312
+ rec.maxRepIntval = buffalo.readUInt16();
313
+ if ((0, utils_1.isAnalogDataType)(dataType)) {
314
+ rec.repChange = buffalo.read(dataType, {});
315
+ }
316
+ }
317
+ else if (direction === enums_1.Direction.SERVER_TO_CLIENT) {
318
+ rec.timeout = buffalo.readUInt16();
319
+ }
320
+ }
321
+ payload.push(rec);
322
+ } while (buffalo.isMore());
323
+ return payload;
324
+ },
325
+ write(buffalo, payload) {
326
+ if (!Array.isArray(payload)) {
327
+ throw new zclStatusError_1.ZclStatusError(status_1.Status.MALFORMED_COMMAND);
328
+ }
329
+ for (const entry of payload) {
330
+ buffalo.writeUInt8(entry.status);
331
+ buffalo.writeUInt8(entry.direction);
332
+ buffalo.writeUInt16(entry.attrId);
333
+ if (entry.status === status_1.Status.SUCCESS) {
334
+ if (entry.direction === enums_1.Direction.CLIENT_TO_SERVER) {
335
+ buffalo.writeUInt8(entry.dataType);
336
+ buffalo.writeUInt16(entry.minRepIntval);
337
+ buffalo.writeUInt16(entry.maxRepIntval);
338
+ if ((0, utils_1.isAnalogDataType)(entry.dataType)) {
339
+ buffalo.write(entry.dataType, entry.repChange, {});
340
+ }
341
+ }
342
+ else if (entry.direction === enums_1.Direction.SERVER_TO_CLIENT) {
343
+ buffalo.writeUInt16(entry.timeout);
344
+ }
345
+ }
346
+ }
347
+ },
183
348
  },
184
349
  /** Report attributes */
185
350
  report: {
351
+ name: "report",
186
352
  ID: 0x0a,
187
- parseStrategy: "repetitive",
188
- parameters: [
189
- { name: "attrId", type: enums_1.DataType.DATA16 },
190
- { name: "dataType", type: enums_1.DataType.DATA8 },
191
- { name: "attrData", type: enums_1.BuffaloZclDataType.USE_DATA_TYPE },
192
- ],
353
+ parse(buffalo) {
354
+ const payload = [];
355
+ do {
356
+ const attrId = buffalo.readUInt16();
357
+ const dataType = buffalo.readUInt8();
358
+ // [workaround] parse char str as Xiaomi struct for attribute 0xff01 (65281)
359
+ const attrData = buffalo.read(attrId === 0xff01 && dataType === enums_1.DataType.CHAR_STR ? enums_1.BuffaloZclDataType.MI_STRUCT : dataType, {});
360
+ payload.push({ attrId, dataType, attrData });
361
+ } while (buffalo.isMore());
362
+ return payload;
363
+ },
364
+ write(buffalo, payload) {
365
+ if (!Array.isArray(payload)) {
366
+ throw new zclStatusError_1.ZclStatusError(status_1.Status.MALFORMED_COMMAND);
367
+ }
368
+ for (const entry of payload) {
369
+ buffalo.writeUInt16(entry.attrId);
370
+ buffalo.writeUInt8(entry.dataType);
371
+ buffalo.write(entry.dataType, entry.attrData, {});
372
+ }
373
+ },
193
374
  },
194
375
  /** Default Response */
195
376
  defaultRsp: {
377
+ name: "defaultRsp",
196
378
  ID: 0x0b,
197
- parseStrategy: "flat",
198
- parameters: [
199
- { name: "cmdId", type: enums_1.DataType.DATA8 },
200
- { name: "statusCode", type: enums_1.DataType.ENUM8 },
201
- ],
379
+ parse(buffalo) {
380
+ const cmdId = buffalo.readUInt8();
381
+ const statusCode = buffalo.readUInt8();
382
+ return { cmdId, statusCode };
383
+ },
384
+ write(buffalo, payload) {
385
+ if (Array.isArray(payload)) {
386
+ throw new zclStatusError_1.ZclStatusError(status_1.Status.MALFORMED_COMMAND);
387
+ }
388
+ buffalo.writeUInt8(payload.cmdId);
389
+ buffalo.writeUInt8(payload.statusCode);
390
+ },
202
391
  },
203
392
  /** Discover Attributes */
204
393
  discover: {
394
+ name: "discover",
205
395
  ID: 0x0c,
206
- parseStrategy: "flat",
207
- parameters: [
208
- { name: "startAttrId", type: enums_1.DataType.DATA16 },
209
- { name: "maxAttrIds", type: enums_1.DataType.DATA8 },
210
- ],
396
+ parse(buffalo) {
397
+ const startAttrId = buffalo.readUInt16();
398
+ const maxAttrIds = buffalo.readUInt8();
399
+ return { startAttrId, maxAttrIds };
400
+ },
401
+ write(buffalo, payload) {
402
+ if (Array.isArray(payload)) {
403
+ throw new zclStatusError_1.ZclStatusError(status_1.Status.MALFORMED_COMMAND);
404
+ }
405
+ buffalo.writeUInt16(payload.startAttrId);
406
+ buffalo.writeUInt8(payload.maxAttrIds);
407
+ },
211
408
  },
212
409
  /** Discover Attributes Response */
213
410
  discoverRsp: {
411
+ name: "discoverRsp",
214
412
  ID: 0x0d,
215
- parseStrategy: "oneof",
216
- parameters: [
217
- { name: "attrId", type: enums_1.DataType.DATA16 },
218
- { name: "dataType", type: enums_1.DataType.DATA8 },
219
- ],
413
+ parse(buffalo) {
414
+ const discComplete = buffalo.readUInt8();
415
+ const attrInfos = [];
416
+ const payload = { discComplete, attrInfos };
417
+ do {
418
+ const attrId = buffalo.readUInt16();
419
+ const dataType = buffalo.readUInt8();
420
+ attrInfos.push({ attrId, dataType });
421
+ } while (buffalo.isMore());
422
+ return payload;
423
+ },
424
+ write(buffalo, payload) {
425
+ if (Array.isArray(payload)) {
426
+ throw new zclStatusError_1.ZclStatusError(status_1.Status.MALFORMED_COMMAND);
427
+ }
428
+ buffalo.writeUInt8(payload.discComplete);
429
+ for (const entry of payload.attrInfos) {
430
+ buffalo.writeUInt16(entry.attrId);
431
+ buffalo.writeUInt8(entry.dataType);
432
+ }
433
+ },
220
434
  },
221
435
  /** Read Attributes Structured */
222
436
  readStructured: {
437
+ name: "readStructured",
223
438
  ID: 0x0e,
224
- parseStrategy: "repetitive",
225
- parameters: [
226
- { name: "attrId", type: enums_1.DataType.DATA16 },
227
- { name: "selector", type: enums_1.BuffaloZclDataType.STRUCTURED_SELECTOR },
228
- ],
439
+ parse(buffalo) {
440
+ const payload = [];
441
+ do {
442
+ const attrId = buffalo.readUInt16();
443
+ const selector = buffalo.readStructuredSelector();
444
+ payload.push({ attrId, selector });
445
+ } while (buffalo.isMore());
446
+ return payload;
447
+ },
448
+ write(buffalo, payload) {
449
+ if (!Array.isArray(payload)) {
450
+ throw new zclStatusError_1.ZclStatusError(status_1.Status.MALFORMED_COMMAND);
451
+ }
452
+ for (const entry of payload) {
453
+ buffalo.writeUInt16(entry.attrId);
454
+ buffalo.writeStructuredSelector(entry.selector);
455
+ }
456
+ },
229
457
  },
230
458
  /** Write Attributes Structured */
231
459
  writeStructured: {
460
+ name: "writeStructured",
232
461
  ID: 0x0f,
233
- parseStrategy: "repetitive",
234
- parameters: [
235
- { name: "attrId", type: enums_1.DataType.DATA16 },
236
- { name: "selector", type: enums_1.BuffaloZclDataType.STRUCTURED_SELECTOR },
237
- { name: "dataType", type: enums_1.DataType.DATA8 },
238
- { name: "elementData", type: enums_1.BuffaloZclDataType.USE_DATA_TYPE },
239
- ],
240
462
  response: 0x10, // writeStructuredRsp
463
+ parse(buffalo) {
464
+ const payload = [];
465
+ do {
466
+ const attrId = buffalo.readUInt16();
467
+ const selector = buffalo.readStructuredSelector();
468
+ const dataType = buffalo.readUInt8();
469
+ const elementData = buffalo.read(dataType, {});
470
+ payload.push({ attrId, selector, dataType, elementData });
471
+ } while (buffalo.isMore());
472
+ return payload;
473
+ },
474
+ write(buffalo, payload) {
475
+ if (!Array.isArray(payload)) {
476
+ throw new zclStatusError_1.ZclStatusError(status_1.Status.MALFORMED_COMMAND);
477
+ }
478
+ for (const entry of payload) {
479
+ buffalo.writeUInt16(entry.attrId);
480
+ buffalo.writeStructuredSelector(entry.selector);
481
+ buffalo.writeUInt8(entry.dataType);
482
+ buffalo.write(entry.dataType, entry.elementData, {});
483
+ }
484
+ },
241
485
  },
242
486
  /** Write Attributes Structured response */
243
487
  writeStructuredRsp: {
488
+ name: "writeStructuredRsp",
244
489
  ID: 0x10,
245
- parseStrategy: "repetitive",
246
- // contains only one SUCCESS record for all written attributes if all written successfully
247
- parameters: [
248
- { name: "status", type: enums_1.DataType.ENUM8 },
249
- {
250
- name: "attrId",
251
- type: enums_1.DataType.DATA16,
252
- conditions: [{ type: enums_1.ParameterCondition.FIELD_EQUAL, field: "status", reversed: true, value: status_1.Status.SUCCESS }],
253
- },
254
- // always one zero-octet if failed attribute not of type array or structure, otherwise can also be zero if no info on which element caused failure
255
- {
256
- name: "selector",
257
- type: enums_1.BuffaloZclDataType.STRUCTURED_SELECTOR,
258
- conditions: [{ type: enums_1.ParameterCondition.FIELD_EQUAL, field: "status", reversed: true, value: status_1.Status.SUCCESS }],
259
- },
260
- ],
490
+ /**
491
+ * Note that write attribute status records are not included for successfully written attributes, to save bandwidth.
492
+ * In the case of successful writing of all attributes, only a single write attribute status record SHALL be included in the command,
493
+ * with the status field set to SUCCESS and the attribute identifier and selector fields omitted.
494
+ */
495
+ parse(buffalo) {
496
+ const firstStatus = buffalo.readUInt8();
497
+ if (firstStatus === status_1.Status.SUCCESS) {
498
+ return [{ status: firstStatus }];
499
+ }
500
+ const payload = [];
501
+ const attrId = buffalo.readUInt16();
502
+ const selector = buffalo.readStructuredSelector();
503
+ payload.push({ status: firstStatus, attrId, selector });
504
+ while (buffalo.isMore()) {
505
+ const status = buffalo.readUInt8();
506
+ const attrId = buffalo.readUInt16();
507
+ const selector = buffalo.readStructuredSelector();
508
+ payload.push({ status, attrId, selector });
509
+ }
510
+ return payload;
511
+ },
512
+ write(buffalo, payload) {
513
+ if (!Array.isArray(payload)) {
514
+ throw new zclStatusError_1.ZclStatusError(status_1.Status.MALFORMED_COMMAND);
515
+ }
516
+ const nonSuccessPayload = payload.filter((entry) => entry.status !== status_1.Status.SUCCESS);
517
+ if (nonSuccessPayload.length === 0) {
518
+ buffalo.writeUInt8(status_1.Status.SUCCESS);
519
+ }
520
+ else {
521
+ for (const entry of nonSuccessPayload) {
522
+ buffalo.writeUInt8(entry.status);
523
+ buffalo.writeUInt16(entry.attrId);
524
+ buffalo.writeStructuredSelector(entry.selector);
525
+ }
526
+ }
527
+ },
261
528
  },
262
529
  /** Discover Commands Received */
263
530
  discoverCommands: {
531
+ name: "discoverCommands",
264
532
  ID: 0x11,
265
- parseStrategy: "flat",
266
- parameters: [
267
- { name: "startCmdId", type: enums_1.DataType.DATA8 },
268
- { name: "maxCmdIds", type: enums_1.DataType.DATA8 },
269
- ],
533
+ parse(buffalo) {
534
+ const startCmdId = buffalo.readUInt8();
535
+ const maxCmdIds = buffalo.readUInt8();
536
+ return { startCmdId, maxCmdIds };
537
+ },
538
+ write(buffalo, payload) {
539
+ if (Array.isArray(payload)) {
540
+ throw new zclStatusError_1.ZclStatusError(status_1.Status.MALFORMED_COMMAND);
541
+ }
542
+ buffalo.writeUInt8(payload.startCmdId);
543
+ buffalo.writeUInt8(payload.maxCmdIds);
544
+ },
270
545
  },
271
546
  /** Discover Commands Received Response */
272
547
  discoverCommandsRsp: {
548
+ name: "discoverCommandsRsp",
273
549
  ID: 0x12,
274
- parseStrategy: "oneof",
275
- parameters: [{ name: "cmdId", type: enums_1.DataType.DATA8 }],
550
+ parse(buffalo) {
551
+ const discComplete = buffalo.readUInt8();
552
+ const commandIds = [];
553
+ const payload = { discComplete, commandIds };
554
+ do {
555
+ const commandId = buffalo.readUInt8();
556
+ commandIds.push(commandId);
557
+ } while (buffalo.isMore());
558
+ return payload;
559
+ },
560
+ write(buffalo, payload) {
561
+ if (Array.isArray(payload)) {
562
+ throw new zclStatusError_1.ZclStatusError(status_1.Status.MALFORMED_COMMAND);
563
+ }
564
+ buffalo.writeUInt8(payload.discComplete);
565
+ for (const commandId of payload.commandIds) {
566
+ buffalo.writeUInt8(commandId);
567
+ }
568
+ },
276
569
  },
277
570
  /** Discover Commands Generated */
278
571
  discoverCommandsGen: {
572
+ name: "discoverCommandsGen",
279
573
  ID: 0x13,
280
- parseStrategy: "flat",
281
- parameters: [
282
- { name: "startCmdId", type: enums_1.DataType.DATA8 },
283
- { name: "maxCmdIds", type: enums_1.DataType.DATA8 },
284
- ],
574
+ parse(buffalo) {
575
+ const startCmdId = buffalo.readUInt8();
576
+ const maxCmdIds = buffalo.readUInt8();
577
+ return { startCmdId, maxCmdIds };
578
+ },
579
+ write(buffalo, payload) {
580
+ if (Array.isArray(payload)) {
581
+ throw new zclStatusError_1.ZclStatusError(status_1.Status.MALFORMED_COMMAND);
582
+ }
583
+ buffalo.writeUInt8(payload.startCmdId);
584
+ buffalo.writeUInt8(payload.maxCmdIds);
585
+ },
285
586
  },
286
587
  /** Discover Commands Generated Response */
287
588
  discoverCommandsGenRsp: {
589
+ name: "discoverCommandsGenRsp",
288
590
  ID: 0x14,
289
- parseStrategy: "oneof",
290
- parameters: [{ name: "cmdId", type: enums_1.DataType.DATA8 }],
591
+ parse(buffalo) {
592
+ const discComplete = buffalo.readUInt8();
593
+ const commandIds = [];
594
+ const payload = { discComplete, commandIds };
595
+ do {
596
+ const commandId = buffalo.readUInt8();
597
+ commandIds.push(commandId);
598
+ } while (buffalo.isMore());
599
+ return payload;
600
+ },
601
+ write(buffalo, payload) {
602
+ if (Array.isArray(payload)) {
603
+ throw new zclStatusError_1.ZclStatusError(status_1.Status.MALFORMED_COMMAND);
604
+ }
605
+ buffalo.writeUInt8(payload.discComplete);
606
+ for (const commandId of payload.commandIds) {
607
+ buffalo.writeUInt8(commandId);
608
+ }
609
+ },
291
610
  },
292
611
  /** Discover Attributes Extended */
293
612
  discoverExt: {
613
+ name: "discoverExt",
294
614
  ID: 0x15,
295
- parseStrategy: "flat",
296
- parameters: [
297
- { name: "startAttrId", type: enums_1.DataType.DATA16 },
298
- { name: "maxAttrIds", type: enums_1.DataType.DATA8 },
299
- ],
615
+ parse(buffalo) {
616
+ const startAttrId = buffalo.readUInt16();
617
+ const maxAttrIds = buffalo.readUInt8();
618
+ return { startAttrId, maxAttrIds };
619
+ },
620
+ write(buffalo, payload) {
621
+ if (Array.isArray(payload)) {
622
+ throw new zclStatusError_1.ZclStatusError(status_1.Status.MALFORMED_COMMAND);
623
+ }
624
+ buffalo.writeUInt16(payload.startAttrId);
625
+ buffalo.writeUInt8(payload.maxAttrIds);
626
+ },
300
627
  },
301
628
  /** Discover Attributes Extended Response */
302
629
  discoverExtRsp: {
630
+ name: "discoverExtRsp",
303
631
  ID: 0x16,
304
- parseStrategy: "oneof",
305
- parameters: [
306
- { name: "attrId", type: enums_1.DataType.DATA16 },
307
- { name: "dataType", type: enums_1.DataType.DATA8 },
308
- { name: "access", type: enums_1.DataType.DATA8 },
309
- ],
632
+ parse(buffalo) {
633
+ const discComplete = buffalo.readUInt8();
634
+ const attrInfos = [];
635
+ const payload = { discComplete, attrInfos };
636
+ do {
637
+ const attrId = buffalo.readUInt16();
638
+ const dataType = buffalo.readUInt8();
639
+ const access = buffalo.readUInt8();
640
+ attrInfos.push({ attrId, dataType, access });
641
+ } while (buffalo.isMore());
642
+ return payload;
643
+ },
644
+ write(buffalo, payload) {
645
+ if (Array.isArray(payload)) {
646
+ throw new zclStatusError_1.ZclStatusError(status_1.Status.MALFORMED_COMMAND);
647
+ }
648
+ buffalo.writeUInt8(payload.discComplete);
649
+ for (const entry of payload.attrInfos) {
650
+ buffalo.writeUInt16(entry.attrId);
651
+ buffalo.writeUInt8(entry.dataType);
652
+ buffalo.writeUInt8(entry.access);
653
+ }
654
+ },
310
655
  },
311
656
  };
312
657
  //# sourceMappingURL=foundation.js.map