@deconz-community/ddf-validator 2.12.0 → 2.13.0

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.
@@ -1,22 +1,22 @@
1
1
  import { z as e } from "zod";
2
- const O = "2.12.0", y = {
2
+ const E = "2.13.0", y = {
3
3
  "devcap1.schema.json": [
4
- E,
5
- T,
6
- w,
4
+ O,
5
+ _,
7
6
  $,
7
+ T,
8
8
  C
9
9
  ],
10
10
  "constants2.schema.json": [
11
- _
11
+ w
12
12
  ]
13
13
  };
14
- function E(t, r, f) {
15
- const o = typeof t.manufacturername == "string" && typeof t.modelid == "string";
16
- if (o)
14
+ function O(t, r, c) {
15
+ const n = typeof t.manufacturername == "string" && typeof t.modelid == "string";
16
+ if (n)
17
17
  return;
18
- const c = Array.isArray(t.manufacturername) && Array.isArray(t.modelid);
19
- if (c && t.manufacturername.length !== t.modelid.length) {
18
+ const d = Array.isArray(t.manufacturername) && Array.isArray(t.modelid);
19
+ if (d && t.manufacturername.length !== t.modelid.length) {
20
20
  r.addIssue({
21
21
  code: e.ZodIssueCode.invalid_intersection_types,
22
22
  message: "When 'manufacturername' and 'modelid' are both arrays they should be the same length",
@@ -24,41 +24,41 @@ function E(t, r, f) {
24
24
  });
25
25
  return;
26
26
  }
27
- (o || c) === !1 && r.addIssue({
27
+ (n || d) === !1 && r.addIssue({
28
28
  code: e.ZodIssueCode.invalid_intersection_types,
29
29
  message: "Invalid properties 'manufacturername' and 'modelid' should have the same type",
30
30
  path: ["manufacturername", "modelid"]
31
31
  });
32
32
  }
33
- function T(t, r, f) {
33
+ function _(t, r, c) {
34
34
  if (!t.bindings)
35
35
  return;
36
- const o = (n) => `0x${(typeof n == "number" ? n : Number.parseInt(n, 16)).toString(16)}`, c = {};
37
- t.bindings.forEach((n) => {
38
- n.bind === "unicast" && n.report && n.report.forEach((s) => {
39
- s.max !== 65535 && (c[`${o(n["src.ep"])}.${o(n.cl)}.${o(s.at)}`] = s.max);
36
+ const n = (o) => `0x${(typeof o == "number" ? o : Number.parseInt(o, 16)).toString(16)}`, d = {};
37
+ t.bindings.forEach((o) => {
38
+ o.bind === "unicast" && o.report && o.report.forEach((s) => {
39
+ s.max !== 65535 && (d[`${n(o["src.ep"])}.${n(o.cl)}.${n(s.at)}`] = s.max);
40
40
  });
41
- }), t.subdevices.forEach((n, s) => {
42
- n.items.forEach((i, d) => {
43
- var m;
41
+ }), t.subdevices.forEach((o, s) => {
42
+ o.items.forEach((i, u) => {
43
+ var p;
44
44
  if (i["refresh.interval"] && i.read && i.read.fn === "zcl") {
45
- const h = o(i.read.ep ?? ((m = n.fingerprint) == null ? void 0 : m.endpoint) ?? n.uuid[1]), b = Array.isArray(i.read.at) ? i.read.at : [i.read.at];
45
+ const h = n(i.read.ep ?? ((p = o.fingerprint) == null ? void 0 : p.endpoint) ?? o.uuid[1]), b = Array.isArray(i.read.at) ? i.read.at : [i.read.at];
46
46
  for (let v = 0; v < b.length; v++) {
47
- const g = `${h}.${o(i.read.cl)}.${o(b[v])}`;
48
- c[g] !== void 0 && i["refresh.interval"] - 60 < c[g] && r.addIssue({
47
+ const g = `${h}.${n(i.read.cl)}.${n(b[v])}`;
48
+ d[g] !== void 0 && i["refresh.interval"] - 60 < d[g] && r.addIssue({
49
49
  code: e.ZodIssueCode.custom,
50
- message: `The refresh interval (${i["refresh.interval"]} - 60 = ${i["refresh.interval"] - 60}) should be greater than the binding max refresh value (${c[g]}) with a margin of 60 seconds`,
51
- path: ["subdevices", s, "items", d, "refresh.interval"]
50
+ message: `The refresh interval (${i["refresh.interval"]} - 60 = ${i["refresh.interval"] - 60}) should be greater than the binding max refresh value (${d[g]}) with a margin of 60 seconds`,
51
+ path: ["subdevices", s, "items", u, "refresh.interval"]
52
52
  });
53
53
  }
54
54
  }
55
55
  });
56
56
  });
57
57
  }
58
- function w(t, r, f) {
58
+ function $(t, r, c) {
59
59
  if (!t.bindings)
60
60
  return;
61
- const o = [
61
+ const n = [
62
62
  /*
63
63
  {
64
64
  description: 'a device should always have basic attributes.',
@@ -139,88 +139,88 @@ function w(t, r, f) {
139
139
  }
140
140
  }
141
141
  ];
142
- t.subdevices.forEach((c, n) => {
143
- const s = c.items.map((i) => i.name);
144
- o.forEach((i) => {
145
- (Object.keys(i.if).length === 0 || Object.keys(i.if).some((d) => {
146
- var m;
147
- switch (d) {
142
+ t.subdevices.forEach((d, o) => {
143
+ const s = d.items.map((i) => i.name);
144
+ n.forEach((i) => {
145
+ (Object.keys(i.if).length === 0 || Object.keys(i.if).some((u) => {
146
+ var p;
147
+ switch (u) {
148
148
  case "type":
149
- return (m = i.if[d]) == null ? void 0 : m.includes(c.type);
149
+ return (p = i.if[u]) == null ? void 0 : p.includes(d.type);
150
150
  case "item":
151
151
  return s.some((h) => {
152
152
  var b;
153
- return (b = i.if[d]) == null ? void 0 : b.includes(h);
153
+ return (b = i.if[u]) == null ? void 0 : b.includes(h);
154
154
  });
155
155
  default:
156
156
  return !1;
157
157
  }
158
- })) && i.need.item.forEach((d) => {
159
- s.includes(d) || r.addIssue({
158
+ })) && i.need.item.forEach((u) => {
159
+ s.includes(u) || r.addIssue({
160
160
  code: e.ZodIssueCode.custom,
161
- message: `The device should have the item "${d}" because ${i.description}`,
162
- path: ["subdevices", n, "items"]
161
+ message: `The device should have the item "${u}" because ${i.description}`,
162
+ path: ["subdevices", o, "items"]
163
163
  });
164
164
  });
165
165
  });
166
166
  });
167
167
  }
168
- function $(t, r, f) {
169
- const o = ["parse", "write"];
170
- t.subdevices.forEach((c, n) => {
171
- c.items.forEach((s, i) => {
172
- o.forEach((d) => {
173
- const m = s[d];
174
- m !== void 0 && (m.fn === void 0 || m.fn === "zcl" || m.fn === "zcl:attr" || m.fn === "zcl:cmd") && (m.eval === void 0 && m.script === void 0 && r.addIssue({
168
+ function T(t, r, c) {
169
+ const n = ["parse", "write"];
170
+ t.subdevices.forEach((d, o) => {
171
+ d.items.forEach((s, i) => {
172
+ n.forEach((u) => {
173
+ const p = s[u];
174
+ p !== void 0 && (p.fn === void 0 || p.fn === "zcl" || p.fn === "zcl:attr" || p.fn === "zcl:cmd") && (p.eval === void 0 && p.script === void 0 && r.addIssue({
175
175
  code: e.ZodIssueCode.custom,
176
- message: `The '${d}' function is missing 'eval' or 'script' option.`,
177
- path: ["subdevices", n, "items", i, d]
178
- }), m.eval !== void 0 && m.script !== void 0 && r.addIssue({
176
+ message: `The '${u}' function is missing 'eval' or 'script' option.`,
177
+ path: ["subdevices", o, "items", i, u]
178
+ }), p.eval !== void 0 && p.script !== void 0 && r.addIssue({
179
179
  code: e.ZodIssueCode.custom,
180
- message: `The '${d}' function is having both 'eval' and 'script' option.`,
181
- path: ["subdevices", n, "items", i, d]
180
+ message: `The '${u}' function is having both 'eval' and 'script' option.`,
181
+ path: ["subdevices", o, "items", i, u]
182
182
  }));
183
183
  });
184
184
  });
185
185
  });
186
186
  }
187
- function _(t, r, f) {
188
- const o = I();
189
- Object.keys(t).forEach((c) => {
190
- if (!Object.keys(o.shape).includes(c)) {
191
- if (!["$MF_", "$TYPE_"].some((n) => c.startsWith(n))) {
187
+ function w(t, r, c) {
188
+ const n = I();
189
+ Object.keys(t).forEach((d) => {
190
+ if (!Object.keys(n.shape).includes(d)) {
191
+ if (!["$MF_", "$TYPE_"].some((o) => d.startsWith(o))) {
192
192
  r.addIssue({
193
193
  code: e.ZodIssueCode.custom,
194
194
  message: "The constant key should start with '$MF_' or '$TYPE_'",
195
- path: [c]
195
+ path: [d]
196
196
  });
197
197
  return;
198
198
  }
199
- typeof t[c] != "string" && r.addIssue({
199
+ typeof t[d] != "string" && r.addIssue({
200
200
  code: e.ZodIssueCode.custom,
201
201
  message: "The constant value should be a string",
202
- path: [c]
202
+ path: [d]
203
203
  });
204
204
  }
205
205
  });
206
206
  }
207
- function C(t, r, f) {
208
- t.bindings && t.subdevices.forEach((o, c) => {
209
- const n = f.subDevices[o.type];
210
- if (!n) {
207
+ function C(t, r, c) {
208
+ t.bindings && t.subdevices.forEach((n, d) => {
209
+ const o = c.subDevices[n.type];
210
+ if (!o) {
211
211
  r.addIssue({
212
212
  code: e.ZodIssueCode.custom,
213
- message: `The device is missing the device definition for the type "${o.type}"`,
214
- path: ["subdevices", c, "items"]
213
+ message: `The device is missing the device definition for the type "${n.type}"`,
214
+ path: ["subdevices", d, "items"]
215
215
  });
216
216
  return;
217
217
  }
218
- let s = n.items;
219
- n.items_optional && (s = s.filter((i) => !n.items_optional.includes(i))), s.forEach((i) => {
220
- o.items.find((d) => d.name === i) || r.addIssue({
218
+ let s = o.items;
219
+ o.items_optional && (s = s.filter((i) => !o.items_optional.includes(i))), s.forEach((i) => {
220
+ n.items.find((u) => u.name === i) || r.addIssue({
221
221
  code: e.ZodIssueCode.custom,
222
- message: `The device should have the item "${i}" because it is mandatory for devices of type "${o.type}"`,
223
- path: ["subdevices", c, "items"]
222
+ message: `The device should have the item "${i}" because it is mandatory for devices of type "${n.type}"`,
223
+ path: ["subdevices", d, "items"]
224
224
  });
225
225
  });
226
226
  });
@@ -239,7 +239,7 @@ function I(t) {
239
239
  schema: e.literal("constants2.schema.json")
240
240
  }).passthrough();
241
241
  }
242
- function S() {
242
+ function M() {
243
243
  return e.string().regex(
244
244
  // Regex for AAAA-MM-JJ
245
245
  /^(\d{4})-(?:(?:0[1-9])|(?:1[0-2]))-(?:(?:0[1-9])|(?:[12][0-9])|(?:3[01]))$/,
@@ -250,19 +250,19 @@ function a(t = void 0) {
250
250
  const r = "Invalid hexadecimal value";
251
251
  return t === void 0 ? e.string().regex(/^0x[0-9a-fA-F]+$/, r) : e.string().regex(new RegExp(`^0x[0-9a-fA-F]{${t}}$`), r);
252
252
  }
253
- function u() {
253
+ function l() {
254
254
  return e.union([
255
255
  a(2),
256
256
  e.number().min(0).max(255)
257
257
  ]);
258
258
  }
259
- function J() {
259
+ function S() {
260
260
  return e.custom((t) => {
261
261
  if (!Array.isArray(t) || t.length % 2 !== 0)
262
262
  return !1;
263
263
  for (let r = 0; r < t.length; r += 2) {
264
- const f = t[r], o = t[r + 1];
265
- if (typeof f != "number" || typeof o != "string")
264
+ const c = t[r], n = t[r + 1];
265
+ if (typeof c != "number" || typeof n != "string")
266
266
  return !1;
267
267
  }
268
268
  return !0;
@@ -281,13 +281,13 @@ function j() {
281
281
  ])
282
282
  ]);
283
283
  }
284
- function p() {
284
+ function f() {
285
285
  return e.string();
286
286
  }
287
- function l() {
287
+ function m() {
288
288
  return e.string();
289
289
  }
290
- function M() {
290
+ function J() {
291
291
  return e.discriminatedUnion("fn", [
292
292
  e.strictObject({
293
293
  fn: e.literal("none")
@@ -296,36 +296,36 @@ function M() {
296
296
  fn: e.undefined().describe("Generic function to read ZCL attributes."),
297
297
  at: a(4).or(e.array(a(4))).describe("Attribute ID."),
298
298
  cl: a(4).describe("Cluster ID."),
299
- ep: e.optional(u()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
299
+ ep: e.optional(l()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
300
300
  mf: e.optional(a(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
301
- eval: e.optional(l()).describe("Javascript expression to transform the raw value.")
301
+ eval: e.optional(m()).describe("Javascript expression to transform the raw value.")
302
302
  }),
303
303
  e.strictObject({
304
304
  fn: e.literal("zcl").describe("Generic function to read ZCL attributes."),
305
305
  at: a(4).or(e.array(a(4))).describe("Attribute ID."),
306
306
  cl: a(4).describe("Cluster ID."),
307
- ep: e.optional(u()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
307
+ ep: e.optional(l()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
308
308
  mf: e.optional(a(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
309
- eval: e.optional(l()).describe("Javascript expression to transform the raw value."),
310
- script: e.optional(p()).describe("Relative path of a Javascript .js file.")
309
+ eval: e.optional(m()).describe("Javascript expression to transform the raw value."),
310
+ script: e.optional(f()).describe("Relative path of a Javascript .js file.")
311
311
  }).describe("Deprecated"),
312
312
  e.strictObject({
313
313
  fn: e.literal("zcl:attr").describe("Generic function to parse ZCL values from read/report commands."),
314
314
  at: a(4).or(e.array(a(4))).describe("String hex value or array of string hex values."),
315
315
  cl: a(4).describe("Cluster ID."),
316
- ep: e.optional(u()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
316
+ ep: e.optional(l()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
317
317
  mf: e.optional(a(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
318
- eval: e.optional(l()).describe("Javascript expression to transform the attribute value to the Item value."),
319
- script: e.optional(p()).describe("Relative path of a Javascript .js file.")
318
+ eval: e.optional(m()).describe("Javascript expression to transform the attribute value to the Item value."),
319
+ script: e.optional(f()).describe("Relative path of a Javascript .js file.")
320
320
  }),
321
321
  e.strictObject({
322
322
  fn: e.literal("zcl:cmd").describe("Generic function to parse ZCL values from read/report commands."),
323
323
  cl: a(4).describe("Cluster ID."),
324
- ep: e.optional(u()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
324
+ ep: e.optional(l()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
325
325
  mf: e.optional(a(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
326
326
  cmd: e.optional(a(2)).describe("Zigbee command."),
327
- eval: e.optional(l()).describe("Javascript expression to transform the attribute value to the Item value."),
328
- script: e.optional(p()).describe("Relative path of a Javascript .js file.")
327
+ eval: e.optional(m()).describe("Javascript expression to transform the attribute value to the Item value."),
328
+ script: e.optional(f()).describe("Relative path of a Javascript .js file.")
329
329
  }),
330
330
  e.strictObject({
331
331
  fn: e.literal("tuya").describe("Generic function to read all Tuya datapoints. It has no parameters.")
@@ -341,40 +341,40 @@ function Z() {
341
341
  at: e.optional(a(4).or(e.array(a(4)))).describe("Attribute ID."),
342
342
  cl: a(4).describe("Cluster ID."),
343
343
  cppsrc: e.optional(e.string()),
344
- ep: e.optional(u()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
344
+ ep: e.optional(l()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
345
345
  cmd: e.optional(a(2)).describe("Zigbee command."),
346
346
  mf: e.optional(a(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
347
- eval: e.optional(l()).describe("Javascript expression to transform the raw value."),
348
- script: e.optional(p()).describe("Relative path of a Javascript .js file.")
347
+ eval: e.optional(m()).describe("Javascript expression to transform the raw value."),
348
+ script: e.optional(f()).describe("Relative path of a Javascript .js file.")
349
349
  }),
350
350
  e.strictObject({
351
351
  fn: e.literal("zcl").describe("Generic function to parse ZCL attributes and commands."),
352
352
  at: e.optional(a(4).or(e.array(a(4)))).describe("Attribute ID."),
353
353
  cl: a(4).describe("Cluster ID."),
354
354
  cppsrc: e.optional(e.string()),
355
- ep: e.optional(u()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
355
+ ep: e.optional(l()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
356
356
  cmd: e.optional(a(2)).describe("Zigbee command."),
357
357
  mf: e.optional(a(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
358
- eval: e.optional(l()).describe("Javascript expression to transform the raw value."),
359
- script: e.optional(p()).describe("Relative path of a Javascript .js file.")
358
+ eval: e.optional(m()).describe("Javascript expression to transform the raw value."),
359
+ script: e.optional(f()).describe("Relative path of a Javascript .js file.")
360
360
  }).describe("Deprecated"),
361
361
  e.strictObject({
362
362
  fn: e.literal("zcl:attr").describe("Generic function to parse ZCL values from read/report commands."),
363
363
  at: a(4).or(e.array(a(4))).describe("String hex value or array of string hex values."),
364
364
  cl: a(4).describe("Cluster ID."),
365
- ep: e.optional(u()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
365
+ ep: e.optional(l()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
366
366
  mf: e.optional(a(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
367
- eval: e.optional(l()).describe("Javascript expression to transform the attribute value to the Item value."),
368
- script: e.optional(p()).describe("Relative path of a Javascript .js file.")
367
+ eval: e.optional(m()).describe("Javascript expression to transform the attribute value to the Item value."),
368
+ script: e.optional(f()).describe("Relative path of a Javascript .js file.")
369
369
  }),
370
370
  e.strictObject({
371
371
  fn: e.literal("zcl:cmd").describe("Generic function to parse ZCL values from read/report commands."),
372
372
  cl: a(4).describe("Cluster ID."),
373
- ep: e.optional(u()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
373
+ ep: e.optional(l()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
374
374
  mf: e.optional(a(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
375
375
  cmd: e.optional(a(2)).describe("Zigbee command."),
376
- eval: e.optional(l()).describe("Javascript expression to transform the attribute value to the Item value."),
377
- script: e.optional(p()).describe("Relative path of a Javascript .js file.")
376
+ eval: e.optional(m()).describe("Javascript expression to transform the attribute value to the Item value."),
377
+ script: e.optional(f()).describe("Relative path of a Javascript .js file.")
378
378
  }),
379
379
  e.strictObject({
380
380
  fn: e.literal("ias:zonestatus").describe("Generic function to parse IAS ZONE status change notifications or zone status from read/report command."),
@@ -385,25 +385,25 @@ function Z() {
385
385
  // TODO use generic
386
386
  srcitem: e.enum(["state/airqualityppb", "state/pm2_5"]).describe("The source item holding the number."),
387
387
  op: e.enum(["lt", "le", "eq", "gt", "ge"]).describe("Comparison operator (lt | le | eq | gt | ge)"),
388
- to: J().describe("Array of (num, string) mappings")
388
+ to: S().describe("Array of (num, string) mappings")
389
389
  }),
390
390
  e.strictObject({
391
391
  fn: e.literal("time").describe("Specialized function to parse time, local and last set time from read/report commands of the time cluster and auto-sync time if needed.")
392
392
  }),
393
393
  e.strictObject({
394
394
  fn: e.literal("xiaomi:special").describe("Generic function to parse custom Xiaomi attributes and commands."),
395
- ep: e.optional(u()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
395
+ ep: e.optional(l()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
396
396
  mf: e.optional(a(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
397
397
  at: e.optional(a(4)).describe("Attribute ID. The attribute to parse, shall be 0xff01, 0xff02 or 0x00f7"),
398
398
  idx: a(2).describe("A 8-bit string hex value."),
399
- eval: e.optional(l()).describe("Javascript expression to transform the raw value."),
400
- script: e.optional(p()).describe("Relative path of a Javascript .js file.")
399
+ eval: e.optional(m()).describe("Javascript expression to transform the raw value."),
400
+ script: e.optional(f()).describe("Relative path of a Javascript .js file.")
401
401
  }),
402
402
  e.strictObject({
403
403
  fn: e.literal("tuya").describe("Generic function to parse Tuya data."),
404
404
  dpid: e.number().describe("Data point ID. 1-255 the datapoint ID."),
405
- eval: e.optional(l()).describe("Javascript expression to transform the raw value."),
406
- script: e.optional(p()).describe("Relative path of a Javascript .js file.")
405
+ eval: e.optional(m()).describe("Javascript expression to transform the raw value."),
406
+ script: e.optional(f()).describe("Relative path of a Javascript .js file.")
407
407
  })
408
408
  ]).refine((t) => !("eval" in t && "script" in t), {
409
409
  message: "eval and script should not both be present"
@@ -421,10 +421,10 @@ function R() {
421
421
  "change.timeout": e.optional(e.number()),
422
422
  cl: a(4).describe("Cluster ID."),
423
423
  dt: a(2).describe("Data type."),
424
- ep: e.optional(u()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
424
+ ep: e.optional(l()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
425
425
  mf: e.optional(a(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
426
- eval: e.optional(l()).describe("Javascript expression to transform the raw value."),
427
- script: e.optional(p()).describe("Relative path of a Javascript .js file.")
426
+ eval: e.optional(m()).describe("Javascript expression to transform the raw value."),
427
+ script: e.optional(f()).describe("Relative path of a Javascript .js file.")
428
428
  }),
429
429
  e.strictObject({
430
430
  fn: e.literal("zcl"),
@@ -433,10 +433,10 @@ function R() {
433
433
  "change.timeout": e.optional(e.number()),
434
434
  cl: a(4).describe("Cluster ID."),
435
435
  dt: a(2).describe("Data type."),
436
- ep: e.optional(u()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
436
+ ep: e.optional(l()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
437
437
  mf: e.optional(a(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
438
- eval: e.optional(l()).describe("Javascript expression to transform the raw value."),
439
- script: e.optional(p()).describe("Relative path of a Javascript .js file.")
438
+ eval: e.optional(m()).describe("Javascript expression to transform the raw value."),
439
+ script: e.optional(f()).describe("Relative path of a Javascript .js file.")
440
440
  }).describe("Deprecated"),
441
441
  e.strictObject({
442
442
  fn: e.literal("zcl:attr").describe("Generic function to parse ZCL values from read/report commands."),
@@ -445,27 +445,27 @@ function R() {
445
445
  "change.timeout": e.optional(e.number()),
446
446
  cl: a(4).describe("Cluster ID."),
447
447
  dt: a(2).describe("Data type."),
448
- ep: e.optional(u()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
448
+ ep: e.optional(l()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
449
449
  mf: e.optional(a(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
450
- eval: e.optional(l()).describe("Javascript expression to transform the attribute value to the Item value."),
451
- script: e.optional(p()).describe("Relative path of a Javascript .js file.")
450
+ eval: e.optional(m()).describe("Javascript expression to transform the attribute value to the Item value."),
451
+ script: e.optional(f()).describe("Relative path of a Javascript .js file.")
452
452
  }),
453
453
  e.strictObject({
454
454
  fn: e.literal("zcl:cmd").describe("Generic function to parse ZCL values from read/report commands."),
455
455
  cl: a(4).describe("Cluster ID."),
456
456
  dt: a(2).describe("Data type."),
457
- ep: e.optional(u()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
457
+ ep: e.optional(l()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
458
458
  mf: e.optional(a(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
459
459
  cmd: e.optional(a(2)).describe("Zigbee command."),
460
- eval: e.optional(l()).describe("Javascript expression to transform the attribute value to the Item value."),
461
- script: e.optional(p()).describe("Relative path of a Javascript .js file.")
460
+ eval: e.optional(m()).describe("Javascript expression to transform the attribute value to the Item value."),
461
+ script: e.optional(f()).describe("Relative path of a Javascript .js file.")
462
462
  }),
463
463
  e.strictObject({
464
464
  fn: e.literal("tuya").describe("Generic function to write Tuya data."),
465
465
  dpid: e.number().describe("Data point ID. 1-255 the datapoint ID."),
466
466
  dt: a(2).describe("Data type."),
467
- eval: e.optional(l()).describe("Javascript expression to transform the raw value."),
468
- script: e.optional(p()).describe("Relative path of a Javascript .js file.")
467
+ eval: e.optional(m()).describe("Javascript expression to transform the raw value."),
468
+ script: e.optional(f()).describe("Relative path of a Javascript .js file.")
469
469
  })
470
470
  ]).refine((t) => !("eval" in t && "script" in t), {
471
471
  message: "eval and script should not both be present"
@@ -478,8 +478,23 @@ function D(t) {
478
478
  id: e.string(),
479
479
  description: e.optional(e.string()).describe("Item description, better to do not use it."),
480
480
  comment: e.optional(e.string()).describe("TODO: What is this ? What the difference with description ?"),
481
- deprecated: e.optional(S()).describe("Date of deprecation, if the item is deprecated, it's better to use the new one."),
482
- datatype: e.optional(e.enum(["String", "Bool", "Int8", "Int16", "Int32", "Int64", "UInt8", "UInt16", "UInt32", "UInt64", "Double", "Array", "Array[3]", "ISO 8601 timestamp"])).describe("Data type of the item."),
481
+ deprecated: e.optional(M()).describe("Date of deprecation, if the item is deprecated, it's better to use the new one."),
482
+ datatype: e.optional(e.enum([
483
+ "String",
484
+ "Bool",
485
+ "Int8",
486
+ "Int16",
487
+ "Int32",
488
+ "Int64",
489
+ "UInt8",
490
+ "UInt16",
491
+ "UInt32",
492
+ "UInt64",
493
+ "Double",
494
+ "Array",
495
+ "Array[3]",
496
+ "ISO 8601 timestamp"
497
+ ])).describe("Data type of the item."),
483
498
  access: e.optional(e.enum(["R", "W", "RW"])).describe("Access mode for this item, some of them are not editable."),
484
499
  public: e.optional(e.boolean()).describe("Item visible on the API."),
485
500
  implicit: e.optional(e.boolean()).describe("TODO: What is this ?"),
@@ -488,7 +503,7 @@ function D(t) {
488
503
  static: e.optional(e.union([e.string(), e.number(), e.boolean()])).describe("A static default value is fixed and can be not changed."),
489
504
  range: e.optional(e.tuple([e.number(), e.number()])).describe("Values range limit."),
490
505
  virtual: e.optional(e.boolean()).describe("TODO: What is this ?"),
491
- read: e.optional(M()).describe("Fonction used to read value."),
506
+ read: e.optional(J()).describe("Fonction used to read value."),
492
507
  parse: e.optional(Z()).describe("Fonction used to parse incoming values."),
493
508
  write: e.optional(R()).describe("Fonction used to write value."),
494
509
  "refresh.interval": e.optional(e.number()).describe("Refresh interval used for read fonction, NEED to be superior at value used in binding part."),
@@ -521,8 +536,8 @@ function G(t) {
521
536
  modelid: e.string().or(e.array(e.string())).describe("Model ID from Basic Cluster."),
522
537
  vendor: e.optional(e.string()).describe("Friendly name of the manufacturer."),
523
538
  comment: e.optional(e.string()),
524
- matchexpr: e.optional(l()).describe("Need to return true for the DDF be used."),
525
- path: e.optional(p()).describe("DDF path, useless, can be removed."),
539
+ matchexpr: e.optional(m()).describe("Need to return true for the DDF be used."),
540
+ path: e.optional(f()).describe("DDF path, useless, can be removed."),
526
541
  product: e.optional(e.string()).describe("Complements the model id to be shown in the UI."),
527
542
  sleeper: e.optional(e.boolean()).describe("Sleeping devices can only receive when awake."),
528
543
  supportsMgmtBind: e.optional(e.boolean()),
@@ -534,7 +549,9 @@ function G(t) {
534
549
  function F(t) {
535
550
  return e.strictObject({
536
551
  type: e.union([
537
- e.enum(Object.keys(t.deviceTypes)),
552
+ e.enum(Object.keys(t.deviceTypes), {
553
+ errorMap: (r, c) => r.code === "invalid_enum_value" ? { message: `Invalid enum value. Expected type from generic attributes definition, received '${r.received}'` } : { message: c.defaultError }
554
+ }),
538
555
  e.string().regex(/^(?!\$TYPE_).*/g, "The type start with $TYPE_ but is not present in constants.json")
539
556
  ]),
540
557
  restapi: e.enum(["/lights", "/sensors"]),
@@ -542,7 +559,7 @@ function F(t) {
542
559
  fingerprint: e.optional(e.strictObject({
543
560
  profile: a(4),
544
561
  device: a(4),
545
- endpoint: u(),
562
+ endpoint: l(),
546
563
  in: e.optional(e.array(a(4))),
547
564
  out: e.optional(e.array(a(4)))
548
565
  })),
@@ -565,15 +582,17 @@ function k(t) {
565
582
  schema: !0,
566
583
  id: !0
567
584
  }).extend({
568
- name: e.enum(t.attributes).describe("Item name.")
585
+ name: e.enum(t.attributes, {
586
+ errorMap: (r, c) => r.code === "invalid_enum_value" ? { message: `Invalid enum value. Expected item from generic attributes definition, received '${r.received}'` } : { message: c.defaultError }
587
+ }).describe("Item name.")
569
588
  });
570
589
  }
571
590
  function z(t) {
572
591
  return e.discriminatedUnion("bind", [
573
592
  e.strictObject({
574
593
  bind: e.literal("unicast"),
575
- "src.ep": u().describe("Source endpoint."),
576
- "dst.ep": e.optional(u()).describe("Destination endpoint, generaly 0x01."),
594
+ "src.ep": l().describe("Source endpoint."),
595
+ "dst.ep": e.optional(l()).describe("Destination endpoint, generaly 0x01."),
577
596
  cl: a(4).describe("Cluster."),
578
597
  report: e.optional(e.array(
579
598
  e.strictObject({
@@ -588,26 +607,33 @@ function z(t) {
588
607
  }),
589
608
  e.strictObject({
590
609
  bind: e.literal("groupcast"),
591
- "src.ep": u().describe("Source endpoint."),
610
+ "src.ep": l().describe("Source endpoint."),
592
611
  cl: a(4).describe("Cluster."),
593
612
  "config.group": e.number().min(0).max(255)
594
613
  })
595
614
  ]);
596
615
  }
597
616
  function L(t) {
617
+ const r = e.array(
618
+ e.enum(t.attributes, {
619
+ errorMap: (c, n) => c.code === "invalid_enum_value" ? { message: `Invalid enum value. Expected item from generic attributes definition, received '${c.received}'` } : { message: n.defaultError }
620
+ })
621
+ );
598
622
  return e.strictObject({
599
623
  $schema: e.optional(e.string()),
600
624
  schema: e.literal("subdevice1.schema.json"),
601
625
  type: e.union([
602
- e.enum(Object.keys(t.deviceTypes)),
626
+ e.enum(Object.keys(t.deviceTypes), {
627
+ errorMap: (c, n) => c.code === "invalid_enum_value" ? { message: `Invalid enum value. Expected type from generic attributes definition, received '${c.received}'` } : { message: n.defaultError }
628
+ }),
603
629
  e.string().regex(/^(?!\$TYPE_).*/g, "The type start with $TYPE_ but is not present in constants.json")
604
630
  ]),
605
631
  name: e.string(),
606
632
  restapi: e.enum(["/lights", "/sensors"]),
607
633
  order: e.number(),
608
634
  uuid: j(),
609
- items: e.array(e.enum(t.attributes)),
610
- items_optional: e.optional(e.array(e.enum(t.attributes)))
635
+ items: r,
636
+ items_optional: e.optional(r)
611
637
  });
612
638
  }
613
639
  function x(t) {
@@ -617,13 +643,13 @@ function x(t) {
617
643
  I(),
618
644
  D(),
619
645
  L(t)
620
- ]).superRefine((r, f) => {
646
+ ]).superRefine((r, c) => {
621
647
  switch (r.schema) {
622
648
  case "devcap1.schema.json":
623
- y[r.schema].map((o) => o(r, f, t));
649
+ y[r.schema].map((n) => n(r, c, t));
624
650
  break;
625
651
  case "constants2.schema.json":
626
- y[r.schema].map((o) => o(r, f, t));
652
+ y[r.schema].map((n) => n(r, c, t));
627
653
  break;
628
654
  }
629
655
  });
@@ -636,11 +662,11 @@ function W(t = {
636
662
  subDevices: {}
637
663
  }) {
638
664
  let r = x(t);
639
- const f = () => {
665
+ const c = () => {
640
666
  r = x(t);
641
667
  };
642
- return { generics: t, loadGeneric: (n) => {
643
- const s = r.parse(n);
668
+ return { generics: t, loadGeneric: (o) => {
669
+ const s = r.parse(o);
644
670
  switch (s.schema) {
645
671
  case "constants1.schema.json":
646
672
  t.manufacturers = {
@@ -662,8 +688,8 @@ function W(t = {
662
688
  case "resourceitem1.schema.json": {
663
689
  if (t.attributes.includes(s.id))
664
690
  throw new Error(`Got duplicate resource item with attribute id '${s.id}'.`);
665
- const i = s, d = s.id;
666
- delete i.$schema, delete i.schema, delete i.id, t.resources[d] = i, t.attributes.push(d);
691
+ const i = s, u = s.id;
692
+ delete i.$schema, delete i.schema, delete i.id, t.resources[u] = i, t.attributes.push(u);
667
693
  break;
668
694
  }
669
695
  case "subdevice1.schema.json":
@@ -672,8 +698,8 @@ function W(t = {
672
698
  case "devcap1.schema.json":
673
699
  throw new Error("Got invalid generic file, got data with schema 'devcap1.schema.json'.");
674
700
  }
675
- return f(), !0;
676
- }, validate: (n) => r.parse(n), getSchema: () => r, version: O };
701
+ return c(), !0;
702
+ }, validate: (o) => r.parse(o), getSchema: () => r, version: E };
677
703
  }
678
704
  export {
679
705
  W as createValidator