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
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The pure parts of the openccu-lite mode: nothing here talks to the system or to ioBroker.
|
|
4
|
+
*
|
|
5
|
+
* openccu-lite is a CCU firmware without ReGaHSS. Its interface processes are reached through lite-rpc
|
|
6
|
+
* (`/api/rpc/v1`): the requests over HTTP(S) with a token, the events as a stream the adapter opens -
|
|
7
|
+
* no callback server, no `init`. The names and rooms of devices and channels are the system's metadata.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.PAIRING_TIMEOUT_MS = exports.LITE_ACCESS = exports.LITE_INTERFACES = void 0;
|
|
11
|
+
exports.interfaceDaemon = interfaceDaemon;
|
|
12
|
+
exports.liteUrlOf = liteUrlOf;
|
|
13
|
+
exports.liteUrlParts = liteUrlParts;
|
|
14
|
+
exports.pairingErrorCode = pairingErrorCode;
|
|
15
|
+
exports.pairingHtml = pairingHtml;
|
|
16
|
+
exports.rpcCallbackError = rpcCallbackError;
|
|
17
|
+
exports.objectIdOfAddress = objectIdOfAddress;
|
|
18
|
+
exports.refOfAddress = refOfAddress;
|
|
19
|
+
exports.datapointName = datapointName;
|
|
20
|
+
exports.enumIdOfPath = enumIdOfPath;
|
|
21
|
+
exports.enumsOfNodes = enumsOfNodes;
|
|
22
|
+
const tools_1 = require("./tools");
|
|
23
|
+
/** The interfaces lite-rpc carries (the names of `InterfacesList.xml`, as `GET /api/rpc/v1/interfaces` lists them) */
|
|
24
|
+
exports.LITE_INTERFACES = ['HmIP-RF', 'BidCos-RF', 'BidCos-Wired', 'VirtualDevices'];
|
|
25
|
+
/** The scopes the pairing asks for: paramsets are written (`configure`), the names are read */
|
|
26
|
+
exports.LITE_ACCESS = { devices: 'configure', names: 'read' };
|
|
27
|
+
/** The pairing waits at most this long for the approval (the system lets a request expire after five minutes) */
|
|
28
|
+
exports.PAIRING_TIMEOUT_MS = 5.5 * 60_000;
|
|
29
|
+
/**
|
|
30
|
+
* The daemon an interface of the system corresponds to. The daemon decides the CCU specific fixes of the
|
|
31
|
+
* paramset descriptions (`fixParamset`) and which devices are filtered on `newDevices`, so the lite mode
|
|
32
|
+
* derives it from the interface instead of asking the user twice.
|
|
33
|
+
*
|
|
34
|
+
* @param iface the interface name, e.g. `HmIP-RF`
|
|
35
|
+
*/
|
|
36
|
+
function interfaceDaemon(iface) {
|
|
37
|
+
switch (iface) {
|
|
38
|
+
case 'HmIP-RF':
|
|
39
|
+
return 'HMIP';
|
|
40
|
+
case 'BidCos-Wired':
|
|
41
|
+
return 'hs485d';
|
|
42
|
+
case 'VirtualDevices':
|
|
43
|
+
return 'virtual-devices';
|
|
44
|
+
default:
|
|
45
|
+
return 'rfd';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The URL of the system from the configuration: `https://<address>:<port>` (`http://` without TLS), the default
|
|
50
|
+
* port of the scheme left out. A scheme or a path the user typed into the address is dropped; blanks are trimmed.
|
|
51
|
+
* An empty address gives an empty URL.
|
|
52
|
+
*
|
|
53
|
+
* @param config the address fields
|
|
54
|
+
*/
|
|
55
|
+
function liteUrlOf(config) {
|
|
56
|
+
const host = String(config.homematicAddress ?? '')
|
|
57
|
+
.trim()
|
|
58
|
+
.replace(/^https?:\/\//i, '')
|
|
59
|
+
.replace(/[/?#].*$/, '');
|
|
60
|
+
if (!host) {
|
|
61
|
+
return '';
|
|
62
|
+
}
|
|
63
|
+
const scheme = config.useHttps === false ? 'http' : 'https';
|
|
64
|
+
const port = parseInt(String(config.homematicPort ?? ''), 10);
|
|
65
|
+
const defaultPort = scheme === 'https' ? 443 : 80;
|
|
66
|
+
const withPort = port > 0 && port !== defaultPort ? `${host}:${port}` : host;
|
|
67
|
+
return `${scheme}://${withPort}`;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The address fields for a URL of the system (the one the pairing stored, after the system's redirect)
|
|
71
|
+
*
|
|
72
|
+
* @param url the system's URL, e.g. `https://192.168.1.20`
|
|
73
|
+
*/
|
|
74
|
+
function liteUrlParts(url) {
|
|
75
|
+
const parsed = new URL(url);
|
|
76
|
+
const useHttps = parsed.protocol === 'https:';
|
|
77
|
+
return {
|
|
78
|
+
homematicAddress: parsed.hostname.replace(/^\[(.*)\]$/, '$1'),
|
|
79
|
+
homematicPort: parsed.port || (useHttps ? '443' : '80'),
|
|
80
|
+
useHttps,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The code the admin shows for an error of the pairing. occulite-client reports its errors as
|
|
85
|
+
* `OccuLiteError` with a `code`; everything else is `failed`.
|
|
86
|
+
*
|
|
87
|
+
* @param e the error
|
|
88
|
+
*/
|
|
89
|
+
function pairingErrorCode(e) {
|
|
90
|
+
const code = typeof e?.code === 'string' ? e.code : '';
|
|
91
|
+
switch (code) {
|
|
92
|
+
case 'rejected':
|
|
93
|
+
case 'expired':
|
|
94
|
+
case 'timeout':
|
|
95
|
+
case 'certificate':
|
|
96
|
+
case 'unreachable':
|
|
97
|
+
return code;
|
|
98
|
+
case 'not-found':
|
|
99
|
+
case 'unsupported':
|
|
100
|
+
// the system has no pairing (an older openccu-lite, or pairing is switched off)
|
|
101
|
+
return 'no-pairing';
|
|
102
|
+
default:
|
|
103
|
+
return 'failed';
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const PAIRING_TEXTS = {
|
|
107
|
+
en: {
|
|
108
|
+
requesting: 'Requesting a pairing code from %url% …',
|
|
109
|
+
waiting: 'Pairing code <b style="font-size: 1.6em; letter-spacing: 0.1em">%code%</b> - approve the request on the <a href="%url%" target="_blank" rel="noopener">Status page of the system</a> (the code must match). Waiting …',
|
|
110
|
+
approved: 'Paired with %url%. Save the configuration to start the instance with the new token.',
|
|
111
|
+
failed: {
|
|
112
|
+
'no-url': 'Enter the address of the system first.',
|
|
113
|
+
unreachable: 'The system %url% is not reachable.',
|
|
114
|
+
'not-openccu-lite': '%url% does not answer as an openccu-lite system (a CCU?).',
|
|
115
|
+
'no-pairing': 'The system %url% offers no pairing (too old, or pairing is switched off).',
|
|
116
|
+
rejected: 'The administrator rejected the request on %url%.',
|
|
117
|
+
expired: 'Nobody approved the request on %url% within five minutes.',
|
|
118
|
+
timeout: 'The pairing with %url% timed out.',
|
|
119
|
+
busy: 'A pairing is already running.',
|
|
120
|
+
certificate: 'The certificate of %url% was not accepted.',
|
|
121
|
+
failed: 'The pairing with %url% failed, see the log.',
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
de: {
|
|
125
|
+
requesting: 'Pairing-Code wird von %url% angefordert …',
|
|
126
|
+
waiting: 'Pairing-Code <b style="font-size: 1.6em; letter-spacing: 0.1em">%code%</b> - die Anfrage auf der <a href="%url%" target="_blank" rel="noopener">Statusseite des Systems</a> bestätigen (der Code muss übereinstimmen). Warte …',
|
|
127
|
+
approved: 'Mit %url% gekoppelt. Die Konfiguration speichern, damit die Instanz mit dem neuen Token startet.',
|
|
128
|
+
failed: {
|
|
129
|
+
'no-url': 'Zuerst die Adresse des Systems eingeben.',
|
|
130
|
+
unreachable: 'Das System %url% ist nicht erreichbar.',
|
|
131
|
+
'not-openccu-lite': '%url% antwortet nicht als openccu-lite-System (eine CCU?).',
|
|
132
|
+
'no-pairing': 'Das System %url% bietet kein Pairing an (zu alt, oder das Pairing ist ausgeschaltet).',
|
|
133
|
+
rejected: 'Der Administrator hat die Anfrage auf %url% abgelehnt.',
|
|
134
|
+
expired: 'Niemand hat die Anfrage auf %url% innerhalb von fünf Minuten bestätigt.',
|
|
135
|
+
timeout: 'Das Pairing mit %url% hat zu lange gedauert.',
|
|
136
|
+
busy: 'Es läuft bereits ein Pairing.',
|
|
137
|
+
certificate: 'Das Zertifikat von %url% wurde nicht akzeptiert.',
|
|
138
|
+
failed: 'Das Pairing mit %url% ist fehlgeschlagen, siehe Log.',
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Escapes a value for the HTML the admin renders
|
|
144
|
+
*
|
|
145
|
+
* @param value the text
|
|
146
|
+
*/
|
|
147
|
+
function escapeHtml(value) {
|
|
148
|
+
return value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* The text of the instance state `info.pairing`, which the admin shows live while a pairing runs: the code
|
|
152
|
+
* with a link to the system's Status page, then the result. HTML, in German or English (English for every
|
|
153
|
+
* other language of the system).
|
|
154
|
+
*
|
|
155
|
+
* @param state the pairing's state
|
|
156
|
+
* @param lang the system language of ioBroker
|
|
157
|
+
*/
|
|
158
|
+
function pairingHtml(state, lang) {
|
|
159
|
+
const texts = lang === 'de' ? PAIRING_TEXTS.de : PAIRING_TEXTS.en;
|
|
160
|
+
if (state.phase === 'idle') {
|
|
161
|
+
return '';
|
|
162
|
+
}
|
|
163
|
+
const url = escapeHtml(state.url);
|
|
164
|
+
switch (state.phase) {
|
|
165
|
+
case 'requesting':
|
|
166
|
+
return texts.requesting.replace('%url%', url);
|
|
167
|
+
case 'waiting':
|
|
168
|
+
return texts.waiting.replace('%code%', escapeHtml(state.code)).replaceAll('%url%', url);
|
|
169
|
+
case 'approved':
|
|
170
|
+
return texts.approved.replace('%url%', url);
|
|
171
|
+
case 'failed':
|
|
172
|
+
return texts.failed[state.error].replace('%url%', url);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* The error string of a failed lite-rpc call for the callback of `methodCall`, in the shape hm-rpc's retry
|
|
177
|
+
* expects: a fault of the interface process is its fault string (`Failure`, `… (UNREACH)`), everything else
|
|
178
|
+
* names the client's error code.
|
|
179
|
+
*
|
|
180
|
+
* @param e the error occulite-client threw
|
|
181
|
+
*/
|
|
182
|
+
function rpcCallbackError(e) {
|
|
183
|
+
const err = e;
|
|
184
|
+
const message = typeof err?.message === 'string' ? err.message : String(e);
|
|
185
|
+
if (err?.code === 'rpc-fault' && err.faultCode !== undefined) {
|
|
186
|
+
return message;
|
|
187
|
+
}
|
|
188
|
+
return typeof err?.code === 'string' ? `${err.code}: ${message}` : message;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* The id of a device or channel object in ioBroker (relative to the namespace) for a CCU address
|
|
192
|
+
*
|
|
193
|
+
* @param address the address, e.g. `000A1B2C3D4E5F:1`
|
|
194
|
+
*/
|
|
195
|
+
function objectIdOfAddress(address) {
|
|
196
|
+
return address.replace(':', '.').replace(tools_1.FORBIDDEN_CHARS, '_');
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* The reference of a device or channel in the system's metadata, as occulite-client keys it
|
|
200
|
+
*
|
|
201
|
+
* @param iface the interface name
|
|
202
|
+
* @param address the address
|
|
203
|
+
*/
|
|
204
|
+
function refOfAddress(iface, address) {
|
|
205
|
+
return `${iface}.${address}`;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* The name of a datapoint object: `<channel name>.<DATAPOINT>` when the system names the channel (as hm-rega
|
|
209
|
+
* names them), else the datapoint alone (hm-rpc's own default)
|
|
210
|
+
*
|
|
211
|
+
* @param channelName the channel's name in the system, or undefined
|
|
212
|
+
* @param datapoint the datapoint, e.g. `STATE`
|
|
213
|
+
*/
|
|
214
|
+
function datapointName(channelName, datapoint) {
|
|
215
|
+
return channelName ? `${channelName}.${datapoint}` : datapoint;
|
|
216
|
+
}
|
|
217
|
+
/** The enum kinds of ioBroker the system's taxonomy maps to: the `room` tree to `enum.rooms`, `function` to `enum.functions` */
|
|
218
|
+
const ENUM_KINDS = { room: 'enum.rooms', function: 'enum.functions' };
|
|
219
|
+
/**
|
|
220
|
+
* The id of the ioBroker enum for a node of the system's taxonomy: a room tree is flattened, every node is an
|
|
221
|
+
* enum of its own named by its path (`room/eg/bad` → `enum.rooms.eg_bad`), so two rooms `bad` on two floors
|
|
222
|
+
* stay apart. Undefined for an enum of the system ioBroker has no counterpart for.
|
|
223
|
+
*
|
|
224
|
+
* @param path the node's path, e.g. `room/eg/bad`
|
|
225
|
+
*/
|
|
226
|
+
function enumIdOfPath(path) {
|
|
227
|
+
const slash = path.indexOf('/');
|
|
228
|
+
if (slash < 0) {
|
|
229
|
+
return undefined;
|
|
230
|
+
}
|
|
231
|
+
const kind = ENUM_KINDS[path.slice(0, slash)];
|
|
232
|
+
if (!kind) {
|
|
233
|
+
return undefined;
|
|
234
|
+
}
|
|
235
|
+
const id = path
|
|
236
|
+
.slice(slash + 1)
|
|
237
|
+
.split('/')
|
|
238
|
+
.map(part => part.replace(tools_1.FORBIDDEN_CHARS, '_').replace(/\./g, '_'))
|
|
239
|
+
.join('_');
|
|
240
|
+
return id ? `${kind}.${id}` : undefined;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* The ioBroker enums an object belongs to: its direct nodes in the system's taxonomy, each mapped to a flat enum
|
|
244
|
+
* (a channel in `room/eg/bad` is a member of `enum.rooms.eg_bad` and not of `enum.rooms.eg` - the innermost room, as
|
|
245
|
+
* hm-rega handles the CCU's flat rooms)
|
|
246
|
+
*
|
|
247
|
+
* @param nodes the direct nodes of the object (`membership(ref, {inherit: false})` of occulite-client, rooms and functions together)
|
|
248
|
+
*/
|
|
249
|
+
function enumsOfNodes(nodes) {
|
|
250
|
+
const out = [];
|
|
251
|
+
for (const node of nodes) {
|
|
252
|
+
const id = enumIdOfPath(node.path);
|
|
253
|
+
if (id && !out.some(e => e.id === id)) {
|
|
254
|
+
out.push({ id, name: node.name || node.path.slice(node.path.lastIndexOf('/') + 1), path: node.path });
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return out;
|
|
258
|
+
}
|
|
259
|
+
//# sourceMappingURL=lite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lite.js","sourceRoot":"","sources":["../../src/lib/lite.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AA0CH,0CAWC;AAgBD,8BAaC;AAOD,oCAQC;AAQD,4CAgBC;AA0DD,kCAgBC;AASD,4CAOC;AAOD,8CAEC;AAQD,oCAEC;AASD,sCAEC;AAYD,oCAeC;AAmBD,oCASC;AArSD,mCAA0C;AAE1C,sHAAsH;AACzG,QAAA,eAAe,GAAG,CAAC,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,gBAAgB,CAAU,CAAC;AAEnG,+FAA+F;AAClF,QAAA,WAAW,GAAG,EAAE,OAA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,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;YACpC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAC1G,CAAC;IACL,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The connection to an openccu-lite system through occulite-client: the requests go to lite-rpc with the
|
|
3
|
+
* token, the events come from the stream the client opens, and `callbackEvents` turns them into the method
|
|
4
|
+
* calls a callback server would make (`event`, `system.multicall`, `newDevices`, `deleteDevices`, ...) with
|
|
5
|
+
* the same argument lists - so the adapter's handlers feed from the stream unchanged.
|
|
6
|
+
*
|
|
7
|
+
* occulite-client is an ES module; it is loaded here by a dynamic import, so the CCU path never loads it.
|
|
8
|
+
*/
|
|
9
|
+
import type { OccuLite, Status } from 'occulite-client';
|
|
10
|
+
import type { callbackEvents, CallbackServer } from 'occulite-client/callbacks';
|
|
11
|
+
import type { nodeTransport, pair, probe } from 'occulite-client/node';
|
|
12
|
+
/** The parts of occulite-client the lite mode uses, loaded once */
|
|
13
|
+
export interface LiteModules {
|
|
14
|
+
OccuLite: typeof OccuLite;
|
|
15
|
+
callbackEvents: typeof callbackEvents;
|
|
16
|
+
nodeTransport: typeof nodeTransport;
|
|
17
|
+
pair: typeof pair;
|
|
18
|
+
probe: typeof probe;
|
|
19
|
+
}
|
|
20
|
+
/** Loads occulite-client, for the tests and the pairing a replaceable step */
|
|
21
|
+
export type LiteLoader = () => Promise<LiteModules>;
|
|
22
|
+
/**
|
|
23
|
+
* occulite-client, loaded once (an ES module, so by a dynamic import)
|
|
24
|
+
*/
|
|
25
|
+
export declare function loadOcculite(): Promise<LiteModules>;
|
|
26
|
+
/** The slice of a homematic-xmlrpc/binrpc client the adapter uses, served by lite-rpc */
|
|
27
|
+
export interface RpcClientLike {
|
|
28
|
+
methodCall(method: string, params: unknown[], callback: (err: unknown, res: unknown) => void): void;
|
|
29
|
+
close(): void;
|
|
30
|
+
}
|
|
31
|
+
export interface LiteConnectionOptions {
|
|
32
|
+
/** the system, scheme and authority */
|
|
33
|
+
url: string;
|
|
34
|
+
/** the paired token */
|
|
35
|
+
token: string;
|
|
36
|
+
/** the certificate pinned at pairing (SHA-256), empty when the system is reached over plain HTTP */
|
|
37
|
+
fingerprint?: string;
|
|
38
|
+
/** the one interface this instance follows, e.g. `HmIP-RF` */
|
|
39
|
+
iface: string;
|
|
40
|
+
/** the first argument of every callback method (the interface id the adapter expects) */
|
|
41
|
+
initId: string;
|
|
42
|
+
log: Pick<Console, 'debug' | 'info' | 'warn' | 'error'>;
|
|
43
|
+
/** the client's state: connecting | ready | degraded | offline | closed */
|
|
44
|
+
onStatus: (state: Status) => void;
|
|
45
|
+
/** after a gap or a restart of the system the values were read again */
|
|
46
|
+
onResync?: () => void;
|
|
47
|
+
/** per request, ms */
|
|
48
|
+
timeout?: number;
|
|
49
|
+
loader?: LiteLoader;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* One instance's connection: one interface, one stream, the callbacks of the adapter fed from it
|
|
53
|
+
*/
|
|
54
|
+
export declare class LiteConnection {
|
|
55
|
+
private readonly opts;
|
|
56
|
+
/** the client as the adapter's `rpcClient` */
|
|
57
|
+
readonly client: RpcClientLike;
|
|
58
|
+
state: Status;
|
|
59
|
+
private box;
|
|
60
|
+
private server;
|
|
61
|
+
private closed;
|
|
62
|
+
constructor(opts: LiteConnectionOptions);
|
|
63
|
+
/**
|
|
64
|
+
* Opens the connection. `register` gets the callback emitter before the stream starts, because the device
|
|
65
|
+
* snapshot arrives as `newDevices` calls while the client connects. Resolves once the first picture is
|
|
66
|
+
* loaded, rejects with the client's reason (unauthenticated, forbidden, unsupported, certificate, timeout).
|
|
67
|
+
*
|
|
68
|
+
* @param register registers the adapter's handlers on the callback emitter
|
|
69
|
+
*/
|
|
70
|
+
start(register: (server: CallbackServer) => void): Promise<void>;
|
|
71
|
+
/** The live copy of the system's names and taxonomy */
|
|
72
|
+
get meta(): OccuLite['meta'] | undefined;
|
|
73
|
+
/** The last value of every datapoint the system's state store keeps, keyed `<iface>.<address>.<KEY>` */
|
|
74
|
+
get values(): OccuLite['values'] | undefined;
|
|
75
|
+
/** Subscribes to the client's events (`meta`, `value`, ...); the answer unsubscribes */
|
|
76
|
+
on(event: string, fn: (arg: any) => void): () => void;
|
|
77
|
+
/**
|
|
78
|
+
* A method of the interface process through lite-rpc, in the callback shape of the RPC clients. A fault
|
|
79
|
+
* of the process reaches the callback as its fault string, so the adapter's retry on `Failure` works.
|
|
80
|
+
*
|
|
81
|
+
* @param method the method name
|
|
82
|
+
* @param params its parameters
|
|
83
|
+
* @param callback (err, result)
|
|
84
|
+
*/
|
|
85
|
+
methodCall(method: string, params: unknown[], callback: (err: unknown, res: unknown) => void): void;
|
|
86
|
+
/** Closes the stream; nothing is de-registered, because nothing was registered */
|
|
87
|
+
close(): void;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The interfaces a system runs, from `GET /api/rpc/v1/interfaces` with the paired token
|
|
91
|
+
*
|
|
92
|
+
* @param opts the system and the credential
|
|
93
|
+
* @param opts.url the system
|
|
94
|
+
* @param opts.token the paired token
|
|
95
|
+
* @param opts.fingerprint the certificate pinned at pairing
|
|
96
|
+
* @param opts.loader loads occulite-client (the tests)
|
|
97
|
+
*/
|
|
98
|
+
export declare function listLiteInterfaces(opts: {
|
|
99
|
+
url: string;
|
|
100
|
+
token: string;
|
|
101
|
+
fingerprint?: string;
|
|
102
|
+
loader?: LiteLoader;
|
|
103
|
+
}): Promise<{
|
|
104
|
+
name: string;
|
|
105
|
+
running: boolean;
|
|
106
|
+
}[]>;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The connection to an openccu-lite system through occulite-client: the requests go to lite-rpc with the
|
|
4
|
+
* token, the events come from the stream the client opens, and `callbackEvents` turns them into the method
|
|
5
|
+
* calls a callback server would make (`event`, `system.multicall`, `newDevices`, `deleteDevices`, ...) with
|
|
6
|
+
* the same argument lists - so the adapter's handlers feed from the stream unchanged.
|
|
7
|
+
*
|
|
8
|
+
* occulite-client is an ES module; it is loaded here by a dynamic import, so the CCU path never loads it.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.LiteConnection = void 0;
|
|
12
|
+
exports.loadOcculite = loadOcculite;
|
|
13
|
+
exports.listLiteInterfaces = listLiteInterfaces;
|
|
14
|
+
const lite_1 = require("./lite");
|
|
15
|
+
let loaded;
|
|
16
|
+
/**
|
|
17
|
+
* occulite-client, loaded once (an ES module, so by a dynamic import)
|
|
18
|
+
*/
|
|
19
|
+
function loadOcculite() {
|
|
20
|
+
loaded ??= (async () => {
|
|
21
|
+
const [client, callbacks, node] = await Promise.all([
|
|
22
|
+
import('occulite-client'),
|
|
23
|
+
import('occulite-client/callbacks'),
|
|
24
|
+
import('occulite-client/node'),
|
|
25
|
+
]);
|
|
26
|
+
return {
|
|
27
|
+
OccuLite: client.OccuLite,
|
|
28
|
+
callbackEvents: callbacks.callbackEvents,
|
|
29
|
+
nodeTransport: node.nodeTransport,
|
|
30
|
+
pair: node.pair,
|
|
31
|
+
probe: node.probe,
|
|
32
|
+
};
|
|
33
|
+
})();
|
|
34
|
+
return loaded;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* One instance's connection: one interface, one stream, the callbacks of the adapter fed from it
|
|
38
|
+
*/
|
|
39
|
+
class LiteConnection {
|
|
40
|
+
constructor(opts) {
|
|
41
|
+
this.opts = opts;
|
|
42
|
+
/** the client as the adapter's `rpcClient` */
|
|
43
|
+
this.client = {
|
|
44
|
+
methodCall: (method, params, callback) => this.methodCall(method, params, callback),
|
|
45
|
+
close: () => this.close(),
|
|
46
|
+
};
|
|
47
|
+
this.state = 'idle';
|
|
48
|
+
this.closed = false;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Opens the connection. `register` gets the callback emitter before the stream starts, because the device
|
|
52
|
+
* snapshot arrives as `newDevices` calls while the client connects. Resolves once the first picture is
|
|
53
|
+
* loaded, rejects with the client's reason (unauthenticated, forbidden, unsupported, certificate, timeout).
|
|
54
|
+
*
|
|
55
|
+
* @param register registers the adapter's handlers on the callback emitter
|
|
56
|
+
*/
|
|
57
|
+
async start(register) {
|
|
58
|
+
const modules = await (this.opts.loader ?? loadOcculite)();
|
|
59
|
+
const trust = this.opts.fingerprint ? { fingerprint256: this.opts.fingerprint } : {};
|
|
60
|
+
const box = new modules.OccuLite({
|
|
61
|
+
url: this.opts.url,
|
|
62
|
+
auth: { token: this.opts.token },
|
|
63
|
+
transport: modules.nodeTransport(trust),
|
|
64
|
+
interfaces: [this.opts.iface],
|
|
65
|
+
timeout: this.opts.timeout,
|
|
66
|
+
log: {
|
|
67
|
+
debug: (m) => this.opts.log.debug(m),
|
|
68
|
+
info: (m) => this.opts.log.debug(m),
|
|
69
|
+
warn: (m) => this.opts.log.warn(m),
|
|
70
|
+
error: (m) => this.opts.log.error(m),
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
this.box = box;
|
|
74
|
+
box.on('status', (s) => {
|
|
75
|
+
this.state = s.state;
|
|
76
|
+
if (!this.closed) {
|
|
77
|
+
this.opts.onStatus(s.state);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
box.on('interface', (ev) => this.opts.log.info(`lite-rpc <- interface ${ev.interface} ${ev.state}`));
|
|
81
|
+
box.on('error', (e) => this.opts.log.warn(`lite-rpc: ${e.message}`));
|
|
82
|
+
box.on('resync', (ev) => {
|
|
83
|
+
this.opts.log.info(`lite-rpc <- resync (${ev.reason}): the values were read again`);
|
|
84
|
+
this.opts.onResync?.();
|
|
85
|
+
});
|
|
86
|
+
this.server = modules.callbackEvents(box, { initId: this.opts.initId });
|
|
87
|
+
register(this.server);
|
|
88
|
+
await box.ready();
|
|
89
|
+
}
|
|
90
|
+
/** The live copy of the system's names and taxonomy */
|
|
91
|
+
get meta() {
|
|
92
|
+
return this.box?.meta;
|
|
93
|
+
}
|
|
94
|
+
/** The last value of every datapoint the system's state store keeps, keyed `<iface>.<address>.<KEY>` */
|
|
95
|
+
get values() {
|
|
96
|
+
return this.box?.values;
|
|
97
|
+
}
|
|
98
|
+
/** Subscribes to the client's events (`meta`, `value`, ...); the answer unsubscribes */
|
|
99
|
+
on(event, fn) {
|
|
100
|
+
return this.box ? this.box.on(event, fn) : () => undefined;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* A method of the interface process through lite-rpc, in the callback shape of the RPC clients. A fault
|
|
104
|
+
* of the process reaches the callback as its fault string, so the adapter's retry on `Failure` works.
|
|
105
|
+
*
|
|
106
|
+
* @param method the method name
|
|
107
|
+
* @param params its parameters
|
|
108
|
+
* @param callback (err, result)
|
|
109
|
+
*/
|
|
110
|
+
methodCall(method, params, callback) {
|
|
111
|
+
if (!this.box || this.closed) {
|
|
112
|
+
callback('not connected', undefined);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
this.box.call(this.opts.iface, method, params).then(result => callback(null, result ?? ''), (e) => callback((0, lite_1.rpcCallbackError)(e), undefined));
|
|
116
|
+
}
|
|
117
|
+
/** Closes the stream; nothing is de-registered, because nothing was registered */
|
|
118
|
+
close() {
|
|
119
|
+
this.closed = true;
|
|
120
|
+
this.server?.close();
|
|
121
|
+
this.server = undefined;
|
|
122
|
+
this.box?.close();
|
|
123
|
+
this.box = undefined;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.LiteConnection = LiteConnection;
|
|
127
|
+
/**
|
|
128
|
+
* The interfaces a system runs, from `GET /api/rpc/v1/interfaces` with the paired token
|
|
129
|
+
*
|
|
130
|
+
* @param opts the system and the credential
|
|
131
|
+
* @param opts.url the system
|
|
132
|
+
* @param opts.token the paired token
|
|
133
|
+
* @param opts.fingerprint the certificate pinned at pairing
|
|
134
|
+
* @param opts.loader loads occulite-client (the tests)
|
|
135
|
+
*/
|
|
136
|
+
async function listLiteInterfaces(opts) {
|
|
137
|
+
const modules = await (opts.loader ?? loadOcculite)();
|
|
138
|
+
const box = new modules.OccuLite({
|
|
139
|
+
url: opts.url,
|
|
140
|
+
auth: { token: opts.token },
|
|
141
|
+
transport: modules.nodeTransport(opts.fingerprint ? { fingerprint256: opts.fingerprint } : {}),
|
|
142
|
+
timeout: 10_000,
|
|
143
|
+
});
|
|
144
|
+
try {
|
|
145
|
+
return (await box.listInterfaces()).map(i => ({ name: i.name, running: i.running }));
|
|
146
|
+
}
|
|
147
|
+
finally {
|
|
148
|
+
box.close();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=liteConnection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"liteConnection.js","sourceRoot":"","sources":["../../src/lib/liteConnection.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAwBH,oCAgBC;AA6ID,gDAkBC;AAlMD,iCAA0C;AAc1C,IAAI,MAAwC,CAAC;AAE7C;;GAEG;AACH,SAAgB,YAAY;IACxB,MAAM,KAAK,CAAC,KAAK,IAAI,EAAE;QACnB,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YAChD,MAAM,CAAC,iBAAiB,CAAC;YACzB,MAAM,CAAC,2BAA2B,CAAC;YACnC,MAAM,CAAC,sBAAsB,CAAC;SACjC,CAAC,CAAC;QACH,OAAO;YACH,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,cAAc,EAAE,SAAS,CAAC,cAAc;YACxC,aAAa,EAAE,IAAI,CA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from an openccu-lite system: the `common.name` of the device, channel and state objects from
|
|
3
|
+
* the system's names, the rooms and functions of its taxonomy as `enum.rooms.*` and `enum.functions.*`. Written
|
|
4
|
+
* as differences only, from the metadata's live copy, whenever it changes.
|
|
5
|
+
*/
|
|
6
|
+
import { type EnumMembership } from './lite';
|
|
7
|
+
/** The slice of the adapter the names need */
|
|
8
|
+
export interface NamesAdapter {
|
|
9
|
+
namespace: string;
|
|
10
|
+
log: Pick<Console, 'debug' | 'info' | 'warn' | 'error'>;
|
|
11
|
+
getForeignObjectsAsync(pattern: string, type: ioBroker.ObjectType): Promise<Record<string, ioBroker.Object>>;
|
|
12
|
+
extendForeignObjectAsync(id: string, part: ioBroker.PartialObject): Promise<unknown>;
|
|
13
|
+
setForeignObjectAsync(id: string, obj: ioBroker.SettableObject): Promise<unknown>;
|
|
14
|
+
delForeignObjectAsync(id: string): Promise<void>;
|
|
15
|
+
setTimeout(cb: () => void, timeout: number): ioBroker.Timeout | undefined;
|
|
16
|
+
clearTimeout(timer: ioBroker.Timeout | undefined): void;
|
|
17
|
+
}
|
|
18
|
+
/** The slice of occulite-client's metadata copy the names read */
|
|
19
|
+
export interface MetaReader {
|
|
20
|
+
name(ref: string): string | undefined;
|
|
21
|
+
membership(ref: string, opts: {
|
|
22
|
+
inherit?: boolean;
|
|
23
|
+
lang?: string;
|
|
24
|
+
}): {
|
|
25
|
+
rooms: {
|
|
26
|
+
path: string;
|
|
27
|
+
name: string;
|
|
28
|
+
}[];
|
|
29
|
+
functions: {
|
|
30
|
+
path: string;
|
|
31
|
+
name: string;
|
|
32
|
+
}[];
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Keeps the objects of one instance named as the system names them
|
|
37
|
+
*/
|
|
38
|
+
export declare class LiteNames {
|
|
39
|
+
private readonly adapter;
|
|
40
|
+
private readonly meta;
|
|
41
|
+
private readonly iface;
|
|
42
|
+
private readonly lang;
|
|
43
|
+
private timer;
|
|
44
|
+
private running;
|
|
45
|
+
private again;
|
|
46
|
+
/**
|
|
47
|
+
* @param adapter the adapter
|
|
48
|
+
* @param meta the system's metadata, live
|
|
49
|
+
* @param iface the interface of this instance
|
|
50
|
+
* @param lang the language the node names are taken in
|
|
51
|
+
*/
|
|
52
|
+
constructor(adapter: NamesAdapter, meta: MetaReader, iface: string, lang: string);
|
|
53
|
+
/**
|
|
54
|
+
* Applies the names soon: several changes in a row (an import, a renamed floor) become one pass
|
|
55
|
+
*
|
|
56
|
+
* @param delay ms to wait for more changes
|
|
57
|
+
*/
|
|
58
|
+
schedule(delay?: number): void;
|
|
59
|
+
/** Stops a scheduled pass */
|
|
60
|
+
stop(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Applies the system's names and taxonomy to every object of the instance. A pass that is asked for while
|
|
63
|
+
* one runs is run after it, once.
|
|
64
|
+
*/
|
|
65
|
+
apply(): Promise<void>;
|
|
66
|
+
private pass;
|
|
67
|
+
/**
|
|
68
|
+
* Brings the rooms and functions in line: only the members of this instance are managed in an enum (another
|
|
69
|
+
* instance on the same system, or the user, may have added others), an enum this adapter created goes when
|
|
70
|
+
* it has no members left. An enum is always written whole: `extendObject` merges arrays index-wise, so a
|
|
71
|
+
* shorter member list would leave the old entries behind.
|
|
72
|
+
*
|
|
73
|
+
* @param wanted enum id → name, path and the members of this instance
|
|
74
|
+
* @returns how many enum objects were written or removed
|
|
75
|
+
*/
|
|
76
|
+
private syncEnums;
|
|
77
|
+
}
|
|
78
|
+
export type { EnumMembership };
|