homematic-manager 3.2.3 → 3.4.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 +19 -19
- package/node_modules/@homematic-manager/backend/README.md +12 -12
- package/node_modules/@homematic-manager/backend/dist/api/backend.d.ts +10 -0
- package/node_modules/@homematic-manager/backend/dist/api/backend.js +79 -9
- package/node_modules/@homematic-manager/backend/dist/config/defaults.js +9 -1
- package/node_modules/@homematic-manager/backend/package.json +1 -1
- package/node_modules/@homematic-manager/core/dist/api/types.d.ts +27 -0
- package/node_modules/@homematic-manager/core/dist/api/types.js +2 -0
- package/node_modules/@homematic-manager/core/package.json +1 -1
- package/package.json +3 -3
- package/ui/assets/index-D94DHu87.css +1 -0
- package/ui/assets/index-Ot-YDwXG.js +21 -0
- package/ui/index.html +2 -2
- package/ui/assets/index-D_4x0bdd.css +0 -1
- package/ui/assets/index-Dz1_561v.js +0 -21
package/README.md
CHANGED
|
@@ -7,13 +7,13 @@ It has three jobs, and they are the same program:
|
|
|
7
7
|
|
|
8
8
|
- **development** - `npm run dev` puts a vite dev server behind this host, so the UI hot-reloads
|
|
9
9
|
against a real backend and a real CCU or hm-simulator;
|
|
10
|
-
- **the e2e target**
|
|
10
|
+
- **the e2e target** - `startForTest()` starts the whole stack on a free port with a
|
|
11
11
|
temporary profile directory, optionally against hm-simulator, and Playwright drives a browser
|
|
12
12
|
against it in a fraction of the time an Electron run takes;
|
|
13
|
-
- **the third deliverable**
|
|
13
|
+
- **the third deliverable** - published to npm as `homematic-manager` (the name the
|
|
14
14
|
2.x desktop app had there), so `npm install -g` gives a Homematic Manager server on a Raspberry Pi
|
|
15
|
-
next to the CCU, on a NAS or in a container; and the exact same process is what the CCU addon
|
|
16
|
-
|
|
15
|
+
next to the CCU, on a NAS or in a container; and the exact same process is what the CCU addon
|
|
16
|
+
runs behind the CCU's lighttpd.
|
|
17
17
|
|
|
18
18
|
The directory is `apps/web` and the package is `homematic-manager`, which is also the name of the
|
|
19
19
|
workspace root - so address this package by path, `-w apps/web`, in anything that has to keep
|
|
@@ -46,7 +46,7 @@ Every option is also an environment variable with the `HMM_` prefix (`--data-dir
|
|
|
46
46
|
`HMM_DATA_DIR`, `--no-auth` is `HMM_AUTH=false`); the command line wins over the environment. There
|
|
47
47
|
is no configuration file - what this host needs is a port and a few paths, and everything about the
|
|
48
48
|
CCU lives in the backend's `config.json`. `--config-schema` prints the whole option set as JSON
|
|
49
|
-
Schema, which is what a configuration UI (and
|
|
49
|
+
Schema, which is what a configuration UI (and the addon's `settings.cgi`) should read instead of
|
|
50
50
|
hard-coding it.
|
|
51
51
|
|
|
52
52
|
| option | default | what it does |
|
|
@@ -56,7 +56,7 @@ hard-coding it.
|
|
|
56
56
|
| `--base` | `/` | URL prefix everything is served under, e.g. `/addons/hmm/` |
|
|
57
57
|
| `--data-dir`, `--profile` | `~/.config/homematic-manager` | profile directory: `config.json` and the caches |
|
|
58
58
|
| `--ui-dir` | `packages/ui/dist`, or `ui/` next to the host | the built UI |
|
|
59
|
-
| `--metadata-dir` | `data/dist`, or `data/` next to the host | generated device metadata
|
|
59
|
+
| `--metadata-dir` | `data/dist`, or `data/` next to the host | generated device metadata |
|
|
60
60
|
| `--ui-dev-server` | - | proxy everything but the API to a vite dev server |
|
|
61
61
|
| `--token` | random | the token clients have to present |
|
|
62
62
|
| `--auth` / `--no-auth` | on | require a token on the API socket |
|
|
@@ -75,9 +75,9 @@ hard-coding it.
|
|
|
75
75
|
`SIGINT` and `SIGTERM` stop the host and run `backend.stop()` - the de-registration the CCU's
|
|
76
76
|
interface processes want - with a five second bound, so a `systemctl restart` cannot hang.
|
|
77
77
|
|
|
78
|
-
## Idle unsubscribe
|
|
78
|
+
## Idle unsubscribe
|
|
79
79
|
|
|
80
|
-
Off by default since 3.2.3
|
|
80
|
+
Off by default since 3.2.3. With an idle time set and no page open for that long, the
|
|
81
81
|
backend sends `init(url, '')` to every interface and
|
|
82
82
|
stops its service-message poll: an interface process should not push events at a browser tab that
|
|
83
83
|
does not exist, and on the CCU those events cost the CCU's own CPU. Nothing else is torn down - the
|
|
@@ -86,7 +86,7 @@ subscribes again with one `init` per interface. That page sees the interfaces ma
|
|
|
86
86
|
until their first `listDevices` sweep is through, because `hmipserver` re-sends every device on
|
|
87
87
|
`init` (occu#45).
|
|
88
88
|
|
|
89
|
-
The time also runs from the start when no page is opened after it
|
|
89
|
+
The time also runs from the start when no page is opened after it. The settings dialog
|
|
90
90
|
offers it (*Unsubscribe when idle*: the default, 15 minutes to 4 hours, or never), saved in the
|
|
91
91
|
profile. `--idle-unsubscribe <duration>` / `HMM_IDLE_UNSUBSCRIBE` sets it at start instead (`5m`,
|
|
92
92
|
`300s`, `90`, `0` for never) and then wins over the dialog, which shows it read-only. Up to 3.2.2 it
|
|
@@ -107,17 +107,17 @@ does. If that matters - watching a duty cycle overnight, say - set `0`.
|
|
|
107
107
|
| `<base>data/...` | `data/dist` as plain files: metadata, profiles, translations, icons |
|
|
108
108
|
| `<base>...` | the built UI |
|
|
109
109
|
|
|
110
|
-
**Device images**
|
|
111
|
-
which every host shares
|
|
110
|
+
**Device images** are the backend's `DeviceImageService` (`packages/backend/src/images/`),
|
|
111
|
+
which every host shares; this one wraps it in an HTTP route, the Electron host in an
|
|
112
112
|
`hmm-image://` protocol handler. They resolve memory → disk → CCU → bundled → 404. `data/dist/device-icons.json`
|
|
113
113
|
maps the (upper-cased) device type to a file name; the CCU serves it as
|
|
114
114
|
`/config/img/devices/250/<file>` (or `250/coupling/<file>`, or as `50/<base>_thumb<ext>` - the `50`
|
|
115
115
|
directory holds the WebUI's list thumbnails and suffixes every name, which is why the single
|
|
116
|
-
`50/<file>` this asked for until
|
|
116
|
+
`50/<file>` this asked for until a measurement on hardware found nothing at all: 0 of 278
|
|
117
117
|
mapped files, against 278 of 278 for the four candidates now tried in turn). What comes back is
|
|
118
118
|
cached under `<data-dir>/images/`. When
|
|
119
119
|
there is no CCU - Homegear, a bare rfd, or one that is simply off - the webp subset that ships in
|
|
120
|
-
`data/dist/icons/` answers instead, so the app is never without pictures
|
|
120
|
+
`data/dist/icons/` answers instead, so the app is never without pictures. The response says
|
|
121
121
|
which of the four it was in `X-Hmm-Image-Source`. Known limitation: with `tls` the CCU's
|
|
122
122
|
certificate is self-signed and `fetch` cannot be told to accept it, so such a request falls through
|
|
123
123
|
to the bundled picture; the addon talks plain HTTP to `127.0.0.1` and is unaffected.
|
|
@@ -161,7 +161,7 @@ Who may be *handed* a cookie is the part that matters:
|
|
|
161
161
|
machine boundary is the only thing between a caller and the socket anyway, and development and
|
|
162
162
|
the Playwright suites need the browser to just work.
|
|
163
163
|
- On any other bind - and behind the CCU's lighttpd - the cookie has to come from something that
|
|
164
|
-
checked who is asking.
|
|
164
|
+
checked who is asking. The addon's `settings.cgi` does the `tclrega.so` session check and sets the
|
|
165
165
|
same cookie (`hmm_token`, `Path=/addons/hmm/`, `HttpOnly`, `SameSite=Strict`, `Secure`); this
|
|
166
166
|
process then only *accepts* it and never issues one. Start it with `--no-issue-cookie`.
|
|
167
167
|
- `?token=` keeps working for everything that is not a browser: `curl`, the e2e helper, and a CGI
|
|
@@ -172,7 +172,7 @@ There is **no Origin check**, deliberately: a reverse proxy forwards the browser
|
|
|
172
172
|
own `Host`, and the token - not the origin - is what guards this socket. The cookie is
|
|
173
173
|
`SameSite=Strict`, so a foreign page cannot make the browser send it.
|
|
174
174
|
|
|
175
|
-
## Behind a reverse proxy
|
|
175
|
+
## Behind a reverse proxy
|
|
176
176
|
|
|
177
177
|
`--base /addons/hmm` serves the UI, the images, the metadata *and* the API socket under that
|
|
178
178
|
prefix; `/addons/hmm` without the trailing slash redirects to `/addons/hmm/`, and anything outside
|
|
@@ -230,7 +230,7 @@ nobody to talk to.
|
|
|
230
230
|
`--demo` is the opposite: the UI on its fixture and no backend at all, for a bug report or a look
|
|
231
231
|
at the app without a CCU.
|
|
232
232
|
|
|
233
|
-
## For the e2e suites
|
|
233
|
+
## For the e2e suites
|
|
234
234
|
|
|
235
235
|
```ts
|
|
236
236
|
import {startForTest, simulatorAvailable} from 'homematic-manager';
|
|
@@ -242,7 +242,7 @@ await host.close(); // backend, simulator and the temporary profile direc
|
|
|
242
242
|
|
|
243
243
|
Port `0`, a temporary profile directory, and `simulator: true` starts an in-process hm-simulator
|
|
244
244
|
with two devices and points the backend at it in `local` mode - which is the only way to reach the
|
|
245
|
-
simulator's rfd, because BIN-RPC exists on a CCU's loopback only
|
|
245
|
+
simulator's rfd, because BIN-RPC exists on a CCU's loopback only. hm-simulator is not
|
|
246
246
|
published yet, so it is imported lazily; `await simulatorAvailable()` is what a suite gates itself
|
|
247
247
|
on, the same `describe.skipIf` arrangement `packages/backend/test/simulator` uses.
|
|
248
248
|
|
|
@@ -266,7 +266,7 @@ compressed:
|
|
|
266
266
|
as dependencies of this package, so npm installs them normally. A fresh install pulls six
|
|
267
267
|
packages in total.
|
|
268
268
|
|
|
269
|
-
`npm run sbom` writes a CycloneDX 1.6 document next to the tarball
|
|
269
|
+
`npm run sbom` writes a CycloneDX 1.6 document next to the tarball. It is taken from the
|
|
270
270
|
tree the tarball really installs - the tarball is unpacked into a temporary directory first - so
|
|
271
271
|
the bundled workspace packages are in it, which a plain `cyclonedx-npm` run against the repository
|
|
272
272
|
would never show. `release-npm.yml` publishes with npm trusted publishing (OIDC, no token secret)
|
|
@@ -285,4 +285,4 @@ token on the upgrade in all three forms, an `ApiFrame` round trip over a real We
|
|
|
285
285
|
real `Backend`, the image proxy against a fake CCU, the base path behind a real reverse proxy in
|
|
286
286
|
the test, the dev-server proxy including its upgrade, the CLI and its environment variables, the
|
|
287
287
|
systemd installer against a fake root with a stubbed `systemctl`, and the graceful shutdown.
|
|
288
|
-
Coverage is reported, never enforced
|
|
288
|
+
Coverage is reported, never enforced.
|
|
@@ -6,8 +6,8 @@ UDP discovery, the paced write queue, and one transport-agnostic API.
|
|
|
6
6
|
|
|
7
7
|
It implements the contract in `packages/core/src/api/types.ts` - every method of `ApiMethods`, every
|
|
8
8
|
event of `ApiEvents`, every rejection an `ApiError` - and nothing above it ever sees a socket, a file
|
|
9
|
-
or an RPC library. Electron main
|
|
10
|
-
a WebSocket, and the CCU addon
|
|
9
|
+
or an RPC library. Electron main hosts it in-process, `apps/web` serves it over
|
|
10
|
+
a WebSocket, and the CCU addon runs the same process on the CCU.
|
|
11
11
|
|
|
12
12
|
## Architecture
|
|
13
13
|
|
|
@@ -34,8 +34,8 @@ a WebSocket, and the CCU addon (task 13) runs the same process on the CCU.
|
|
|
34
34
|
| `api/transport.ts` | `InProcessTransport`: the `Transport` without a wire (Electron main, tests) |
|
|
35
35
|
| `transport/codec.ts` | `ApiFrame` as JSON, strict about what it accepts |
|
|
36
36
|
| `transport/wsServer.ts` | `ApiWebSocketServer`: the contract over `ws`, with token auth |
|
|
37
|
-
| `config/defaults.ts` | defaults, normalisation, validation, interface resolution
|
|
38
|
-
| `config/legacyImport.ts` | the one-time import of the 2.x configuration
|
|
37
|
+
| `config/defaults.ts` | defaults, normalisation, validation, interface resolution |
|
|
38
|
+
| `config/legacyImport.ts` | the one-time import of the 2.x configuration |
|
|
39
39
|
| `config/store.ts` | `config.json`, the profile directory, the per-host cache directory |
|
|
40
40
|
| `config/linkTemplates.ts` | `link-templates.json`: the tuned link profiles of #21, in the profile directory |
|
|
41
41
|
| `rpc/client.ts` | one promise-shaped RPC client per interface: timeout, faults, call log |
|
|
@@ -43,7 +43,7 @@ a WebSocket, and the CCU addon (task 13) runs the same process on the CCU.
|
|
|
43
43
|
| `interfaces/manager.ts` | `init`, the ping watchdog, re-init, `init('')`, the background port probe |
|
|
44
44
|
| `cache/devices.ts` | device descriptions per interface, and the core's `DeviceIndex` |
|
|
45
45
|
| `cache/descriptions.ts` | paramset descriptions by `paramsetIdentity()` |
|
|
46
|
-
| `cache/names.ts` | the local name store, with ReGa as an overlay
|
|
46
|
+
| `cache/names.ts` | the local name store, with ReGa as an overlay |
|
|
47
47
|
| `cache/unreach.ts` | how often each device went unreachable (#26), edge-counted and persisted |
|
|
48
48
|
| `cache/store.ts` | all caches of one connection, and what of them is persisted |
|
|
49
49
|
| `rega/client.ts` | names and renames through ReGa; every failure is a state, never an exception |
|
|
@@ -52,10 +52,10 @@ a WebSocket, and the CCU addon (task 13) runs the same process on the CCU.
|
|
|
52
52
|
| `write/queue.ts` | one paced queue per interface, cancellable |
|
|
53
53
|
| `write/log.ts` | the session write log and the 2.x `rpcLogFolder` dumps |
|
|
54
54
|
| `write/paramset.ts` | the changed-only `putParamset`, multi-apply, link writes, `setValue` |
|
|
55
|
-
| `write/repair.ts` | `devices.repairConfig`: the recovery
|
|
55
|
+
| `write/repair.ts` | `devices.repairConfig`: the measured recovery, per channel |
|
|
56
56
|
| `devices/installMode.ts` | install mode in all its variants, incl. the HmIP key conversion |
|
|
57
57
|
| `data/files.ts` | `data.file`: reads from injected roots and nothing else |
|
|
58
|
-
| `images/deviceImages.ts` | device pictures
|
|
58
|
+
| `images/deviceImages.ts` | device pictures: memory, disk, the CCU's four candidate URLs, the bundled webp subset |
|
|
59
59
|
| `util/*` | the typed event emitter, atomic and debounced JSON files, net helpers |
|
|
60
60
|
| `errors.ts` | `ApiError` as a throwable, and the classification of anything thrown |
|
|
61
61
|
|
|
@@ -85,7 +85,7 @@ Three rules run through the whole class:
|
|
|
85
85
|
- **nothing rejects except as `ApiError`.** A CCU that is off, a ReGa that wants a password, a cache
|
|
86
86
|
file that cannot be written - each is a typed rejection or a `notice` event, never an exception in
|
|
87
87
|
the host process.
|
|
88
|
-
- **nothing invalid reaches an interface process.** Not as a courtesy: the lab study
|
|
88
|
+
- **nothing invalid reaches an interface process.** Not as a courtesy: the lab study
|
|
89
89
|
([`docs/config-pending.md`](../../docs/config-pending.md)) found that hmipserver **stores what it
|
|
90
90
|
rejects**, so one `putParamset` with a parameter the channel does not have leaves that channel
|
|
91
91
|
unwritable for the life of the pairing, and that **neither** interface process checks
|
|
@@ -125,7 +125,7 @@ is not on the list.
|
|
|
125
125
|
basic auth, the callbacks, `dropConnection()`, the caches, the ReGa mock, the write path, the
|
|
126
126
|
`CONFIG_PENDING` modes and both transports.
|
|
127
127
|
|
|
128
|
-
|
|
128
|
+
The simulator's `hmip` and `bidcos` modes are what the two interface processes of a
|
|
129
129
|
CCU on firmware 3.89.8 were **measured** to do, and the suites run against those by default: the
|
|
130
130
|
wrong type that sticks in `CONFIG_PENDING`, the unknown parameter that makes a channel unwritable
|
|
131
131
|
for good, and `devices.repairConfig` on both. `configPendingMode: 'strict'` in
|
|
@@ -164,7 +164,7 @@ queue because it changes the device.
|
|
|
164
164
|
|
|
165
165
|
**HmIP is not covered.** An HmIP-SWSD is not teamed with `setTeam`; the CCU builds an HmIP smoke
|
|
166
166
|
alarm group through its group process (the `VirtualDevices` interface on `/groups`), with calls that
|
|
167
|
-
are not part of the 51-method catalogue this application speaks (
|
|
167
|
+
are not part of the 51-method catalogue this application speaks (XML-RPC/BIN-RPC to the
|
|
168
168
|
interface processes, no CCU JSON-API). Doing it would need a surface we deliberately do not use, so
|
|
169
169
|
it is not done and not faked: on an HmIP channel the team entry stays disabled, because HmIP channels
|
|
170
170
|
carry no `TEAM_TAG`.
|
|
@@ -192,7 +192,7 @@ this package does about it, and what it cannot:
|
|
|
192
192
|
`homematic-xmlrpc`**.
|
|
193
193
|
- **Requests are sent as UTF-8, always.** `homematic-xmlrpc` writes the body with `request.write(xml,
|
|
194
194
|
'utf8')` and emits `<?xml version="1.0"?>` with no encoding declaration; `binrpc` writes `latin1`.
|
|
195
|
-
**Measured in the lab on 2026-09-05** (
|
|
195
|
+
**Measured in the lab on 2026-09-05** (`docs/config-pending.md`), by writing
|
|
196
196
|
`Tür Küche äöüß °C` into device metadata and reading the raw bytes back over both transports:
|
|
197
197
|
rfd stores what XML-RPC sends, so the string lands on the CCU as **UTF-8 bytes in an ISO-8859-1
|
|
198
198
|
world** and the WebUI shows mojibake. A value stored correctly comes back correctly through our
|
|
@@ -203,7 +203,7 @@ this package does about it, and what it cannot:
|
|
|
203
203
|
`toString()`, i.e. UTF-8, so `0xFC` comes back as U+FFFD and the character is gone. Verified by
|
|
204
204
|
running the round trip on the CCU itself, because **BIN-RPC is not reachable from outside a stock
|
|
205
205
|
CCU at all**: port 2001 is lighttpd and speaks XML-RPC over HTTP only, and rfd's own port 32001 is
|
|
206
|
-
`local-only` in the CCU firewall. BIN-RPC is in practice an addon transport
|
|
206
|
+
`local-only` in the CCU firewall. BIN-RPC is in practice an addon transport.
|
|
207
207
|
|
|
208
208
|
## Tests
|
|
209
209
|
|
|
@@ -35,6 +35,8 @@ export declare const SERVICE_MESSAGE_POLL_MS = 300000;
|
|
|
35
35
|
export declare const REGA_CONNECT_WAIT_MS = 3000;
|
|
36
36
|
/** How long the HmIP `getParamset(:0, VALUES)` sweep waits for the device list to settle. */
|
|
37
37
|
export declare const HMIP_SWEEP_DELAY_MS = 1000;
|
|
38
|
+
/** Task 107: the addon's id on openccu-lite (`files/openccu-lite.json`), whose token the system mints. */
|
|
39
|
+
export declare const ADDON_ID = "hmm";
|
|
38
40
|
export interface BackendOptions extends Omit<ConfigStoreOptions, 'version'> {
|
|
39
41
|
/** `AppConfig.version`; the host passes its package version. */
|
|
40
42
|
readonly version?: string;
|
|
@@ -92,6 +94,14 @@ export interface BackendOptions extends Omit<ConfigStoreOptions, 'version'> {
|
|
|
92
94
|
/** Task 72: the same for the openccu-lite path of a remote connection. */
|
|
93
95
|
readonly createLiteInterfaces?: (options: LiteInterfacesOptions) => LiteInterfaces;
|
|
94
96
|
readonly liteOptions?: Partial<LiteInterfacesOptions>;
|
|
97
|
+
/**
|
|
98
|
+
* Task 107: the addon's id on openccu-lite, whose own API token the system mints from the
|
|
99
|
+
* manifest's `api_scopes` into `<addonTokenDir>/<id>.api`. Read when the connection is `local`:
|
|
100
|
+
* the token found there is what makes the interfaces go through lite-rpc on the system itself.
|
|
101
|
+
* `hmm` unless a test says otherwise; the directory is occulite-client's default.
|
|
102
|
+
*/
|
|
103
|
+
readonly addonId?: string;
|
|
104
|
+
readonly addonTokenDir?: string;
|
|
95
105
|
/** Task 72: occulite-client's `pair()`, replaced by the tests. */
|
|
96
106
|
readonly pair?: PairWithSystemOptions['pair'];
|
|
97
107
|
readonly createRega?: (options: RegaServiceOptions) => RegaService;
|
|
@@ -26,8 +26,9 @@ import { BackendError, configError, connectionError, errorMessage, internalError
|
|
|
26
26
|
import { DEFAULT_IDLE_UNSUBSCRIBE_MS, InterfaceManager, LOOPBACK_IP, callbackBindHost, firstBidcosInterfaceAddress, } from '../interfaces/manager.js';
|
|
27
27
|
import { LiteInterfaces } from '../interfaces/lite.js';
|
|
28
28
|
import { HeatingGroupsClient } from '../groups/client.js';
|
|
29
|
-
import { MetaService, hostBaseUrl } from '../meta/service.js';
|
|
29
|
+
import { MetaService, hostBaseUrl, metaBaseUrl } from '../meta/service.js';
|
|
30
30
|
import { DETECT_TIMEOUT_MS, detectSystem, pairWithSystem, testSystem, transportFor, } from '../meta/system.js';
|
|
31
|
+
import { nodeAuth } from 'occulite-client/node';
|
|
31
32
|
import { RegaService } from '../rega/client.js';
|
|
32
33
|
import { listDevicesAnswer } from '../rpc/server.js';
|
|
33
34
|
import { ApiEventEmitter } from '../util/emitter.js';
|
|
@@ -51,6 +52,8 @@ export const REGA_CONNECT_WAIT_MS = 3000;
|
|
|
51
52
|
const OWN_PARAMSETS = new Set(['MASTER', 'VALUES', 'SERVICE', 'ROUTING_TABLE']);
|
|
52
53
|
/** How long the HmIP `getParamset(:0, VALUES)` sweep waits for the device list to settle. */
|
|
53
54
|
export const HMIP_SWEEP_DELAY_MS = 1000;
|
|
55
|
+
/** Task 107: the addon's id on openccu-lite (`files/openccu-lite.json`), whose token the system mints. */
|
|
56
|
+
export const ADDON_ID = 'hmm';
|
|
54
57
|
/**
|
|
55
58
|
* An HmIP interface, by name or by interface type - the same rule the UI's settings dialog uses to
|
|
56
59
|
* count the messages it asks about (task 34), so the question and the writes agree.
|
|
@@ -88,6 +91,12 @@ export class Backend {
|
|
|
88
91
|
#manager;
|
|
89
92
|
/** Task 72: counts the connects, so a connect that waited for the probe knows it is still the current one. */
|
|
90
93
|
#connectSeq = 0;
|
|
94
|
+
/**
|
|
95
|
+
* Task 107: the addon's own API token, read at every connect of a `local` connection. Found,
|
|
96
|
+
* the host is an openccu-lite system that minted it (nothing else writes that directory), and
|
|
97
|
+
* the settings dialog may offer the choice between lite-rpc and the direct connection.
|
|
98
|
+
*/
|
|
99
|
+
#addonToken;
|
|
91
100
|
/** Task 72: the pairing with an openccu-lite system that is running, if any. */
|
|
92
101
|
#pairing;
|
|
93
102
|
#rega;
|
|
@@ -611,7 +620,7 @@ export class Backend {
|
|
|
611
620
|
return runWithOrigin('background', () => this.#connectNow());
|
|
612
621
|
}
|
|
613
622
|
async #connectNow() {
|
|
614
|
-
const
|
|
623
|
+
const configured = this.#config.connection;
|
|
615
624
|
const seq = ++this.#connectSeq;
|
|
616
625
|
this.#paramsetIds.clear();
|
|
617
626
|
this.#noServiceMessages.clear();
|
|
@@ -624,7 +633,29 @@ export class Backend {
|
|
|
624
633
|
// the probe waited for - for everybody else (the addon on the system, a profile without a
|
|
625
634
|
// token, every CCU) it runs alongside the interface start as before (D-40's rule: a host
|
|
626
635
|
// that swallows the packet holds up the names, never the interfaces).
|
|
627
|
-
|
|
636
|
+
// Task 107: on the system itself the addon's own token decides. The system mints it from
|
|
637
|
+
// the manifest's scopes at every start, so finding it means "this is openccu-lite, and
|
|
638
|
+
// lite-rpc is open to us": the profile is moved to lite-rpc once (the marker says whether
|
|
639
|
+
// that happened before), and then its choice holds - `direct` keeps the callbacks.
|
|
640
|
+
let localLite = false;
|
|
641
|
+
if (configured.local === true) {
|
|
642
|
+
this.#addonToken = await this.#readAddonToken();
|
|
643
|
+
if (this.#superseded(seq)) {
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
if (this.#addonToken !== undefined) {
|
|
647
|
+
await this.#migrateLocalRpc();
|
|
648
|
+
if (this.#superseded(seq)) {
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
localLite = this.#config.connection.localRpc !== 'direct';
|
|
652
|
+
}
|
|
653
|
+
else if (configured.localRpc === 'lite') {
|
|
654
|
+
this.#notice('info', 'the profile asks for lite-rpc, but the system minted no API token for this addon (an openccu-lite before task 107, or a CCU): the interfaces are reached directly, with callbacks');
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
const connection = this.#config.connection;
|
|
658
|
+
const token = localLite ? this.#addonToken : (connection.metaToken ?? '').trim();
|
|
628
659
|
const mayBeRemoteLite = connection.local !== true && token !== '';
|
|
629
660
|
let hostProbe;
|
|
630
661
|
let liteProbe;
|
|
@@ -639,6 +670,7 @@ export class Backend {
|
|
|
639
670
|
else {
|
|
640
671
|
hostProbe = this.#probeHost(connection);
|
|
641
672
|
}
|
|
673
|
+
const useLite = localLite || liteProbe?.answer !== undefined;
|
|
642
674
|
const shared = {
|
|
643
675
|
connection,
|
|
644
676
|
handler: this.#callbackHandler(),
|
|
@@ -654,10 +686,11 @@ export class Backend {
|
|
|
654
686
|
},
|
|
655
687
|
originOf: currentOrigin,
|
|
656
688
|
};
|
|
657
|
-
const manager =
|
|
689
|
+
const manager = useLite
|
|
658
690
|
? (this.#options.createLiteInterfaces ?? ((options) => new LiteInterfaces(options)))({
|
|
659
691
|
...shared,
|
|
660
|
-
|
|
692
|
+
// on the system: the loopback lighttpd (or `metaUrl`, the integration tests' door)
|
|
693
|
+
baseUrl: localLite ? metaBaseUrl(connection) : (liteProbe?.baseUrl ?? hostBaseUrl(connection)),
|
|
661
694
|
token,
|
|
662
695
|
transport: transportFor({
|
|
663
696
|
fetch: this.#options.metaOptions?.fetch,
|
|
@@ -680,16 +713,17 @@ export class Backend {
|
|
|
680
713
|
...(this.#options.watchdogIntervalMs === undefined
|
|
681
714
|
? {}
|
|
682
715
|
: { watchdogIntervalMs: this.#options.watchdogIntervalMs }),
|
|
683
|
-
...(this.#options.localAddresses === undefined
|
|
684
|
-
? {}
|
|
685
|
-
: { localAddresses: this.#options.localAddresses }),
|
|
716
|
+
...(this.#options.localAddresses === undefined ? {} : { localAddresses: this.#options.localAddresses }),
|
|
686
717
|
...(this.#options.network === undefined ? {} : { network: this.#options.network }),
|
|
687
718
|
...(this.#keepsConfiguredCallbackIp() ? { keepConfiguredCallbackIp: true } : {}),
|
|
688
719
|
...(this.#options.now === undefined ? {} : { now: this.#options.now }),
|
|
689
720
|
...this.#options.interfaceManagerOptions,
|
|
690
721
|
});
|
|
691
722
|
this.#manager = manager;
|
|
692
|
-
if (
|
|
723
|
+
if (localLite) {
|
|
724
|
+
this.#notice('info', "this openccu-lite system: the interfaces are reached through its lite-rpc with the addon's own token, without callbacks (the direct connection is selectable in the settings)");
|
|
725
|
+
}
|
|
726
|
+
else if (liteProbe?.answer !== undefined) {
|
|
693
727
|
this.#notice('info', `${connection.host}: an openccu-lite system - the interfaces are reached through its lite-rpc with the API token, without callbacks`);
|
|
694
728
|
}
|
|
695
729
|
try {
|
|
@@ -756,6 +790,39 @@ export class Backend {
|
|
|
756
790
|
// B-70: counted from the start (or the reconnect of a save) when no page is open
|
|
757
791
|
this.#armIdleTimer();
|
|
758
792
|
}
|
|
793
|
+
/** Disconnected, or another connect started, while this one was waiting (read through a call, so an `await` cannot narrow it away). */
|
|
794
|
+
#superseded(seq) {
|
|
795
|
+
return this.#stopped || seq !== this.#connectSeq;
|
|
796
|
+
}
|
|
797
|
+
/** Task 107: the addon's own API token on openccu-lite, or `undefined` everywhere else. */
|
|
798
|
+
async #readAddonToken() {
|
|
799
|
+
const found = await nodeAuth({ addon: this.#options.addonId ?? ADDON_ID }, this.#options.addonTokenDir === undefined ? {} : { addonTokenDir: this.#options.addonTokenDir }).resolve('start');
|
|
800
|
+
const token = found.token?.trim() ?? '';
|
|
801
|
+
return token === '' ? undefined : token;
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* Task 107: the one-time move of a `local` profile to lite-rpc, on the first connect on
|
|
805
|
+
* openccu-lite that found the addon's token. A profile that was never moved - every one of an
|
|
806
|
+
* earlier version, which connected directly, and a fresh one - gets `localRpc: 'lite'` and the
|
|
807
|
+
* marker; a profile that carries the marker is left exactly as it is, whatever it says, so a
|
|
808
|
+
* `direct` the user chose afterwards survives every restart and update.
|
|
809
|
+
*/
|
|
810
|
+
async #migrateLocalRpc() {
|
|
811
|
+
const connection = this.#config.connection;
|
|
812
|
+
if (connection.connectionMigrated === 1) {
|
|
813
|
+
return;
|
|
814
|
+
}
|
|
815
|
+
const moved = connection.localRpc === undefined;
|
|
816
|
+
const config = this.#withHostFacts(await this.#config.setConnection({
|
|
817
|
+
...connection,
|
|
818
|
+
...(moved ? { localRpc: 'lite' } : {}),
|
|
819
|
+
connectionMigrated: 1,
|
|
820
|
+
}));
|
|
821
|
+
this.events.emit('config.changed', config);
|
|
822
|
+
if (moved) {
|
|
823
|
+
this.#notice('info', 'connection: moved to lite-rpc, the default on openccu-lite - once; the direct connection with callbacks stays selectable in the settings and is never changed again');
|
|
824
|
+
}
|
|
825
|
+
}
|
|
759
826
|
/**
|
|
760
827
|
* B-62: whether the connection's own host is an openccu-lite system - decided from what exists,
|
|
761
828
|
* openccu-lite's own rule (D-40): `GET /api/meta/v1/version` on the host itself answers
|
|
@@ -1167,6 +1234,9 @@ export class Backend {
|
|
|
1167
1234
|
...(ports === undefined ? {} : { callbackDefaultPorts: { xmlrpc: ports.xmlrpc, binrpc: ports.binrpc } }),
|
|
1168
1235
|
...(pins === undefined ? {} : { callbackPinned: { ...pins } }),
|
|
1169
1236
|
...(publish ? { publishCallbackPorts: true } : {}),
|
|
1237
|
+
// task 107: the addon's token was found, so the host is an openccu-lite system and the
|
|
1238
|
+
// settings dialog may offer lite-rpc or the direct connection
|
|
1239
|
+
...(this.#addonToken === undefined ? {} : { liteSystem: true }),
|
|
1170
1240
|
// B-70: only a host that goes idle offers the time; the default of an unpinned host is
|
|
1171
1241
|
// D-31's default (never, since B-95), whatever it was started with, so "the default" means one thing
|
|
1172
1242
|
...(idle === undefined
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* have - is caught here rather than at the first `init` call, where the error would arrive as a
|
|
7
7
|
* socket timeout twenty seconds later.
|
|
8
8
|
*/
|
|
9
|
-
import { DEFAULT_INTERFACES, INTERFACE_NAMES, META_PROVIDERS, isKnownInterface, resolveInterface, resolveUserDefinedInterface, validateUserDefinedInterface, } from '@homematic-manager/core';
|
|
9
|
+
import { DEFAULT_INTERFACES, INTERFACE_NAMES, LOCAL_RPC_CHOICES, META_PROVIDERS, isKnownInterface, resolveInterface, resolveUserDefinedInterface, validateUserDefinedInterface, } from '@homematic-manager/core';
|
|
10
10
|
/**
|
|
11
11
|
* Minimum pause between two writes to one interface.
|
|
12
12
|
*
|
|
@@ -85,6 +85,12 @@ export function normaliseConnection(input) {
|
|
|
85
85
|
const metaProvider = META_PROVIDERS.find((candidate) => candidate === raw.metaProvider);
|
|
86
86
|
const metaToken = stringOr(raw.metaToken, '').trim();
|
|
87
87
|
const metaUrl = stringOr(raw.metaUrl, '').trim();
|
|
88
|
+
// Task 107: the addon's way to the interfaces on openccu-lite, and the marker that the
|
|
89
|
+
// one-time move to lite-rpc has run. A value that is neither choice is dropped (the backend
|
|
90
|
+
// then treats the profile as never migrated, which is the safe reading); the marker is kept
|
|
91
|
+
// only as the `1` this version writes.
|
|
92
|
+
const localRpc = LOCAL_RPC_CHOICES.find((candidate) => candidate === raw.localRpc);
|
|
93
|
+
const connectionMigrated = raw.connectionMigrated === 1 ? 1 : undefined;
|
|
88
94
|
const connection = {
|
|
89
95
|
host: stringOr(raw.host, defaults.host).trim(),
|
|
90
96
|
interfaces: interfaces.length > 0 ? [...new Set(interfaces)] : defaults.interfaces,
|
|
@@ -92,6 +98,8 @@ export function normaliseConnection(input) {
|
|
|
92
98
|
extraInterfaces,
|
|
93
99
|
tls: typeof raw.tls === 'boolean' ? raw.tls : defaults.tls,
|
|
94
100
|
...(raw.local === true ? { local: true } : {}),
|
|
101
|
+
...(localRpc === undefined ? {} : { localRpc }),
|
|
102
|
+
...(connectionMigrated === undefined ? {} : { connectionMigrated }),
|
|
95
103
|
rega: typeof raw.rega === 'boolean' ? raw.rega : defaults.rega,
|
|
96
104
|
callback: {
|
|
97
105
|
ip: stringOr(callback['ip'], defaults.callback.ip).trim(),
|
|
@@ -32,6 +32,23 @@ export interface ConnectionConfig {
|
|
|
32
32
|
* and no CCU authentication. What the addon of task 13 sets; `local` wins over `tls`.
|
|
33
33
|
*/
|
|
34
34
|
local?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Task 107: how the addon on an openccu-lite system (`local`) reaches the interface processes.
|
|
37
|
+
*
|
|
38
|
+
* `lite` (the default) goes through the system's lite-rpc with the addon's own API token - one
|
|
39
|
+
* subscriber at the daemons for every client, the events replayed after a break, nothing
|
|
40
|
+
* registered with `init`; `direct` keeps the CCU way, XML-RPC/BIN-RPC on the processes' own
|
|
41
|
+
* ports with callback servers, for whoever wants it (CUxD, say, which lite-rpc does not carry).
|
|
42
|
+
* Read only on a system that minted the addon's token; a CCU connects directly whatever it says.
|
|
43
|
+
*/
|
|
44
|
+
localRpc?: LocalRpcChoice;
|
|
45
|
+
/**
|
|
46
|
+
* Task 107: the one-time move to lite-rpc has run (`1`). A profile that connected directly to
|
|
47
|
+
* the interfaces is moved to `lite` once, at the first start on openccu-lite that finds the
|
|
48
|
+
* addon's token; from then on the choice is the user's, and a later version never moves it
|
|
49
|
+
* again - so `direct` chosen afterwards stays `direct` across restarts and updates.
|
|
50
|
+
*/
|
|
51
|
+
connectionMigrated?: number;
|
|
35
52
|
auth?: {
|
|
36
53
|
user: string;
|
|
37
54
|
password: string;
|
|
@@ -260,6 +277,12 @@ export interface AppConfig {
|
|
|
260
277
|
defaultMs: number;
|
|
261
278
|
pinnedMs?: number;
|
|
262
279
|
};
|
|
280
|
+
/**
|
|
281
|
+
* Task 107: the host runs as the addon on an openccu-lite system that minted its API token, so
|
|
282
|
+
* the settings dialog offers {@link ConnectionConfig.localRpc}. A property of the host, learnt at
|
|
283
|
+
* the connect; absent everywhere else, where the choice means nothing.
|
|
284
|
+
*/
|
|
285
|
+
liteSystem?: boolean;
|
|
263
286
|
}
|
|
264
287
|
/**
|
|
265
288
|
* B-53 (#162, #165): why the automatic callback address is the one it is.
|
|
@@ -496,6 +519,10 @@ export type NameMap = Record<string, string>;
|
|
|
496
519
|
export type MetaProviderChoice = 'auto' | 'local' | 'occulite' | 'rega';
|
|
497
520
|
/** The values of {@link MetaProviderChoice} as a runtime list, for validation and a select. */
|
|
498
521
|
export declare const META_PROVIDERS: readonly MetaProviderChoice[];
|
|
522
|
+
/** Task 107: {@link ConnectionConfig.localRpc} - the addon's way to the interfaces on openccu-lite. */
|
|
523
|
+
export type LocalRpcChoice = 'lite' | 'direct';
|
|
524
|
+
/** The values of {@link LocalRpcChoice} as a runtime list, for validation and a select. */
|
|
525
|
+
export declare const LOCAL_RPC_CHOICES: readonly LocalRpcChoice[];
|
|
499
526
|
/**
|
|
500
527
|
* D-40: which store the names, rooms and functions come from, and whether it can be written.
|
|
501
528
|
*
|
|
@@ -23,6 +23,8 @@ export function callbackPinOption(field) {
|
|
|
23
23
|
}
|
|
24
24
|
/** The values of {@link MetaProviderChoice} as a runtime list, for validation and a select. */
|
|
25
25
|
export const META_PROVIDERS = Object.freeze(['auto', 'local', 'occulite', 'rega']);
|
|
26
|
+
/** The values of {@link LocalRpcChoice} as a runtime list, for validation and a select. */
|
|
27
|
+
export const LOCAL_RPC_CHOICES = Object.freeze(['lite', 'direct']);
|
|
26
28
|
export const RPC_ORIGINS = Object.freeze(['console', 'ui', 'background']);
|
|
27
29
|
/**
|
|
28
30
|
* Every event of {@link ApiEvents} as a runtime value, because a type has none.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homematic-manager",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Configure and administer Homematic and HomematicIP devices - devices and channels, direct links, paramsets, RSSI, service messages, events and an RPC console - from a local HTTP/WebSocket server that also serves the web UI",
|
|
6
6
|
"keywords": [
|
|
@@ -67,8 +67,8 @@
|
|
|
67
67
|
"hm-simulator": "^1.4.0"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@homematic-manager/backend": "3.
|
|
71
|
-
"@homematic-manager/core": "3.
|
|
70
|
+
"@homematic-manager/backend": "3.4.0",
|
|
71
|
+
"@homematic-manager/core": "3.4.0",
|
|
72
72
|
"binrpc": "^4.2.0",
|
|
73
73
|
"homematic-rega": "^2.0.0",
|
|
74
74
|
"homematic-xmlrpc": "^2.0.0",
|