@deconz-community/ddf-validator 2.0.0 → 2.1.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,358 +1,416 @@
1
- import { z as t } from "zod";
2
- function v(e) {
3
- return t.strictObject({
4
- $schema: t.optional(t.string()),
5
- schema: t.literal("constants1.schema.json"),
6
- manufacturers: t.record(t.string().startsWith("$MF_"), t.string()),
7
- "device-types": t.record(t.string().startsWith("$TYPE_"), t.string())
1
+ import { z as e } from "zod";
2
+ const D = [
3
+ A,
4
+ O
5
+ ];
6
+ function A(t, r) {
7
+ const o = typeof t.manufacturername == "string" && typeof t.modelid == "string";
8
+ if (o)
9
+ return;
10
+ const i = Array.isArray(t.manufacturername) && Array.isArray(t.modelid);
11
+ if (i && t.manufacturername.length !== t.modelid.length) {
12
+ r.addIssue({
13
+ code: e.ZodIssueCode.invalid_intersection_types,
14
+ message: "When 'manufacturername' and 'modelid' are both arrays they should be the same length",
15
+ path: ["manufacturername", "modelid"]
16
+ });
17
+ return;
18
+ }
19
+ (o || i) === !1 && r.addIssue({
20
+ code: e.ZodIssueCode.invalid_intersection_types,
21
+ message: "Invalid properties 'manufacturername' and 'modelid' should have the same type",
22
+ path: ["manufacturername", "modelid"]
23
+ });
24
+ }
25
+ function O(t, r) {
26
+ if (!t.bindings)
27
+ return;
28
+ const o = {}, i = (s) => typeof s == "number" ? s : parseInt(s, 16);
29
+ t.bindings.forEach((s) => {
30
+ s.bind === "unicast" && s.report && s.report.forEach((u) => {
31
+ o[`${i(s["src.ep"])}.${i(s.cl)}.${i(u.at)}`] = u.max;
32
+ });
33
+ }), t.subdevices.forEach((s, u) => {
34
+ s.items.forEach((a, x) => {
35
+ var b;
36
+ if (a["refresh.interval"] && a.read && a.read.fn === "zcl") {
37
+ const w = i(a.read.ep ?? ((b = s.fingerprint) == null ? void 0 : b.endpoint) ?? s.uuid[1]), f = Array.isArray(a.read.at) ? a.read.at : [a.read.at];
38
+ for (let p = 0; p < f.length; p++) {
39
+ const m = `${w}.${i(a.read.cl)}.${i(f[p])}`;
40
+ o[m] !== void 0 && a["refresh.interval"] - 60 < o[m] && r.addIssue({
41
+ code: e.ZodIssueCode.custom,
42
+ message: `The refresh interval (${a["refresh.interval"]} - 60 = ${a["refresh.interval"] - 60}) should be greater than the binding max refresh value (${o[m]}) with a margin of 60 seconds`,
43
+ path: ["subdevices", u, "items", x, "refresh.interval"]
44
+ });
45
+ }
46
+ }
47
+ });
48
+ });
49
+ }
50
+ function $(t) {
51
+ return e.strictObject({
52
+ $schema: e.optional(e.string()),
53
+ schema: e.literal("constants1.schema.json"),
54
+ manufacturers: e.record(e.string().startsWith("$MF_"), e.string()),
55
+ "device-types": e.record(e.string().startsWith("$TYPE_"), e.string())
8
56
  });
9
57
  }
10
- function m() {
11
- return t.string().regex(
58
+ function v() {
59
+ return e.string().regex(
12
60
  // Regex for AAAA-MM-JJ
13
61
  /^(\d{4})-(?:(?:0[1-9])|(?:1[0-2]))-(?:(?:0[1-9])|(?:[12][0-9])|(?:3[01]))$/,
14
62
  "Invalid date value"
15
63
  );
16
64
  }
17
- function n(e = void 0) {
18
- const i = "Invalid hexadecimal value";
19
- return e === void 0 ? t.string().regex(/^0x[0-9a-fA-F]+$/, i) : t.string().regex(new RegExp(`^0x[0-9a-fA-F]{${e}}$`), i);
65
+ function n(t = void 0) {
66
+ const r = "Invalid hexadecimal value";
67
+ 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);
20
68
  }
21
- function a() {
22
- return t.union([
69
+ function c() {
70
+ return e.union([
23
71
  n(2),
24
- t.number().min(0).max(255)
72
+ e.number().min(0).max(255)
25
73
  ]);
26
74
  }
27
- function g() {
28
- return t.custom((e) => {
29
- if (!Array.isArray(e) || e.length % 2 !== 0)
75
+ function T() {
76
+ return e.custom((t) => {
77
+ if (!Array.isArray(t) || t.length % 2 !== 0)
30
78
  return !1;
31
- for (let i = 0; i < e.length; i += 2) {
32
- const l = e[i], p = e[i + 1];
33
- if (typeof l != "number" || typeof p != "string")
79
+ for (let r = 0; r < t.length; r += 2) {
80
+ const o = t[r], i = t[r + 1];
81
+ if (typeof o != "number" || typeof i != "string")
34
82
  return !1;
35
83
  }
36
84
  return !0;
37
85
  }, "The value must be an array with an even number of values and alternating between number and string.");
38
86
  }
39
- function d() {
40
- return t.union([
41
- t.tuple([
42
- t.literal("$address.ext"),
87
+ function g() {
88
+ return e.union([
89
+ e.tuple([
90
+ e.literal("$address.ext"),
43
91
  n(2)
44
92
  ]),
45
- t.tuple([
46
- t.literal("$address.ext"),
93
+ e.tuple([
94
+ e.literal("$address.ext"),
47
95
  n(2),
48
96
  n(4)
49
97
  ])
50
98
  ]);
51
99
  }
52
- function o() {
53
- return t.string();
100
+ function l() {
101
+ return e.string();
54
102
  }
55
- function r() {
56
- return t.string();
103
+ function d() {
104
+ return e.string();
57
105
  }
58
- function b() {
59
- return t.discriminatedUnion("fn", [
60
- t.strictObject({
61
- fn: t.literal("none")
106
+ function y() {
107
+ return e.discriminatedUnion("fn", [
108
+ e.strictObject({
109
+ fn: e.literal("none")
62
110
  }),
63
- t.strictObject({
64
- fn: t.undefined(),
65
- at: t.optional(n(4).or(t.array(n(4)))),
66
- cl: n(4),
67
- ep: t.optional(a()),
68
- mf: t.optional(n(4)),
69
- eval: t.optional(r())
111
+ e.strictObject({
112
+ fn: e.undefined().describe("Generic function to read ZCL attributes."),
113
+ at: n(4).or(e.array(n(4))).describe("Attribute ID."),
114
+ cl: n(4).describe("Cluster ID."),
115
+ ep: e.optional(c()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
116
+ mf: e.optional(n(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
117
+ eval: e.optional(d()).describe("Javascript expression to transform the raw value.")
70
118
  }),
71
- t.strictObject({
72
- fn: t.literal("zcl"),
73
- at: t.optional(n(4).or(t.array(n(4)))),
74
- cl: n(4),
75
- ep: t.optional(a()),
76
- mf: t.optional(n(4)),
77
- eval: t.optional(r())
119
+ e.strictObject({
120
+ fn: e.literal("zcl").describe("Generic function to read ZCL attributes."),
121
+ at: n(4).or(e.array(n(4))).describe("Attribute ID."),
122
+ cl: n(4).describe("Cluster ID."),
123
+ ep: e.optional(c()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
124
+ mf: e.optional(n(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
125
+ eval: e.optional(d()).describe("Javascript expression to transform the raw value.")
78
126
  }),
79
- t.strictObject({
80
- fn: t.literal("tuya")
127
+ e.strictObject({
128
+ fn: e.literal("tuya").describe("Generic function to read all Tuya datapoints. It has no parameters.")
81
129
  })
82
- ]);
130
+ ]).refine((t) => !("eval" in t && "script" in t), {
131
+ message: "eval and script should not both be present"
132
+ });
83
133
  }
84
- function f() {
85
- return t.discriminatedUnion("fn", [
86
- t.strictObject({
87
- fn: t.undefined(),
88
- at: t.optional(n(4)),
89
- cl: n(4),
90
- cppsrc: t.optional(t.string()),
91
- ep: t.optional(a()),
92
- cmd: t.optional(n(2)),
93
- mf: t.optional(n(4)),
94
- eval: t.optional(r()),
95
- script: t.optional(o())
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")))
134
+ function j() {
135
+ return e.discriminatedUnion("fn", [
136
+ e.strictObject({
137
+ fn: e.undefined().describe("Generic function to parse ZCL attributes and commands."),
138
+ at: e.optional(n(4)).describe("Attribute ID."),
139
+ cl: n(4).describe("Cluster ID."),
140
+ cppsrc: e.optional(e.string()),
141
+ ep: e.optional(c()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
142
+ cmd: e.optional(n(2)).describe("Zigbee command."),
143
+ mf: e.optional(n(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
144
+ eval: e.optional(d()).describe("Javascript expression to transform the raw value."),
145
+ script: e.optional(l()).describe("Relative path of a Javascript .js file.")
115
146
  }),
116
- t.strictObject({
117
- fn: t.literal("numtostr"),
118
- srcitem: t.enum(["state/airqualityppb", "state/pm2_5"]),
119
- op: t.literal("le"),
120
- to: g()
147
+ e.strictObject({
148
+ fn: e.literal("zcl").describe("Generic function to parse ZCL attributes and commands."),
149
+ at: e.optional(n(4)).describe("Attribute ID."),
150
+ cl: n(4).describe("Cluster ID."),
151
+ cppsrc: e.optional(e.string()),
152
+ ep: e.optional(c()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
153
+ cmd: e.optional(n(2)).describe("Zigbee command."),
154
+ mf: e.optional(n(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
155
+ eval: e.optional(d()).describe("Javascript expression to transform the raw value."),
156
+ script: e.optional(l()).describe("Relative path of a Javascript .js file.")
121
157
  }),
122
- t.strictObject({
123
- fn: t.literal("time")
158
+ e.strictObject({
159
+ fn: e.literal("ias:zonestatus").describe("Generic function to parse IAS ZONE status change notifications or zone status from read/report command."),
160
+ 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.")
124
161
  }),
125
- t.strictObject({
126
- fn: t.literal("xiaomi:special"),
127
- ep: t.optional(a()),
128
- at: t.optional(n(4)),
129
- idx: n(2),
130
- eval: t.optional(r()),
131
- script: t.optional(o())
132
- }).refine((e) => !("eval" in e && "script" in e), {
133
- message: "eval and script should not both be present"
134
- }).innerType(),
135
- t.strictObject({
136
- fn: t.literal("tuya"),
137
- dpid: t.number(),
138
- eval: t.optional(r()),
139
- script: t.optional(o())
140
- }).refine((e) => !("eval" in e && "script" in e), {
141
- message: "eval and script should not both be present"
142
- }).innerType()
143
- ]);
162
+ e.strictObject({
163
+ fn: e.literal("numtostr").describe("Generic function to to convert number to string."),
164
+ // TODO use generic
165
+ srcitem: e.enum(["state/airqualityppb", "state/pm2_5"]).describe("The source item holding the number."),
166
+ op: e.enum(["lt", "le", "eq", "gt", "ge"]).describe("Comparison operator (lt | le | eq | gt | ge)"),
167
+ to: T().describe("Array of (num, string) mappings")
168
+ }),
169
+ e.strictObject({
170
+ 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.")
171
+ }),
172
+ e.strictObject({
173
+ fn: e.literal("xiaomi:special").describe("Generic function to parse custom Xiaomi attributes and commands."),
174
+ ep: e.optional(c()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
175
+ at: e.optional(n(4)).describe("Attribute ID. The attribute to parse, shall be 0xff01, 0xff02 or 0x00f7"),
176
+ idx: n(2).describe("A 8-bit string hex value."),
177
+ eval: e.optional(d()).describe("Javascript expression to transform the raw value."),
178
+ script: e.optional(l()).describe("Relative path of a Javascript .js file.")
179
+ }),
180
+ e.strictObject({
181
+ fn: e.literal("tuya").describe("Generic function to parse Tuya data."),
182
+ dpid: e.number().describe("Data point ID. 1-255 the datapoint ID."),
183
+ eval: e.optional(d()).describe("Javascript expression to transform the raw value."),
184
+ script: e.optional(l()).describe("Relative path of a Javascript .js file.")
185
+ })
186
+ ]).refine((t) => !("eval" in t && "script" in t), {
187
+ message: "eval and script should not both be present"
188
+ });
144
189
  }
145
- function h() {
146
- return t.discriminatedUnion("fn", [
147
- t.strictObject({
148
- fn: t.literal("none")
190
+ function I() {
191
+ return e.discriminatedUnion("fn", [
192
+ e.strictObject({
193
+ fn: e.literal("none")
149
194
  }),
150
- t.strictObject({
151
- fn: t.undefined(),
152
- at: t.optional(n(4).or(t.array(n(4)))),
153
- "state.timeout": t.optional(t.number()),
154
- "change.timeout": t.optional(t.number()),
155
- cl: n(4),
156
- dt: n(2),
157
- ep: t.optional(a()),
158
- mf: t.optional(n(4)),
159
- eval: t.optional(r()),
160
- script: t.optional(o())
161
- }).refine((e) => !("eval" in e && "script" in e), {
162
- message: "eval and script should not both be present"
163
- }).innerType(),
164
- t.strictObject({
165
- fn: t.literal("zcl"),
166
- at: t.optional(n(4).or(t.array(n(4)))),
167
- "state.timeout": t.optional(t.number()),
168
- "change.timeout": t.optional(t.number()),
169
- cl: n(4),
170
- dt: n(2),
171
- ep: t.optional(a()),
172
- mf: t.optional(n(4)),
173
- eval: t.optional(r()),
174
- script: t.optional(o())
175
- }).refine((e) => !("eval" in e && "script" in e), {
176
- message: "eval and script should not both be present"
177
- }).innerType(),
178
- t.strictObject({
179
- fn: t.literal("tuya"),
180
- dpid: t.number(),
181
- dt: n(2),
182
- eval: t.optional(r()),
183
- script: t.optional(o())
184
- }).refine((e) => !("eval" in e && "script" in e), {
185
- message: "eval and script should not both be present"
186
- }).innerType()
187
- ]);
195
+ e.strictObject({
196
+ fn: e.undefined(),
197
+ at: e.optional(n(4).or(e.array(n(4)))).describe("Attribute ID."),
198
+ "state.timeout": e.optional(e.number()),
199
+ "change.timeout": e.optional(e.number()),
200
+ cl: n(4).describe("Cluster ID."),
201
+ dt: n(2).describe("Data type."),
202
+ ep: e.optional(c()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
203
+ mf: e.optional(n(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
204
+ eval: e.optional(d()).describe("Javascript expression to transform the raw value."),
205
+ script: e.optional(l()).describe("Relative path of a Javascript .js file.")
206
+ }),
207
+ e.strictObject({
208
+ fn: e.literal("zcl"),
209
+ at: e.optional(n(4).or(e.array(n(4)))).describe("Attribute ID."),
210
+ "state.timeout": e.optional(e.number()),
211
+ "change.timeout": e.optional(e.number()),
212
+ cl: n(4).describe("Cluster ID."),
213
+ dt: n(2).describe("Data type."),
214
+ ep: e.optional(c()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
215
+ mf: e.optional(n(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
216
+ eval: e.optional(d()).describe("Javascript expression to transform the raw value."),
217
+ script: e.optional(l()).describe("Relative path of a Javascript .js file.")
218
+ }),
219
+ e.strictObject({
220
+ fn: e.literal("tuya").describe("Generic function to write Tuya data."),
221
+ dpid: e.number().describe("Data point ID. 1-255 the datapoint ID."),
222
+ dt: n(2).describe("Data type."),
223
+ eval: e.optional(d()).describe("Javascript expression to transform the raw value."),
224
+ script: e.optional(l()).describe("Relative path of a Javascript .js file.")
225
+ })
226
+ ]).refine((t) => !("eval" in t && "script" in t), {
227
+ message: "eval and script should not both be present"
228
+ });
188
229
  }
189
- function y(e) {
190
- return t.strictObject({
191
- $schema: t.optional(t.string()),
192
- schema: t.literal("devcap1.schema.json"),
193
- "doc:path": t.optional(t.string()),
194
- "doc:hdr": t.optional(t.string()),
195
- "md:known_issues": t.optional(t.array(t.string())),
196
- manufacturername: t.string().or(t.array(t.string())),
197
- modelid: t.string().or(t.array(t.string())),
198
- vendor: t.optional(t.string()),
199
- comment: t.optional(t.string()),
200
- matchexpr: t.optional(r()),
201
- path: t.optional(o()),
202
- product: t.optional(t.string()),
203
- sleeper: t.optional(t.boolean()),
204
- supportsMgmtBind: t.optional(t.boolean()),
205
- status: t.enum(["Draft", "Bronze", "Silver", "Gold"]).describe("The code quality of the DDF file."),
206
- subdevices: t.array(j(e)),
207
- bindings: t.optional(t.array(T()))
208
- }).refine((i) => typeof i.manufacturername == "string" && typeof i.modelid == "string" || Array.isArray(i.manufacturername) && Array.isArray(i.modelid) && i.manufacturername.length === i.modelid.length, {
209
- message: "manufacturername and modelid should be both strings or arrays with the same length.",
210
- path: ["manufacturername", "modelid"]
211
- }).innerType();
230
+ function S(t) {
231
+ return e.strictObject({
232
+ $schema: e.optional(e.string()),
233
+ schema: e.literal("devcap1.schema.json"),
234
+ "doc:path": e.optional(e.string()),
235
+ "doc:hdr": e.optional(e.string()),
236
+ "md:known_issues": e.optional(e.array(e.string())).describe("Know issues for this device, markdown file."),
237
+ manufacturername: e.union([
238
+ e.enum(Object.keys(t.manufacturers)),
239
+ e.string().regex(/^(?!\$MF_).*/g, "The manufacturer name start with $MF_ but is not present in constants.json"),
240
+ e.array(
241
+ e.union([
242
+ e.enum(Object.keys(t.manufacturers)),
243
+ e.string().regex(/^(?!\$MF_).*/g, "The manufacturer name start with $MF_ but is not present in constants.json")
244
+ ])
245
+ )
246
+ ]).describe("Manufacturer name from Basic Cluster."),
247
+ modelid: e.string().or(e.array(e.string())).describe("Model ID from Basic Cluster."),
248
+ vendor: e.optional(e.string()).describe("Friendly name of the manufacturer."),
249
+ comment: e.optional(e.string()),
250
+ matchexpr: e.optional(d()).describe("Need to return true for the DDF be used."),
251
+ path: e.optional(l()).describe("DDF path, useless, can be removed."),
252
+ product: e.optional(e.string()).describe("Complements the model id to be shown in the UI."),
253
+ sleeper: e.optional(e.boolean()).describe("Sleeping devices can only receive when awake."),
254
+ supportsMgmtBind: e.optional(e.boolean()),
255
+ status: e.enum(["Draft", "Bronze", "Silver", "Gold"]).describe("The code quality of the DDF file."),
256
+ subdevices: e.array(E(t)).describe("Devices section."),
257
+ bindings: e.optional(e.array(C())).describe("Bindings section.")
258
+ });
212
259
  }
213
- function j(e) {
214
- return t.strictObject({
215
- type: t.union([
216
- t.enum(Object.keys(e.deviceTypes)),
217
- t.enum(Object.values(e.deviceTypes))
260
+ function E(t) {
261
+ return e.strictObject({
262
+ type: e.union([
263
+ e.enum(Object.keys(t.deviceTypes)),
264
+ e.string().regex(/^(?!\$TYPE_).*/g, "The type start with $TYPE_ but is not present in constants.json")
218
265
  ]),
219
- restapi: t.enum(["/lights", "/sensors"]),
220
- uuid: d(),
221
- fingerprint: t.optional(t.strictObject({
266
+ restapi: e.enum(["/lights", "/sensors"]),
267
+ uuid: g(),
268
+ fingerprint: e.optional(e.strictObject({
222
269
  profile: n(4),
223
270
  device: n(4),
224
- endpoint: a(),
225
- in: t.optional(t.array(n(4))),
226
- out: t.optional(t.array(n(4)))
271
+ endpoint: c(),
272
+ in: e.optional(e.array(n(4))),
273
+ out: e.optional(e.array(n(4)))
227
274
  })),
228
- meta: t.optional(t.strictObject({
275
+ meta: e.optional(e.strictObject({
229
276
  // TODO validate this
230
- values: t.any(),
231
- "group.endpoints": t.optional(t.array(t.number()))
277
+ values: e.any(),
278
+ "group.endpoints": e.optional(e.array(e.number()))
232
279
  })),
233
280
  // TODO validate this
234
- buttons: t.optional(t.any()),
281
+ buttons: e.optional(e.any()),
235
282
  // TODO validate this
236
- buttonevents: t.optional(t.any()),
237
- items: t.array(O(e)),
238
- example: t.optional(t.unknown())
283
+ buttonevents: e.optional(e.any()),
284
+ items: e.array(k(t)),
285
+ example: e.optional(e.unknown())
239
286
  });
240
287
  }
241
- function O(e) {
242
- return t.strictObject({
243
- name: t.enum(e.attributes),
244
- description: t.optional(t.string()),
245
- comment: t.optional(t.string()),
246
- public: t.optional(t.boolean()),
247
- static: t.optional(t.union([t.string(), t.number(), t.boolean()])),
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())
288
+ function k(t) {
289
+ return e.strictObject({
290
+ name: e.enum(t.attributes).describe("Item name."),
291
+ description: e.optional(e.string()).describe("Item description, better to do not use it."),
292
+ comment: e.optional(e.string()),
293
+ public: e.optional(e.boolean()).describe("Item visible on the API."),
294
+ static: e.optional(e.union([e.string(), e.number(), e.boolean()])).describe("A static default value is fixed and can be not changed."),
295
+ range: e.optional(e.tuple([e.number(), e.number()])).describe("Values range limit."),
296
+ deprecated: e.optional(v()),
297
+ access: e.optional(e.literal("R")).describe("Access mode for this item, some of them are not editable."),
298
+ read: e.optional(y()).describe("Fonction used to read value."),
299
+ parse: e.optional(j()).describe("Fonction used to parse incoming values."),
300
+ write: e.optional(I()).describe("Fonction used to write value."),
301
+ awake: e.optional(e.boolean()).describe("The device is considered awake when this item is set due a incoming command."),
302
+ default: e.optional(e.unknown()).describe("Defaut value."),
303
+ values: e.optional(e.unknown()),
304
+ "refresh.interval": e.optional(e.number()).describe("Refresh interval used for read fonction, NEED to be superior at value used in binding part.")
258
305
  });
259
306
  }
260
- function T(e) {
261
- return t.discriminatedUnion("bind", [
262
- t.strictObject({
263
- bind: t.literal("unicast"),
264
- "src.ep": a(),
265
- "dst.ep": t.optional(a()),
266
- cl: n(4),
267
- report: t.optional(t.array(t.strictObject({
268
- at: n(4),
269
- dt: n(2),
270
- mf: t.optional(n(4)),
271
- min: t.number(),
272
- max: t.number(),
273
- change: t.optional(n().or(t.number()))
274
- })))
307
+ function C(t) {
308
+ return e.discriminatedUnion("bind", [
309
+ e.strictObject({
310
+ bind: e.literal("unicast"),
311
+ "src.ep": c().describe("Source endpoint."),
312
+ "dst.ep": e.optional(c()).describe("Destination endpoint, generaly 0x01."),
313
+ cl: n(4).describe("Cluster."),
314
+ report: e.optional(e.array(
315
+ e.strictObject({
316
+ at: n(4),
317
+ dt: n(2),
318
+ mf: e.optional(n(4)),
319
+ min: e.number(),
320
+ max: e.number(),
321
+ change: e.optional(n().or(e.number()))
322
+ }).refine((r) => r.min <= r.max, { message: "invalid report time, min should be smaller than max" })
323
+ ))
275
324
  }),
276
- t.strictObject({
277
- bind: t.literal("groupcast"),
278
- "src.ep": a(),
279
- cl: n(4),
280
- "config.group": t.number()
325
+ e.strictObject({
326
+ bind: e.literal("groupcast"),
327
+ "src.ep": c().describe("Source endpoint."),
328
+ cl: n(4).describe("Cluster."),
329
+ "config.group": e.number().min(0).max(255)
281
330
  })
282
331
  ]);
283
332
  }
284
- function w(e) {
285
- return t.strictObject({
286
- $schema: t.optional(t.string()),
287
- schema: t.literal("resourceitem1.schema.json"),
288
- id: t.string(),
289
- description: t.string(),
290
- deprecated: t.optional(m()),
291
- datatype: t.enum(["String", "Bool", "Int8", "Int16", "Int32", "Int64", "UInt8", "UInt16", "UInt32", "UInt64", "Array", "Array[3]", "ISO 8601 timestamp"]),
292
- access: t.enum(["R", "W", "RW"]),
293
- public: t.boolean(),
294
- implicit: t.optional(t.boolean()),
295
- managed: t.optional(t.boolean()),
296
- static: t.optional(t.boolean()),
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()),
333
+ function _(t) {
334
+ return e.strictObject({
335
+ $schema: e.optional(e.string()),
336
+ schema: e.literal("resourceitem1.schema.json"),
337
+ id: e.string(),
338
+ description: e.string(),
339
+ deprecated: e.optional(v()),
340
+ datatype: e.enum(["String", "Bool", "Int8", "Int16", "Int32", "Int64", "UInt8", "UInt16", "UInt32", "UInt64", "Array", "Array[3]", "ISO 8601 timestamp"]),
341
+ access: e.enum(["R", "W", "RW"]),
342
+ public: e.boolean(),
343
+ implicit: e.optional(e.boolean()),
344
+ managed: e.optional(e.boolean()),
345
+ static: e.optional(e.boolean()),
346
+ virtual: e.optional(e.boolean()),
347
+ parse: e.optional(j()),
348
+ read: e.optional(y()),
349
+ write: e.optional(I()),
350
+ "refresh.interval": e.optional(e.number()),
302
351
  // 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())
352
+ values: e.optional(e.unknown()),
353
+ range: e.optional(e.tuple([e.number(), e.number()])),
354
+ default: e.optional(e.unknown())
306
355
  });
307
356
  }
308
- function x(e) {
309
- return t.strictObject({
310
- $schema: t.optional(t.string()),
311
- schema: t.literal("subdevice1.schema.json"),
312
- type: t.enum(Object.keys(e.deviceTypes)),
313
- name: t.enum(Object.values(e.deviceTypes)),
314
- restapi: t.enum(["/lights", "/sensors"]),
315
- order: t.number(),
316
- uuid: d(),
317
- items: t.array(t.enum(e.attributes))
357
+ function F(t) {
358
+ return e.strictObject({
359
+ $schema: e.optional(e.string()),
360
+ schema: e.literal("subdevice1.schema.json"),
361
+ type: e.union([
362
+ e.enum(Object.keys(t.deviceTypes)),
363
+ e.string().regex(/^(?!\$TYPE_).*/g, "The type start with $TYPE_ but is not present in constants.json")
364
+ ]),
365
+ name: e.string(),
366
+ restapi: e.enum(["/lights", "/sensors"]),
367
+ order: e.number(),
368
+ uuid: g(),
369
+ items: e.array(e.enum(t.attributes))
318
370
  });
319
371
  }
320
- function u(e) {
321
- return t.discriminatedUnion("schema", [
322
- y(e),
323
- v(),
324
- w(),
325
- x(e)
326
- ]);
372
+ function h(t) {
373
+ return e.discriminatedUnion("schema", [
374
+ S(t),
375
+ $(),
376
+ _(),
377
+ F(t)
378
+ ]).superRefine((r, o) => {
379
+ switch (r.schema) {
380
+ case "devcap1.schema.json":
381
+ D.map((i) => i(r, o));
382
+ break;
383
+ }
384
+ });
327
385
  }
328
- function I(e = { attributes: [], manufacturers: {}, deviceTypes: {} }) {
329
- let i = u(e);
330
- const l = () => {
331
- i = u(e);
386
+ function J(t = { attributes: [], manufacturers: {}, deviceTypes: {} }) {
387
+ let r = h(t);
388
+ const o = () => {
389
+ r = h(t);
332
390
  };
333
- return { generics: e, loadGeneric: (c) => {
334
- const s = i.parse(c);
335
- switch (s.schema) {
391
+ return { generics: t, loadGeneric: (u) => {
392
+ const a = r.parse(u);
393
+ switch (a.schema) {
336
394
  case "constants1.schema.json":
337
- e.manufacturers = {
338
- ...e.manufacturers,
339
- ...s.manufacturers
340
- }, e.deviceTypes = {
341
- ...e.deviceTypes,
342
- ...s["device-types"]
395
+ t.manufacturers = {
396
+ ...t.manufacturers,
397
+ ...a.manufacturers
398
+ }, t.deviceTypes = {
399
+ ...t.deviceTypes,
400
+ ...a["device-types"]
343
401
  };
344
402
  break;
345
403
  case "resourceitem1.schema.json":
346
- e.attributes.includes(s.id) || e.attributes.push(s.id);
404
+ t.attributes.includes(a.id) || t.attributes.push(a.id);
347
405
  break;
348
406
  case "subdevice1.schema.json":
349
407
  break;
350
408
  case "devcap1.schema.json":
351
409
  throw new Error("Got invalid generic file, got data with schema 'devcap1.schema.json'.");
352
410
  }
353
- return l(), s;
354
- }, validate: (c) => i.parse(c), getSchema: () => i };
411
+ return o(), a;
412
+ }, validate: (u) => r.parse(u), getSchema: () => r };
355
413
  }
356
414
  export {
357
- I as createValidator
415
+ J as createValidator
358
416
  };