@nebulahome/integration-sdk 1.2.0 → 1.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/CHANGELOG.md +39 -0
- package/FILES.md +137 -18
- package/README.md +5 -3
- package/dist/chunks/node-dist.js +2781 -292
- package/dist/chunks/node-index.d.ts +219 -20
- package/dist/chunks/node-project.js +2 -1
- package/dist/index.d.ts +63 -12
- package/dist/schemas.d.ts +154 -19
- 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 +491 -0
- package/schemas/driver.schema.json +8 -1
- package/schemas/modbus-template.schema.json +285 -0
|
@@ -199,25 +199,25 @@ type EntityStateClass = (typeof ENTITY_STATE_CLASSES)[number];
|
|
|
199
199
|
*/
|
|
200
200
|
declare const declaredCapabilitiesSchema: z.ZodRecord<z.ZodEnum<{
|
|
201
201
|
number: "number";
|
|
202
|
-
|
|
202
|
+
custom: "custom";
|
|
203
|
+
image: "image";
|
|
203
204
|
level: "level";
|
|
205
|
+
select: "select";
|
|
206
|
+
button: "button";
|
|
207
|
+
sensor_numeric: "sensor_numeric";
|
|
208
|
+
sensor_text: "sensor_text";
|
|
209
|
+
sensor_binary: "sensor_binary";
|
|
210
|
+
on_off: "on_off";
|
|
204
211
|
color_hs: "color_hs";
|
|
205
212
|
color_temp: "color_temp";
|
|
206
213
|
cover: "cover";
|
|
207
214
|
lock: "lock";
|
|
208
215
|
thermostat: "thermostat";
|
|
209
|
-
sensor_numeric: "sensor_numeric";
|
|
210
|
-
sensor_binary: "sensor_binary";
|
|
211
|
-
sensor_text: "sensor_text";
|
|
212
216
|
media_player: "media_player";
|
|
213
217
|
camera: "camera";
|
|
214
|
-
button: "button";
|
|
215
218
|
update: "update";
|
|
216
219
|
lawn_mower: "lawn_mower";
|
|
217
|
-
select: "select";
|
|
218
220
|
vacuum: "vacuum";
|
|
219
|
-
image: "image";
|
|
220
|
-
custom: "custom";
|
|
221
221
|
}> & z.core.$partial, z.ZodType<JsonObject, unknown, z.core.$ZodTypeInternals<JsonObject, unknown>>>;
|
|
222
222
|
/** What an entity declares it can do, with the device's own limits for each. */
|
|
223
223
|
type DeclaredCapabilities = z.output<typeof declaredCapabilitiesSchema>;
|
|
@@ -723,6 +723,79 @@ declare const integrationInstallSchema: z.ZodObject<{
|
|
|
723
723
|
/** How the platform installed a vendor. */
|
|
724
724
|
type IntegrationInstall = z.output<typeof integrationInstallSchema>;
|
|
725
725
|
//#endregion
|
|
726
|
+
//#region ../contracts/dist/modbus.d.ts
|
|
727
|
+
/**
|
|
728
|
+
* A template: the device's entities, each capability mapped to the register it is read from and
|
|
729
|
+
* the command it is written with.
|
|
730
|
+
*
|
|
731
|
+
* Every rule that ties fields together is here, so the editor's blocks, its file and the hub
|
|
732
|
+
* refuse the same templates with the same words.
|
|
733
|
+
*/
|
|
734
|
+
declare const modbusTemplateSchema: z.ZodObject<{
|
|
735
|
+
name: z.ZodString;
|
|
736
|
+
device: z.ZodDefault<z.ZodString>;
|
|
737
|
+
port: z.ZodDefault<z.ZodInt>;
|
|
738
|
+
unitId: z.ZodDefault<z.ZodInt>;
|
|
739
|
+
wordOrder: z.ZodDefault<z.ZodEnum<{
|
|
740
|
+
high: "high";
|
|
741
|
+
low: "low";
|
|
742
|
+
}>>;
|
|
743
|
+
pollSeconds: z.ZodDefault<z.ZodInt>;
|
|
744
|
+
entities: z.ZodArray<z.ZodObject<{
|
|
745
|
+
id: z.ZodOptional<z.ZodString>;
|
|
746
|
+
name: z.ZodString;
|
|
747
|
+
domain: z.ZodEnum<{
|
|
748
|
+
number: "number";
|
|
749
|
+
sensor: "sensor";
|
|
750
|
+
binary_sensor: "binary_sensor";
|
|
751
|
+
switch: "switch";
|
|
752
|
+
light: "light";
|
|
753
|
+
select: "select";
|
|
754
|
+
button: "button";
|
|
755
|
+
}>;
|
|
756
|
+
capabilities: z.ZodRecord<z.ZodEnum<{
|
|
757
|
+
number: "number";
|
|
758
|
+
select: "select";
|
|
759
|
+
button: "button";
|
|
760
|
+
sensor_numeric: "sensor_numeric";
|
|
761
|
+
sensor_text: "sensor_text";
|
|
762
|
+
sensor_binary: "sensor_binary";
|
|
763
|
+
on_off: "on_off";
|
|
764
|
+
level: "level";
|
|
765
|
+
}> & z.core.$partial, z.ZodObject<{
|
|
766
|
+
read: z.ZodOptional<z.ZodObject<{
|
|
767
|
+
function: z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<2>, z.ZodLiteral<3>, z.ZodLiteral<4>]>;
|
|
768
|
+
address: z.ZodUnion<readonly [z.ZodInt, z.ZodString]>;
|
|
769
|
+
type: z.ZodOptional<z.ZodEnum<{
|
|
770
|
+
string: "string";
|
|
771
|
+
u16: "u16";
|
|
772
|
+
s16: "s16";
|
|
773
|
+
u32: "u32";
|
|
774
|
+
s32: "s32";
|
|
775
|
+
f32: "f32";
|
|
776
|
+
}>>;
|
|
777
|
+
count: z.ZodOptional<z.ZodInt>;
|
|
778
|
+
bit: z.ZodOptional<z.ZodInt>;
|
|
779
|
+
scale: z.ZodOptional<z.ZodNumber>;
|
|
780
|
+
unit: z.ZodOptional<z.ZodString>;
|
|
781
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
782
|
+
}, z.core.$strict>>;
|
|
783
|
+
write: z.ZodOptional<z.ZodObject<{
|
|
784
|
+
function: z.ZodUnion<readonly [z.ZodLiteral<5>, z.ZodLiteral<6>, z.ZodLiteral<15>, z.ZodLiteral<16>]>;
|
|
785
|
+
address: z.ZodOptional<z.ZodUnion<readonly [z.ZodInt, z.ZodString]>>;
|
|
786
|
+
on: z.ZodOptional<z.ZodUnion<readonly [z.ZodInt, z.ZodString]>>;
|
|
787
|
+
off: z.ZodOptional<z.ZodUnion<readonly [z.ZodInt, z.ZodString]>>;
|
|
788
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
789
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
790
|
+
step: z.ZodOptional<z.ZodNumber>;
|
|
791
|
+
value: z.ZodOptional<z.ZodUnion<readonly [z.ZodInt, z.ZodString]>>;
|
|
792
|
+
}, z.core.$strict>>;
|
|
793
|
+
}, z.core.$strict>>;
|
|
794
|
+
}, z.core.$strict>>;
|
|
795
|
+
}, z.core.$strict>;
|
|
796
|
+
/** A template, checked. */
|
|
797
|
+
type ModbusTemplate = z.output<typeof modbusTemplateSchema>;
|
|
798
|
+
//#endregion
|
|
726
799
|
//#region ../package-runtime/dist/transport.d.ts
|
|
727
800
|
/** What an integration asks a transport to do, expressed as data. */
|
|
728
801
|
type TransportRequest = {
|
|
@@ -1350,10 +1423,59 @@ type ManagedMqtt = {
|
|
|
1350
1423
|
};
|
|
1351
1424
|
/** Opens a managed MQTT session. */
|
|
1352
1425
|
type OpenMqtt = (options: ManagedMqttOptions) => ManagedMqtt;
|
|
1426
|
+
/** A Modbus server, as a session to it is opened: where it is, and how frames travel. */
|
|
1427
|
+
type ModbusServerOptions = {
|
|
1428
|
+
readonly host: string;
|
|
1429
|
+
/** 502 unless said. */
|
|
1430
|
+
readonly port?: number;
|
|
1431
|
+
/** `tcp` (MBAP) unless said; `rtu` for RTU frames a transparent adapter carries over TCP. */
|
|
1432
|
+
readonly framing?: 'tcp' | 'rtu';
|
|
1433
|
+
};
|
|
1434
|
+
/** One read: a run of coils, inputs or registers of one unit. */
|
|
1435
|
+
type ModbusReadOptions = {
|
|
1436
|
+
readonly unitId: number;
|
|
1437
|
+
readonly function: 1 | 2 | 3 | 4;
|
|
1438
|
+
readonly address: number;
|
|
1439
|
+
/** How many bits or registers, 1 to 125. */
|
|
1440
|
+
readonly count: number;
|
|
1441
|
+
/** How long to wait for the answer; 3 s unless said. */
|
|
1442
|
+
readonly timeoutMs?: number;
|
|
1443
|
+
};
|
|
1444
|
+
/** One write: a coil, a register, coils or registers of one unit. */
|
|
1445
|
+
type ModbusWriteOptions = {
|
|
1446
|
+
readonly unitId: number;
|
|
1447
|
+
readonly function: 5 | 6 | 15 | 16;
|
|
1448
|
+
readonly address: number;
|
|
1449
|
+
/** The word for 05 (0xFF00 on, 0 off) and 06; the bits for 15; the registers for 16. */
|
|
1450
|
+
readonly values: readonly number[];
|
|
1451
|
+
readonly timeoutMs?: number;
|
|
1452
|
+
};
|
|
1453
|
+
/**
|
|
1454
|
+
* A session to a Modbus server through the hub's one connection to it: requests of every
|
|
1455
|
+
* session to the same server wait their turn, so a gateway that answers one client at a time is
|
|
1456
|
+
* never asked twice at once.
|
|
1457
|
+
*
|
|
1458
|
+
* A failed request rejects with an error whose `name` says why: `ModbusException` - the server
|
|
1459
|
+
* refused, its `code` the exception - `ModbusNoConnection` or `ModbusSilence`.
|
|
1460
|
+
*/
|
|
1461
|
+
type ModbusSession = {
|
|
1462
|
+
/**
|
|
1463
|
+
* Reads bits or registers.
|
|
1464
|
+
*
|
|
1465
|
+
* @returns One number per bit (0 or 1) or register (a 16-bit word).
|
|
1466
|
+
*/
|
|
1467
|
+
read: (options: ModbusReadOptions, signal?: AbortSignal) => Promise<number[]>;
|
|
1468
|
+
/** Writes a coil, a register, coils or registers. */
|
|
1469
|
+
write: (options: ModbusWriteOptions, signal?: AbortSignal) => Promise<void>;
|
|
1470
|
+
/** Lets go of the server; the connection closes once nothing else holds it. */
|
|
1471
|
+
close: () => Promise<void>;
|
|
1472
|
+
};
|
|
1473
|
+
/** Opens a session to a Modbus server. */
|
|
1474
|
+
type OpenModbus = (server: ModbusServerOptions) => ModbusSession;
|
|
1353
1475
|
/**
|
|
1354
|
-
* The house's MQTT broker, as the hub reaches it: the
|
|
1355
|
-
*
|
|
1356
|
-
*
|
|
1476
|
+
* The house's MQTT broker, as the hub reaches it: the one the hub runs, with the hub's own
|
|
1477
|
+
* username - or the broker `NEBULA_MQTT_URL` names. Read again each time it is needed: a session
|
|
1478
|
+
* opened while the broker is still coming up retries until it listens.
|
|
1357
1479
|
*/
|
|
1358
1480
|
type PlatformMqtt = {
|
|
1359
1481
|
readonly url: string;
|
|
@@ -1364,7 +1486,7 @@ type PlatformMqtt = {
|
|
|
1364
1486
|
type PlatformServices = {
|
|
1365
1487
|
/**
|
|
1366
1488
|
* The house's broker, for a vendor whose devices report through it - zigbee2mqtt - and which
|
|
1367
|
-
* runs its own program beside the platform. Null
|
|
1489
|
+
* runs its own program beside the platform. Null only while the hub cannot run one.
|
|
1368
1490
|
*/
|
|
1369
1491
|
readonly mqtt: PlatformMqtt | null;
|
|
1370
1492
|
};
|
|
@@ -1411,6 +1533,8 @@ type BundleSdk = {
|
|
|
1411
1533
|
readonly openUdpSocket: OpenUdpSocket;
|
|
1412
1534
|
/** An MQTT session, for a vendor whose devices report through a broker of its own. */
|
|
1413
1535
|
readonly openMqtt: OpenMqtt;
|
|
1536
|
+
/** A session to a Modbus server, through the hub's one connection to it. */
|
|
1537
|
+
readonly openModbus: OpenModbus;
|
|
1414
1538
|
/** How a camera's stream source is written, as defineTransport is for a transport. */
|
|
1415
1539
|
readonly defineStreamSource: typeof defineStreamSource;
|
|
1416
1540
|
/** An RTSP session over TCP, yielding a camera's H.264 as it comes. */
|
|
@@ -1676,13 +1800,13 @@ declare const vendorManifestSchema: z.ZodObject<{
|
|
|
1676
1800
|
transports: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
1677
1801
|
module: z.ZodString;
|
|
1678
1802
|
wires: z.ZodArray<z.ZodEnum<{
|
|
1679
|
-
udp: "udp";
|
|
1680
1803
|
matter: "matter";
|
|
1681
|
-
|
|
1804
|
+
modbus: "modbus";
|
|
1682
1805
|
mqtt: "mqtt";
|
|
1806
|
+
http: "http";
|
|
1683
1807
|
ble: "ble";
|
|
1684
1808
|
zigbee: "zigbee";
|
|
1685
|
-
|
|
1809
|
+
udp: "udp";
|
|
1686
1810
|
}>>;
|
|
1687
1811
|
}, z.core.$strict>]>>>;
|
|
1688
1812
|
streams: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
@@ -1771,15 +1895,18 @@ declare const bundleManifestSchema: z.ZodObject<{
|
|
|
1771
1895
|
modelCodes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>>;
|
|
1772
1896
|
modelSeries: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
1773
1897
|
kind: z.ZodEnum<{
|
|
1774
|
-
declarative: "declarative";
|
|
1775
|
-
code: "code";
|
|
1776
1898
|
matter: "matter";
|
|
1899
|
+
modbus: "modbus";
|
|
1900
|
+
mqtt: "mqtt";
|
|
1901
|
+
code: "code";
|
|
1902
|
+
declarative: "declarative";
|
|
1777
1903
|
}>;
|
|
1778
1904
|
defaultIcon: z.ZodOptional<z.ZodString>;
|
|
1779
1905
|
webPagePort: z.ZodOptional<z.ZodInt>;
|
|
1780
1906
|
webPagePath: z.ZodOptional<z.ZodString>;
|
|
1781
1907
|
profile: z.ZodOptional<z.ZodString>;
|
|
1782
1908
|
entry: z.ZodOptional<z.ZodString>;
|
|
1909
|
+
template: z.ZodOptional<z.ZodString>;
|
|
1783
1910
|
setup: z.ZodString;
|
|
1784
1911
|
id: z.ZodString;
|
|
1785
1912
|
version: z.ZodString;
|
|
@@ -1889,6 +2016,76 @@ declare const vendorDiscoverySchema: z.ZodObject<{
|
|
|
1889
2016
|
}, z.core.$strict>]>>;
|
|
1890
2017
|
model: z.ZodDefault<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
1891
2018
|
}, z.core.$strict>>;
|
|
2019
|
+
mqtt: z.ZodOptional<z.ZodObject<{
|
|
2020
|
+
match: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
2021
|
+
path: z.ZodString;
|
|
2022
|
+
equals: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
|
|
2023
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
2024
|
+
path: z.ZodString;
|
|
2025
|
+
exists: z.ZodLiteral<true>;
|
|
2026
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
2027
|
+
path: z.ZodString;
|
|
2028
|
+
oneOf: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
2029
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
2030
|
+
path: z.ZodString;
|
|
2031
|
+
startsWith: z.ZodString;
|
|
2032
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
2033
|
+
path: z.ZodString;
|
|
2034
|
+
endsWith: z.ZodString;
|
|
2035
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
2036
|
+
path: z.ZodString;
|
|
2037
|
+
contains: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
|
|
2038
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
2039
|
+
path: z.ZodString;
|
|
2040
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
2041
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
2042
|
+
}, z.core.$strict>]>>;
|
|
2043
|
+
model: z.ZodDefault<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
2044
|
+
}, z.core.$strict>>;
|
|
2045
|
+
modbus: z.ZodOptional<z.ZodObject<{
|
|
2046
|
+
match: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
2047
|
+
path: z.ZodString;
|
|
2048
|
+
equals: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
|
|
2049
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
2050
|
+
path: z.ZodString;
|
|
2051
|
+
exists: z.ZodLiteral<true>;
|
|
2052
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
2053
|
+
path: z.ZodString;
|
|
2054
|
+
oneOf: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
2055
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
2056
|
+
path: z.ZodString;
|
|
2057
|
+
startsWith: z.ZodString;
|
|
2058
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
2059
|
+
path: z.ZodString;
|
|
2060
|
+
endsWith: z.ZodString;
|
|
2061
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
2062
|
+
path: z.ZodString;
|
|
2063
|
+
contains: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
|
|
2064
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
2065
|
+
path: z.ZodString;
|
|
2066
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
2067
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
2068
|
+
}, z.core.$strict>]>>;
|
|
2069
|
+
model: z.ZodDefault<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
2070
|
+
unitId: z.ZodDefault<z.ZodInt>;
|
|
2071
|
+
read: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
2072
|
+
function: z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<2>, z.ZodLiteral<3>, z.ZodLiteral<4>]>;
|
|
2073
|
+
address: z.ZodUnion<readonly [z.ZodInt, z.ZodString]>;
|
|
2074
|
+
type: z.ZodOptional<z.ZodEnum<{
|
|
2075
|
+
string: "string";
|
|
2076
|
+
u16: "u16";
|
|
2077
|
+
s16: "s16";
|
|
2078
|
+
u32: "u32";
|
|
2079
|
+
s32: "s32";
|
|
2080
|
+
f32: "f32";
|
|
2081
|
+
}>>;
|
|
2082
|
+
count: z.ZodOptional<z.ZodInt>;
|
|
2083
|
+
bit: z.ZodOptional<z.ZodInt>;
|
|
2084
|
+
scale: z.ZodOptional<z.ZodNumber>;
|
|
2085
|
+
unit: z.ZodOptional<z.ZodString>;
|
|
2086
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
2087
|
+
}, z.core.$strict>>>;
|
|
2088
|
+
}, z.core.$strict>>;
|
|
1892
2089
|
adopt: z.ZodDefault<z.ZodEnum<{
|
|
1893
2090
|
owner: "owner";
|
|
1894
2091
|
automatic: "automatic";
|
|
@@ -1908,8 +2105,8 @@ type DiscoveryDriver = {
|
|
|
1908
2105
|
/** The driver's own name, offered as its one model when it lists none. */
|
|
1909
2106
|
readonly name: string;
|
|
1910
2107
|
/**
|
|
1911
|
-
* What reaches its devices. A driver on
|
|
1912
|
-
* other driver does.
|
|
2108
|
+
* What reaches its devices. A driver on a broker's transport - `matter`, `mqtt-house` - takes
|
|
2109
|
+
* only that broker's devices, and no other driver does.
|
|
1913
2110
|
*/
|
|
1914
2111
|
readonly transport: string;
|
|
1915
2112
|
readonly models: readonly string[];
|
|
@@ -2042,6 +2239,8 @@ type LoadedBundle = {
|
|
|
2042
2239
|
readonly setup: IntegrationSetup;
|
|
2043
2240
|
/** Where it was read from, for a message that has to name it. */
|
|
2044
2241
|
readonly directory: string;
|
|
2242
|
+
/** The template a Modbus driver reads its devices through, every entity with its id. */
|
|
2243
|
+
readonly modbusTemplate?: ModbusTemplate;
|
|
2045
2244
|
};
|
|
2046
2245
|
/**
|
|
2047
2246
|
* Which of the two places a vendor was read from.
|
|
@@ -2050,7 +2249,7 @@ type LoadedBundle = {
|
|
|
2050
2249
|
* from the integrations index or its local folder, and the only place a production hub reads.
|
|
2051
2250
|
* `development` is a directory of bundles under development - an integration repository's
|
|
2052
2251
|
* `dist/`, named in the hub's `HUB_DEV_BUNDLE_DIR` - read beside it. `platform` is no place at
|
|
2053
|
-
* all: the
|
|
2252
|
+
* all: the vendors the hub is itself, `matter` and `mqtt`, built in code.
|
|
2054
2253
|
*/
|
|
2055
2254
|
type BundleOrigin = 'development' | 'installed' | 'platform';
|
|
2056
2255
|
/** Where a vendor's devices announce themselves, ready to listen to. */
|
|
@@ -89,7 +89,7 @@ function defineTransport(spec) {
|
|
|
89
89
|
* bundle built with this SDK says `^<major>.<minor>.0`.
|
|
90
90
|
*/
|
|
91
91
|
/** The SDK's own version: `1.0.0`, or a prerelease of it. */
|
|
92
|
-
const SDK_VERSION = "1.
|
|
92
|
+
const SDK_VERSION = "1.4.0";
|
|
93
93
|
/**
|
|
94
94
|
* The runtime range a bundle built with this SDK declares: this version's major and minor, so a
|
|
95
95
|
* platform with the same contract or a later one of the same major loads it.
|
|
@@ -391,6 +391,7 @@ function createFakeSdk(options = {}) {
|
|
|
391
391
|
openUdpSocket,
|
|
392
392
|
openWebSocket,
|
|
393
393
|
openMqtt: notFaked("openMqtt"),
|
|
394
|
+
openModbus: notFaked("openModbus"),
|
|
394
395
|
openRtsp: notFaked("openRtsp"),
|
|
395
396
|
platform: options.platform ?? { mqtt: null },
|
|
396
397
|
codecs: { lzma: notFaked("codecs.lzma") },
|
package/dist/index.d.ts
CHANGED
|
@@ -199,25 +199,25 @@ type EntityStateClass = (typeof ENTITY_STATE_CLASSES)[number];
|
|
|
199
199
|
*/
|
|
200
200
|
declare const declaredCapabilitiesSchema: z.ZodRecord<z.ZodEnum<{
|
|
201
201
|
number: "number";
|
|
202
|
-
|
|
202
|
+
custom: "custom";
|
|
203
|
+
image: "image";
|
|
203
204
|
level: "level";
|
|
205
|
+
select: "select";
|
|
206
|
+
button: "button";
|
|
207
|
+
sensor_numeric: "sensor_numeric";
|
|
208
|
+
sensor_text: "sensor_text";
|
|
209
|
+
sensor_binary: "sensor_binary";
|
|
210
|
+
on_off: "on_off";
|
|
204
211
|
color_hs: "color_hs";
|
|
205
212
|
color_temp: "color_temp";
|
|
206
213
|
cover: "cover";
|
|
207
214
|
lock: "lock";
|
|
208
215
|
thermostat: "thermostat";
|
|
209
|
-
sensor_numeric: "sensor_numeric";
|
|
210
|
-
sensor_binary: "sensor_binary";
|
|
211
|
-
sensor_text: "sensor_text";
|
|
212
216
|
media_player: "media_player";
|
|
213
217
|
camera: "camera";
|
|
214
|
-
button: "button";
|
|
215
218
|
update: "update";
|
|
216
219
|
lawn_mower: "lawn_mower";
|
|
217
|
-
select: "select";
|
|
218
220
|
vacuum: "vacuum";
|
|
219
|
-
image: "image";
|
|
220
|
-
custom: "custom";
|
|
221
221
|
}> & z.core.$partial, z.ZodType<JsonObject, unknown, z.core.$ZodTypeInternals<JsonObject, unknown>>>;
|
|
222
222
|
/** What an entity declares it can do, with the device's own limits for each. */
|
|
223
223
|
type DeclaredCapabilities = z.output<typeof declaredCapabilitiesSchema>;
|
|
@@ -1115,10 +1115,59 @@ type ManagedMqtt = {
|
|
|
1115
1115
|
};
|
|
1116
1116
|
/** Opens a managed MQTT session. */
|
|
1117
1117
|
type OpenMqtt = (options: ManagedMqttOptions) => ManagedMqtt;
|
|
1118
|
+
/** A Modbus server, as a session to it is opened: where it is, and how frames travel. */
|
|
1119
|
+
type ModbusServerOptions = {
|
|
1120
|
+
readonly host: string;
|
|
1121
|
+
/** 502 unless said. */
|
|
1122
|
+
readonly port?: number;
|
|
1123
|
+
/** `tcp` (MBAP) unless said; `rtu` for RTU frames a transparent adapter carries over TCP. */
|
|
1124
|
+
readonly framing?: 'tcp' | 'rtu';
|
|
1125
|
+
};
|
|
1126
|
+
/** One read: a run of coils, inputs or registers of one unit. */
|
|
1127
|
+
type ModbusReadOptions = {
|
|
1128
|
+
readonly unitId: number;
|
|
1129
|
+
readonly function: 1 | 2 | 3 | 4;
|
|
1130
|
+
readonly address: number;
|
|
1131
|
+
/** How many bits or registers, 1 to 125. */
|
|
1132
|
+
readonly count: number;
|
|
1133
|
+
/** How long to wait for the answer; 3 s unless said. */
|
|
1134
|
+
readonly timeoutMs?: number;
|
|
1135
|
+
};
|
|
1136
|
+
/** One write: a coil, a register, coils or registers of one unit. */
|
|
1137
|
+
type ModbusWriteOptions = {
|
|
1138
|
+
readonly unitId: number;
|
|
1139
|
+
readonly function: 5 | 6 | 15 | 16;
|
|
1140
|
+
readonly address: number;
|
|
1141
|
+
/** The word for 05 (0xFF00 on, 0 off) and 06; the bits for 15; the registers for 16. */
|
|
1142
|
+
readonly values: readonly number[];
|
|
1143
|
+
readonly timeoutMs?: number;
|
|
1144
|
+
};
|
|
1145
|
+
/**
|
|
1146
|
+
* A session to a Modbus server through the hub's one connection to it: requests of every
|
|
1147
|
+
* session to the same server wait their turn, so a gateway that answers one client at a time is
|
|
1148
|
+
* never asked twice at once.
|
|
1149
|
+
*
|
|
1150
|
+
* A failed request rejects with an error whose `name` says why: `ModbusException` - the server
|
|
1151
|
+
* refused, its `code` the exception - `ModbusNoConnection` or `ModbusSilence`.
|
|
1152
|
+
*/
|
|
1153
|
+
type ModbusSession = {
|
|
1154
|
+
/**
|
|
1155
|
+
* Reads bits or registers.
|
|
1156
|
+
*
|
|
1157
|
+
* @returns One number per bit (0 or 1) or register (a 16-bit word).
|
|
1158
|
+
*/
|
|
1159
|
+
read: (options: ModbusReadOptions, signal?: AbortSignal) => Promise<number[]>;
|
|
1160
|
+
/** Writes a coil, a register, coils or registers. */
|
|
1161
|
+
write: (options: ModbusWriteOptions, signal?: AbortSignal) => Promise<void>;
|
|
1162
|
+
/** Lets go of the server; the connection closes once nothing else holds it. */
|
|
1163
|
+
close: () => Promise<void>;
|
|
1164
|
+
};
|
|
1165
|
+
/** Opens a session to a Modbus server. */
|
|
1166
|
+
type OpenModbus = (server: ModbusServerOptions) => ModbusSession;
|
|
1118
1167
|
/**
|
|
1119
|
-
* The house's MQTT broker, as the hub reaches it: the
|
|
1120
|
-
*
|
|
1121
|
-
*
|
|
1168
|
+
* The house's MQTT broker, as the hub reaches it: the one the hub runs, with the hub's own
|
|
1169
|
+
* username - or the broker `NEBULA_MQTT_URL` names. Read again each time it is needed: a session
|
|
1170
|
+
* opened while the broker is still coming up retries until it listens.
|
|
1122
1171
|
*/
|
|
1123
1172
|
type PlatformMqtt = {
|
|
1124
1173
|
readonly url: string;
|
|
@@ -1129,7 +1178,7 @@ type PlatformMqtt = {
|
|
|
1129
1178
|
type PlatformServices = {
|
|
1130
1179
|
/**
|
|
1131
1180
|
* The house's broker, for a vendor whose devices report through it - zigbee2mqtt - and which
|
|
1132
|
-
* runs its own program beside the platform. Null
|
|
1181
|
+
* runs its own program beside the platform. Null only while the hub cannot run one.
|
|
1133
1182
|
*/
|
|
1134
1183
|
readonly mqtt: PlatformMqtt | null;
|
|
1135
1184
|
};
|
|
@@ -1176,6 +1225,8 @@ type BundleSdk = {
|
|
|
1176
1225
|
readonly openUdpSocket: OpenUdpSocket;
|
|
1177
1226
|
/** An MQTT session, for a vendor whose devices report through a broker of its own. */
|
|
1178
1227
|
readonly openMqtt: OpenMqtt;
|
|
1228
|
+
/** A session to a Modbus server, through the hub's one connection to it. */
|
|
1229
|
+
readonly openModbus: OpenModbus;
|
|
1179
1230
|
/** How a camera's stream source is written, as defineTransport is for a transport. */
|
|
1180
1231
|
readonly defineStreamSource: typeof defineStreamSource;
|
|
1181
1232
|
/** An RTSP session over TCP, yielding a camera's H.264 as it comes. */
|