@nebulahome/integration-sdk 1.2.0 → 1.5.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/CHANGELOG.md +48 -0
- package/FILES.md +139 -18
- package/README.md +5 -3
- package/dist/chunks/node-dist.js +2786 -291
- package/dist/chunks/node-index.d.ts +215 -15
- package/dist/chunks/node-project.js +2 -1
- package/dist/index.d.ts +61 -10
- package/dist/schemas.d.ts +144 -8
- package/dist/schemas.js +3 -2
- package/dist/testing.d.ts +39 -1
- package/dist/testing.js +44 -4
- package/package.json +5 -5
- package/schemas/discovery.schema.json +490 -0
- package/schemas/driver.schema.json +8 -1
- package/schemas/modbus-template.schema.json +288 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,54 @@
|
|
|
3
3
|
The SDK's version is the version of the integration contract the platform implements: a minor
|
|
4
4
|
version adds to the contract, a major one breaks it, and a patch leaves it as it is.
|
|
5
5
|
|
|
6
|
+
## 1.5.0
|
|
7
|
+
|
|
8
|
+
A Modbus template's entities say their icon, and its units are the platform's.
|
|
9
|
+
|
|
10
|
+
- An entity of a Modbus template may name its `icon`, a catalogue icon id; the domain's is used
|
|
11
|
+
when it does not.
|
|
12
|
+
- A read's `unit` must be one the platform knows - a unit of one of its sensor classes (`W`,
|
|
13
|
+
`kWh`, `°C`) - and a template with another is refused when it is checked.
|
|
14
|
+
|
|
15
|
+
## 1.4.0
|
|
16
|
+
|
|
17
|
+
The house's Modbus client is the platform's.
|
|
18
|
+
|
|
19
|
+
- The platform runs the house's Modbus TCP client in the hub, the way it runs the MQTT broker:
|
|
20
|
+
one connection per server, one request at a time, shared by everything in the hub that speaks
|
|
21
|
+
Modbus - over MBAP, or RTU frames a transparent RS485 adapter carries over TCP.
|
|
22
|
+
- A driver may run on the platform's `modbus` transport with `"kind": "modbus"` and a `template`:
|
|
23
|
+
the platform reads the device through the template - each entity's capabilities mapped to the
|
|
24
|
+
register it is read from (functions 01-04) and the command it is written with (05, 06, 15, 16) -
|
|
25
|
+
with neither a profile nor code. The template is the one the owner writes on the Brokers page,
|
|
26
|
+
and the integration's show there, read-only, for the owner to duplicate.
|
|
27
|
+
- `discovery.json` may say which of the Modbus servers the network search finds are the vendor's,
|
|
28
|
+
in a `modbus` block: the values to read - registers, as a template reads them - and conditions on
|
|
29
|
+
`values.<name>`; `listen` may then be left out. The platform recognises no server on its own.
|
|
30
|
+
- `sdk.openModbus({ host, port, framing })` opens a session through the hub's one connection to a
|
|
31
|
+
server, for a transport of the vendor's own: its requests wait their turn with the platform's,
|
|
32
|
+
so a gateway that takes one client at a time is never asked twice at once.
|
|
33
|
+
- `identifyModbus(vendor, identity)` in `@nebulahome/integration-sdk/testing` says whether the
|
|
34
|
+
vendor's `modbus` rules take a server, and `schemas/modbus-template.schema.json` checks a
|
|
35
|
+
template in the editor.
|
|
36
|
+
|
|
37
|
+
## 1.3.0
|
|
38
|
+
|
|
39
|
+
The house's MQTT broker is the platform's.
|
|
40
|
+
|
|
41
|
+
- The platform runs the house's MQTT broker in the hub, the way it runs the Matter fabric:
|
|
42
|
+
`requires: { "services": ["mqtt-broker"] }` is always met, and `sdk.platform.mqtt` is the hub's
|
|
43
|
+
own username on it.
|
|
44
|
+
- A driver may run on the platform's `mqtt-house` transport with `"kind": "mqtt"`: the platform's
|
|
45
|
+
MQTT mapping is its driver, with neither a profile nor code, for the devices that announce
|
|
46
|
+
themselves on the broker the way the MQTT discovery convention says, and those the owner maps
|
|
47
|
+
by hand.
|
|
48
|
+
- `discovery.json` may say which of those devices are the vendor's, in an `mqtt` block of
|
|
49
|
+
conditions on who each says it is - `manufacturer`, `model`, `originName` and the rest; `listen`
|
|
50
|
+
may then be left out.
|
|
51
|
+
- `identifyMqtt(vendor, identity)` in `@nebulahome/integration-sdk/testing` says whether the
|
|
52
|
+
vendor's `mqtt` rules take such a device, and as which driver and model.
|
|
53
|
+
|
|
6
54
|
## 1.2.0
|
|
7
55
|
|
|
8
56
|
One device reached two ways.
|
package/FILES.md
CHANGED
|
@@ -74,8 +74,9 @@ which of its readings is which in Matter.
|
|
|
74
74
|
|
|
75
75
|
`requires` says what the vendor's devices need besides the hub, in the grammar a
|
|
76
76
|
package's manifest uses (PACKAGES.md §8, Dependencies):
|
|
77
|
-
`{ "services": ["mqtt-broker"] }` for Zigbee2MQTT, which talks through the house's broker
|
|
78
|
-
package by id and range. Until what it needs
|
|
77
|
+
`{ "services": ["mqtt-broker"] }` for Zigbee2MQTT, which talks through the house's broker - one
|
|
78
|
+
the platform runs itself, so it is always met - or a package by id and range. Until what it needs
|
|
79
|
+
runs, the vendor waits: its instances fail with the
|
|
79
80
|
sentence that names the package, `api` refuses its devices with `409 needs-package`, and its page
|
|
80
81
|
says so first. The hub follows the packages at every `pkg.*` event and starts only that vendor's
|
|
81
82
|
instances again when its standing changes. A container that speaks to the broker names its topics
|
|
@@ -127,7 +128,7 @@ the vendor's models by series, across its drivers - the series by name, the mode
|
|
|
127
128
|
counting order - and a device's page says its series where it would say the driver's name. A
|
|
128
129
|
model given no series is grouped under its driver. Every model named must be in `models`.
|
|
129
130
|
|
|
130
|
-
`transport` is a platform transport - `http`, `mqtt`, `matter` - or one the driver's own vendor
|
|
131
|
+
`transport` is a platform transport - `http`, `mqtt`, `matter`, `mqtt-house`, `modbus` - or one the driver's own vendor
|
|
131
132
|
ships, named after the vendor: `shelly/rpc`. Never another vendor's: vendors load in no particular
|
|
132
133
|
order, and a driver leaning on another's transport would load or not by luck.
|
|
133
134
|
|
|
@@ -138,6 +139,72 @@ Matter devices are its own, on its page, without code. Which devices those are i
|
|
|
138
139
|
`discovery.json` says (below), and `modelCodes` maps what they call their model - their product id,
|
|
139
140
|
unless the vendor says another field - onto the models it lists.
|
|
140
141
|
|
|
142
|
+
A driver of the vendor's devices that **announce themselves on the house's MQTT broker** is
|
|
143
|
+
`"transport": "mqtt-house"` with `"kind": "mqtt"`, likewise with neither a profile nor an entry:
|
|
144
|
+
the platform's own MQTT mapping runs it - sensors, binary sensors, switches, lights, covers,
|
|
145
|
+
buttons, numbers, selects and locks, as each announces itself - and `modelCodes` maps the model
|
|
146
|
+
the device announces onto the models it lists.
|
|
147
|
+
|
|
148
|
+
A driver of the vendor's **Modbus devices** is `"transport": "modbus"` with `"kind": "modbus"` and a
|
|
149
|
+
`template` - `"template": "./template.json"` - instead of a profile or an entry: the platform reads
|
|
150
|
+
the device through the template, over the house's one connection to its server. The template is
|
|
151
|
+
the format the owner writes on the Brokers page, and the vendor's show there for the owner to
|
|
152
|
+
duplicate:
|
|
153
|
+
|
|
154
|
+
```json
|
|
155
|
+
{
|
|
156
|
+
"$schema": "../../node_modules/@nebulahome/integration-sdk/schemas/modbus-template.schema.json",
|
|
157
|
+
"name": "SDM630",
|
|
158
|
+
"device": "Eastron SDM630",
|
|
159
|
+
"wordOrder": "high",
|
|
160
|
+
"pollSeconds": 10,
|
|
161
|
+
"entities": [
|
|
162
|
+
{
|
|
163
|
+
"id": "power",
|
|
164
|
+
"name": "Power",
|
|
165
|
+
"domain": "sensor",
|
|
166
|
+
"capabilities": {
|
|
167
|
+
"sensor_numeric": {
|
|
168
|
+
"read": { "function": 4, "address": "0x0034", "type": "f32", "unit": "W" }
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
"id": "relay_1",
|
|
174
|
+
"name": "Relay 1",
|
|
175
|
+
"domain": "switch",
|
|
176
|
+
"capabilities": {
|
|
177
|
+
"on_off": {
|
|
178
|
+
"read": { "function": 1, "address": "0x0000" },
|
|
179
|
+
"write": { "function": 5, "on": "0xFF00", "off": "0x0000" }
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
]
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
- `port` (502) and `unitId` (1) are what adding a device offers; `wordOrder` says which register
|
|
188
|
+
of a 32-bit value holds its high word; `pollSeconds` how often the device is read.
|
|
189
|
+
- Each entity is a `domain` - `sensor`, `binary_sensor`, `switch`, `light`, `number`, `select`,
|
|
190
|
+
`button` - and its capabilities: a sensor `sensor_numeric` or `sensor_text`, a binary sensor
|
|
191
|
+
`sensor_binary`, a switch `on_off`, a light `on_off` and maybe `level`, the others their own.
|
|
192
|
+
`id` is what the entity stays when it is renamed; give every one. `icon`, a catalogue icon id,
|
|
193
|
+
is the one it starts with - the domain's when left out.
|
|
194
|
+
- `read`: `function` 1 (coils), 2 (discrete inputs), 3 (holding registers) or 4 (input registers);
|
|
195
|
+
`address`, a number or `"0x…"`; for registers a `type` - `u16` (the default), `s16`, `u32`, `s32`,
|
|
196
|
+
`f32`, or `string` with a `count` of registers - a `bit` for an on/off value, a `scale` (`0.1`
|
|
197
|
+
for tenths), a `unit` the platform knows (`W`, `kWh`, `°C`: those of the sensor classes, an
|
|
198
|
+
unknown one is refused), and `options` naming what each raw number means (`{ "0": "Off" }`, which
|
|
199
|
+
a select needs).
|
|
200
|
+
- `write`: `function` 5 (one coil), 6 (one register), 15 (coils) or 16 (registers - a 32-bit value
|
|
201
|
+
needs it); `address`, the read's when left out; `on` and `off` for a switch; `min`, `max` and
|
|
202
|
+
`step` for a number, refused outside before anything is sent; `value` for a button.
|
|
203
|
+
|
|
204
|
+
The rules that tie these together - a number is not read from coils, a coil is not written with
|
|
205
|
+
06, a table read with 02 or 04 cannot be written back without an address - are checked when the
|
|
206
|
+
bundle loads, with the words the editor uses.
|
|
207
|
+
|
|
141
208
|
`defaultIcon` names the icon a device of this driver starts with, by its id in the platform's
|
|
142
209
|
icon catalogue (`packages/icons/catalogue.json` lists the platform's own ids - `light`,
|
|
143
210
|
`relay`, `printer`, `sensor`… - and every lucide icon is there under its own name). The owner
|
|
@@ -358,6 +425,59 @@ at once to the vendor whose `matter` rules take it:
|
|
|
358
425
|
model: a Matter driver that lists models must map every product in `modelCodes`, or a product
|
|
359
426
|
it misses is never added. A driver that lists none takes them all, under its own name.
|
|
360
427
|
|
|
428
|
+
**MQTT devices.** The house's MQTT broker, which the platform runs on port 1883, hears every device
|
|
429
|
+
that announces itself the way the MQTT discovery convention says - a retained JSON document on
|
|
430
|
+
`<prefix>/<component>/[<node>/]<object>/config`, which Tasmota, ESPHome, OpenMQTTGateway and most
|
|
431
|
+
others publish under `homeassistant` - and each device the owner maps by hand on the Brokers page.
|
|
432
|
+
Each is added at once to the vendor whose `mqtt` rules take it:
|
|
433
|
+
|
|
434
|
+
```json
|
|
435
|
+
{
|
|
436
|
+
"mqtt": {
|
|
437
|
+
"match": [{ "path": "originName", "equals": "Tasmota" }],
|
|
438
|
+
"model": "model"
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
- `match` - at least one condition, all of which must hold of who the device says it is: its
|
|
444
|
+
`deviceKey` (its first identifier), `source` (`announced`, `mapped` or `broker`), `name`,
|
|
445
|
+
`manufacturer`, `model`, `modelId`, `swVersion`, `hwVersion`, `serialNumber`, `identifiers` and
|
|
446
|
+
`macAddresses` (lists), `viaDevice`, `originName` and `originSwVersion` (the firmware or program
|
|
447
|
+
that announced it) and `components` (a list: `switch`, `sensor`, `light`…). A field the device
|
|
448
|
+
does not say is `null`.
|
|
449
|
+
- `model` - where the device says its model, looked up in the `modelCodes` of the vendor's drivers
|
|
450
|
+
that say `"kind": "mqtt"`; `model` when absent. A model no driver maps goes to the vendor's MQTT
|
|
451
|
+
driver when it has only one, as with Matter.
|
|
452
|
+
|
|
453
|
+
**Modbus servers.** The house's Modbus client searches the network, when the owner turns the search
|
|
454
|
+
on: every address of the ranges the owner gives - or of the networks the hub is on - on port 502.
|
|
455
|
+
It recognises nothing on its own: a server is the vendor's when its `modbus` rules take it, and the
|
|
456
|
+
owner adds it from the Brokers page with the vendor's template. Whenever a vendor is installed or
|
|
457
|
+
removed, the servers found are asked again.
|
|
458
|
+
|
|
459
|
+
```json
|
|
460
|
+
{
|
|
461
|
+
"modbus": {
|
|
462
|
+
"unitId": 1,
|
|
463
|
+
"read": { "serial": { "function": 3, "address": "0x0000", "type": "string", "count": 7 } },
|
|
464
|
+
"match": [{ "path": "values.serial", "startsWith": "H3" }],
|
|
465
|
+
"model": "values.model"
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
- `read` - at most eight values, by the name the rules use, each read as a template's `read` is,
|
|
471
|
+
from `unitId` (1 unless said); one the server refuses is `null`.
|
|
472
|
+
- `match` - at least one condition, all of which must hold of `values.<name>`, `host`, `port` and
|
|
473
|
+
`unitId`.
|
|
474
|
+
- `model` - where the server says its model, looked up in the `modelCodes` of the vendor's drivers
|
|
475
|
+
that say `"kind": "modbus"`; `values.model` when absent.
|
|
476
|
+
|
|
477
|
+
A vendor may have `mqtt` alone, with no `listen`. A device that more than one vendor's rules take,
|
|
478
|
+
and one that none takes, is added as the platform's own MQTT device, and one added so before the
|
|
479
|
+
vendor was installed becomes the vendor's once it is.
|
|
480
|
+
|
|
361
481
|
A vendor may have `matter` alone, with no `listen`. A device behind a Matter bridge is a device of
|
|
362
482
|
its own, ruled on by what the bridge says of it. A device that more than one vendor's rules take,
|
|
363
483
|
and one that none takes, is added as the platform's own Matter device, and the Brokers page says
|
|
@@ -625,21 +745,22 @@ the manifest names, and its default export - typed with `defineTransportModule`
|
|
|
625
745
|
the hub calls with the **SDK**, the runtime's pieces a transport needs, since the bundle cannot
|
|
626
746
|
import them:
|
|
627
747
|
|
|
628
|
-
| `sdk.` | What
|
|
629
|
-
| -------------------- |
|
|
630
|
-
| `version` | the runtime version, the one `manifest.sdk` was matched against
|
|
631
|
-
| `z` | the runtime's zod, so the transport's settings validate as the hub's do
|
|
632
|
-
| `defineTransport` | the contract the platform's own transports are written against
|
|
633
|
-
| `openWebSocket` | a WebSocket the hub keeps open: reconnection with a doubling pause, resets
|
|
634
|
-
| `openUdpSocket` | a UDP socket the hub binds, joins to a multicast group, and closes with the vendor
|
|
635
|
-
| `openMqtt` | an MQTT session with a client certificate, for a vendor's own broker
|
|
636
|
-
| `
|
|
637
|
-
| `
|
|
638
|
-
| `
|
|
639
|
-
| `
|
|
640
|
-
| `
|
|
641
|
-
| `
|
|
642
|
-
| `
|
|
748
|
+
| `sdk.` | What |
|
|
749
|
+
| -------------------- | ------------------------------------------------------------------------------------- |
|
|
750
|
+
| `version` | the runtime version, the one `manifest.sdk` was matched against |
|
|
751
|
+
| `z` | the runtime's zod, so the transport's settings validate as the hub's do |
|
|
752
|
+
| `defineTransport` | the contract the platform's own transports are written against |
|
|
753
|
+
| `openWebSocket` | a WebSocket the hub keeps open: reconnection with a doubling pause, resets |
|
|
754
|
+
| `openUdpSocket` | a UDP socket the hub binds, joins to a multicast group, and closes with the vendor |
|
|
755
|
+
| `openMqtt` | an MQTT session with a client certificate, for a vendor's own broker |
|
|
756
|
+
| `openModbus` | a Modbus session through the hub's one connection to a server, closed with the vendor |
|
|
757
|
+
| `defineStreamSource` | the contract a camera's stream source is written against |
|
|
758
|
+
| `openRtsp` | an RTSP(S) session over TCP, yielding a camera's H.264 as it comes |
|
|
759
|
+
| `platform.mqtt` | the house's MQTT broker the hub runs, with the hub's username; null if it cannot |
|
|
760
|
+
| `defineAccount` | the contract an account's sign-in module is written against |
|
|
761
|
+
| `codecs.lzma` | unpacks an LZMA stream in the alone format, as some clouds pack maps |
|
|
762
|
+
| `images.png` | encodes a picture of a palette as a PNG, for an image entity |
|
|
763
|
+
| `logger` | the hub's logger, for what happens outside a connection |
|
|
643
764
|
|
|
644
765
|
`openWebSocket` also takes `headers` - sent on every handshake and never logged, or a
|
|
645
766
|
function called before each attempt, for a token that expires - `ping: { everyMs, timeoutMs }`,
|
package/README.md
CHANGED
|
@@ -86,7 +86,8 @@ light.command('light.device', 'on_off', { command: 'turn_on' }); // → the HTTP
|
|
|
86
86
|
```
|
|
87
87
|
|
|
88
88
|
`identify` says what discovery makes of a device heard, `identifyMatter` what the vendor's `matter`
|
|
89
|
-
rules make of one of the house's Matter devices,
|
|
89
|
+
rules make of one of the house's Matter devices, `identifyMqtt` what its `mqtt` rules make of a
|
|
90
|
+
device the house's MQTT broker hears, and `createFakeSdk` is the SDK handed to
|
|
90
91
|
the code, recording what it logged and sent: its UDP sockets and WebSockets connect to nothing, and
|
|
91
92
|
a test opens, delivers to and drops them.
|
|
92
93
|
|
|
@@ -121,8 +122,9 @@ git tag integration-sdk@<version> && git push origin integration-sdk@<version>
|
|
|
121
122
|
```
|
|
122
123
|
|
|
123
124
|
`.github/workflows/release-integration-sdk.yml` checks the tag says the package's version, runs the
|
|
124
|
-
SDK's gates and
|
|
125
|
-
|
|
125
|
+
SDK's gates and keeps the archive npm will receive as the run's artifact; it makes no GitHub
|
|
126
|
+
release, npm is where the SDK is published. The maintainer downloads that artifact from the run
|
|
127
|
+
and publishes it, signed in to npm:
|
|
126
128
|
|
|
127
129
|
```sh
|
|
128
130
|
npm publish nebulahome-integration-sdk-<version>.tgz
|