iobroker.hm-rpc 4.2.4 → 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 +56 -4
- 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 +53 -0
- package/build/main.js +310 -25
- package/build/main.js.map +1 -1
- package/io-package.json +37 -29
- package/package.json +5 -4
package/build/main.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ export declare class HomematicRpc extends Adapter {
|
|
|
16
16
|
private clientIdPrefix;
|
|
17
17
|
private readonly metaValues;
|
|
18
18
|
private readonly dpTypes;
|
|
19
|
+
/** holds back interim LEVEL values of moving channels, if `suppressTransitionalLevel` is enabled */
|
|
20
|
+
private transitionFilter;
|
|
19
21
|
private lastEvent;
|
|
20
22
|
private eventInterval?;
|
|
21
23
|
private connInterval?;
|
|
@@ -26,6 +28,14 @@ export declare class HomematicRpc extends Adapter {
|
|
|
26
28
|
private usedCallbackPort;
|
|
27
29
|
private readonly COMMON_TYPE_MAPPING;
|
|
28
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;
|
|
29
39
|
/** admin/icons sits next to build/ in the installed package */
|
|
30
40
|
private readonly iconDir;
|
|
31
41
|
/** icon file -> `common.icon` value, so each SVG is read from disk only once */
|
|
@@ -57,6 +67,40 @@ export declare class HomematicRpc extends Adapter {
|
|
|
57
67
|
*/
|
|
58
68
|
private migrateDeviceIcons;
|
|
59
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;
|
|
60
104
|
/**
|
|
61
105
|
* Is called when adapter shuts down - callback has to be called under any circumstances!
|
|
62
106
|
*
|
|
@@ -128,6 +172,15 @@ export declare class HomematicRpc extends Adapter {
|
|
|
128
172
|
* Inits the RPC server
|
|
129
173
|
*/
|
|
130
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;
|
|
131
184
|
/**
|
|
132
185
|
* Adds the paramset objects of the given paramset to the given channel
|
|
133
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 = {};
|
|
@@ -72,6 +77,8 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
72
77
|
this.clientIdPrefix = '';
|
|
73
78
|
this.metaValues = {};
|
|
74
79
|
this.dpTypes = {};
|
|
80
|
+
/** holds back interim LEVEL values of moving channels, if `suppressTransitionalLevel` is enabled */
|
|
81
|
+
this.transitionFilter = null;
|
|
75
82
|
this.lastEvent = 0;
|
|
76
83
|
this.daemonURL = '';
|
|
77
84
|
this.daemonProto = '';
|
|
@@ -89,6 +96,8 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
89
96
|
EPAPER_TONE_INTERVAL: 'number',
|
|
90
97
|
EPAPER_TONE_REPETITIONS: 'number',
|
|
91
98
|
};
|
|
99
|
+
/** The language of ioBroker, for the names of rooms and functions and the pairing texts */
|
|
100
|
+
this.liteLanguage = 'en';
|
|
92
101
|
/** admin/icons sits next to build/ in the installed package */
|
|
93
102
|
this.iconDir = (0, node_path_1.join)(__dirname, '..', 'admin', 'icons');
|
|
94
103
|
/** icon file -> `common.icon` value, so each SVG is read from disk only once */
|
|
@@ -140,6 +149,10 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
140
149
|
}
|
|
141
150
|
val = tools.fixEvent({ val, dpType: this.dpTypes[name] });
|
|
142
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
|
+
}
|
|
143
156
|
this.setStateAsync(`${channel}.${params[2]}`, { val: val, ack: true }).catch(e => this.log.error(`Cannot set state ${name}: ${e.message}`));
|
|
144
157
|
// unfortunately, this is necessary
|
|
145
158
|
return '';
|
|
@@ -218,6 +231,17 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
218
231
|
}
|
|
219
232
|
async onReady() {
|
|
220
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
|
+
}
|
|
221
245
|
this.subscribeStates('*');
|
|
222
246
|
// #1003: CCU-Jack serves its virtual devices on /RPC3 (/RPC2 is taken by the callbacks of the CCU)
|
|
223
247
|
this.homematicPath =
|
|
@@ -234,6 +258,18 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
234
258
|
}
|
|
235
259
|
await this.setState('info.connection', false, true);
|
|
236
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
|
+
}
|
|
237
273
|
// #1349: CUxD supports only BIN-RPC, HomeMatic IP, Virtual Devices and CCU-Jack only XML-RPC
|
|
238
274
|
const requiredType = this.config.daemon === 'CUxD'
|
|
239
275
|
? 'bin'
|
|
@@ -246,7 +282,10 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
246
282
|
this.log.warn(`${this.config.daemon} supports only ${requiredType === 'bin' ? 'BIN-RPC' : 'XML-RPC'}, the configured protocol is ignored`);
|
|
247
283
|
this.config.type = requiredType;
|
|
248
284
|
}
|
|
249
|
-
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') {
|
|
250
289
|
rpc = await import('binrpc');
|
|
251
290
|
this.daemonProto = 'xmlrpc_bin://';
|
|
252
291
|
}
|
|
@@ -256,7 +295,7 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
256
295
|
this.config.type = 'xml';
|
|
257
296
|
this.daemonProto = 'http://';
|
|
258
297
|
}
|
|
259
|
-
if (rpc
|
|
298
|
+
if (rpc?.default) {
|
|
260
299
|
rpc = rpc.default;
|
|
261
300
|
}
|
|
262
301
|
// Clean up objects if still hm-rpc.meta exist
|
|
@@ -329,7 +368,225 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
329
368
|
this.log.error(`Could not get state view on start: ${e.message}`);
|
|
330
369
|
}
|
|
331
370
|
// Start Adapter
|
|
332
|
-
|
|
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
|
+
}
|
|
333
590
|
}
|
|
334
591
|
/**
|
|
335
592
|
* Is called when adapter shuts down - callback has to be called under any circumstances!
|
|
@@ -338,6 +595,7 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
338
595
|
*/
|
|
339
596
|
async onUnload(callback) {
|
|
340
597
|
try {
|
|
598
|
+
this.transitionFilter?.clear();
|
|
341
599
|
if (this.eventInterval) {
|
|
342
600
|
this.clearInterval(this.eventInterval);
|
|
343
601
|
this.eventInterval = undefined;
|
|
@@ -346,7 +604,9 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
346
604
|
this.clearInterval(this.connInterval);
|
|
347
605
|
this.connInterval = undefined;
|
|
348
606
|
}
|
|
349
|
-
|
|
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) {
|
|
350
610
|
// tell CCU that we are no longer the client under this URL
|
|
351
611
|
const deinitParams = this.getDeinitParams();
|
|
352
612
|
this.log.info(`${this.config.type}rpc -> ${this.config.homematicAddress}:${this.config.homematicPort}${this.homematicPath} init ${JSON.stringify(deinitParams)}`);
|
|
@@ -356,11 +616,11 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
356
616
|
catch (e) {
|
|
357
617
|
this.log.error(`Cannot call init: ${JSON.stringify(deinitParams)} ${e.message}`);
|
|
358
618
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
619
|
+
}
|
|
620
|
+
if (connected) {
|
|
621
|
+
this.log.info('Disconnected');
|
|
622
|
+
connected = false;
|
|
623
|
+
await this.setState('info.connection', false, true);
|
|
364
624
|
}
|
|
365
625
|
await this.closeRpc();
|
|
366
626
|
}
|
|
@@ -580,6 +840,9 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
580
840
|
if (obj.command.startsWith('dm:')) {
|
|
581
841
|
return;
|
|
582
842
|
}
|
|
843
|
+
if (obj.command.startsWith('lite:')) {
|
|
844
|
+
return this.onLiteMessage(obj);
|
|
845
|
+
}
|
|
583
846
|
if (obj.command === undefined ||
|
|
584
847
|
obj.command === null ||
|
|
585
848
|
typeof obj.message !== 'object' ||
|
|
@@ -893,8 +1156,19 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
893
1156
|
this.log.info(`${this.config.type}rpc server is trying to listen on ${this.config.adapterAddress}:${adapterPort}`);
|
|
894
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])}`);
|
|
895
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) {
|
|
896
1170
|
// Not found has special structure and no callback
|
|
897
|
-
|
|
1171
|
+
server.on('NotFound', (method, params) => {
|
|
898
1172
|
if (!method) {
|
|
899
1173
|
// the request could not be parsed as RPC call, e.g. an HTTP request of another client (#1151)
|
|
900
1174
|
this.log.debug(`${this.config.type}rpc <- invalid request without method ignored`);
|
|
@@ -902,11 +1176,11 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
902
1176
|
}
|
|
903
1177
|
this.log.warn(`${this.config.type}rpc <- undefined method ${method} with parameters ${typeof params === 'object' ? JSON.stringify(params).slice(0, 80) : params}`);
|
|
904
1178
|
});
|
|
905
|
-
|
|
1179
|
+
server.on('readdedDevice', (error, params, callback) => {
|
|
906
1180
|
this.log.info(`Readded device ${JSON.stringify(params)}`);
|
|
907
1181
|
callback(null, '');
|
|
908
1182
|
});
|
|
909
|
-
|
|
1183
|
+
server.on('firmwareUpdateStatusChanged', async (error, params, callback) => {
|
|
910
1184
|
this.log.info(`Firmware update status of ${params[1]} changed to ${params[2]}`);
|
|
911
1185
|
callback(null, '');
|
|
912
1186
|
// the status is a number, the device description delivers it as text (#1137)
|
|
@@ -919,7 +1193,7 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
919
1193
|
this.log.warn(`Cannot read the firmware update status of ${address}: ${e.message}`);
|
|
920
1194
|
}
|
|
921
1195
|
});
|
|
922
|
-
|
|
1196
|
+
server.on('replaceDevice', async (error, params, callback) => {
|
|
923
1197
|
const oldDeviceName = params[1];
|
|
924
1198
|
const newDeviceName = params[2];
|
|
925
1199
|
this.log.info(`Device "${oldDeviceName}" has been replaced by "${newDeviceName}"`);
|
|
@@ -937,7 +1211,7 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
937
1211
|
}
|
|
938
1212
|
callback(null, '');
|
|
939
1213
|
});
|
|
940
|
-
|
|
1214
|
+
server.on('system.multicall', (err, params, callback) => {
|
|
941
1215
|
this.updateConnection();
|
|
942
1216
|
const response = [];
|
|
943
1217
|
const events = params[0];
|
|
@@ -953,7 +1227,7 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
953
1227
|
}
|
|
954
1228
|
callback(null, response);
|
|
955
1229
|
});
|
|
956
|
-
|
|
1230
|
+
server.on('system.listMethods', (err, params, callback) => {
|
|
957
1231
|
if (err) {
|
|
958
1232
|
this.log.warn(`Error on system.listMethods: ${err}`);
|
|
959
1233
|
}
|
|
@@ -971,7 +1245,7 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
971
1245
|
'setReadyConfig',
|
|
972
1246
|
]);
|
|
973
1247
|
});
|
|
974
|
-
|
|
1248
|
+
server.on('event', (err, params, callback) => {
|
|
975
1249
|
if (err) {
|
|
976
1250
|
this.log.warn(`Error on event: ${err}`);
|
|
977
1251
|
}
|
|
@@ -983,7 +1257,7 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
983
1257
|
this.log.error(`Cannot send response to event: ${e.message}`);
|
|
984
1258
|
}
|
|
985
1259
|
});
|
|
986
|
-
|
|
1260
|
+
server.on('newDevices', async (err, params, callback) => {
|
|
987
1261
|
if (err) {
|
|
988
1262
|
this.log.warn(`Error on newDevices: ${err}`);
|
|
989
1263
|
}
|
|
@@ -994,9 +1268,13 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
994
1268
|
}
|
|
995
1269
|
this.log.info(`${this.config.type}rpc <- newDevices ${newDevices.length}`);
|
|
996
1270
|
// for a HmIP-adapter (and virtual-devices) we have to filter out the devices that
|
|
997
|
-
// are already present if forceReinit is not set
|
|
998
|
-
|
|
999
|
-
|
|
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) {
|
|
1000
1278
|
const knownDevices = [];
|
|
1001
1279
|
let doc;
|
|
1002
1280
|
try {
|
|
@@ -1072,7 +1350,7 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
1072
1350
|
// call it otherwise HMIP won't work
|
|
1073
1351
|
callback(null, '');
|
|
1074
1352
|
});
|
|
1075
|
-
|
|
1353
|
+
server.on('listDevices', async (err, params, callback) => {
|
|
1076
1354
|
if (err) {
|
|
1077
1355
|
this.log.warn(`Error on listDevices: ${err}`);
|
|
1078
1356
|
}
|
|
@@ -1116,7 +1394,7 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
1116
1394
|
this.log.error(JSON.stringify(response));
|
|
1117
1395
|
}
|
|
1118
1396
|
});
|
|
1119
|
-
|
|
1397
|
+
server.on('deleteDevices', (err, params, callback) => {
|
|
1120
1398
|
if (err) {
|
|
1121
1399
|
this.log.warn(`Error on deleteDevices: ${err.message}`);
|
|
1122
1400
|
}
|
|
@@ -1145,7 +1423,7 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
1145
1423
|
this.log.error(`Cannot response on deleteDevices: ${e.message}`);
|
|
1146
1424
|
}
|
|
1147
1425
|
});
|
|
1148
|
-
|
|
1426
|
+
server.on('setReadyConfig', (err, params, callback) => {
|
|
1149
1427
|
if (err) {
|
|
1150
1428
|
this.log.warn(`Error on setReadyConfig: ${err.message}`);
|
|
1151
1429
|
}
|
|
@@ -1800,6 +2078,12 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
1800
2078
|
}
|
|
1801
2079
|
await this.getValueParamsets(queueValueParamsets);
|
|
1802
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
|
+
}
|
|
1803
2087
|
}
|
|
1804
2088
|
/**
|
|
1805
2089
|
* Writes the firmware update state of the devices to `<device>.0.FIRMWARE_UPDATE_STATE` and updates the firmware
|
|
@@ -1938,8 +2222,9 @@ class HomematicRpc extends adapter_core_1.Adapter {
|
|
|
1938
2222
|
this.clearInterval(this.connInterval);
|
|
1939
2223
|
this.connInterval = undefined;
|
|
1940
2224
|
}
|
|
1941
|
-
// Virtual Devices API does now also support PING (tested with 3.55.5.20201226 - see #308)
|
|
1942
|
-
|
|
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) {
|
|
1943
2228
|
this.log.debug('start ping interval');
|
|
1944
2229
|
this.eventInterval = this.setInterval(() => this.keepAlive(), (this.config.checkInitInterval * 1000) / 2);
|
|
1945
2230
|
}
|