homematic-manager 3.9.1 → 3.10.1
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/node_modules/@homematic-manager/backend/dist/images/deviceImages.d.ts +26 -1
- package/node_modules/@homematic-manager/backend/dist/images/deviceImages.js +195 -11
- package/node_modules/@homematic-manager/backend/package.json +1 -1
- package/node_modules/@homematic-manager/core/dist/devices/deviceClass.d.ts +23 -0
- package/node_modules/@homematic-manager/core/dist/devices/deviceClass.js +65 -0
- package/node_modules/@homematic-manager/core/dist/index.d.ts +3 -0
- package/node_modules/@homematic-manager/core/dist/index.js +3 -0
- package/node_modules/@homematic-manager/core/dist/paramset/displayText.d.ts +58 -0
- package/node_modules/@homematic-manager/core/dist/paramset/displayText.js +113 -0
- package/node_modules/@homematic-manager/core/dist/paramset/signalModes.d.ts +101 -0
- package/node_modules/@homematic-manager/core/dist/paramset/signalModes.js +260 -0
- package/node_modules/@homematic-manager/core/package.json +1 -1
- package/package.json +3 -3
- package/ui/assets/index-C5T8txO4.js +21 -0
- package/ui/assets/index-CneXmAJq.css +1 -0
- package/ui/index.html +2 -2
- package/ui/assets/index--iLjuQoI.css +0 -1
- package/ui/assets/index-0Xq1YvNy.js +0 -21
|
@@ -31,6 +31,16 @@
|
|
|
31
31
|
* else. The hosts keep their own wrappers (an HTTP route in `apps/web`, an `hmm-image://` protocol
|
|
32
32
|
* handler in `apps/electron`) but the chain, the caching and the safety checks are this module.
|
|
33
33
|
*
|
|
34
|
+
* **A type the mapping lacks** (task 127: the homebrew devices, which openccu-data 2026.9.1 has none
|
|
35
|
+
* of; a device newer than the pinned data) is asked of the CCU itself before giving up: first its
|
|
36
|
+
* own catalogue `DEVDB.tcl` (`/config/devdescr/DEVDB.tcl`, served as text by a CCU, OpenCCU and
|
|
37
|
+
* openccu-lite alike; `DEV_PATHS` names each type's 250 and 50 px picture), then the picture named
|
|
38
|
+
* after the type in lower case (`hb-ou-mot-fan.png`, how the homebrew set names 71 of its 93). A
|
|
39
|
+
* picture found that way is cached under the type's own lower-case name, since the next start has no
|
|
40
|
+
* mapping to find it by. Nothing found is "no picture" - not the unknown-device one: the UI then
|
|
41
|
+
* draws a generic picture of the device's class, which says more than a question mark. A miss is
|
|
42
|
+
* remembered for {@link MISS_TTL_MS}, so a grid of such devices does not ask again on every draw.
|
|
43
|
+
*
|
|
34
44
|
* **Known limitation**: with `tls` the CCU's certificate is self-signed, and `fetch` has no
|
|
35
45
|
* per-request way to accept it. Such a request fails and the bundled picture is served instead.
|
|
36
46
|
* The addon of task 13 runs on the CCU and talks plain http to `127.0.0.1`, so it is unaffected.
|
|
@@ -41,6 +51,10 @@ export declare const CCU_IMAGE_BASE = "/config/img/devices";
|
|
|
41
51
|
export declare const UNKNOWN_DEVICE_KEY = "DEVICE";
|
|
42
52
|
/** How long a fetch from the CCU may take before the bundled picture wins. */
|
|
43
53
|
export declare const DEFAULT_IMAGE_TIMEOUT_MS = 5000;
|
|
54
|
+
/** The CCU's own device catalogue (task 127): type -> picture, for a type the mapping lacks. */
|
|
55
|
+
export declare const CCU_DEVDB_PATH = "/config/devdescr/DEVDB.tcl";
|
|
56
|
+
/** How long the CCU's catalogue and a type with no picture anywhere are remembered. */
|
|
57
|
+
export declare const MISS_TTL_MS: number;
|
|
44
58
|
/** How many pictures are kept decoded in memory; the rest is one `readFile` away. */
|
|
45
59
|
export declare const MEMORY_CACHE_LIMIT = 200;
|
|
46
60
|
/** The content types the CCU's pictures and the bundled subset use. */
|
|
@@ -66,6 +80,15 @@ export declare function isSafeIconName(file: string): boolean;
|
|
|
66
80
|
* what each of them is worth on a real CCU.
|
|
67
81
|
*/
|
|
68
82
|
export declare function ccuImagePaths(iconFile: string): string[];
|
|
83
|
+
/**
|
|
84
|
+
* The picture paths of `DEVDB.tcl`'s `DEV_PATHS`, by device type in lower case: the 250 px one first,
|
|
85
|
+
* then the 50 px one. The file is Tcl - `array set DEV_PATHS {<type> {{50 <path>} {250 <path>}} ...}`,
|
|
86
|
+
* a type with a space in braces (occulited's `devimg` reads it the same way). Only paths under
|
|
87
|
+
* `/config/img/devices/` with a safe file name are taken: the file comes from the network.
|
|
88
|
+
*/
|
|
89
|
+
export declare function parseDevDb(text: string): Map<string, string[]>;
|
|
90
|
+
/** A path of `DEV_PATHS` the service may request: under the pictures, no way out, a picture's name. */
|
|
91
|
+
export declare function isSafeCcuImagePath(file: string): boolean;
|
|
69
92
|
/** The CCU to ask, as the image service needs it. */
|
|
70
93
|
export interface ImageUpstream {
|
|
71
94
|
readonly host: string;
|
|
@@ -124,8 +147,10 @@ export declare class DeviceImageService {
|
|
|
124
147
|
constructor(options: DeviceImageServiceOptions);
|
|
125
148
|
/** The device-type to file-name mapping, read once. */
|
|
126
149
|
icons(): Promise<Readonly<Record<string, string>>>;
|
|
127
|
-
/** The file name the CCU knows this device type under
|
|
150
|
+
/** The file name the CCU knows this device type under (the unknown device's for a type the mapping lacks). */
|
|
128
151
|
fileFor(deviceType: string): Promise<string | undefined>;
|
|
152
|
+
/** The mapping's own file for this type, or `undefined` when the mapping does not know it. */
|
|
153
|
+
mappedFileFor(deviceType: string): Promise<string | undefined>;
|
|
129
154
|
/**
|
|
130
155
|
* The picture for a device type, or `undefined` when there is not even a fallback. Two requests
|
|
131
156
|
* for the same type while one is in flight share the answer - the device grid asks for a
|
|
@@ -31,6 +31,16 @@
|
|
|
31
31
|
* else. The hosts keep their own wrappers (an HTTP route in `apps/web`, an `hmm-image://` protocol
|
|
32
32
|
* handler in `apps/electron`) but the chain, the caching and the safety checks are this module.
|
|
33
33
|
*
|
|
34
|
+
* **A type the mapping lacks** (task 127: the homebrew devices, which openccu-data 2026.9.1 has none
|
|
35
|
+
* of; a device newer than the pinned data) is asked of the CCU itself before giving up: first its
|
|
36
|
+
* own catalogue `DEVDB.tcl` (`/config/devdescr/DEVDB.tcl`, served as text by a CCU, OpenCCU and
|
|
37
|
+
* openccu-lite alike; `DEV_PATHS` names each type's 250 and 50 px picture), then the picture named
|
|
38
|
+
* after the type in lower case (`hb-ou-mot-fan.png`, how the homebrew set names 71 of its 93). A
|
|
39
|
+
* picture found that way is cached under the type's own lower-case name, since the next start has no
|
|
40
|
+
* mapping to find it by. Nothing found is "no picture" - not the unknown-device one: the UI then
|
|
41
|
+
* draws a generic picture of the device's class, which says more than a question mark. A miss is
|
|
42
|
+
* remembered for {@link MISS_TTL_MS}, so a grid of such devices does not ask again on every draw.
|
|
43
|
+
*
|
|
34
44
|
* **Known limitation**: with `tls` the CCU's certificate is self-signed, and `fetch` has no
|
|
35
45
|
* per-request way to accept it. Such a request fails and the bundled picture is served instead.
|
|
36
46
|
* The addon of task 13 runs on the CCU and talks plain http to `127.0.0.1`, so it is unaffected.
|
|
@@ -44,6 +54,10 @@ export const CCU_IMAGE_BASE = '/config/img/devices';
|
|
|
44
54
|
export const UNKNOWN_DEVICE_KEY = 'DEVICE';
|
|
45
55
|
/** How long a fetch from the CCU may take before the bundled picture wins. */
|
|
46
56
|
export const DEFAULT_IMAGE_TIMEOUT_MS = 5000;
|
|
57
|
+
/** The CCU's own device catalogue (task 127): type -> picture, for a type the mapping lacks. */
|
|
58
|
+
export const CCU_DEVDB_PATH = '/config/devdescr/DEVDB.tcl';
|
|
59
|
+
/** How long the CCU's catalogue and a type with no picture anywhere are remembered. */
|
|
60
|
+
export const MISS_TTL_MS = 10 * 60_000;
|
|
47
61
|
/** How many pictures are kept decoded in memory; the rest is one `readFile` away. */
|
|
48
62
|
export const MEMORY_CACHE_LIMIT = 200;
|
|
49
63
|
/** The content types the CCU's pictures and the bundled subset use. */
|
|
@@ -106,6 +120,93 @@ export function ccuImagePaths(iconFile) {
|
|
|
106
120
|
`${CCU_IMAGE_BASE}/50/${iconFile}`,
|
|
107
121
|
];
|
|
108
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* The picture paths of `DEVDB.tcl`'s `DEV_PATHS`, by device type in lower case: the 250 px one first,
|
|
125
|
+
* then the 50 px one. The file is Tcl - `array set DEV_PATHS {<type> {{50 <path>} {250 <path>}} ...}`,
|
|
126
|
+
* a type with a space in braces (occulited's `devimg` reads it the same way). Only paths under
|
|
127
|
+
* `/config/img/devices/` with a safe file name are taken: the file comes from the network.
|
|
128
|
+
*/
|
|
129
|
+
export function parseDevDb(text) {
|
|
130
|
+
const out = new Map();
|
|
131
|
+
const start = text.indexOf('array set DEV_PATHS');
|
|
132
|
+
if (start < 0) {
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
const open = text.indexOf('{', start);
|
|
136
|
+
const body = open < 0 ? undefined : braced(text, open);
|
|
137
|
+
if (body === undefined) {
|
|
138
|
+
return out;
|
|
139
|
+
}
|
|
140
|
+
const items = tclList(body);
|
|
141
|
+
for (let index = 0; index + 1 < items.length; index += 2) {
|
|
142
|
+
const type = (items[index] ?? '').split(/\s+/).filter(Boolean).join(' ').toLowerCase();
|
|
143
|
+
const bySize = new Map();
|
|
144
|
+
for (const pair of tclList(items[index + 1] ?? '')) {
|
|
145
|
+
const [size, file, ...rest] = tclList(pair);
|
|
146
|
+
if (size !== undefined && file !== undefined && rest.length === 0 && isSafeCcuImagePath(file)) {
|
|
147
|
+
bySize.set(size, file);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const paths = ['250', '50'].map((size) => bySize.get(size)).filter((file) => file !== undefined);
|
|
151
|
+
if (type !== '' && paths.length > 0) {
|
|
152
|
+
out.set(type, paths);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return out;
|
|
156
|
+
}
|
|
157
|
+
/** A path of `DEV_PATHS` the service may request: under the pictures, no way out, a picture's name. */
|
|
158
|
+
export function isSafeCcuImagePath(file) {
|
|
159
|
+
if (!file.startsWith(`${CCU_IMAGE_BASE}/`) || file.includes('..')) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
const parts = file.slice(CCU_IMAGE_BASE.length + 1).split('/');
|
|
163
|
+
const name = parts.pop() ?? '';
|
|
164
|
+
return parts.every((part) => /^[A-Za-z0-9_-]+$/.test(part)) && isSafeIconName(name);
|
|
165
|
+
}
|
|
166
|
+
/** The text between the brace at `open` and its partner, or `undefined` when it never closes. */
|
|
167
|
+
function braced(text, open) {
|
|
168
|
+
let depth = 0;
|
|
169
|
+
for (let index = open; index < text.length; index += 1) {
|
|
170
|
+
const char = text[index];
|
|
171
|
+
if (char === '{') {
|
|
172
|
+
depth += 1;
|
|
173
|
+
}
|
|
174
|
+
else if (char === '}') {
|
|
175
|
+
depth -= 1;
|
|
176
|
+
if (depth === 0) {
|
|
177
|
+
return text.slice(open + 1, index);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return undefined;
|
|
182
|
+
}
|
|
183
|
+
/** A Tcl list's elements: words, or braced groups without their braces. */
|
|
184
|
+
function tclList(text) {
|
|
185
|
+
const out = [];
|
|
186
|
+
let index = 0;
|
|
187
|
+
while (index < text.length) {
|
|
188
|
+
while (index < text.length && /\s/.test(text[index] ?? '')) {
|
|
189
|
+
index += 1;
|
|
190
|
+
}
|
|
191
|
+
if (index >= text.length) {
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
if (text[index] === '{') {
|
|
195
|
+
const inner = braced(text, index);
|
|
196
|
+
if (inner === undefined) {
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
out.push(inner);
|
|
200
|
+
index += inner.length + 2;
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
const end = text.slice(index).search(/\s/);
|
|
204
|
+
const word = end < 0 ? text.slice(index) : text.slice(index, index + end);
|
|
205
|
+
out.push(word);
|
|
206
|
+
index += word.length;
|
|
207
|
+
}
|
|
208
|
+
return out;
|
|
209
|
+
}
|
|
109
210
|
/** The URL of the CCU's web server, or `undefined` when no host is configured. */
|
|
110
211
|
export function ccuOrigin(upstream) {
|
|
111
212
|
if (upstream === undefined || upstream.host === '') {
|
|
@@ -148,7 +249,11 @@ export class DeviceImageService {
|
|
|
148
249
|
#log;
|
|
149
250
|
#memory = new Map();
|
|
150
251
|
#inFlight = new Map();
|
|
252
|
+
/** Task 127: types that have no picture anywhere, until when that holds. */
|
|
253
|
+
#misses = new Map();
|
|
151
254
|
#icons;
|
|
255
|
+
/** Task 127: the CCU's catalogue, per origin, and when it was read. */
|
|
256
|
+
#devDb;
|
|
152
257
|
constructor(options) {
|
|
153
258
|
this.#options = options;
|
|
154
259
|
this.#log = options.log ?? silentLog;
|
|
@@ -162,13 +267,22 @@ export class DeviceImageService {
|
|
|
162
267
|
});
|
|
163
268
|
return this.#icons;
|
|
164
269
|
}
|
|
165
|
-
/** The file name the CCU knows this device type under
|
|
270
|
+
/** The file name the CCU knows this device type under (the unknown device's for a type the mapping lacks). */
|
|
166
271
|
async fileFor(deviceType) {
|
|
272
|
+
const mapped = await this.mappedFileFor(deviceType);
|
|
273
|
+
if (mapped !== undefined) {
|
|
274
|
+
return mapped;
|
|
275
|
+
}
|
|
276
|
+
const unknown = (await this.icons())[UNKNOWN_DEVICE_KEY];
|
|
277
|
+
return unknown !== undefined && isSafeIconName(unknown) ? unknown : undefined;
|
|
278
|
+
}
|
|
279
|
+
/** The mapping's own file for this type, or `undefined` when the mapping does not know it. */
|
|
280
|
+
async mappedFileFor(deviceType) {
|
|
167
281
|
const icons = await this.icons();
|
|
168
282
|
// the pipeline keys the mapping by the upper-cased type with spaces as `_`; the CCU reports
|
|
169
283
|
// `HM-LC-Sw1-Pl` and `HmIP-eTRV-B-2 R4M` (B-103)
|
|
170
|
-
const file = icons[deviceType] ?? icons[dataKey(deviceType)]
|
|
171
|
-
if (file === undefined) {
|
|
284
|
+
const file = icons[deviceType] ?? icons[dataKey(deviceType)];
|
|
285
|
+
if (file === undefined || file === icons[UNKNOWN_DEVICE_KEY]) {
|
|
172
286
|
return undefined;
|
|
173
287
|
}
|
|
174
288
|
return isSafeIconName(file) ? file : undefined;
|
|
@@ -192,9 +306,9 @@ export class DeviceImageService {
|
|
|
192
306
|
return pending;
|
|
193
307
|
}
|
|
194
308
|
async #resolve(deviceType) {
|
|
195
|
-
const iconFile = await this.
|
|
309
|
+
const iconFile = await this.mappedFileFor(deviceType);
|
|
196
310
|
if (iconFile === undefined) {
|
|
197
|
-
return
|
|
311
|
+
return this.#resolveUnmapped(deviceType);
|
|
198
312
|
}
|
|
199
313
|
const cacheFile = path.join(this.#options.cacheDir, cacheFileName(iconFile));
|
|
200
314
|
let fromDisk = await readIfPresent(cacheFile);
|
|
@@ -222,17 +336,87 @@ export class DeviceImageService {
|
|
|
222
336
|
this.#log.debug(`no image for device type ${deviceType} (${iconFile})`);
|
|
223
337
|
return undefined;
|
|
224
338
|
}
|
|
225
|
-
|
|
339
|
+
/**
|
|
340
|
+
* Task 127: a type the mapping lacks - the CCU's catalogue, then the picture named after the type,
|
|
341
|
+
* then nothing (see the top of this module).
|
|
342
|
+
*/
|
|
343
|
+
async #resolveUnmapped(deviceType) {
|
|
344
|
+
const until = this.#misses.get(deviceType);
|
|
345
|
+
if (until !== undefined && until > Date.now()) {
|
|
346
|
+
return undefined;
|
|
347
|
+
}
|
|
348
|
+
const own = `${deviceType.toLowerCase()}.png`;
|
|
349
|
+
const ownSafe = isSafeIconName(own);
|
|
350
|
+
const cacheFile = path.join(this.#options.cacheDir, cacheFileName(own));
|
|
351
|
+
const fromDisk = ownSafe ? await readIfPresent(cacheFile) : undefined;
|
|
352
|
+
if (fromDisk && looksLikeImage(fromDisk)) {
|
|
353
|
+
return this.#remember(deviceType, { mime: mimeOrDefault(cacheFile), body: fromDisk, source: 'disk' });
|
|
354
|
+
}
|
|
355
|
+
const catalogue = await this.#catalogue();
|
|
356
|
+
const candidates = [
|
|
357
|
+
...(catalogue?.get(deviceType.toLowerCase()) ?? []),
|
|
358
|
+
...(ownSafe ? ccuImagePaths(own) : []),
|
|
359
|
+
];
|
|
360
|
+
const found = catalogue === undefined ? undefined : await this.#fetchPaths(candidates);
|
|
361
|
+
if (found) {
|
|
362
|
+
if (ownSafe) {
|
|
363
|
+
await this.#store(cacheFile, found.body);
|
|
364
|
+
}
|
|
365
|
+
return this.#remember(deviceType, { mime: mimeOrDefault(found.path), body: found.body, source: 'ccu' });
|
|
366
|
+
}
|
|
367
|
+
this.#misses.set(deviceType, Date.now() + MISS_TTL_MS);
|
|
368
|
+
this.#log.debug(`no image for device type ${deviceType}: not in the mapping, nor on the CCU`);
|
|
369
|
+
return undefined;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* The CCU's `DEVDB.tcl`, read once per origin and again after {@link MISS_TTL_MS} (an addon may
|
|
373
|
+
* bring devices). An empty map when it is not there or not the catalogue; `undefined` when the
|
|
374
|
+
* CCU cannot be reached at all, so the caller does not try a handful of paths more.
|
|
375
|
+
*/
|
|
376
|
+
async #catalogue() {
|
|
226
377
|
const origin = ccuOrigin(this.#options.upstream());
|
|
227
378
|
if (origin === undefined) {
|
|
228
379
|
return undefined;
|
|
229
380
|
}
|
|
381
|
+
const cached = this.#devDb;
|
|
382
|
+
if (cached && cached.origin === origin && Date.now() - cached.at < MISS_TTL_MS) {
|
|
383
|
+
return cached.paths;
|
|
384
|
+
}
|
|
230
385
|
const request = this.#options.fetch ?? globalThis.fetch;
|
|
386
|
+
let paths = new Map();
|
|
387
|
+
try {
|
|
388
|
+
const response = await request(`${origin}${CCU_DEVDB_PATH}`, {
|
|
389
|
+
headers: this.#headers(),
|
|
390
|
+
signal: AbortSignal.timeout(this.#options.timeoutMs ?? DEFAULT_IMAGE_TIMEOUT_MS),
|
|
391
|
+
});
|
|
392
|
+
if (response.ok) {
|
|
393
|
+
paths = parseDevDb(await response.text());
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
catch (error) {
|
|
397
|
+
this.#log.warn(`${origin}${CCU_DEVDB_PATH} failed:`, error);
|
|
398
|
+
this.#devDb = { origin, at: Date.now(), paths };
|
|
399
|
+
return undefined;
|
|
400
|
+
}
|
|
401
|
+
this.#devDb = { origin, at: Date.now(), paths };
|
|
402
|
+
return paths;
|
|
403
|
+
}
|
|
404
|
+
#headers() {
|
|
231
405
|
const auth = this.#options.upstream()?.auth;
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
406
|
+
return auth ? { Authorization: `Basic ${Buffer.from(`${auth.user}:${auth.password}`).toString('base64')}` } : {};
|
|
407
|
+
}
|
|
408
|
+
async #fetch(iconFile) {
|
|
409
|
+
return (await this.#fetchPaths(ccuImagePaths(iconFile)))?.body;
|
|
410
|
+
}
|
|
411
|
+
/** The first of these CCU paths that answers with a picture, or `undefined`. */
|
|
412
|
+
async #fetchPaths(paths) {
|
|
413
|
+
const origin = ccuOrigin(this.#options.upstream());
|
|
414
|
+
if (origin === undefined) {
|
|
415
|
+
return undefined;
|
|
416
|
+
}
|
|
417
|
+
const request = this.#options.fetch ?? globalThis.fetch;
|
|
418
|
+
const headers = this.#headers();
|
|
419
|
+
for (const candidate of [...new Set(paths)]) {
|
|
236
420
|
const url = `${origin}${candidate}`;
|
|
237
421
|
try {
|
|
238
422
|
const response = await request(url, {
|
|
@@ -243,7 +427,7 @@ export class DeviceImageService {
|
|
|
243
427
|
const body = Buffer.from(await response.arrayBuffer());
|
|
244
428
|
const type = (response.headers.get('content-type') ?? '').toLowerCase();
|
|
245
429
|
if ((type === '' || type.startsWith('image/')) && looksLikeImage(body)) {
|
|
246
|
-
return body;
|
|
430
|
+
return { path: candidate, body };
|
|
247
431
|
}
|
|
248
432
|
// B-57: a box without the file answered with a page; the next shape may exist
|
|
249
433
|
this.#log.debug(`${url} answered ${response.status} with ${type || 'no type'}, not a picture`);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What kind of device something is, from its channel types (task 127): the generic picture the UI
|
|
3
|
+
* draws for a device type that has no picture of its own - a homebrew device before the data knows
|
|
4
|
+
* it, a type newer than the pinned mapping, a Homegear or bare-rfd system without the CCU's
|
|
5
|
+
* pictures. "Something with a switch" says more than a question mark or two letters.
|
|
6
|
+
*
|
|
7
|
+
* The class of the device is the class of its most telling channel: an actuator before a sensor,
|
|
8
|
+
* and a sensor before a key, so a switch actuator with two push buttons on it is a switch and a
|
|
9
|
+
* weather station with a key is a sensor. `MAINTENANCE` and the like say nothing.
|
|
10
|
+
*/
|
|
11
|
+
/** The classes there is a generic picture for. */
|
|
12
|
+
export type DeviceClass = 'display' | 'lock' | 'blind' | 'light' | 'motor' | 'switch' | 'climate' | 'signal' | 'meter' | 'sensor' | 'remote' | 'generic';
|
|
13
|
+
/** Every class, in the order the rules below are tried. */
|
|
14
|
+
export declare const DEVICE_CLASSES: readonly DeviceClass[];
|
|
15
|
+
/** The class of one channel type, or `undefined` for one that says nothing (`MAINTENANCE`). */
|
|
16
|
+
export declare function channelClass(channelType: string): DeviceClass | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* The class of a device: the earliest class of {@link DEVICE_CLASSES} any of its channels has. A
|
|
19
|
+
* device type that names a display (`HB-DIS-EP-42BW`, `HM-Dis-WM55`, `HB-RC-4-Dis-TH`) is a display
|
|
20
|
+
* whatever its channels are - those are `KEY`s.
|
|
21
|
+
*/
|
|
22
|
+
export declare function deviceClassOf(channelTypes: Iterable<string>, deviceType?: string): DeviceClass;
|
|
23
|
+
//# sourceMappingURL=deviceClass.d.ts.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What kind of device something is, from its channel types (task 127): the generic picture the UI
|
|
3
|
+
* draws for a device type that has no picture of its own - a homebrew device before the data knows
|
|
4
|
+
* it, a type newer than the pinned mapping, a Homegear or bare-rfd system without the CCU's
|
|
5
|
+
* pictures. "Something with a switch" says more than a question mark or two letters.
|
|
6
|
+
*
|
|
7
|
+
* The class of the device is the class of its most telling channel: an actuator before a sensor,
|
|
8
|
+
* and a sensor before a key, so a switch actuator with two push buttons on it is a switch and a
|
|
9
|
+
* weather station with a key is a sensor. `MAINTENANCE` and the like say nothing.
|
|
10
|
+
*/
|
|
11
|
+
/** Every class, in the order the rules below are tried. */
|
|
12
|
+
export const DEVICE_CLASSES = [
|
|
13
|
+
'display',
|
|
14
|
+
'lock',
|
|
15
|
+
'blind',
|
|
16
|
+
'light',
|
|
17
|
+
'motor',
|
|
18
|
+
'switch',
|
|
19
|
+
'climate',
|
|
20
|
+
'signal',
|
|
21
|
+
'meter',
|
|
22
|
+
'sensor',
|
|
23
|
+
'remote',
|
|
24
|
+
'generic',
|
|
25
|
+
];
|
|
26
|
+
/** The channel types of each class, as patterns over the `TYPE` of a channel. */
|
|
27
|
+
const RULES = [
|
|
28
|
+
['display', /DISPLAY/],
|
|
29
|
+
['lock', /^(KEYMATIC|DOOR_LOCK_|ACCESS_)/],
|
|
30
|
+
['blind', /^(BLIND|SHUTTER_(TRANSMITTER|VIRTUAL_RECEIVER)|JALOUSIE|WINMATIC|WINDOW_DRIVE|JPWNDCTRL|AKKU)/],
|
|
31
|
+
['light', /^(DIMMER|VIRTUAL_DIMMER|UNIVERSAL_LIGHT|RGBW_|DUAL_WHITE|VIRTUAL_DUAL_WHITE)/],
|
|
32
|
+
['motor', /^(FAN|SERVO|AIRFLAP)/],
|
|
33
|
+
['switch', /^(SWITCH($|_VIRTUAL_RECEIVER|_TRANSMITTER|_PANIC)|SIMPLE_SWITCH|ACTOR_|WATER_SWITCH|UNIVERSAL_ACTOR)/],
|
|
34
|
+
['climate', /^(CLIMATECONTROL|HEATING_|THERMALCONTROL|HEATINGTHERMOSTAT)/],
|
|
35
|
+
['signal', /^(SIGNAL_|ALARMACTUATOR|ACOUSTIC_|OPTICAL_SIGNAL)/],
|
|
36
|
+
['meter', /(POWERMETER|ENERGIE_METER|ENERGY_METER|PW_METER|GAS_|POWER_)/],
|
|
37
|
+
[
|
|
38
|
+
'sensor',
|
|
39
|
+
/^(WEATHER|SHUTTER_CONTACT|ROTARY_HANDLE|MOTION|PRESENCE|SMOKE|WATER_DETECT|TILT|RAIN|CAPACITIVE|CONDITION_|SENSOR|HB_|CLIMATE_TRANSCEIVER|BRIGHTNESS|LUXMETER|ACCELERATION|DOOR_STATE|THERMOSTAT_|HUMIDITY|TEMPERATURE|MULTI_MODE_INPUT)/,
|
|
40
|
+
],
|
|
41
|
+
['remote', /^(KEY|VIRTUAL_KEY|REMOTE|BUTTON|CENTRAL_KEY)/],
|
|
42
|
+
];
|
|
43
|
+
/** The class of one channel type, or `undefined` for one that says nothing (`MAINTENANCE`). */
|
|
44
|
+
export function channelClass(channelType) {
|
|
45
|
+
return RULES.find(([, pattern]) => pattern.test(channelType))?.[0];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The class of a device: the earliest class of {@link DEVICE_CLASSES} any of its channels has. A
|
|
49
|
+
* device type that names a display (`HB-DIS-EP-42BW`, `HM-Dis-WM55`, `HB-RC-4-Dis-TH`) is a display
|
|
50
|
+
* whatever its channels are - those are `KEY`s.
|
|
51
|
+
*/
|
|
52
|
+
export function deviceClassOf(channelTypes, deviceType = '') {
|
|
53
|
+
if (/(^|-)DIS(-|$)/i.test(deviceType)) {
|
|
54
|
+
return 'display';
|
|
55
|
+
}
|
|
56
|
+
let best = DEVICE_CLASSES.length - 1;
|
|
57
|
+
for (const type of channelTypes) {
|
|
58
|
+
const found = channelClass(type);
|
|
59
|
+
if (found !== undefined) {
|
|
60
|
+
best = Math.min(best, DEVICE_CLASSES.indexOf(found));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return DEVICE_CLASSES[best] ?? 'generic';
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=deviceClass.js.map
|
|
@@ -15,6 +15,7 @@ export * from './interfaces/table.js';
|
|
|
15
15
|
export * from './address/address.js';
|
|
16
16
|
export * from './address/names.js';
|
|
17
17
|
export * from './devices/index.js';
|
|
18
|
+
export * from './devices/deviceClass.js';
|
|
18
19
|
export * from './devices/smokeGroups.js';
|
|
19
20
|
export * from './devices/hmipKey.js';
|
|
20
21
|
export * from './links/roles.js';
|
|
@@ -30,6 +31,8 @@ export * from './paramset/validate.js';
|
|
|
30
31
|
export * from './paramset/diff.js';
|
|
31
32
|
export * from './paramset/multiApply.js';
|
|
32
33
|
export * from './paramset/powerMeter.js';
|
|
34
|
+
export * from './paramset/displayText.js';
|
|
35
|
+
export * from './paramset/signalModes.js';
|
|
33
36
|
export * from './easymodes/engine.js';
|
|
34
37
|
export * from './easymodes/form.js';
|
|
35
38
|
export * from './easymodes/linkTypes.js';
|
|
@@ -17,6 +17,7 @@ export * from './interfaces/table.js';
|
|
|
17
17
|
export * from './address/address.js';
|
|
18
18
|
export * from './address/names.js';
|
|
19
19
|
export * from './devices/index.js';
|
|
20
|
+
export * from './devices/deviceClass.js';
|
|
20
21
|
export * from './devices/smokeGroups.js';
|
|
21
22
|
export * from './devices/hmipKey.js';
|
|
22
23
|
export * from './links/roles.js';
|
|
@@ -33,6 +34,8 @@ export * from './paramset/validate.js';
|
|
|
33
34
|
export * from './paramset/diff.js';
|
|
34
35
|
export * from './paramset/multiApply.js';
|
|
35
36
|
export * from './paramset/powerMeter.js';
|
|
37
|
+
export * from './paramset/displayText.js';
|
|
38
|
+
export * from './paramset/signalModes.js';
|
|
36
39
|
// Easy modes and the MASTER metadata layer
|
|
37
40
|
export * from './easymodes/engine.js';
|
|
38
41
|
export * from './easymodes/form.js';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The text lines of the display devices' MASTER paramsets (task 127): the e-paper displays and
|
|
3
|
+
* display remotes of the homebrew set (`HB-DIS-EP-*`, `HB-RC-12-EP-*`, `HB-RC-4-Dis-TH*`) and the
|
|
4
|
+
* stock ones with `TEXTLINE_1`/`TEXTLINE_2` (HM-PB-4Dis-WM, HM-Dis-WM55, HM-Dis-EP-WM55, ...).
|
|
5
|
+
*
|
|
6
|
+
* The description says nothing but `TYPE: STRING`: no length, no character set. The CCU's WebUI
|
|
7
|
+
* knows both by device type (`ic_common.tcl`'s STRING branch, OpenCCU-Base#414 at `6eb475b`):
|
|
8
|
+
*
|
|
9
|
+
* - a `maxlength` per device and parameter - 16 on the HB-DIS-EP-42BW/75BW, 10 on the HB-RC-12-EP
|
|
10
|
+
* and the HB-RC-4-Dis-TH, 12 on every other `TEXTLINE_1`/`_2` - which is the `size` of the
|
|
11
|
+
* parameter's `config_string` in the device XML: a longer text is cut by rfd;
|
|
12
|
+
* - `encodeStringStatusDisplay(id, true, sz)` on blur (`functions.js`): the displays' font has the
|
|
13
|
+
* German letters at the code points of ASCII characters, so the text is stored with `Ä` as `[`,
|
|
14
|
+
* `Ö` as `#`, `Ü` as `$`, `ä` as `{`, `ö` as `|`, `ü` as `}`, `&` as `]`, `=` as `'` and `ß` as
|
|
15
|
+
* `~` - or `_` on the HM-Dis-WM55 and HM-Dis-EP-WM55, whose fonts have `ß` there.
|
|
16
|
+
*
|
|
17
|
+
* The same table is lite-addon-logic's display action (its task 68, `SUBMIT_CHARS`), and the rule
|
|
18
|
+
* for what a display can show is the same as there: printable ASCII except the characters whose
|
|
19
|
+
* code points the letters above took, plus those letters. So a text means the same in both.
|
|
20
|
+
*/
|
|
21
|
+
/** A display text parameter: how long it may be and which character stands for `ß`. */
|
|
22
|
+
export interface DisplayTextSpec {
|
|
23
|
+
/** Characters, which are bytes here: every character a display shows is one. */
|
|
24
|
+
readonly maxLength: number;
|
|
25
|
+
/** The ASCII character the device's font shows as `ß`. */
|
|
26
|
+
readonly sz: '~' | '_';
|
|
27
|
+
}
|
|
28
|
+
/** The letters a display shows at the place of an ASCII character, `ß` aside (it is per device). */
|
|
29
|
+
export declare const DISPLAY_TEXT_CHARS: Readonly<Record<string, string>>;
|
|
30
|
+
/** The ASCII characters whose code points the letters took; a display cannot show them as themselves. */
|
|
31
|
+
export declare const DISPLAY_TEXT_TAKEN = "[#${|}]'_~";
|
|
32
|
+
/** The stock text lines' length. */
|
|
33
|
+
export declare const STOCK_TEXT_LINE_LENGTH = 12;
|
|
34
|
+
/**
|
|
35
|
+
* The spec of a MASTER text parameter, or `undefined` when it is none. The device type is matched
|
|
36
|
+
* without regard to case. A homebrew display has exactly its own parameters; any other device has
|
|
37
|
+
* `TEXTLINE_1` and `TEXTLINE_2`, as in the WebUI.
|
|
38
|
+
*/
|
|
39
|
+
export declare function displayTextSpec(deviceType: string | undefined, param: string): DisplayTextSpec | undefined;
|
|
40
|
+
/** Whether a display shows a character (what can be typed into a text line). */
|
|
41
|
+
export declare function displayShows(char: string): boolean;
|
|
42
|
+
/** A typed text as the device stores it. A character the display cannot show passes unchanged. */
|
|
43
|
+
export declare function encodeDisplayText(text: string, spec: DisplayTextSpec): string;
|
|
44
|
+
/** A stored text as the display shows it - the inverse of {@link encodeDisplayText}. */
|
|
45
|
+
export declare function decodeDisplayText(stored: string, spec: DisplayTextSpec): string;
|
|
46
|
+
/** A text's length as a display counts it: in characters, not in UTF-16 units. */
|
|
47
|
+
export declare function displayTextLength(text: string): number;
|
|
48
|
+
/** What is wrong with a typed text: too long, or a character the display cannot show. */
|
|
49
|
+
export type DisplayTextProblem = {
|
|
50
|
+
readonly kind: 'length';
|
|
51
|
+
readonly max: number;
|
|
52
|
+
} | {
|
|
53
|
+
readonly kind: 'char';
|
|
54
|
+
readonly char: string;
|
|
55
|
+
};
|
|
56
|
+
/** The first problem of a typed text, or `undefined` when it can be written as it is. */
|
|
57
|
+
export declare function displayTextProblem(text: string, spec: DisplayTextSpec): DisplayTextProblem | undefined;
|
|
58
|
+
//# sourceMappingURL=displayText.d.ts.map
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The text lines of the display devices' MASTER paramsets (task 127): the e-paper displays and
|
|
3
|
+
* display remotes of the homebrew set (`HB-DIS-EP-*`, `HB-RC-12-EP-*`, `HB-RC-4-Dis-TH*`) and the
|
|
4
|
+
* stock ones with `TEXTLINE_1`/`TEXTLINE_2` (HM-PB-4Dis-WM, HM-Dis-WM55, HM-Dis-EP-WM55, ...).
|
|
5
|
+
*
|
|
6
|
+
* The description says nothing but `TYPE: STRING`: no length, no character set. The CCU's WebUI
|
|
7
|
+
* knows both by device type (`ic_common.tcl`'s STRING branch, OpenCCU-Base#414 at `6eb475b`):
|
|
8
|
+
*
|
|
9
|
+
* - a `maxlength` per device and parameter - 16 on the HB-DIS-EP-42BW/75BW, 10 on the HB-RC-12-EP
|
|
10
|
+
* and the HB-RC-4-Dis-TH, 12 on every other `TEXTLINE_1`/`_2` - which is the `size` of the
|
|
11
|
+
* parameter's `config_string` in the device XML: a longer text is cut by rfd;
|
|
12
|
+
* - `encodeStringStatusDisplay(id, true, sz)` on blur (`functions.js`): the displays' font has the
|
|
13
|
+
* German letters at the code points of ASCII characters, so the text is stored with `Ä` as `[`,
|
|
14
|
+
* `Ö` as `#`, `Ü` as `$`, `ä` as `{`, `ö` as `|`, `ü` as `}`, `&` as `]`, `=` as `'` and `ß` as
|
|
15
|
+
* `~` - or `_` on the HM-Dis-WM55 and HM-Dis-EP-WM55, whose fonts have `ß` there.
|
|
16
|
+
*
|
|
17
|
+
* The same table is lite-addon-logic's display action (its task 68, `SUBMIT_CHARS`), and the rule
|
|
18
|
+
* for what a display can show is the same as there: printable ASCII except the characters whose
|
|
19
|
+
* code points the letters above took, plus those letters. So a text means the same in both.
|
|
20
|
+
*/
|
|
21
|
+
/** The letters a display shows at the place of an ASCII character, `ß` aside (it is per device). */
|
|
22
|
+
export const DISPLAY_TEXT_CHARS = {
|
|
23
|
+
Ä: '[',
|
|
24
|
+
Ö: '#',
|
|
25
|
+
Ü: '$',
|
|
26
|
+
ä: '{',
|
|
27
|
+
ö: '|',
|
|
28
|
+
ü: '}',
|
|
29
|
+
'&': ']',
|
|
30
|
+
'=': "'",
|
|
31
|
+
};
|
|
32
|
+
/** The ASCII characters whose code points the letters took; a display cannot show them as themselves. */
|
|
33
|
+
export const DISPLAY_TEXT_TAKEN = "[#${|}]'_~";
|
|
34
|
+
/** The homebrew displays, by device type in lower case: their text parameters and lengths. */
|
|
35
|
+
const HB_DISPLAYS = (() => {
|
|
36
|
+
const ep42 = { TEXTLINE_1: 16, TEXTLINE_2: 16, HBTEXTLINE_1: 16, HBTEXTLINE_2: 16 };
|
|
37
|
+
const ep75 = { HBTEXTLINE_1: 16, HBTEXTLINE_2: 16, HBTEXTLINE_3: 16, HBTEXTLINE_4: 16 };
|
|
38
|
+
const rc12 = { TEXTLINE_1: 10 };
|
|
39
|
+
const rc4 = { HB_HEADERLINE: 10, HBTEXTLINE_UPPER: 10, HBTEXTLINE_LOWER: 10 };
|
|
40
|
+
return {
|
|
41
|
+
'hb-dis-ep-42bw': ep42,
|
|
42
|
+
'hb-dis-ep-42bw-mains': ep42,
|
|
43
|
+
'hb-dis-ep-75bw': ep75,
|
|
44
|
+
'hb-dis-ep-75bw-mains': ep75,
|
|
45
|
+
'hb-rc-12-ep-c': rc12,
|
|
46
|
+
'hb-rc-12-ep-bw': rc12,
|
|
47
|
+
'hb-rc-4-dis-th': rc4,
|
|
48
|
+
'hb-rc-4-dis-th-crg': rc4,
|
|
49
|
+
};
|
|
50
|
+
})();
|
|
51
|
+
/** The stock displays whose font has `ß` at `_` rather than at `~`. */
|
|
52
|
+
const UNDERSCORE_SZ = new Set(['hm-dis-wm55', 'hm-dis-ep-wm55']);
|
|
53
|
+
/** The text lines every other device gets, as the WebUI gives them to any device that has them. */
|
|
54
|
+
const STOCK_TEXT_LINES = new Set(['TEXTLINE_1', 'TEXTLINE_2']);
|
|
55
|
+
/** The stock text lines' length. */
|
|
56
|
+
export const STOCK_TEXT_LINE_LENGTH = 12;
|
|
57
|
+
/**
|
|
58
|
+
* The spec of a MASTER text parameter, or `undefined` when it is none. The device type is matched
|
|
59
|
+
* without regard to case. A homebrew display has exactly its own parameters; any other device has
|
|
60
|
+
* `TEXTLINE_1` and `TEXTLINE_2`, as in the WebUI.
|
|
61
|
+
*/
|
|
62
|
+
export function displayTextSpec(deviceType, param) {
|
|
63
|
+
if (deviceType === undefined || deviceType === '') {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
const type = deviceType.toLowerCase();
|
|
67
|
+
const hb = HB_DISPLAYS[type];
|
|
68
|
+
if (hb !== undefined) {
|
|
69
|
+
const maxLength = hb[param];
|
|
70
|
+
return maxLength === undefined ? undefined : { maxLength, sz: '~' };
|
|
71
|
+
}
|
|
72
|
+
if (!STOCK_TEXT_LINES.has(param)) {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
return { maxLength: STOCK_TEXT_LINE_LENGTH, sz: UNDERSCORE_SZ.has(type) ? '_' : '~' };
|
|
76
|
+
}
|
|
77
|
+
/** Whether a display shows a character (what can be typed into a text line). */
|
|
78
|
+
export function displayShows(char) {
|
|
79
|
+
if (char in DISPLAY_TEXT_CHARS || char === 'ß') {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
return char.length === 1 && char >= ' ' && char <= '~' && !DISPLAY_TEXT_TAKEN.includes(char);
|
|
83
|
+
}
|
|
84
|
+
/** A typed text as the device stores it. A character the display cannot show passes unchanged. */
|
|
85
|
+
export function encodeDisplayText(text, spec) {
|
|
86
|
+
return Array.from(text)
|
|
87
|
+
.map((char) => (char === 'ß' ? spec.sz : (DISPLAY_TEXT_CHARS[char] ?? char)))
|
|
88
|
+
.join('');
|
|
89
|
+
}
|
|
90
|
+
/** A stored text as the display shows it - the inverse of {@link encodeDisplayText}. */
|
|
91
|
+
export function decodeDisplayText(stored, spec) {
|
|
92
|
+
const back = {
|
|
93
|
+
...Object.fromEntries(Object.entries(DISPLAY_TEXT_CHARS).map(([letter, ascii]) => [ascii, letter])),
|
|
94
|
+
[spec.sz]: 'ß',
|
|
95
|
+
};
|
|
96
|
+
return Array.from(stored)
|
|
97
|
+
.map((char) => back[char] ?? char)
|
|
98
|
+
.join('');
|
|
99
|
+
}
|
|
100
|
+
/** A text's length as a display counts it: in characters, not in UTF-16 units. */
|
|
101
|
+
export function displayTextLength(text) {
|
|
102
|
+
return Array.from(text).length;
|
|
103
|
+
}
|
|
104
|
+
/** The first problem of a typed text, or `undefined` when it can be written as it is. */
|
|
105
|
+
export function displayTextProblem(text, spec) {
|
|
106
|
+
const chars = Array.from(text);
|
|
107
|
+
const odd = chars.find((char) => !displayShows(char));
|
|
108
|
+
if (odd !== undefined) {
|
|
109
|
+
return { kind: 'char', char: odd };
|
|
110
|
+
}
|
|
111
|
+
return chars.length > spec.maxLength ? { kind: 'length', max: spec.maxLength } : undefined;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=displayText.js.map
|