@deconz-community/ddf-validator 2.14.0 → 2.16.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.
- package/dist/ddf-schema.json +1 -1
- package/dist/ddf-validator.cjs +1 -1
- package/dist/ddf-validator.d.ts +9 -9
- package/dist/ddf-validator.mjs +104 -99
- package/package.json +1 -1
package/dist/ddf-validator.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z as e } from "zod";
|
|
2
|
-
const E = "2.
|
|
2
|
+
const E = "2.16.0", y = {
|
|
3
3
|
"devcap1.schema.json": [
|
|
4
4
|
O,
|
|
5
5
|
_,
|
|
@@ -11,9 +11,9 @@ const E = "2.14.0", y = {
|
|
|
11
11
|
T
|
|
12
12
|
]
|
|
13
13
|
};
|
|
14
|
-
function O(t, a,
|
|
15
|
-
const
|
|
16
|
-
if (
|
|
14
|
+
function O(t, a, u) {
|
|
15
|
+
const n = typeof t.manufacturername == "string" && typeof t.modelid == "string";
|
|
16
|
+
if (n)
|
|
17
17
|
return;
|
|
18
18
|
const c = Array.isArray(t.manufacturername) && Array.isArray(t.modelid);
|
|
19
19
|
if (c && t.manufacturername.length !== t.modelid.length) {
|
|
@@ -24,39 +24,39 @@ function O(t, a, d) {
|
|
|
24
24
|
});
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
|
-
(
|
|
27
|
+
(n || c) === !1 && a.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, a,
|
|
33
|
+
function _(t, a, u) {
|
|
34
34
|
if (!t.bindings)
|
|
35
35
|
return;
|
|
36
|
-
const
|
|
36
|
+
const n = (s) => `0x${(typeof s == "number" ? s : Number.parseInt(s, 16)).toString(16)}`, c = {};
|
|
37
37
|
t.bindings.forEach((s) => {
|
|
38
|
-
s.bind === "unicast" && s.report && s.report.forEach((
|
|
39
|
-
|
|
38
|
+
s.bind === "unicast" && s.report && s.report.forEach((d) => {
|
|
39
|
+
d.max !== 65535 && (c[`${n(s["src.ep"])}.${n(s.cl)}.${n(d.at)}`] = d.max);
|
|
40
40
|
});
|
|
41
|
-
}), t.subdevices.forEach((s,
|
|
42
|
-
s.items.forEach((i,
|
|
43
|
-
var
|
|
41
|
+
}), t.subdevices.forEach((s, d) => {
|
|
42
|
+
s.items.forEach((i, o) => {
|
|
43
|
+
var l;
|
|
44
44
|
if (i["refresh.interval"] && i.read && i.read.fn === "zcl") {
|
|
45
|
-
const h =
|
|
45
|
+
const h = n(i.read.ep ?? ((l = s.fingerprint) == null ? void 0 : l.endpoint) ?? s.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}.${
|
|
47
|
+
const g = `${h}.${n(i.read.cl)}.${n(b[v])}`;
|
|
48
48
|
c[g] !== void 0 && i["refresh.interval"] - 60 < c[g] && a.addIssue({
|
|
49
49
|
code: e.ZodIssueCode.custom,
|
|
50
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",
|
|
51
|
+
path: ["subdevices", d, "items", o, "refresh.interval"]
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
});
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
-
function $(t, a,
|
|
59
|
-
const
|
|
58
|
+
function $(t, a, u) {
|
|
59
|
+
const n = [
|
|
60
60
|
/*
|
|
61
61
|
{
|
|
62
62
|
description: 'a device should always have basic attributes.',
|
|
@@ -146,12 +146,12 @@ function $(t, a, d) {
|
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
|
-
], c = (s,
|
|
150
|
-
t.subdevices.forEach((s,
|
|
151
|
-
const i = s.items.map((
|
|
152
|
-
|
|
153
|
-
(Object.keys(
|
|
154
|
-
switch (
|
|
149
|
+
], c = (s, d) => typeof s == "string" ? d(s) : Array.isArray(s) ? s.every((i) => c(i, d)) : "and" in s ? s.and.every((i) => c(i, d)) : "or" in s ? s.or.some((i) => c(i, d)) : !1;
|
|
150
|
+
t.subdevices.forEach((s, d) => {
|
|
151
|
+
const i = s.items.map((o) => o.name);
|
|
152
|
+
n.forEach((o) => {
|
|
153
|
+
(Object.keys(o.if).length === 0 || Object.entries(o.if).some(([l, h]) => {
|
|
154
|
+
switch (l) {
|
|
155
155
|
case "type":
|
|
156
156
|
return c(h, (b) => b === s.type);
|
|
157
157
|
case "item":
|
|
@@ -159,37 +159,37 @@ function $(t, a, d) {
|
|
|
159
159
|
default:
|
|
160
160
|
return !1;
|
|
161
161
|
}
|
|
162
|
-
})) && (c(
|
|
162
|
+
})) && (c(o.need.item, (l) => i.includes(l)) || a.addIssue({
|
|
163
163
|
code: e.ZodIssueCode.custom,
|
|
164
|
-
message: `The device is missing some items because ${
|
|
165
|
-
path: ["subdevices",
|
|
164
|
+
message: `The device is missing some items because ${o.description}`,
|
|
165
|
+
path: ["subdevices", d, "items"]
|
|
166
166
|
}));
|
|
167
167
|
});
|
|
168
168
|
});
|
|
169
169
|
}
|
|
170
|
-
function w(t, a,
|
|
171
|
-
const
|
|
170
|
+
function w(t, a, u) {
|
|
171
|
+
const n = ["parse", "write"];
|
|
172
172
|
t.subdevices.forEach((c, s) => {
|
|
173
|
-
c.items.forEach((
|
|
174
|
-
|
|
175
|
-
const
|
|
176
|
-
|
|
173
|
+
c.items.forEach((d, i) => {
|
|
174
|
+
n.forEach((o) => {
|
|
175
|
+
const l = d[o];
|
|
176
|
+
l !== void 0 && (l.fn === void 0 || l.fn === "zcl" || l.fn === "zcl:attr" || l.fn === "zcl:cmd") && (l.eval === void 0 && l.script === void 0 && a.addIssue({
|
|
177
177
|
code: e.ZodIssueCode.custom,
|
|
178
|
-
message: `The '${
|
|
179
|
-
path: ["subdevices", s, "items", i,
|
|
180
|
-
}),
|
|
178
|
+
message: `The '${o}' function is missing 'eval' or 'script' option.`,
|
|
179
|
+
path: ["subdevices", s, "items", i, o]
|
|
180
|
+
}), l.eval !== void 0 && l.script !== void 0 && a.addIssue({
|
|
181
181
|
code: e.ZodIssueCode.custom,
|
|
182
|
-
message: `The '${
|
|
183
|
-
path: ["subdevices", s, "items", i,
|
|
182
|
+
message: `The '${o}' function is having both 'eval' and 'script' option.`,
|
|
183
|
+
path: ["subdevices", s, "items", i, o]
|
|
184
184
|
}));
|
|
185
185
|
});
|
|
186
186
|
});
|
|
187
187
|
});
|
|
188
188
|
}
|
|
189
|
-
function T(t, a,
|
|
190
|
-
const
|
|
189
|
+
function T(t, a, u) {
|
|
190
|
+
const n = I();
|
|
191
191
|
Object.keys(t).forEach((c) => {
|
|
192
|
-
if (!Object.keys(
|
|
192
|
+
if (!Object.keys(n.shape).includes(c)) {
|
|
193
193
|
if (!["$MF_", "$TYPE_"].some((s) => c.startsWith(s))) {
|
|
194
194
|
a.addIssue({
|
|
195
195
|
code: e.ZodIssueCode.custom,
|
|
@@ -206,22 +206,22 @@ function T(t, a, d) {
|
|
|
206
206
|
}
|
|
207
207
|
});
|
|
208
208
|
}
|
|
209
|
-
function C(t, a,
|
|
210
|
-
t.subdevices.forEach((
|
|
211
|
-
const s =
|
|
209
|
+
function C(t, a, u) {
|
|
210
|
+
t.subdevices.forEach((n, c) => {
|
|
211
|
+
const s = u.subDevices[n.type];
|
|
212
212
|
if (!s) {
|
|
213
213
|
a.addIssue({
|
|
214
214
|
code: e.ZodIssueCode.custom,
|
|
215
|
-
message: `The device is missing the device definition for the type "${
|
|
215
|
+
message: `The device is missing the device definition for the type "${n.type}"`,
|
|
216
216
|
path: ["subdevices", c, "items"]
|
|
217
217
|
});
|
|
218
218
|
return;
|
|
219
219
|
}
|
|
220
|
-
let
|
|
221
|
-
s.items_optional && (
|
|
222
|
-
|
|
220
|
+
let d = s.items;
|
|
221
|
+
s.items_optional && (d = d.filter((i) => !s.items_optional.includes(i))), d.forEach((i) => {
|
|
222
|
+
n.items.find((o) => o.name === i) || a.addIssue({
|
|
223
223
|
code: e.ZodIssueCode.custom,
|
|
224
|
-
message: `The device should have the item "${i}" because it is mandatory for devices of type "${
|
|
224
|
+
message: `The device should have the item "${i}" because it is mandatory for devices of type "${n.type}"`,
|
|
225
225
|
path: ["subdevices", c, "items"]
|
|
226
226
|
});
|
|
227
227
|
});
|
|
@@ -252,7 +252,7 @@ function r(t = void 0) {
|
|
|
252
252
|
const a = "Invalid hexadecimal value";
|
|
253
253
|
return t === void 0 ? e.string().regex(/^0x[0-9a-fA-F]+$/, a) : e.string().regex(new RegExp(`^0x[0-9a-fA-F]{${t}}$`), a);
|
|
254
254
|
}
|
|
255
|
-
function
|
|
255
|
+
function m() {
|
|
256
256
|
return e.union([
|
|
257
257
|
r(2),
|
|
258
258
|
e.number().min(0).max(255)
|
|
@@ -263,8 +263,8 @@ function S() {
|
|
|
263
263
|
if (!Array.isArray(t) || t.length % 2 !== 0)
|
|
264
264
|
return !1;
|
|
265
265
|
for (let a = 0; a < t.length; a += 2) {
|
|
266
|
-
const
|
|
267
|
-
if (typeof
|
|
266
|
+
const u = t[a], n = t[a + 1];
|
|
267
|
+
if (typeof u != "number" || typeof n != "string")
|
|
268
268
|
return !1;
|
|
269
269
|
}
|
|
270
270
|
return !0;
|
|
@@ -298,7 +298,7 @@ function J() {
|
|
|
298
298
|
fn: e.undefined().describe("Generic function to read ZCL attributes."),
|
|
299
299
|
at: r(4).or(e.array(r(4))).describe("Attribute ID."),
|
|
300
300
|
cl: r(4).describe("Cluster ID."),
|
|
301
|
-
ep: e.optional(
|
|
301
|
+
ep: e.optional(m()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
302
302
|
mf: e.optional(r(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
303
303
|
eval: e.optional(p()).describe("Javascript expression to transform the raw value.")
|
|
304
304
|
}),
|
|
@@ -306,7 +306,7 @@ function J() {
|
|
|
306
306
|
fn: e.literal("zcl").describe("Generic function to read ZCL attributes."),
|
|
307
307
|
at: r(4).or(e.array(r(4))).describe("Attribute ID."),
|
|
308
308
|
cl: r(4).describe("Cluster ID."),
|
|
309
|
-
ep: e.optional(
|
|
309
|
+
ep: e.optional(m()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
310
310
|
mf: e.optional(r(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
311
311
|
eval: e.optional(p()).describe("Javascript expression to transform the raw value."),
|
|
312
312
|
script: e.optional(f()).describe("Relative path of a Javascript .js file.")
|
|
@@ -315,7 +315,7 @@ function J() {
|
|
|
315
315
|
fn: e.literal("zcl:attr").describe("Generic function to parse ZCL values from read/report commands."),
|
|
316
316
|
at: r(4).or(e.array(r(4))).describe("String hex value or array of string hex values."),
|
|
317
317
|
cl: r(4).describe("Cluster ID."),
|
|
318
|
-
ep: e.optional(
|
|
318
|
+
ep: e.optional(m()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
319
319
|
mf: e.optional(r(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
320
320
|
eval: e.optional(p()).describe("Javascript expression to transform the attribute value to the Item value."),
|
|
321
321
|
script: e.optional(f()).describe("Relative path of a Javascript .js file.")
|
|
@@ -323,10 +323,11 @@ function J() {
|
|
|
323
323
|
e.strictObject({
|
|
324
324
|
fn: e.literal("zcl:cmd").describe("Generic function to parse ZCL values from read/report commands."),
|
|
325
325
|
cl: r(4).describe("Cluster ID."),
|
|
326
|
-
ep: e.optional(
|
|
326
|
+
ep: e.optional(m()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
327
327
|
mf: e.optional(r(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
328
328
|
cmd: e.optional(r(2)).describe("Zigbee command."),
|
|
329
329
|
eval: e.optional(p()).describe("Javascript expression to transform the attribute value to the Item value."),
|
|
330
|
+
fc: e.optional(r(2).or(e.number())).describe("Zigbee command frame control."),
|
|
330
331
|
script: e.optional(f()).describe("Relative path of a Javascript .js file.")
|
|
331
332
|
}),
|
|
332
333
|
e.strictObject({
|
|
@@ -343,7 +344,7 @@ function Z() {
|
|
|
343
344
|
at: e.optional(r(4).or(e.array(r(4)))).describe("Attribute ID."),
|
|
344
345
|
cl: r(4).describe("Cluster ID."),
|
|
345
346
|
cppsrc: e.optional(e.string()),
|
|
346
|
-
ep: e.optional(
|
|
347
|
+
ep: e.optional(m()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
347
348
|
cmd: e.optional(r(2)).describe("Zigbee command."),
|
|
348
349
|
mf: e.optional(r(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
349
350
|
eval: e.optional(p()).describe("Javascript expression to transform the raw value."),
|
|
@@ -354,7 +355,7 @@ function Z() {
|
|
|
354
355
|
at: e.optional(r(4).or(e.array(r(4)))).describe("Attribute ID."),
|
|
355
356
|
cl: r(4).describe("Cluster ID."),
|
|
356
357
|
cppsrc: e.optional(e.string()),
|
|
357
|
-
ep: e.optional(
|
|
358
|
+
ep: e.optional(m()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
358
359
|
cmd: e.optional(r(2)).describe("Zigbee command."),
|
|
359
360
|
mf: e.optional(r(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
360
361
|
eval: e.optional(p()).describe("Javascript expression to transform the raw value."),
|
|
@@ -364,7 +365,7 @@ function Z() {
|
|
|
364
365
|
fn: e.literal("zcl:attr").describe("Generic function to parse ZCL values from read/report commands."),
|
|
365
366
|
at: r(4).or(e.array(r(4))).describe("String hex value or array of string hex values."),
|
|
366
367
|
cl: r(4).describe("Cluster ID."),
|
|
367
|
-
ep: e.optional(
|
|
368
|
+
ep: e.optional(m()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
368
369
|
mf: e.optional(r(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
369
370
|
eval: e.optional(p()).describe("Javascript expression to transform the attribute value to the Item value."),
|
|
370
371
|
script: e.optional(f()).describe("Relative path of a Javascript .js file.")
|
|
@@ -372,7 +373,7 @@ function Z() {
|
|
|
372
373
|
e.strictObject({
|
|
373
374
|
fn: e.literal("zcl:cmd").describe("Generic function to parse ZCL values from read/report commands."),
|
|
374
375
|
cl: r(4).describe("Cluster ID."),
|
|
375
|
-
ep: e.optional(
|
|
376
|
+
ep: e.optional(m()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
376
377
|
mf: e.optional(r(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
377
378
|
cmd: e.optional(r(2)).describe("Zigbee command."),
|
|
378
379
|
eval: e.optional(p()).describe("Javascript expression to transform the attribute value to the Item value."),
|
|
@@ -394,7 +395,7 @@ function Z() {
|
|
|
394
395
|
}),
|
|
395
396
|
e.strictObject({
|
|
396
397
|
fn: e.literal("xiaomi:special").describe("Generic function to parse custom Xiaomi attributes and commands."),
|
|
397
|
-
ep: e.optional(
|
|
398
|
+
ep: e.optional(m()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
398
399
|
mf: e.optional(r(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
399
400
|
at: e.optional(r(4)).describe("Attribute ID. The attribute to parse, shall be 0xff01, 0xff02 or 0x00f7"),
|
|
400
401
|
idx: r(2).describe("A 8-bit string hex value."),
|
|
@@ -411,7 +412,7 @@ function Z() {
|
|
|
411
412
|
message: "eval and script should not both be present"
|
|
412
413
|
});
|
|
413
414
|
}
|
|
414
|
-
function
|
|
415
|
+
function G() {
|
|
415
416
|
return e.discriminatedUnion("fn", [
|
|
416
417
|
e.strictObject({
|
|
417
418
|
fn: e.literal("none")
|
|
@@ -423,7 +424,7 @@ function R() {
|
|
|
423
424
|
"change.timeout": e.optional(e.number()),
|
|
424
425
|
cl: r(4).describe("Cluster ID."),
|
|
425
426
|
dt: r(2).describe("Data type."),
|
|
426
|
-
ep: e.optional(
|
|
427
|
+
ep: e.optional(m()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
427
428
|
mf: e.optional(r(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
428
429
|
eval: e.optional(p()).describe("Javascript expression to transform the raw value."),
|
|
429
430
|
script: e.optional(f()).describe("Relative path of a Javascript .js file.")
|
|
@@ -435,7 +436,7 @@ function R() {
|
|
|
435
436
|
"change.timeout": e.optional(e.number()),
|
|
436
437
|
cl: r(4).describe("Cluster ID."),
|
|
437
438
|
dt: r(2).describe("Data type."),
|
|
438
|
-
ep: e.optional(
|
|
439
|
+
ep: e.optional(m()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
439
440
|
mf: e.optional(r(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
440
441
|
eval: e.optional(p()).describe("Javascript expression to transform the raw value."),
|
|
441
442
|
script: e.optional(f()).describe("Relative path of a Javascript .js file.")
|
|
@@ -447,7 +448,7 @@ function R() {
|
|
|
447
448
|
"change.timeout": e.optional(e.number()),
|
|
448
449
|
cl: r(4).describe("Cluster ID."),
|
|
449
450
|
dt: r(2).describe("Data type."),
|
|
450
|
-
ep: e.optional(
|
|
451
|
+
ep: e.optional(m()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
451
452
|
mf: e.optional(r(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
452
453
|
eval: e.optional(p()).describe("Javascript expression to transform the attribute value to the Item value."),
|
|
453
454
|
script: e.optional(f()).describe("Relative path of a Javascript .js file.")
|
|
@@ -455,8 +456,7 @@ function R() {
|
|
|
455
456
|
e.strictObject({
|
|
456
457
|
fn: e.literal("zcl:cmd").describe("Generic function to parse ZCL values from read/report commands."),
|
|
457
458
|
cl: r(4).describe("Cluster ID."),
|
|
458
|
-
|
|
459
|
-
ep: e.optional(l()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
459
|
+
ep: e.optional(m()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
460
460
|
mf: e.optional(r(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
461
461
|
cmd: e.optional(r(2)).describe("Zigbee command."),
|
|
462
462
|
eval: e.optional(p()).describe("Javascript expression to transform the attribute value to the Item value."),
|
|
@@ -507,7 +507,7 @@ function D(t) {
|
|
|
507
507
|
virtual: e.optional(e.boolean()).describe("TODO: What is this ?"),
|
|
508
508
|
read: e.optional(J()).describe("Fonction used to read value."),
|
|
509
509
|
parse: e.optional(Z()).describe("Fonction used to parse incoming values."),
|
|
510
|
-
write: e.optional(
|
|
510
|
+
write: e.optional(G()).describe("Fonction used to write value."),
|
|
511
511
|
"refresh.interval": e.optional(e.number()).describe("Refresh interval used for read fonction, NEED to be superior at value used in binding part."),
|
|
512
512
|
// TODO Validate this
|
|
513
513
|
values: e.optional(e.unknown()).describe("TODO: What is this ?"),
|
|
@@ -515,7 +515,7 @@ function D(t) {
|
|
|
515
515
|
default: e.optional(e.unknown()).describe("Defaut value.")
|
|
516
516
|
});
|
|
517
517
|
}
|
|
518
|
-
function
|
|
518
|
+
function R(t) {
|
|
519
519
|
return e.strictObject({
|
|
520
520
|
$schema: e.optional(e.string()),
|
|
521
521
|
schema: e.literal("devcap1.schema.json"),
|
|
@@ -552,7 +552,7 @@ function F(t) {
|
|
|
552
552
|
return e.strictObject({
|
|
553
553
|
type: e.union([
|
|
554
554
|
e.enum(Object.keys(t.deviceTypes), {
|
|
555
|
-
errorMap: (a,
|
|
555
|
+
errorMap: (a, u) => a.code === "invalid_enum_value" ? { message: `Invalid enum value. Expected type from generic attributes definition, received '${a.received}'` } : { message: u.defaultError }
|
|
556
556
|
}),
|
|
557
557
|
e.string().regex(/^(?!\$TYPE_).*/g, "The type start with $TYPE_ but is not present in constants.json")
|
|
558
558
|
]),
|
|
@@ -561,7 +561,7 @@ function F(t) {
|
|
|
561
561
|
fingerprint: e.optional(e.strictObject({
|
|
562
562
|
profile: r(4),
|
|
563
563
|
device: r(4),
|
|
564
|
-
endpoint:
|
|
564
|
+
endpoint: m(),
|
|
565
565
|
in: e.optional(e.array(r(4))),
|
|
566
566
|
out: e.optional(e.array(r(4)))
|
|
567
567
|
})),
|
|
@@ -585,7 +585,7 @@ function z(t) {
|
|
|
585
585
|
id: !0
|
|
586
586
|
}).extend({
|
|
587
587
|
name: e.enum(t.attributes, {
|
|
588
|
-
errorMap: (a,
|
|
588
|
+
errorMap: (a, u) => a.code === "invalid_enum_value" ? { message: `Invalid enum value. Expected item from generic attributes definition, received '${a.received}'` } : { message: u.defaultError }
|
|
589
589
|
}).describe("Item name.")
|
|
590
590
|
});
|
|
591
591
|
}
|
|
@@ -593,8 +593,8 @@ function k(t) {
|
|
|
593
593
|
return e.discriminatedUnion("bind", [
|
|
594
594
|
e.strictObject({
|
|
595
595
|
bind: e.literal("unicast"),
|
|
596
|
-
"src.ep":
|
|
597
|
-
"dst.ep": e.optional(
|
|
596
|
+
"src.ep": m().describe("Source endpoint."),
|
|
597
|
+
"dst.ep": e.optional(m()).describe("Destination endpoint, generaly 0x01."),
|
|
598
598
|
cl: r(4).describe("Cluster."),
|
|
599
599
|
report: e.optional(e.array(
|
|
600
600
|
e.strictObject({
|
|
@@ -609,7 +609,7 @@ function k(t) {
|
|
|
609
609
|
}),
|
|
610
610
|
e.strictObject({
|
|
611
611
|
bind: e.literal("groupcast"),
|
|
612
|
-
"src.ep":
|
|
612
|
+
"src.ep": m().describe("Source endpoint."),
|
|
613
613
|
cl: r(4).describe("Cluster."),
|
|
614
614
|
"config.group": e.number().min(0).max(255)
|
|
615
615
|
})
|
|
@@ -618,7 +618,7 @@ function k(t) {
|
|
|
618
618
|
function L(t) {
|
|
619
619
|
const a = e.array(
|
|
620
620
|
e.enum(t.attributes, {
|
|
621
|
-
errorMap: (
|
|
621
|
+
errorMap: (u, n) => u.code === "invalid_enum_value" ? { message: `Invalid enum value. Expected item from generic attributes definition, received '${u.received}'` } : { message: n.defaultError }
|
|
622
622
|
})
|
|
623
623
|
);
|
|
624
624
|
return e.strictObject({
|
|
@@ -626,7 +626,7 @@ function L(t) {
|
|
|
626
626
|
schema: e.literal("subdevice1.schema.json"),
|
|
627
627
|
type: e.union([
|
|
628
628
|
e.enum(Object.keys(t.deviceTypes), {
|
|
629
|
-
errorMap: (
|
|
629
|
+
errorMap: (u, n) => u.code === "invalid_enum_value" ? { message: `Invalid enum value. Expected type from generic attributes definition, received '${u.received}'` } : { message: n.defaultError }
|
|
630
630
|
}),
|
|
631
631
|
e.string().regex(/^(?!\$TYPE_).*/g, "The type start with $TYPE_ but is not present in constants.json")
|
|
632
632
|
]),
|
|
@@ -640,18 +640,18 @@ function L(t) {
|
|
|
640
640
|
}
|
|
641
641
|
function x(t) {
|
|
642
642
|
return e.discriminatedUnion("schema", [
|
|
643
|
-
|
|
643
|
+
R(t),
|
|
644
644
|
A(),
|
|
645
645
|
I(),
|
|
646
646
|
D(),
|
|
647
647
|
L(t)
|
|
648
|
-
]).superRefine((a,
|
|
648
|
+
]).superRefine((a, u) => {
|
|
649
649
|
switch (a.schema) {
|
|
650
650
|
case "devcap1.schema.json":
|
|
651
|
-
y[a.schema].map((
|
|
651
|
+
y[a.schema].map((n) => n(a, u, t));
|
|
652
652
|
break;
|
|
653
653
|
case "constants2.schema.json":
|
|
654
|
-
y[a.schema].map((
|
|
654
|
+
y[a.schema].map((n) => n(a, u, t));
|
|
655
655
|
break;
|
|
656
656
|
}
|
|
657
657
|
});
|
|
@@ -664,44 +664,49 @@ function P(t = {
|
|
|
664
664
|
subDevices: {}
|
|
665
665
|
}) {
|
|
666
666
|
let a = x(t);
|
|
667
|
-
const
|
|
667
|
+
const u = () => {
|
|
668
668
|
a = x(t);
|
|
669
669
|
};
|
|
670
|
-
return { generics: t, loadGeneric: (
|
|
671
|
-
const
|
|
672
|
-
switch (
|
|
670
|
+
return { generics: t, loadGeneric: (d) => {
|
|
671
|
+
const i = a.parse(d);
|
|
672
|
+
switch (i.schema) {
|
|
673
673
|
case "constants1.schema.json":
|
|
674
674
|
t.manufacturers = {
|
|
675
675
|
...t.manufacturers,
|
|
676
|
-
...
|
|
676
|
+
...i.manufacturers
|
|
677
677
|
}, t.deviceTypes = {
|
|
678
678
|
...t.deviceTypes,
|
|
679
|
-
...
|
|
679
|
+
...i["device-types"]
|
|
680
680
|
};
|
|
681
681
|
break;
|
|
682
682
|
case "constants2.schema.json": {
|
|
683
|
-
Object.keys(
|
|
684
|
-
t.manufacturers[
|
|
685
|
-
}), Object.keys(
|
|
686
|
-
t.deviceTypes[
|
|
683
|
+
Object.keys(i).filter((o) => o.startsWith("$MF_")).forEach((o) => {
|
|
684
|
+
t.manufacturers[o] = i[o];
|
|
685
|
+
}), Object.keys(i).filter((o) => o.startsWith("$TYPE_")).forEach((o) => {
|
|
686
|
+
t.deviceTypes[o] = i[o];
|
|
687
687
|
});
|
|
688
688
|
break;
|
|
689
689
|
}
|
|
690
690
|
case "resourceitem1.schema.json": {
|
|
691
|
-
if (t.attributes.includes(
|
|
692
|
-
throw new Error(`Got duplicate resource item with attribute id '${
|
|
693
|
-
const
|
|
694
|
-
delete
|
|
691
|
+
if (t.attributes.includes(i.id))
|
|
692
|
+
throw new Error(`Got duplicate resource item with attribute id '${i.id}'.`);
|
|
693
|
+
const o = i, l = i.id;
|
|
694
|
+
delete o.$schema, delete o.schema, delete o.id, t.resources[l] = o, t.attributes.push(l);
|
|
695
695
|
break;
|
|
696
696
|
}
|
|
697
697
|
case "subdevice1.schema.json":
|
|
698
|
-
t.subDevices[
|
|
698
|
+
t.subDevices[i.type] = i, t.subDevices[i.name] = i;
|
|
699
699
|
break;
|
|
700
|
-
|
|
701
|
-
throw new Error(
|
|
700
|
+
default:
|
|
701
|
+
throw new Error(`Got invalid generic file, got data with schema '${i.schema}'.`);
|
|
702
702
|
}
|
|
703
|
-
return
|
|
704
|
-
}, validate: (
|
|
703
|
+
return u(), !0;
|
|
704
|
+
}, validate: (d) => a.parse(d), getSchema: () => a, version: E, isGeneric: (d) => [
|
|
705
|
+
"constants1.schema.json",
|
|
706
|
+
"constants2.schema.json",
|
|
707
|
+
"resourceitem1.schema.json",
|
|
708
|
+
"subdevice1.schema.json"
|
|
709
|
+
].includes(d) };
|
|
705
710
|
}
|
|
706
711
|
export {
|
|
707
712
|
P as createValidator
|