@deconz-community/ddf-validator 2.0.0 → 2.2.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 +428 -40
- package/dist/ddf-validator.mjs +527 -292
- package/package.json +15 -15
package/dist/ddf-validator.mjs
CHANGED
|
@@ -1,358 +1,593 @@
|
|
|
1
|
-
import { z as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { z as e } from "zod";
|
|
2
|
+
const I = [
|
|
3
|
+
j,
|
|
4
|
+
D,
|
|
5
|
+
O,
|
|
6
|
+
w
|
|
7
|
+
];
|
|
8
|
+
function j(a, i) {
|
|
9
|
+
const n = typeof a.manufacturername == "string" && typeof a.modelid == "string";
|
|
10
|
+
if (n)
|
|
11
|
+
return;
|
|
12
|
+
const c = Array.isArray(a.manufacturername) && Array.isArray(a.modelid);
|
|
13
|
+
if (c && a.manufacturername.length !== a.modelid.length) {
|
|
14
|
+
i.addIssue({
|
|
15
|
+
code: e.ZodIssueCode.invalid_intersection_types,
|
|
16
|
+
message: "When 'manufacturername' and 'modelid' are both arrays they should be the same length",
|
|
17
|
+
path: ["manufacturername", "modelid"]
|
|
18
|
+
});
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
(n || c) === !1 && i.addIssue({
|
|
22
|
+
code: e.ZodIssueCode.invalid_intersection_types,
|
|
23
|
+
message: "Invalid properties 'manufacturername' and 'modelid' should have the same type",
|
|
24
|
+
path: ["manufacturername", "modelid"]
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function D(a, i) {
|
|
28
|
+
if (!a.bindings)
|
|
29
|
+
return;
|
|
30
|
+
const n = (s) => `0x${(typeof s == "number" ? s : parseInt(s, 16)).toString(16)}`, c = {};
|
|
31
|
+
a.bindings.forEach((s) => {
|
|
32
|
+
s.bind === "unicast" && s.report && s.report.forEach((m) => {
|
|
33
|
+
c[`${n(s["src.ep"])}.${n(s.cl)}.${n(m.at)}`] = m.max;
|
|
34
|
+
});
|
|
35
|
+
}), a.subdevices.forEach((s, m) => {
|
|
36
|
+
s.items.forEach((r, o) => {
|
|
37
|
+
var l;
|
|
38
|
+
if (r["refresh.interval"] && r.read && r.read.fn === "zcl") {
|
|
39
|
+
const f = n(r.read.ep ?? ((l = s.fingerprint) == null ? void 0 : l.endpoint) ?? s.uuid[1]), b = Array.isArray(r.read.at) ? r.read.at : [r.read.at];
|
|
40
|
+
for (let h = 0; h < b.length; h++) {
|
|
41
|
+
const v = `${f}.${n(r.read.cl)}.${n(b[h])}`;
|
|
42
|
+
c[v] !== void 0 && r["refresh.interval"] - 60 < c[v] && i.addIssue({
|
|
43
|
+
code: e.ZodIssueCode.custom,
|
|
44
|
+
message: `The refresh interval (${r["refresh.interval"]} - 60 = ${r["refresh.interval"] - 60}) should be greater than the binding max refresh value (${c[v]}) with a margin of 60 seconds`,
|
|
45
|
+
path: ["subdevices", m, "items", o, "refresh.interval"]
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function O(a, i) {
|
|
53
|
+
if (!a.bindings)
|
|
54
|
+
return;
|
|
55
|
+
const n = [
|
|
56
|
+
/*
|
|
57
|
+
{
|
|
58
|
+
description: 'a device should always have basic attributes.',
|
|
59
|
+
if: {},
|
|
60
|
+
need: {
|
|
61
|
+
item: [
|
|
62
|
+
'attr/id',
|
|
63
|
+
'attr/name',
|
|
64
|
+
'attr/uniqueid',
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
*/
|
|
69
|
+
{
|
|
70
|
+
description: 'a color light should always have "state/ct" item.',
|
|
71
|
+
if: {
|
|
72
|
+
type: [
|
|
73
|
+
"$TYPE_COLOR_TEMPERATURE_LIGHT",
|
|
74
|
+
"Color Temperature Light",
|
|
75
|
+
"$TYPE_EXTENDED_COLOR_LIGHT",
|
|
76
|
+
"Extended Color Light"
|
|
77
|
+
]
|
|
78
|
+
},
|
|
79
|
+
need: {
|
|
80
|
+
item: [
|
|
81
|
+
"state/ct"
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
description: 'a device with "state/ct" need the "min" and "max" values for capability.',
|
|
87
|
+
if: {
|
|
88
|
+
item: ["state/ct"]
|
|
89
|
+
},
|
|
90
|
+
need: {
|
|
91
|
+
item: [
|
|
92
|
+
"cap/color/ct/min",
|
|
93
|
+
"cap/color/ct/max"
|
|
94
|
+
// 'config/color/ct/startup',
|
|
95
|
+
]
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
description: 'a device with "state/x" or "state/y" need the corresponding red, green and blue x and y values.',
|
|
100
|
+
if: {
|
|
101
|
+
item: [
|
|
102
|
+
"state/x",
|
|
103
|
+
"state/y"
|
|
104
|
+
]
|
|
105
|
+
},
|
|
106
|
+
need: {
|
|
107
|
+
item: [
|
|
108
|
+
"state/x",
|
|
109
|
+
"state/y",
|
|
110
|
+
"cap/color/xy/red_x",
|
|
111
|
+
"cap/color/xy/green_x",
|
|
112
|
+
"cap/color/xy/blue_x",
|
|
113
|
+
"cap/color/xy/red_y",
|
|
114
|
+
"cap/color/xy/green_y",
|
|
115
|
+
"cap/color/xy/blue_y"
|
|
116
|
+
// 'cap/color/ct/computes_xy',
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
];
|
|
121
|
+
a.subdevices.forEach((c, s) => {
|
|
122
|
+
const m = c.items.map((r) => r.name);
|
|
123
|
+
n.forEach((r) => {
|
|
124
|
+
(Object.keys(r.if).length === 0 || Object.keys(r.if).some((o) => {
|
|
125
|
+
var l;
|
|
126
|
+
switch (o) {
|
|
127
|
+
case "type":
|
|
128
|
+
return (l = r.if[o]) == null ? void 0 : l.includes(c.type);
|
|
129
|
+
case "item":
|
|
130
|
+
return m.some((f) => {
|
|
131
|
+
var b;
|
|
132
|
+
return (b = r.if[o]) == null ? void 0 : b.includes(f);
|
|
133
|
+
});
|
|
134
|
+
default:
|
|
135
|
+
return !1;
|
|
136
|
+
}
|
|
137
|
+
})) && r.need.item.forEach((o) => {
|
|
138
|
+
m.includes(o) || i.addIssue({
|
|
139
|
+
code: e.ZodIssueCode.custom,
|
|
140
|
+
message: `The device should have the item "${o}" because ${r.description}`,
|
|
141
|
+
path: ["subdevices", s, "items"]
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
});
|
|
8
145
|
});
|
|
9
146
|
}
|
|
10
|
-
function
|
|
11
|
-
|
|
147
|
+
function w(a, i) {
|
|
148
|
+
const n = ["parse", "write"];
|
|
149
|
+
a.subdevices.forEach((c, s) => {
|
|
150
|
+
c.items.forEach((m, r) => {
|
|
151
|
+
n.forEach((o) => {
|
|
152
|
+
const l = m[o];
|
|
153
|
+
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 && i.addIssue({
|
|
154
|
+
code: e.ZodIssueCode.custom,
|
|
155
|
+
message: `The '${o}' function is missing 'eval' or 'script' option.`,
|
|
156
|
+
path: ["subdevices", s, "items", r, o]
|
|
157
|
+
}), l.eval !== void 0 && l.script !== void 0 && i.addIssue({
|
|
158
|
+
code: e.ZodIssueCode.custom,
|
|
159
|
+
message: `The '${o}' function is having both 'eval' and 'script' option.`,
|
|
160
|
+
path: ["subdevices", s, "items", r, o]
|
|
161
|
+
}));
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
function E(a) {
|
|
167
|
+
return e.strictObject({
|
|
168
|
+
$schema: e.optional(e.string()),
|
|
169
|
+
schema: e.literal("constants1.schema.json"),
|
|
170
|
+
manufacturers: e.record(e.string().startsWith("$MF_"), e.string()),
|
|
171
|
+
"device-types": e.record(e.string().startsWith("$TYPE_"), e.string())
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
function T() {
|
|
175
|
+
return e.string().regex(
|
|
12
176
|
// Regex for AAAA-MM-JJ
|
|
13
177
|
/^(\d{4})-(?:(?:0[1-9])|(?:1[0-2]))-(?:(?:0[1-9])|(?:[12][0-9])|(?:3[01]))$/,
|
|
14
178
|
"Invalid date value"
|
|
15
179
|
);
|
|
16
180
|
}
|
|
17
|
-
function
|
|
181
|
+
function t(a = void 0) {
|
|
18
182
|
const i = "Invalid hexadecimal value";
|
|
19
|
-
return
|
|
183
|
+
return a === void 0 ? e.string().regex(/^0x[0-9a-fA-F]+$/, i) : e.string().regex(new RegExp(`^0x[0-9a-fA-F]{${a}}$`), i);
|
|
20
184
|
}
|
|
21
|
-
function
|
|
22
|
-
return
|
|
23
|
-
|
|
24
|
-
|
|
185
|
+
function d() {
|
|
186
|
+
return e.union([
|
|
187
|
+
t(2),
|
|
188
|
+
e.number().min(0).max(255)
|
|
25
189
|
]);
|
|
26
190
|
}
|
|
27
|
-
function
|
|
28
|
-
return
|
|
29
|
-
if (!Array.isArray(
|
|
191
|
+
function C() {
|
|
192
|
+
return e.custom((a) => {
|
|
193
|
+
if (!Array.isArray(a) || a.length % 2 !== 0)
|
|
30
194
|
return !1;
|
|
31
|
-
for (let i = 0; i <
|
|
32
|
-
const
|
|
33
|
-
if (typeof
|
|
195
|
+
for (let i = 0; i < a.length; i += 2) {
|
|
196
|
+
const n = a[i], c = a[i + 1];
|
|
197
|
+
if (typeof n != "number" || typeof c != "string")
|
|
34
198
|
return !1;
|
|
35
199
|
}
|
|
36
200
|
return !0;
|
|
37
201
|
}, "The value must be an array with an even number of values and alternating between number and string.");
|
|
38
202
|
}
|
|
39
|
-
function
|
|
40
|
-
return
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
203
|
+
function y() {
|
|
204
|
+
return e.union([
|
|
205
|
+
e.tuple([
|
|
206
|
+
e.literal("$address.ext"),
|
|
207
|
+
t(2)
|
|
44
208
|
]),
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
209
|
+
e.tuple([
|
|
210
|
+
e.literal("$address.ext"),
|
|
211
|
+
t(2),
|
|
212
|
+
t(4)
|
|
49
213
|
])
|
|
50
214
|
]);
|
|
51
215
|
}
|
|
52
|
-
function
|
|
53
|
-
return
|
|
216
|
+
function p() {
|
|
217
|
+
return e.string();
|
|
54
218
|
}
|
|
55
|
-
function
|
|
56
|
-
return
|
|
219
|
+
function u() {
|
|
220
|
+
return e.string();
|
|
57
221
|
}
|
|
58
|
-
function
|
|
59
|
-
return
|
|
60
|
-
|
|
61
|
-
fn:
|
|
222
|
+
function $() {
|
|
223
|
+
return e.discriminatedUnion("fn", [
|
|
224
|
+
e.strictObject({
|
|
225
|
+
fn: e.literal("none")
|
|
226
|
+
}),
|
|
227
|
+
e.strictObject({
|
|
228
|
+
fn: e.undefined().describe("Generic function to read ZCL attributes."),
|
|
229
|
+
at: t(4).or(e.array(t(4))).describe("Attribute ID."),
|
|
230
|
+
cl: t(4).describe("Cluster ID."),
|
|
231
|
+
ep: e.optional(d()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
232
|
+
mf: e.optional(t(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
233
|
+
eval: e.optional(u()).describe("Javascript expression to transform the raw value.")
|
|
62
234
|
}),
|
|
63
|
-
|
|
64
|
-
fn:
|
|
65
|
-
at: t
|
|
66
|
-
cl:
|
|
67
|
-
ep:
|
|
68
|
-
mf:
|
|
69
|
-
eval:
|
|
235
|
+
e.strictObject({
|
|
236
|
+
fn: e.literal("zcl").describe("Generic function to read ZCL attributes."),
|
|
237
|
+
at: t(4).or(e.array(t(4))).describe("Attribute ID."),
|
|
238
|
+
cl: t(4).describe("Cluster ID."),
|
|
239
|
+
ep: e.optional(d()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
240
|
+
mf: e.optional(t(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
241
|
+
eval: e.optional(u()).describe("Javascript expression to transform the raw value."),
|
|
242
|
+
script: e.optional(p()).describe("Relative path of a Javascript .js file.")
|
|
243
|
+
}).describe("Deprecated"),
|
|
244
|
+
e.strictObject({
|
|
245
|
+
fn: e.literal("zcl:attr").describe("Generic function to parse ZCL values from read/report commands."),
|
|
246
|
+
at: t(4).or(e.array(t(4))).describe("String hex value or array of string hex values."),
|
|
247
|
+
cl: t(4).describe("Cluster ID."),
|
|
248
|
+
ep: e.optional(d()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
249
|
+
mf: e.optional(t(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
250
|
+
eval: e.optional(u()).describe("Javascript expression to transform the attribute value to the Item value."),
|
|
251
|
+
script: e.optional(p()).describe("Relative path of a Javascript .js file.")
|
|
70
252
|
}),
|
|
71
|
-
|
|
72
|
-
fn:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
eval:
|
|
253
|
+
e.strictObject({
|
|
254
|
+
fn: e.literal("zcl:cmd").describe("Generic function to parse ZCL values from read/report commands."),
|
|
255
|
+
cl: t(4).describe("Cluster ID."),
|
|
256
|
+
ep: e.optional(d()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
257
|
+
mf: e.optional(t(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
258
|
+
cmd: e.optional(t(2)).describe("Zigbee command."),
|
|
259
|
+
eval: e.optional(u()).describe("Javascript expression to transform the attribute value to the Item value."),
|
|
260
|
+
script: e.optional(p()).describe("Relative path of a Javascript .js file.")
|
|
78
261
|
}),
|
|
79
|
-
|
|
80
|
-
fn:
|
|
262
|
+
e.strictObject({
|
|
263
|
+
fn: e.literal("tuya").describe("Generic function to read all Tuya datapoints. It has no parameters.")
|
|
81
264
|
})
|
|
82
|
-
])
|
|
265
|
+
]).refine((a) => !("eval" in a && "script" in a), {
|
|
266
|
+
message: "eval and script should not both be present"
|
|
267
|
+
});
|
|
83
268
|
}
|
|
84
|
-
function
|
|
85
|
-
return
|
|
86
|
-
|
|
87
|
-
fn:
|
|
88
|
-
at:
|
|
89
|
-
cl:
|
|
90
|
-
cppsrc:
|
|
91
|
-
ep:
|
|
92
|
-
cmd:
|
|
93
|
-
mf:
|
|
94
|
-
eval:
|
|
95
|
-
script:
|
|
96
|
-
}).refine((e) => !("eval" in e && "script" in e), {
|
|
97
|
-
message: "eval and script should not both be present"
|
|
98
|
-
}).innerType(),
|
|
99
|
-
t.strictObject({
|
|
100
|
-
fn: t.literal("zcl"),
|
|
101
|
-
at: t.optional(n(4)),
|
|
102
|
-
cl: n(4),
|
|
103
|
-
cppsrc: t.optional(t.string()),
|
|
104
|
-
ep: t.optional(a()),
|
|
105
|
-
cmd: t.optional(n(2)),
|
|
106
|
-
mf: t.optional(n(4)),
|
|
107
|
-
eval: t.optional(r()),
|
|
108
|
-
script: t.optional(o())
|
|
109
|
-
}).refine((e) => !("eval" in e && "script" in e), {
|
|
110
|
-
message: "eval and script should not both be present"
|
|
111
|
-
}).innerType(),
|
|
112
|
-
t.strictObject({
|
|
113
|
-
fn: t.literal("ias:zonestatus"),
|
|
114
|
-
mask: t.optional(t.enum(["alarm1", "alarm2"]).or(t.literal("alarm1,alarm2")))
|
|
269
|
+
function A() {
|
|
270
|
+
return e.discriminatedUnion("fn", [
|
|
271
|
+
e.strictObject({
|
|
272
|
+
fn: e.undefined().describe("Generic function to parse ZCL attributes and commands."),
|
|
273
|
+
at: e.optional(t(4).or(e.array(t(4)))).describe("Attribute ID."),
|
|
274
|
+
cl: t(4).describe("Cluster ID."),
|
|
275
|
+
cppsrc: e.optional(e.string()),
|
|
276
|
+
ep: e.optional(d()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
277
|
+
cmd: e.optional(t(2)).describe("Zigbee command."),
|
|
278
|
+
mf: e.optional(t(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
279
|
+
eval: e.optional(u()).describe("Javascript expression to transform the raw value."),
|
|
280
|
+
script: e.optional(p()).describe("Relative path of a Javascript .js file.")
|
|
115
281
|
}),
|
|
116
|
-
|
|
117
|
-
fn:
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
282
|
+
e.strictObject({
|
|
283
|
+
fn: e.literal("zcl").describe("Generic function to parse ZCL attributes and commands."),
|
|
284
|
+
at: e.optional(t(4).or(e.array(t(4)))).describe("Attribute ID."),
|
|
285
|
+
cl: t(4).describe("Cluster ID."),
|
|
286
|
+
cppsrc: e.optional(e.string()),
|
|
287
|
+
ep: e.optional(d()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
288
|
+
cmd: e.optional(t(2)).describe("Zigbee command."),
|
|
289
|
+
mf: e.optional(t(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
290
|
+
eval: e.optional(u()).describe("Javascript expression to transform the raw value."),
|
|
291
|
+
script: e.optional(p()).describe("Relative path of a Javascript .js file.")
|
|
292
|
+
}).describe("Deprecated"),
|
|
293
|
+
e.strictObject({
|
|
294
|
+
fn: e.literal("zcl:attr").describe("Generic function to parse ZCL values from read/report commands."),
|
|
295
|
+
at: t(4).or(e.array(t(4))).describe("String hex value or array of string hex values."),
|
|
296
|
+
cl: t(4).describe("Cluster ID."),
|
|
297
|
+
ep: e.optional(d()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
298
|
+
mf: e.optional(t(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
299
|
+
eval: e.optional(u()).describe("Javascript expression to transform the attribute value to the Item value."),
|
|
300
|
+
script: e.optional(p()).describe("Relative path of a Javascript .js file.")
|
|
121
301
|
}),
|
|
122
|
-
|
|
123
|
-
fn:
|
|
302
|
+
e.strictObject({
|
|
303
|
+
fn: e.literal("zcl:cmd").describe("Generic function to parse ZCL values from read/report commands."),
|
|
304
|
+
cl: t(4).describe("Cluster ID."),
|
|
305
|
+
ep: e.optional(d()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
306
|
+
mf: e.optional(t(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
307
|
+
cmd: e.optional(t(2)).describe("Zigbee command."),
|
|
308
|
+
eval: e.optional(u()).describe("Javascript expression to transform the attribute value to the Item value."),
|
|
309
|
+
script: e.optional(p()).describe("Relative path of a Javascript .js file.")
|
|
124
310
|
}),
|
|
125
|
-
|
|
126
|
-
fn:
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
311
|
+
e.strictObject({
|
|
312
|
+
fn: e.literal("ias:zonestatus").describe("Generic function to parse IAS ZONE status change notifications or zone status from read/report command."),
|
|
313
|
+
mask: e.optional(e.enum(["alarm1", "alarm2"]).or(e.literal("alarm1,alarm2"))).describe("Sets the bitmask for Alert1 and Alert2 item of the IAS Zone status.")
|
|
314
|
+
}),
|
|
315
|
+
e.strictObject({
|
|
316
|
+
fn: e.literal("numtostr").describe("Generic function to to convert number to string."),
|
|
317
|
+
// TODO use generic
|
|
318
|
+
srcitem: e.enum(["state/airqualityppb", "state/pm2_5"]).describe("The source item holding the number."),
|
|
319
|
+
op: e.enum(["lt", "le", "eq", "gt", "ge"]).describe("Comparison operator (lt | le | eq | gt | ge)"),
|
|
320
|
+
to: C().describe("Array of (num, string) mappings")
|
|
321
|
+
}),
|
|
322
|
+
e.strictObject({
|
|
323
|
+
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.")
|
|
324
|
+
}),
|
|
325
|
+
e.strictObject({
|
|
326
|
+
fn: e.literal("xiaomi:special").describe("Generic function to parse custom Xiaomi attributes and commands."),
|
|
327
|
+
ep: e.optional(d()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
328
|
+
at: e.optional(t(4)).describe("Attribute ID. The attribute to parse, shall be 0xff01, 0xff02 or 0x00f7"),
|
|
329
|
+
idx: t(2).describe("A 8-bit string hex value."),
|
|
330
|
+
eval: e.optional(u()).describe("Javascript expression to transform the raw value."),
|
|
331
|
+
script: e.optional(p()).describe("Relative path of a Javascript .js file.")
|
|
332
|
+
}),
|
|
333
|
+
e.strictObject({
|
|
334
|
+
fn: e.literal("tuya").describe("Generic function to parse Tuya data."),
|
|
335
|
+
dpid: e.number().describe("Data point ID. 1-255 the datapoint ID."),
|
|
336
|
+
eval: e.optional(u()).describe("Javascript expression to transform the raw value."),
|
|
337
|
+
script: e.optional(p()).describe("Relative path of a Javascript .js file.")
|
|
338
|
+
})
|
|
339
|
+
]).refine((a) => !("eval" in a && "script" in a), {
|
|
340
|
+
message: "eval and script should not both be present"
|
|
341
|
+
});
|
|
144
342
|
}
|
|
145
|
-
function
|
|
146
|
-
return
|
|
147
|
-
|
|
148
|
-
fn:
|
|
343
|
+
function J() {
|
|
344
|
+
return e.discriminatedUnion("fn", [
|
|
345
|
+
e.strictObject({
|
|
346
|
+
fn: e.literal("none")
|
|
149
347
|
}),
|
|
150
|
-
|
|
151
|
-
fn:
|
|
152
|
-
at:
|
|
153
|
-
"state.timeout":
|
|
154
|
-
"change.timeout":
|
|
155
|
-
cl:
|
|
156
|
-
dt:
|
|
157
|
-
ep:
|
|
158
|
-
mf:
|
|
159
|
-
eval:
|
|
160
|
-
script:
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
348
|
+
e.strictObject({
|
|
349
|
+
fn: e.undefined(),
|
|
350
|
+
at: e.optional(t(4).or(e.array(t(4)))).describe("Attribute ID."),
|
|
351
|
+
"state.timeout": e.optional(e.number()),
|
|
352
|
+
"change.timeout": e.optional(e.number()),
|
|
353
|
+
cl: t(4).describe("Cluster ID."),
|
|
354
|
+
dt: t(2).describe("Data type."),
|
|
355
|
+
ep: e.optional(d()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
356
|
+
mf: e.optional(t(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
357
|
+
eval: e.optional(u()).describe("Javascript expression to transform the raw value."),
|
|
358
|
+
script: e.optional(p()).describe("Relative path of a Javascript .js file.")
|
|
359
|
+
}),
|
|
360
|
+
e.strictObject({
|
|
361
|
+
fn: e.literal("zcl"),
|
|
362
|
+
at: e.optional(t(4).or(e.array(t(4)))).describe("Attribute ID."),
|
|
363
|
+
"state.timeout": e.optional(e.number()),
|
|
364
|
+
"change.timeout": e.optional(e.number()),
|
|
365
|
+
cl: t(4).describe("Cluster ID."),
|
|
366
|
+
dt: t(2).describe("Data type."),
|
|
367
|
+
ep: e.optional(d()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
368
|
+
mf: e.optional(t(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
369
|
+
eval: e.optional(u()).describe("Javascript expression to transform the raw value."),
|
|
370
|
+
script: e.optional(p()).describe("Relative path of a Javascript .js file.")
|
|
371
|
+
}).describe("Deprecated"),
|
|
372
|
+
e.strictObject({
|
|
373
|
+
fn: e.literal("zcl:attr").describe("Generic function to parse ZCL values from read/report commands."),
|
|
374
|
+
at: t(4).or(e.array(t(4))).describe("String hex value or array of string hex values."),
|
|
375
|
+
"state.timeout": e.optional(e.number()),
|
|
376
|
+
"change.timeout": e.optional(e.number()),
|
|
377
|
+
cl: t(4).describe("Cluster ID."),
|
|
378
|
+
dt: t(2).describe("Data type."),
|
|
379
|
+
ep: e.optional(d()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
380
|
+
mf: e.optional(t(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
381
|
+
eval: e.optional(u()).describe("Javascript expression to transform the attribute value to the Item value."),
|
|
382
|
+
script: e.optional(p()).describe("Relative path of a Javascript .js file.")
|
|
383
|
+
}),
|
|
384
|
+
e.strictObject({
|
|
385
|
+
fn: e.literal("zcl:cmd").describe("Generic function to parse ZCL values from read/report commands."),
|
|
386
|
+
cl: t(4).describe("Cluster ID."),
|
|
387
|
+
dt: t(2).describe("Data type."),
|
|
388
|
+
ep: e.optional(d()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
389
|
+
mf: e.optional(t(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
390
|
+
cmd: e.optional(t(2)).describe("Zigbee command."),
|
|
391
|
+
eval: e.optional(u()).describe("Javascript expression to transform the attribute value to the Item value."),
|
|
392
|
+
script: e.optional(p()).describe("Relative path of a Javascript .js file.")
|
|
393
|
+
}),
|
|
394
|
+
e.strictObject({
|
|
395
|
+
fn: e.literal("tuya").describe("Generic function to write Tuya data."),
|
|
396
|
+
dpid: e.number().describe("Data point ID. 1-255 the datapoint ID."),
|
|
397
|
+
dt: t(2).describe("Data type."),
|
|
398
|
+
eval: e.optional(u()).describe("Javascript expression to transform the raw value."),
|
|
399
|
+
script: e.optional(p()).describe("Relative path of a Javascript .js file.")
|
|
400
|
+
})
|
|
401
|
+
]).refine((a) => !("eval" in a && "script" in a), {
|
|
402
|
+
message: "eval and script should not both be present"
|
|
403
|
+
});
|
|
188
404
|
}
|
|
189
|
-
function
|
|
190
|
-
return
|
|
191
|
-
$schema:
|
|
192
|
-
schema:
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
405
|
+
function x(a) {
|
|
406
|
+
return e.strictObject({
|
|
407
|
+
$schema: e.optional(e.string()),
|
|
408
|
+
schema: e.literal("resourceitem1.schema.json"),
|
|
409
|
+
id: e.string(),
|
|
410
|
+
description: e.optional(e.string()).describe("Item description, better to do not use it."),
|
|
411
|
+
comment: e.optional(e.string()).describe("TODO: What is this ? What the difference with description ?"),
|
|
412
|
+
deprecated: e.optional(T()).describe("Date of deprecation, if the item is deprecated, it's better to use the new one."),
|
|
413
|
+
datatype: e.optional(e.enum(["String", "Bool", "Int8", "Int16", "Int32", "Int64", "UInt8", "UInt16", "UInt32", "UInt64", "Array", "Array[3]", "ISO 8601 timestamp"])).describe("Data type of the item."),
|
|
414
|
+
access: e.optional(e.enum(["R", "W", "RW"])).describe("Access mode for this item, some of them are not editable."),
|
|
415
|
+
public: e.optional(e.boolean()).describe("Item visible on the API."),
|
|
416
|
+
implicit: e.optional(e.boolean()).describe("TODO: What is this ?"),
|
|
417
|
+
managed: e.optional(e.boolean()).describe("TODO: What is this ?"),
|
|
418
|
+
awake: e.optional(e.boolean()).describe("The device is considered awake when this item is set due a incoming command."),
|
|
419
|
+
static: e.optional(e.union([e.string(), e.number(), e.boolean()])).describe("A static default value is fixed and can be not changed."),
|
|
420
|
+
range: e.optional(e.tuple([e.number(), e.number()])).describe("Values range limit."),
|
|
421
|
+
virtual: e.optional(e.boolean()).describe("TODO: What is this ?"),
|
|
422
|
+
read: e.optional($()).describe("Fonction used to read value."),
|
|
423
|
+
parse: e.optional(A()).describe("Fonction used to parse incoming values."),
|
|
424
|
+
write: e.optional(J()).describe("Fonction used to write value."),
|
|
425
|
+
"refresh.interval": e.optional(e.number()).describe("Refresh interval used for read fonction, NEED to be superior at value used in binding part."),
|
|
426
|
+
// TODO Validate this
|
|
427
|
+
values: e.optional(e.unknown()).describe("TODO: What is this ?"),
|
|
428
|
+
// TODO Validate this
|
|
429
|
+
default: e.optional(e.unknown()).describe("Defaut value.")
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
function _(a) {
|
|
433
|
+
return e.strictObject({
|
|
434
|
+
$schema: e.optional(e.string()),
|
|
435
|
+
schema: e.literal("devcap1.schema.json"),
|
|
436
|
+
"doc:path": e.optional(e.string()),
|
|
437
|
+
"doc:hdr": e.optional(e.string()),
|
|
438
|
+
"md:known_issues": e.optional(e.array(e.string())).describe("Know issues for this device, markdown file."),
|
|
439
|
+
manufacturername: e.union([
|
|
440
|
+
e.enum(Object.keys(a.manufacturers)),
|
|
441
|
+
e.string().regex(/^(?!\$MF_).*/g, "The manufacturer name start with $MF_ but is not present in constants.json"),
|
|
442
|
+
e.array(
|
|
443
|
+
e.union([
|
|
444
|
+
e.enum(Object.keys(a.manufacturers)),
|
|
445
|
+
e.string().regex(/^(?!\$MF_).*/g, "The manufacturer name start with $MF_ but is not present in constants.json")
|
|
446
|
+
])
|
|
447
|
+
)
|
|
448
|
+
]).describe("Manufacturer name from Basic Cluster."),
|
|
449
|
+
modelid: e.string().or(e.array(e.string())).describe("Model ID from Basic Cluster."),
|
|
450
|
+
vendor: e.optional(e.string()).describe("Friendly name of the manufacturer."),
|
|
451
|
+
comment: e.optional(e.string()),
|
|
452
|
+
matchexpr: e.optional(u()).describe("Need to return true for the DDF be used."),
|
|
453
|
+
path: e.optional(p()).describe("DDF path, useless, can be removed."),
|
|
454
|
+
product: e.optional(e.string()).describe("Complements the model id to be shown in the UI."),
|
|
455
|
+
sleeper: e.optional(e.boolean()).describe("Sleeping devices can only receive when awake."),
|
|
456
|
+
supportsMgmtBind: e.optional(e.boolean()),
|
|
457
|
+
status: e.enum(["Draft", "Bronze", "Silver", "Gold"]).describe("The code quality of the DDF file."),
|
|
458
|
+
subdevices: e.array(S(a)).describe("Devices section."),
|
|
459
|
+
bindings: e.optional(e.array(M())).describe("Bindings section.")
|
|
460
|
+
});
|
|
212
461
|
}
|
|
213
|
-
function
|
|
214
|
-
return
|
|
215
|
-
type:
|
|
216
|
-
|
|
217
|
-
|
|
462
|
+
function S(a) {
|
|
463
|
+
return e.strictObject({
|
|
464
|
+
type: e.union([
|
|
465
|
+
e.enum(Object.keys(a.deviceTypes)),
|
|
466
|
+
e.string().regex(/^(?!\$TYPE_).*/g, "The type start with $TYPE_ but is not present in constants.json")
|
|
218
467
|
]),
|
|
219
|
-
restapi:
|
|
220
|
-
uuid:
|
|
221
|
-
fingerprint:
|
|
222
|
-
profile:
|
|
223
|
-
device:
|
|
224
|
-
endpoint:
|
|
225
|
-
in:
|
|
226
|
-
out:
|
|
468
|
+
restapi: e.enum(["/lights", "/sensors"]),
|
|
469
|
+
uuid: y(),
|
|
470
|
+
fingerprint: e.optional(e.strictObject({
|
|
471
|
+
profile: t(4),
|
|
472
|
+
device: t(4),
|
|
473
|
+
endpoint: d(),
|
|
474
|
+
in: e.optional(e.array(t(4))),
|
|
475
|
+
out: e.optional(e.array(t(4)))
|
|
227
476
|
})),
|
|
228
|
-
meta:
|
|
477
|
+
meta: e.optional(e.strictObject({
|
|
229
478
|
// TODO validate this
|
|
230
|
-
values:
|
|
231
|
-
"group.endpoints":
|
|
479
|
+
values: e.any(),
|
|
480
|
+
"group.endpoints": e.optional(e.array(e.number()))
|
|
232
481
|
})),
|
|
233
482
|
// TODO validate this
|
|
234
|
-
buttons:
|
|
483
|
+
buttons: e.optional(e.any()),
|
|
235
484
|
// TODO validate this
|
|
236
|
-
buttonevents:
|
|
237
|
-
items:
|
|
238
|
-
example:
|
|
485
|
+
buttonevents: e.optional(e.any()),
|
|
486
|
+
items: e.array(R(a)),
|
|
487
|
+
example: e.optional(e.unknown())
|
|
239
488
|
});
|
|
240
489
|
}
|
|
241
|
-
function
|
|
242
|
-
return
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
range: t.optional(t.tuple([t.number(), t.number()])),
|
|
249
|
-
deprecated: t.optional(m()),
|
|
250
|
-
access: t.optional(t.literal("R")),
|
|
251
|
-
read: t.optional(b()),
|
|
252
|
-
parse: t.optional(f()),
|
|
253
|
-
write: t.optional(h()),
|
|
254
|
-
awake: t.optional(t.boolean()),
|
|
255
|
-
default: t.optional(t.unknown()),
|
|
256
|
-
values: t.optional(t.unknown()),
|
|
257
|
-
"refresh.interval": t.optional(t.number())
|
|
490
|
+
function R(a) {
|
|
491
|
+
return x().omit({
|
|
492
|
+
$schema: !0,
|
|
493
|
+
schema: !0,
|
|
494
|
+
id: !0
|
|
495
|
+
}).extend({
|
|
496
|
+
name: e.enum(a.attributes).describe("Item name.")
|
|
258
497
|
});
|
|
259
498
|
}
|
|
260
|
-
function
|
|
261
|
-
return
|
|
262
|
-
|
|
263
|
-
bind:
|
|
264
|
-
"src.ep":
|
|
265
|
-
"dst.ep":
|
|
266
|
-
cl:
|
|
267
|
-
report:
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
499
|
+
function M(a) {
|
|
500
|
+
return e.discriminatedUnion("bind", [
|
|
501
|
+
e.strictObject({
|
|
502
|
+
bind: e.literal("unicast"),
|
|
503
|
+
"src.ep": d().describe("Source endpoint."),
|
|
504
|
+
"dst.ep": e.optional(d()).describe("Destination endpoint, generaly 0x01."),
|
|
505
|
+
cl: t(4).describe("Cluster."),
|
|
506
|
+
report: e.optional(e.array(
|
|
507
|
+
e.strictObject({
|
|
508
|
+
at: t(4),
|
|
509
|
+
dt: t(2),
|
|
510
|
+
mf: e.optional(t(4)),
|
|
511
|
+
min: e.number(),
|
|
512
|
+
max: e.number(),
|
|
513
|
+
change: e.optional(t().or(e.number()))
|
|
514
|
+
}).refine((i) => i.min <= i.max, { message: "invalid report time, min should be smaller than max" })
|
|
515
|
+
))
|
|
275
516
|
}),
|
|
276
|
-
|
|
277
|
-
bind:
|
|
278
|
-
"src.ep":
|
|
279
|
-
cl:
|
|
280
|
-
"config.group":
|
|
517
|
+
e.strictObject({
|
|
518
|
+
bind: e.literal("groupcast"),
|
|
519
|
+
"src.ep": d().describe("Source endpoint."),
|
|
520
|
+
cl: t(4).describe("Cluster."),
|
|
521
|
+
"config.group": e.number().min(0).max(255)
|
|
281
522
|
})
|
|
282
523
|
]);
|
|
283
524
|
}
|
|
284
|
-
function
|
|
285
|
-
return
|
|
286
|
-
$schema:
|
|
287
|
-
schema:
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
virtual: t.optional(t.boolean()),
|
|
298
|
-
parse: t.optional(f()),
|
|
299
|
-
read: t.optional(b()),
|
|
300
|
-
write: t.optional(h()),
|
|
301
|
-
"refresh.interval": t.optional(t.number()),
|
|
302
|
-
// TODO Validate this
|
|
303
|
-
values: t.optional(t.unknown()),
|
|
304
|
-
range: t.optional(t.tuple([t.number(), t.number()])),
|
|
305
|
-
default: t.optional(t.unknown())
|
|
525
|
+
function G(a) {
|
|
526
|
+
return e.strictObject({
|
|
527
|
+
$schema: e.optional(e.string()),
|
|
528
|
+
schema: e.literal("subdevice1.schema.json"),
|
|
529
|
+
type: e.union([
|
|
530
|
+
e.enum(Object.keys(a.deviceTypes)),
|
|
531
|
+
e.string().regex(/^(?!\$TYPE_).*/g, "The type start with $TYPE_ but is not present in constants.json")
|
|
532
|
+
]),
|
|
533
|
+
name: e.string(),
|
|
534
|
+
restapi: e.enum(["/lights", "/sensors"]),
|
|
535
|
+
order: e.number(),
|
|
536
|
+
uuid: y(),
|
|
537
|
+
items: e.array(e.enum(a.attributes))
|
|
306
538
|
});
|
|
307
539
|
}
|
|
308
|
-
function
|
|
309
|
-
return
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
540
|
+
function g(a) {
|
|
541
|
+
return e.discriminatedUnion("schema", [
|
|
542
|
+
_(a),
|
|
543
|
+
E(),
|
|
544
|
+
x(),
|
|
545
|
+
G(a)
|
|
546
|
+
]).superRefine((i, n) => {
|
|
547
|
+
switch (i.schema) {
|
|
548
|
+
case "devcap1.schema.json":
|
|
549
|
+
I.map((c) => c(i, n));
|
|
550
|
+
break;
|
|
551
|
+
}
|
|
318
552
|
});
|
|
319
553
|
}
|
|
320
|
-
function
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
let i = u(e);
|
|
330
|
-
const l = () => {
|
|
331
|
-
i = u(e);
|
|
554
|
+
function k(a = {
|
|
555
|
+
attributes: [],
|
|
556
|
+
manufacturers: {},
|
|
557
|
+
deviceTypes: {},
|
|
558
|
+
resources: {}
|
|
559
|
+
}) {
|
|
560
|
+
let i = g(a);
|
|
561
|
+
const n = () => {
|
|
562
|
+
i = g(a);
|
|
332
563
|
};
|
|
333
|
-
return { generics:
|
|
334
|
-
const
|
|
335
|
-
switch (
|
|
564
|
+
return { generics: a, loadGeneric: (m) => {
|
|
565
|
+
const r = i.parse(m);
|
|
566
|
+
switch (r.schema) {
|
|
336
567
|
case "constants1.schema.json":
|
|
337
|
-
|
|
338
|
-
...
|
|
339
|
-
...
|
|
340
|
-
},
|
|
341
|
-
...
|
|
342
|
-
...
|
|
568
|
+
a.manufacturers = {
|
|
569
|
+
...a.manufacturers,
|
|
570
|
+
...r.manufacturers
|
|
571
|
+
}, a.deviceTypes = {
|
|
572
|
+
...a.deviceTypes,
|
|
573
|
+
...r["device-types"]
|
|
343
574
|
};
|
|
344
575
|
break;
|
|
345
|
-
case "resourceitem1.schema.json":
|
|
346
|
-
|
|
576
|
+
case "resourceitem1.schema.json": {
|
|
577
|
+
if (a.attributes.includes(r.id))
|
|
578
|
+
throw new Error(`Got duplicate resource item with attribute id '${r.id}'.`);
|
|
579
|
+
const o = structuredClone(r);
|
|
580
|
+
delete o.$schema, delete o.schema, delete o.id, a.resources[r.id] = o, a.attributes.push(r.id);
|
|
347
581
|
break;
|
|
582
|
+
}
|
|
348
583
|
case "subdevice1.schema.json":
|
|
349
584
|
break;
|
|
350
585
|
case "devcap1.schema.json":
|
|
351
586
|
throw new Error("Got invalid generic file, got data with schema 'devcap1.schema.json'.");
|
|
352
587
|
}
|
|
353
|
-
return
|
|
354
|
-
}, validate: (
|
|
588
|
+
return n(), r;
|
|
589
|
+
}, validate: (m) => i.parse(m), getSchema: () => i };
|
|
355
590
|
}
|
|
356
591
|
export {
|
|
357
|
-
|
|
592
|
+
k as createValidator
|
|
358
593
|
};
|