iobroker.hm-rpc 4.2.3 → 4.3.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/README.md +59 -10
- package/admin/i18n/de.json +14 -1
- package/admin/i18n/en.json +38 -25
- package/admin/i18n/es.json +14 -1
- package/admin/i18n/fr.json +14 -1
- package/admin/i18n/it.json +14 -1
- package/admin/i18n/nl.json +14 -1
- package/admin/i18n/pl.json +14 -1
- package/admin/i18n/pt.json +14 -1
- package/admin/i18n/ru.json +14 -1
- package/admin/i18n/uk.json +14 -1
- package/admin/i18n/zh-cn.json +14 -1
- package/admin/jsonConfig.json +189 -14
- package/build/lib/lite.d.ts +138 -0
- package/build/lib/lite.js +259 -0
- package/build/lib/lite.js.map +1 -0
- package/build/lib/liteConnection.d.ts +106 -0
- package/build/lib/liteConnection.js +151 -0
- package/build/lib/liteConnection.js.map +1 -0
- package/build/lib/liteNames.d.ts +78 -0
- package/build/lib/liteNames.js +189 -0
- package/build/lib/liteNames.js.map +1 -0
- package/build/lib/litePairing.d.ts +50 -0
- package/build/lib/litePairing.js +94 -0
- package/build/lib/litePairing.js.map +1 -0
- package/build/lib/tools.d.ts +12 -0
- package/build/lib/tools.js +22 -1
- package/build/lib/tools.js.map +1 -1
- package/build/lib/transitionFilter.d.ts +43 -0
- package/build/lib/transitionFilter.js +87 -0
- package/build/lib/transitionFilter.js.map +1 -0
- package/build/main.d.ts +58 -1
- package/build/main.js +328 -26
- package/build/main.js.map +1 -1
- package/io-package.json +50 -42
- package/package.json +5 -4
package/build/main.d.ts
CHANGED
|
@@ -8,10 +8,16 @@ export declare class HomematicRpc extends Adapter {
|
|
|
8
8
|
/** Register again at most every X ms, if events with an outdated interface id of this instance arrive */
|
|
9
9
|
private readonly STALE_ID_REINIT_DELAY_MS;
|
|
10
10
|
private lastStaleIdReinit;
|
|
11
|
+
/** Outdated interface ids, which already caused a registration. Never cleared, else the re-init loop starts again */
|
|
12
|
+
private readonly staleClientIds;
|
|
13
|
+
/** Outdated interface ids, which still arrive after the registration and were reported on info level */
|
|
14
|
+
private readonly reportedStaleClientIds;
|
|
11
15
|
/** `<host>:<namespace>:`, every interface id of this instance starts with it */
|
|
12
16
|
private clientIdPrefix;
|
|
13
17
|
private readonly metaValues;
|
|
14
18
|
private readonly dpTypes;
|
|
19
|
+
/** holds back interim LEVEL values of moving channels, if `suppressTransitionalLevel` is enabled */
|
|
20
|
+
private transitionFilter;
|
|
15
21
|
private lastEvent;
|
|
16
22
|
private eventInterval?;
|
|
17
23
|
private connInterval?;
|
|
@@ -22,6 +28,14 @@ export declare class HomematicRpc extends Adapter {
|
|
|
22
28
|
private usedCallbackPort;
|
|
23
29
|
private readonly COMMON_TYPE_MAPPING;
|
|
24
30
|
private deviceManagement;
|
|
31
|
+
/** The connection to an openccu-lite system (connection type `openccu-lite`), else undefined */
|
|
32
|
+
private lite;
|
|
33
|
+
/** Names and rooms from the openccu-lite system, when switched on */
|
|
34
|
+
private liteNames;
|
|
35
|
+
/** The pairing with an openccu-lite system, created with the first request of the admin */
|
|
36
|
+
private litePairing;
|
|
37
|
+
/** The language of ioBroker, for the names of rooms and functions and the pairing texts */
|
|
38
|
+
private liteLanguage;
|
|
25
39
|
/** admin/icons sits next to build/ in the installed package */
|
|
26
40
|
private readonly iconDir;
|
|
27
41
|
/** icon file -> `common.icon` value, so each SVG is read from disk only once */
|
|
@@ -53,6 +67,40 @@ export declare class HomematicRpc extends Adapter {
|
|
|
53
67
|
*/
|
|
54
68
|
private migrateDeviceIcons;
|
|
55
69
|
private onReady;
|
|
70
|
+
/**
|
|
71
|
+
* Connects to the openccu-lite system: the requests through lite-rpc, the events from its stream, no callback
|
|
72
|
+
* server and no `init`. The device snapshot of the stream arrives as `newDevices`, which creates the new devices
|
|
73
|
+
* and removes the stale ones; the state of the connection follows the client's status instead of a PING.
|
|
74
|
+
*/
|
|
75
|
+
private startLite;
|
|
76
|
+
/**
|
|
77
|
+
* The state of the lite-rpc connection: `ready` is connected, everything else (connecting, the stream lost,
|
|
78
|
+
* the credential refused, closed) is not
|
|
79
|
+
*
|
|
80
|
+
* @param state the client's status
|
|
81
|
+
*/
|
|
82
|
+
private onLiteStatus;
|
|
83
|
+
/**
|
|
84
|
+
* Writes the values the system's state store holds into the states, through the event path: at connect, for
|
|
85
|
+
* the devices just created and after a resync, so a restart of ioBroker shows the current values before the
|
|
86
|
+
* first event comes. Only values a device has confirmed since the system started; datapoints without an object
|
|
87
|
+
* are discarded as any event of an unknown device
|
|
88
|
+
*
|
|
89
|
+
* @param devices only the datapoints of these devices (addresses), else every known one
|
|
90
|
+
*/
|
|
91
|
+
private seedLiteValues;
|
|
92
|
+
/**
|
|
93
|
+
* The state `info.pairing` (what the admin shows while a pairing runs) and the pairing runner, created once:
|
|
94
|
+
* at start in lite mode, or with the first pairing request of the admin (the user may pair before saving the
|
|
95
|
+
* connection type)
|
|
96
|
+
*/
|
|
97
|
+
private ensurePairing;
|
|
98
|
+
/**
|
|
99
|
+
* The messages of the instance settings for the openccu-lite mode
|
|
100
|
+
*
|
|
101
|
+
* @param obj the message
|
|
102
|
+
*/
|
|
103
|
+
private onLiteMessage;
|
|
56
104
|
/**
|
|
57
105
|
* Is called when adapter shuts down - callback has to be called under any circumstances!
|
|
58
106
|
*
|
|
@@ -115,7 +163,7 @@ export declare class HomematicRpc extends Adapter {
|
|
|
115
163
|
private getDeinitParams;
|
|
116
164
|
/**
|
|
117
165
|
* Called on an event with an interface id of this instance, which is not the current one. The CCU still has an
|
|
118
|
-
* outdated registration, e.g. after an unclean stop, so register again (#1542)
|
|
166
|
+
* outdated registration, e.g. after an unclean stop, so register again once per outdated id (#1542)
|
|
119
167
|
*
|
|
120
168
|
* @param staleId the interface id of the event
|
|
121
169
|
*/
|
|
@@ -124,6 +172,15 @@ export declare class HomematicRpc extends Adapter {
|
|
|
124
172
|
* Inits the RPC server
|
|
125
173
|
*/
|
|
126
174
|
private initRpcServer;
|
|
175
|
+
/**
|
|
176
|
+
* Registers the handlers of the methods the CCU calls on the adapter. `server` is the RPC callback server on a
|
|
177
|
+
* CCU, or occulite-client's callback emitter on openccu-lite, which emits the same methods with the same
|
|
178
|
+
* argument lists from the event stream (`listDevices`, `system.listMethods` and `setReadyConfig` are never
|
|
179
|
+
* emitted there - the system does not ask a client for its device list)
|
|
180
|
+
*
|
|
181
|
+
* @param server what emits the method calls
|
|
182
|
+
*/
|
|
183
|
+
private registerCallbackHandlers;
|
|
127
184
|
/**
|
|
128
185
|
* Adds the paramset objects of the given paramset to the given channel
|
|
129
186
|
*
|
package/build/main.js
CHANGED
|
@@ -40,8 +40,13 @@ const node_path_1 = require("node:path");
|
|
|
40
40
|
const adapter_core_1 = require("@iobroker/adapter-core");
|
|
41
41
|
const images_1 = require("./lib/images");
|
|
42
42
|
const tools = __importStar(require("./lib/tools"));
|
|
43
|
+
const transitionFilter_1 = require("./lib/transitionFilter");
|
|
43
44
|
const roles_1 = require("./lib/roles");
|
|
44
45
|
const deviceManager_1 = require("./lib/deviceManager");
|
|
46
|
+
const lite_1 = require("./lib/lite");
|
|
47
|
+
const liteConnection_1 = require("./lib/liteConnection");
|
|
48
|
+
const liteNames_1 = require("./lib/liteNames");
|
|
49
|
+
const litePairing_1 = require("./lib/litePairing");
|
|
45
50
|
const usedResources_1 = require("./lib/usedResources");
|
|
46
51
|
let connected = false;
|
|
47
52
|
const displays = {};
|
|
@@ -64,10 +69,16 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
64
69
|
/** Register again at most every X ms, if events with an outdated interface id of this instance arrive */
|
|
65
70
|
this.STALE_ID_REINIT_DELAY_MS = 5 * 60_000;
|
|
66
71
|
this.lastStaleIdReinit = 0;
|
|
72
|
+
/** Outdated interface ids, which already caused a registration. Never cleared, else the re-init loop starts again */
|
|
73
|
+
this.staleClientIds = new Set();
|
|
74
|
+
/** Outdated interface ids, which still arrive after the registration and were reported on info level */
|
|
75
|
+
this.reportedStaleClientIds = new Set();
|
|
67
76
|
/** `<host>:<namespace>:`, every interface id of this instance starts with it */
|
|
68
77
|
this.clientIdPrefix = '';
|
|
69
78
|
this.metaValues = {};
|
|
70
79
|
this.dpTypes = {};
|
|
80
|
+
/** holds back interim LEVEL values of moving channels, if `suppressTransitionalLevel` is enabled */
|
|
81
|
+
this.transitionFilter = null;
|
|
71
82
|
this.lastEvent = 0;
|
|
72
83
|
this.daemonURL = '';
|
|
73
84
|
this.daemonProto = '';
|
|
@@ -85,6 +96,8 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
85
96
|
EPAPER_TONE_INTERVAL: 'number',
|
|
86
97
|
EPAPER_TONE_REPETITIONS: 'number',
|
|
87
98
|
};
|
|
99
|
+
/** The language of ioBroker, for the names of rooms and functions and the pairing texts */
|
|
100
|
+
this.liteLanguage = 'en';
|
|
88
101
|
/** admin/icons sits next to build/ in the installed package */
|
|
89
102
|
this.iconDir = (0, node_path_1.join)(__dirname, '..', 'admin', 'icons');
|
|
90
103
|
/** icon file -> `common.icon` value, so each SVG is read from disk only once */
|
|
@@ -136,6 +149,10 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
136
149
|
}
|
|
137
150
|
val = tools.fixEvent({ val, dpType: this.dpTypes[name] });
|
|
138
151
|
this.log.debug(`${name} ==> UNIT: "${this.dpTypes[name] ? this.dpTypes[name].UNIT : 'none'}" (min: ${this.dpTypes[name] ? this.dpTypes[name].MIN : 'none'}, max: ${this.dpTypes[name] ? this.dpTypes[name].MAX : 'none'}) From "${params[3]}" => "${val}"`);
|
|
152
|
+
if (this.transitionFilter?.handle(channel, params[2], val)) {
|
|
153
|
+
// held back or dropped: interim LEVEL of a moving channel
|
|
154
|
+
return '';
|
|
155
|
+
}
|
|
139
156
|
this.setStateAsync(`${channel}.${params[2]}`, { val: val, ack: true }).catch(e => this.log.error(`Cannot set state ${name}: ${e.message}`));
|
|
140
157
|
// unfortunately, this is necessary
|
|
141
158
|
return '';
|
|
@@ -214,6 +231,17 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
214
231
|
}
|
|
215
232
|
async onReady() {
|
|
216
233
|
this.deviceManagement = new deviceManager_1.dmHmRpc(this);
|
|
234
|
+
if (this.config.suppressTransitionalLevel) {
|
|
235
|
+
this.transitionFilter = new transitionFilter_1.TransitionFilter({
|
|
236
|
+
write: (id, val) => this.setStateAsync(id, { val, ack: true }).catch(e => this.log.error(`Cannot set state ${id}: ${e.message}`)),
|
|
237
|
+
hasFlag: channelId => !!this.dpTypes[`${this.namespace}.${channelId}.WORKING`] ||
|
|
238
|
+
!!this.dpTypes[`${this.namespace}.${channelId}.PROCESS`],
|
|
239
|
+
setTimeout: (cb, ms) => this.setTimeout(cb, ms),
|
|
240
|
+
clearTimeout: timer => this.clearTimeout(timer),
|
|
241
|
+
log: msg => this.log.debug(msg),
|
|
242
|
+
});
|
|
243
|
+
this.log.info('Interim LEVEL values of moving channels are suppressed');
|
|
244
|
+
}
|
|
217
245
|
this.subscribeStates('*');
|
|
218
246
|
// #1003: CCU-Jack serves its virtual devices on /RPC3 (/RPC2 is taken by the callbacks of the CCU)
|
|
219
247
|
this.homematicPath =
|
|
@@ -230,6 +258,18 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
230
258
|
}
|
|
231
259
|
await this.setState('info.connection', false, true);
|
|
232
260
|
await this.migrateDeviceIcons();
|
|
261
|
+
const lite = this.config.daemon === 'openccu-lite';
|
|
262
|
+
if (lite) {
|
|
263
|
+
// the interface decides the daemon from here on: its paramset fixes and the device filter of newDevices
|
|
264
|
+
// apply as on a CCU
|
|
265
|
+
this.config.daemon = (0, lite_1.interfaceDaemon)(this.config.liteInterface);
|
|
266
|
+
this.config.type = 'xml';
|
|
267
|
+
await this.ensurePairing();
|
|
268
|
+
if (!this.config.homematicAddress || !this.config.liteToken) {
|
|
269
|
+
this.log.info('Not paired with an openccu-lite system yet: pair the instance in its settings');
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
233
273
|
// #1349: CUxD supports only BIN-RPC, HomeMatic IP, Virtual Devices and CCU-Jack only XML-RPC
|
|
234
274
|
const requiredType = this.config.daemon === 'CUxD'
|
|
235
275
|
? 'bin'
|
|
@@ -242,7 +282,10 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
242
282
|
this.log.warn(`${this.config.daemon} supports only ${requiredType === 'bin' ? 'BIN-RPC' : 'XML-RPC'}, the configured protocol is ignored`);
|
|
243
283
|
this.config.type = requiredType;
|
|
244
284
|
}
|
|
245
|
-
if (
|
|
285
|
+
if (lite) {
|
|
286
|
+
// lite-rpc: no RPC library, occulite-client is loaded by the connection
|
|
287
|
+
}
|
|
288
|
+
else if (this.config.type === 'bin') {
|
|
246
289
|
rpc = await import('binrpc');
|
|
247
290
|
this.daemonProto = 'xmlrpc_bin://';
|
|
248
291
|
}
|
|
@@ -252,7 +295,7 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
252
295
|
this.config.type = 'xml';
|
|
253
296
|
this.daemonProto = 'http://';
|
|
254
297
|
}
|
|
255
|
-
if (rpc
|
|
298
|
+
if (rpc?.default) {
|
|
256
299
|
rpc = rpc.default;
|
|
257
300
|
}
|
|
258
301
|
// Clean up objects if still hm-rpc.meta exist
|
|
@@ -325,7 +368,225 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
325
368
|
this.log.error(`Could not get state view on start: ${e.message}`);
|
|
326
369
|
}
|
|
327
370
|
// Start Adapter
|
|
328
|
-
|
|
371
|
+
if (lite) {
|
|
372
|
+
await this.startLite();
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
await this.initRpcServer();
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Connects to the openccu-lite system: the requests through lite-rpc, the events from its stream, no callback
|
|
380
|
+
* server and no `init`. The device snapshot of the stream arrives as `newDevices`, which creates the new devices
|
|
381
|
+
* and removes the stale ones; the state of the connection follows the client's status instead of a PING.
|
|
382
|
+
*/
|
|
383
|
+
async startLite() {
|
|
384
|
+
clientId = this.namespace;
|
|
385
|
+
this.clientIdPrefix = '';
|
|
386
|
+
const url = (0, lite_1.liteUrlOf)(this.config);
|
|
387
|
+
this.lite = new liteConnection_1.LiteConnection({
|
|
388
|
+
url,
|
|
389
|
+
token: this.config.liteToken,
|
|
390
|
+
fingerprint: this.config.liteFingerprint,
|
|
391
|
+
iface: this.config.liteInterface,
|
|
392
|
+
initId: this.namespace,
|
|
393
|
+
log: this.log,
|
|
394
|
+
onStatus: state => this.onLiteStatus(state),
|
|
395
|
+
onResync: () => this.seedLiteValues(),
|
|
396
|
+
});
|
|
397
|
+
rpcClient = this.lite.client;
|
|
398
|
+
this.log.info(`lite-rpc client is connecting to ${url} for the interface ${this.config.liteInterface}`);
|
|
399
|
+
try {
|
|
400
|
+
await this.lite.start(server => this.registerCallbackHandlers(server));
|
|
401
|
+
}
|
|
402
|
+
catch (e) {
|
|
403
|
+
const code = e.code;
|
|
404
|
+
if (code === 'unauthenticated' || code === 'forbidden' || code === 'certificate') {
|
|
405
|
+
// does not get better by trying again: the token was revoked, or the system has a new certificate
|
|
406
|
+
this.log.error(`Cannot connect to ${url}: ${e.message}. Pair the instance again in its settings`);
|
|
407
|
+
this.lite.close();
|
|
408
|
+
this.lite = undefined;
|
|
409
|
+
rpcClient = undefined;
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
this.log.error(`Cannot connect to ${url}: ${e.message}. Restarting in ${this.SERVER_RESTART_DELAY_MS / 1_000} seconds`);
|
|
413
|
+
this.serverRestartTimer ??= this.setTimeout(() => this.restart(), this.SERVER_RESTART_DELAY_MS);
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
if (this.config.liteNames !== false && this.lite.meta) {
|
|
417
|
+
this.liteNames = new liteNames_1.LiteNames(this, this.lite.meta, this.config.liteInterface, this.liteLanguage);
|
|
418
|
+
// every change of the names, rooms and functions on the system, once the client's copy is in step again
|
|
419
|
+
// (right after a change applied in place, or once the snapshot is read again): a pass, debounced
|
|
420
|
+
this.lite.on('metaSettled', () => this.liteNames?.schedule());
|
|
421
|
+
this.liteNames.schedule();
|
|
422
|
+
}
|
|
423
|
+
this.seedLiteValues();
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* The state of the lite-rpc connection: `ready` is connected, everything else (connecting, the stream lost,
|
|
427
|
+
* the credential refused, closed) is not
|
|
428
|
+
*
|
|
429
|
+
* @param state the client's status
|
|
430
|
+
*/
|
|
431
|
+
onLiteStatus(state) {
|
|
432
|
+
if (state === 'ready') {
|
|
433
|
+
this.updateConnection();
|
|
434
|
+
}
|
|
435
|
+
else if (connected) {
|
|
436
|
+
this.log.info(`Disconnected (${state})`);
|
|
437
|
+
connected = false;
|
|
438
|
+
this.setStateAsync('info.connection', false, true).catch(e => this.log.error(`Cannot set state info.connection: ${e.message}`));
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Writes the values the system's state store holds into the states, through the event path: at connect, for
|
|
443
|
+
* the devices just created and after a resync, so a restart of ioBroker shows the current values before the
|
|
444
|
+
* first event comes. Only values a device has confirmed since the system started; datapoints without an object
|
|
445
|
+
* are discarded as any event of an unknown device
|
|
446
|
+
*
|
|
447
|
+
* @param devices only the datapoints of these devices (addresses), else every known one
|
|
448
|
+
*/
|
|
449
|
+
seedLiteValues(devices) {
|
|
450
|
+
const values = this.lite?.values;
|
|
451
|
+
if (!values) {
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
const prefix = `${this.config.liteInterface}.`;
|
|
455
|
+
let seeded = 0;
|
|
456
|
+
for (const [ref, value] of values) {
|
|
457
|
+
if (!ref.startsWith(prefix) || !value.confirmed) {
|
|
458
|
+
continue;
|
|
459
|
+
}
|
|
460
|
+
const datapoint = ref.slice(prefix.length);
|
|
461
|
+
const dot = datapoint.lastIndexOf('.');
|
|
462
|
+
const address = datapoint.slice(0, dot);
|
|
463
|
+
const key = datapoint.slice(dot + 1);
|
|
464
|
+
if (devices && !devices.includes(address.split(':')[0])) {
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
const id = `${this.namespace}.${address.replace(':', '.').replace(tools.FORBIDDEN_CHARS, '_')}.${key}`;
|
|
468
|
+
if (this.dpTypes[id]) {
|
|
469
|
+
this.methods.event(null, [this.namespace, address, key, value.value]);
|
|
470
|
+
seeded++;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
this.log.debug(`lite-rpc <- ${seeded} values of the state store written`);
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* The state `info.pairing` (what the admin shows while a pairing runs) and the pairing runner, created once:
|
|
477
|
+
* at start in lite mode, or with the first pairing request of the admin (the user may pair before saving the
|
|
478
|
+
* connection type)
|
|
479
|
+
*/
|
|
480
|
+
async ensurePairing() {
|
|
481
|
+
if (this.litePairing) {
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
try {
|
|
485
|
+
const systemConfig = await this.getForeignObjectAsync('system.config');
|
|
486
|
+
if (systemConfig?.common?.language) {
|
|
487
|
+
this.liteLanguage = systemConfig.common.language;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
catch (e) {
|
|
491
|
+
this.log.debug(`Cannot read the system language: ${e.message}`);
|
|
492
|
+
}
|
|
493
|
+
await this.setObjectNotExistsAsync('info.pairing', {
|
|
494
|
+
type: 'state',
|
|
495
|
+
common: {
|
|
496
|
+
name: {
|
|
497
|
+
en: 'Pairing with the openccu-lite system',
|
|
498
|
+
de: 'Kopplung mit dem openccu-lite-System',
|
|
499
|
+
},
|
|
500
|
+
type: 'string',
|
|
501
|
+
role: 'html',
|
|
502
|
+
read: true,
|
|
503
|
+
write: false,
|
|
504
|
+
def: '',
|
|
505
|
+
},
|
|
506
|
+
native: {},
|
|
507
|
+
});
|
|
508
|
+
await this.setStateAsync('info.pairing', '', true);
|
|
509
|
+
this.litePairing = new litePairing_1.LitePairing({
|
|
510
|
+
app: 'ioBroker.hm-rpc',
|
|
511
|
+
appVersion: this.version ?? '',
|
|
512
|
+
instance: `${this.namespace} on ${this.host}`,
|
|
513
|
+
log: this.log,
|
|
514
|
+
onState: (state) => this.setStateAsync('info.pairing', (0, lite_1.pairingHtml)(state, this.liteLanguage), true).catch(e => this.log.error(`Cannot set state info.pairing: ${e.message}`)),
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* The messages of the instance settings for the openccu-lite mode
|
|
519
|
+
*
|
|
520
|
+
* @param obj the message
|
|
521
|
+
*/
|
|
522
|
+
async onLiteMessage(obj) {
|
|
523
|
+
const message = typeof obj.message === 'object' && obj.message ? obj.message : {};
|
|
524
|
+
const answer = (response) => {
|
|
525
|
+
if (obj.callback) {
|
|
526
|
+
this.sendTo(obj.from, obj.command, response, obj.callback);
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
switch (obj.command) {
|
|
530
|
+
case 'lite:pair': {
|
|
531
|
+
// the admin shows the code from info.pairing while this waits for the approval on the system
|
|
532
|
+
await this.ensurePairing();
|
|
533
|
+
try {
|
|
534
|
+
const paired = await this.litePairing.pair((0, lite_1.liteUrlOf)({
|
|
535
|
+
homematicAddress: String(message.address ?? ''),
|
|
536
|
+
homematicPort: String(message.port ?? ''),
|
|
537
|
+
useHttps: message.https !== false && message.https !== 'false',
|
|
538
|
+
}));
|
|
539
|
+
// the system's URL as it answered, in the fields of the form
|
|
540
|
+
answer({
|
|
541
|
+
native: {
|
|
542
|
+
daemon: 'openccu-lite',
|
|
543
|
+
type: 'xml',
|
|
544
|
+
...(0, lite_1.liteUrlParts)(paired.url),
|
|
545
|
+
liteToken: paired.token,
|
|
546
|
+
liteFingerprint: paired.fingerprint,
|
|
547
|
+
},
|
|
548
|
+
saveConfig: true,
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
catch (e) {
|
|
552
|
+
answer({ error: e instanceof litePairing_1.PairingError ? e.code : 'failed' });
|
|
553
|
+
}
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
case 'lite:interfaces': {
|
|
557
|
+
// the interfaces the system runs, for the select; the ones lite-rpc carries while there is no token
|
|
558
|
+
const fallback = lite_1.LITE_INTERFACES.map(name => ({ value: name, label: name }));
|
|
559
|
+
const url = (0, lite_1.liteUrlOf)({
|
|
560
|
+
homematicAddress: String(message.address ?? ''),
|
|
561
|
+
homematicPort: String(message.port ?? ''),
|
|
562
|
+
useHttps: message.https !== false && message.https !== 'false',
|
|
563
|
+
});
|
|
564
|
+
if (!url || !message.token) {
|
|
565
|
+
answer(fallback);
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
try {
|
|
569
|
+
const list = await (0, liteConnection_1.listLiteInterfaces)({
|
|
570
|
+
url,
|
|
571
|
+
token: message.token,
|
|
572
|
+
fingerprint: message.fingerprint || undefined,
|
|
573
|
+
});
|
|
574
|
+
answer(list.map(i => ({
|
|
575
|
+
value: i.name,
|
|
576
|
+
label: i.name,
|
|
577
|
+
description: i.running ? 'running' : 'not running',
|
|
578
|
+
})));
|
|
579
|
+
}
|
|
580
|
+
catch (e) {
|
|
581
|
+
this.log.warn(`Cannot read the interfaces of ${url}: ${e.message}`);
|
|
582
|
+
answer(fallback);
|
|
583
|
+
}
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
default:
|
|
587
|
+
this.log.warn(`Received unknown command "${obj.command}" from ${obj.from}`);
|
|
588
|
+
answer({ error: 'Unknown command' });
|
|
589
|
+
}
|
|
329
590
|
}
|
|
330
591
|
/**
|
|
331
592
|
* Is called when adapter shuts down - callback has to be called under any circumstances!
|
|
@@ -334,6 +595,7 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
334
595
|
*/
|
|
335
596
|
async onUnload(callback) {
|
|
336
597
|
try {
|
|
598
|
+
this.transitionFilter?.clear();
|
|
337
599
|
if (this.eventInterval) {
|
|
338
600
|
this.clearInterval(this.eventInterval);
|
|
339
601
|
this.eventInterval = undefined;
|
|
@@ -342,7 +604,9 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
342
604
|
this.clearInterval(this.connInterval);
|
|
343
605
|
this.connInterval = undefined;
|
|
344
606
|
}
|
|
345
|
-
|
|
607
|
+
this.liteNames?.stop();
|
|
608
|
+
// on openccu-lite nothing was registered, so nothing is de-registered: the stream is just closed
|
|
609
|
+
if (this.config && rpcClient && !this.lite) {
|
|
346
610
|
// tell CCU that we are no longer the client under this URL
|
|
347
611
|
const deinitParams = this.getDeinitParams();
|
|
348
612
|
this.log.info(`${this.config.type}rpc -> ${this.config.homematicAddress}:${this.config.homematicPort}${this.homematicPath} init ${JSON.stringify(deinitParams)}`);
|
|
@@ -352,11 +616,11 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
352
616
|
catch (e) {
|
|
353
617
|
this.log.error(`Cannot call init: ${JSON.stringify(deinitParams)} ${e.message}`);
|
|
354
618
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
619
|
+
}
|
|
620
|
+
if (connected) {
|
|
621
|
+
this.log.info('Disconnected');
|
|
622
|
+
connected = false;
|
|
623
|
+
await this.setState('info.connection', false, true);
|
|
360
624
|
}
|
|
361
625
|
await this.closeRpc();
|
|
362
626
|
}
|
|
@@ -576,6 +840,9 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
576
840
|
if (obj.command.startsWith('dm:')) {
|
|
577
841
|
return;
|
|
578
842
|
}
|
|
843
|
+
if (obj.command.startsWith('lite:')) {
|
|
844
|
+
return this.onLiteMessage(obj);
|
|
845
|
+
}
|
|
579
846
|
if (obj.command === undefined ||
|
|
580
847
|
obj.command === null ||
|
|
581
848
|
typeof obj.message !== 'object' ||
|
|
@@ -798,13 +1065,26 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
798
1065
|
}
|
|
799
1066
|
/**
|
|
800
1067
|
* Called on an event with an interface id of this instance, which is not the current one. The CCU still has an
|
|
801
|
-
* outdated registration, e.g. after an unclean stop, so register again (#1542)
|
|
1068
|
+
* outdated registration, e.g. after an unclean stop, so register again once per outdated id (#1542)
|
|
802
1069
|
*
|
|
803
1070
|
* @param staleId the interface id of the event
|
|
804
1071
|
*/
|
|
805
1072
|
onStaleClientId(staleId) {
|
|
1073
|
+
if (this.staleClientIds.has(staleId)) {
|
|
1074
|
+
// registering again did not remove it, so it belongs to a registration we cannot remove
|
|
1075
|
+
if (!this.reportedStaleClientIds.has(staleId)) {
|
|
1076
|
+
this.reportedStaleClientIds.add(staleId);
|
|
1077
|
+
this.log.info(`${this.config.type}rpc <- CCU still sends events to the outdated registration "${staleId}". It probably belongs to another callback URL and cannot be removed from here. A restart of the CCU removes it`);
|
|
1078
|
+
}
|
|
1079
|
+
else {
|
|
1080
|
+
this.log.debug(`${this.config.type}rpc <- event with outdated interface id "${staleId}" discarded`);
|
|
1081
|
+
}
|
|
1082
|
+
return;
|
|
1083
|
+
}
|
|
1084
|
+
this.staleClientIds.add(staleId);
|
|
806
1085
|
const now = Date.now();
|
|
807
1086
|
if (now - this.lastStaleIdReinit < this.STALE_ID_REINIT_DELAY_MS) {
|
|
1087
|
+
// registered again just now, which covers this id too
|
|
808
1088
|
this.log.debug(`${this.config.type}rpc <- event with outdated interface id "${staleId}" discarded`);
|
|
809
1089
|
return;
|
|
810
1090
|
}
|
|
@@ -876,8 +1156,19 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
876
1156
|
this.log.info(`${this.config.type}rpc server is trying to listen on ${this.config.adapterAddress}:${adapterPort}`);
|
|
877
1157
|
this.log.info(`${this.config.type}rpc client is trying to connect to ${this.config.homematicAddress}:${this.config.homematicPort}${this.homematicPath} with ${JSON.stringify([this.daemonURL, clientId])}`);
|
|
878
1158
|
this.connect(true);
|
|
1159
|
+
this.registerCallbackHandlers(rpcServer);
|
|
1160
|
+
}
|
|
1161
|
+
/**
|
|
1162
|
+
* Registers the handlers of the methods the CCU calls on the adapter. `server` is the RPC callback server on a
|
|
1163
|
+
* CCU, or occulite-client's callback emitter on openccu-lite, which emits the same methods with the same
|
|
1164
|
+
* argument lists from the event stream (`listDevices`, `system.listMethods` and `setReadyConfig` are never
|
|
1165
|
+
* emitted there - the system does not ask a client for its device list)
|
|
1166
|
+
*
|
|
1167
|
+
* @param server what emits the method calls
|
|
1168
|
+
*/
|
|
1169
|
+
registerCallbackHandlers(server) {
|
|
879
1170
|
// Not found has special structure and no callback
|
|
880
|
-
|
|
1171
|
+
server.on('NotFound', (method, params) => {
|
|
881
1172
|
if (!method) {
|
|
882
1173
|
// the request could not be parsed as RPC call, e.g. an HTTP request of another client (#1151)
|
|
883
1174
|
this.log.debug(`${this.config.type}rpc <- invalid request without method ignored`);
|
|
@@ -885,11 +1176,11 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
885
1176
|
}
|
|
886
1177
|
this.log.warn(`${this.config.type}rpc <- undefined method ${method} with parameters ${typeof params === 'object' ? JSON.stringify(params).slice(0, 80) : params}`);
|
|
887
1178
|
});
|
|
888
|
-
|
|
1179
|
+
server.on('readdedDevice', (error, params, callback) => {
|
|
889
1180
|
this.log.info(`Readded device ${JSON.stringify(params)}`);
|
|
890
1181
|
callback(null, '');
|
|
891
1182
|
});
|
|
892
|
-
|
|
1183
|
+
server.on('firmwareUpdateStatusChanged', async (error, params, callback) => {
|
|
893
1184
|
this.log.info(`Firmware update status of ${params[1]} changed to ${params[2]}`);
|
|
894
1185
|
callback(null, '');
|
|
895
1186
|
// the status is a number, the device description delivers it as text (#1137)
|
|
@@ -902,7 +1193,7 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
902
1193
|
this.log.warn(`Cannot read the firmware update status of ${address}: ${e.message}`);
|
|
903
1194
|
}
|
|
904
1195
|
});
|
|
905
|
-
|
|
1196
|
+
server.on('replaceDevice', async (error, params, callback) => {
|
|
906
1197
|
const oldDeviceName = params[1];
|
|
907
1198
|
const newDeviceName = params[2];
|
|
908
1199
|
this.log.info(`Device "${oldDeviceName}" has been replaced by "${newDeviceName}"`);
|
|
@@ -920,7 +1211,7 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
920
1211
|
}
|
|
921
1212
|
callback(null, '');
|
|
922
1213
|
});
|
|
923
|
-
|
|
1214
|
+
server.on('system.multicall', (err, params, callback) => {
|
|
924
1215
|
this.updateConnection();
|
|
925
1216
|
const response = [];
|
|
926
1217
|
const events = params[0];
|
|
@@ -936,7 +1227,7 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
936
1227
|
}
|
|
937
1228
|
callback(null, response);
|
|
938
1229
|
});
|
|
939
|
-
|
|
1230
|
+
server.on('system.listMethods', (err, params, callback) => {
|
|
940
1231
|
if (err) {
|
|
941
1232
|
this.log.warn(`Error on system.listMethods: ${err}`);
|
|
942
1233
|
}
|
|
@@ -954,7 +1245,7 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
954
1245
|
'setReadyConfig',
|
|
955
1246
|
]);
|
|
956
1247
|
});
|
|
957
|
-
|
|
1248
|
+
server.on('event', (err, params, callback) => {
|
|
958
1249
|
if (err) {
|
|
959
1250
|
this.log.warn(`Error on event: ${err}`);
|
|
960
1251
|
}
|
|
@@ -966,7 +1257,7 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
966
1257
|
this.log.error(`Cannot send response to event: ${e.message}`);
|
|
967
1258
|
}
|
|
968
1259
|
});
|
|
969
|
-
|
|
1260
|
+
server.on('newDevices', async (err, params, callback) => {
|
|
970
1261
|
if (err) {
|
|
971
1262
|
this.log.warn(`Error on newDevices: ${err}`);
|
|
972
1263
|
}
|
|
@@ -977,9 +1268,13 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
977
1268
|
}
|
|
978
1269
|
this.log.info(`${this.config.type}rpc <- newDevices ${newDevices.length}`);
|
|
979
1270
|
// for a HmIP-adapter (and virtual-devices) we have to filter out the devices that
|
|
980
|
-
// are already present if forceReinit is not set
|
|
981
|
-
|
|
982
|
-
|
|
1271
|
+
// are already present if forceReinit is not set. The same for every interface of an openccu-lite
|
|
1272
|
+
// system, whose stream sends the whole device list at every connect
|
|
1273
|
+
const filterKnown = this.lite
|
|
1274
|
+
? !this.config.forceReInit
|
|
1275
|
+
: this.config.forceReInit === false &&
|
|
1276
|
+
(this.config.daemon === 'HMIP' || this.config.daemon === 'virtual-devices');
|
|
1277
|
+
if (filterKnown) {
|
|
983
1278
|
const knownDevices = [];
|
|
984
1279
|
let doc;
|
|
985
1280
|
try {
|
|
@@ -1055,7 +1350,7 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
1055
1350
|
// call it otherwise HMIP won't work
|
|
1056
1351
|
callback(null, '');
|
|
1057
1352
|
});
|
|
1058
|
-
|
|
1353
|
+
server.on('listDevices', async (err, params, callback) => {
|
|
1059
1354
|
if (err) {
|
|
1060
1355
|
this.log.warn(`Error on listDevices: ${err}`);
|
|
1061
1356
|
}
|
|
@@ -1099,7 +1394,7 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
1099
1394
|
this.log.error(JSON.stringify(response));
|
|
1100
1395
|
}
|
|
1101
1396
|
});
|
|
1102
|
-
|
|
1397
|
+
server.on('deleteDevices', (err, params, callback) => {
|
|
1103
1398
|
if (err) {
|
|
1104
1399
|
this.log.warn(`Error on deleteDevices: ${err.message}`);
|
|
1105
1400
|
}
|
|
@@ -1128,7 +1423,7 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
1128
1423
|
this.log.error(`Cannot response on deleteDevices: ${e.message}`);
|
|
1129
1424
|
}
|
|
1130
1425
|
});
|
|
1131
|
-
|
|
1426
|
+
server.on('setReadyConfig', (err, params, callback) => {
|
|
1132
1427
|
if (err) {
|
|
1133
1428
|
this.log.warn(`Error on setReadyConfig: ${err.message}`);
|
|
1134
1429
|
}
|
|
@@ -1783,6 +2078,12 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
1783
2078
|
}
|
|
1784
2079
|
await this.getValueParamsets(queueValueParamsets);
|
|
1785
2080
|
await this.updateFirmwareStates(deviceArr);
|
|
2081
|
+
if (this.lite) {
|
|
2082
|
+
// the objects were created with the address as name: the names of the system follow, and the values
|
|
2083
|
+
// the state store holds for them
|
|
2084
|
+
this.liteNames?.schedule();
|
|
2085
|
+
this.seedLiteValues(deviceArr.map(device => String(device.ADDRESS).split(':')[0]));
|
|
2086
|
+
}
|
|
1786
2087
|
}
|
|
1787
2088
|
/**
|
|
1788
2089
|
* Writes the firmware update state of the devices to `<device>.0.FIRMWARE_UPDATE_STATE` and updates the firmware
|
|
@@ -1921,8 +2222,9 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
1921
2222
|
this.clearInterval(this.connInterval);
|
|
1922
2223
|
this.connInterval = undefined;
|
|
1923
2224
|
}
|
|
1924
|
-
// Virtual Devices API does now also support PING (tested with 3.55.5.20201226 - see #308)
|
|
1925
|
-
|
|
2225
|
+
// Virtual Devices API does now also support PING (tested with 3.55.5.20201226 - see #308).
|
|
2226
|
+
// On openccu-lite the stream's state replaces the PING
|
|
2227
|
+
if (!this.eventInterval && !this.lite) {
|
|
1926
2228
|
this.log.debug('start ping interval');
|
|
1927
2229
|
this.eventInterval = this.setInterval(() => this.keepAlive(), (this.config.checkInitInterval * 1000) / 2);
|
|
1928
2230
|
}
|