mqtt2matter 0.0.0-stage → 0.2.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 +76 -0
- package/LICENSE +202 -0
- package/NOTICE +23 -0
- package/README.md +172 -2
- package/dist/app.d.ts +34 -0
- package/dist/app.js +157 -0
- package/dist/app.js.map +1 -0
- package/dist/commands/import-z2m.d.ts +20 -0
- package/dist/commands/import-z2m.js +173 -0
- package/dist/commands/import-z2m.js.map +1 -0
- package/dist/commands/install.d.ts +41 -0
- package/dist/commands/install.js +250 -0
- package/dist/commands/install.js.map +1 -0
- package/dist/commands/update.d.ts +14 -0
- package/dist/commands/update.js +109 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +3 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/load.d.ts +57 -0
- package/dist/config/load.js +137 -0
- package/dist/config/load.js.map +1 -0
- package/dist/config/schema.d.ts +496 -0
- package/dist/config/schema.js +115 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/engine/payload.d.ts +94 -0
- package/dist/engine/payload.js +515 -0
- package/dist/engine/payload.js.map +1 -0
- package/dist/engine/runtime.d.ts +79 -0
- package/dist/engine/runtime.js +438 -0
- package/dist/engine/runtime.js.map +1 -0
- package/dist/engine/template.d.ts +20 -0
- package/dist/engine/template.js +264 -0
- package/dist/engine/template.js.map +1 -0
- package/dist/engine/units.d.ts +9 -0
- package/dist/engine/units.js +42 -0
- package/dist/engine/units.js.map +1 -0
- package/dist/families/climate.d.ts +11 -0
- package/dist/families/climate.js +68 -0
- package/dist/families/climate.js.map +1 -0
- package/dist/families/color.d.ts +30 -0
- package/dist/families/color.js +152 -0
- package/dist/families/color.js.map +1 -0
- package/dist/families/cover.d.ts +17 -0
- package/dist/families/cover.js +308 -0
- package/dist/families/cover.js.map +1 -0
- package/dist/families/fan.d.ts +16 -0
- package/dist/families/fan.js +154 -0
- package/dist/families/fan.js.map +1 -0
- package/dist/families/index.d.ts +32 -0
- package/dist/families/index.js +162 -0
- package/dist/families/index.js.map +1 -0
- package/dist/families/light.d.ts +36 -0
- package/dist/families/light.js +258 -0
- package/dist/families/light.js.map +1 -0
- package/dist/families/lock.d.ts +10 -0
- package/dist/families/lock.js +31 -0
- package/dist/families/lock.js.map +1 -0
- package/dist/families/on-off.d.ts +7 -0
- package/dist/families/on-off.js +56 -0
- package/dist/families/on-off.js.map +1 -0
- package/dist/families/power-source.d.ts +12 -0
- package/dist/families/power-source.js +60 -0
- package/dist/families/power-source.js.map +1 -0
- package/dist/families/registry.d.ts +40 -0
- package/dist/families/registry.js +72 -0
- package/dist/families/registry.js.map +1 -0
- package/dist/families/rvc.d.ts +40 -0
- package/dist/families/rvc.js +83 -0
- package/dist/families/rvc.js.map +1 -0
- package/dist/families/switch.d.ts +19 -0
- package/dist/families/switch.js +94 -0
- package/dist/families/switch.js.map +1 -0
- package/dist/importers/actions.d.ts +19 -0
- package/dist/importers/actions.js +98 -0
- package/dist/importers/actions.js.map +1 -0
- package/dist/importers/ha/areas.d.ts +6 -0
- package/dist/importers/ha/areas.js +279 -0
- package/dist/importers/ha/areas.js.map +1 -0
- package/dist/importers/ha/generate.d.ts +51 -0
- package/dist/importers/ha/generate.js +1376 -0
- package/dist/importers/ha/generate.js.map +1 -0
- package/dist/importers/ha/index.d.ts +6 -0
- package/dist/importers/ha/index.js +7 -0
- package/dist/importers/ha/index.js.map +1 -0
- package/dist/importers/ha/source.d.ts +36 -0
- package/dist/importers/ha/source.js +95 -0
- package/dist/importers/ha/source.js.map +1 -0
- package/dist/importers/ha/sync.d.ts +29 -0
- package/dist/importers/ha/sync.js +132 -0
- package/dist/importers/ha/sync.js.map +1 -0
- package/dist/importers/ha/templates.d.ts +18 -0
- package/dist/importers/ha/templates.js +285 -0
- package/dist/importers/ha/templates.js.map +1 -0
- package/dist/importers/ha/types.d.ts +78 -0
- package/dist/importers/ha/types.js +479 -0
- package/dist/importers/ha/types.js.map +1 -0
- package/dist/importers/index.d.ts +5 -0
- package/dist/importers/index.js +8 -0
- package/dist/importers/index.js.map +1 -0
- package/dist/importers/patch.d.ts +50 -0
- package/dist/importers/patch.js +224 -0
- package/dist/importers/patch.js.map +1 -0
- package/dist/importers/sync.d.ts +112 -0
- package/dist/importers/sync.js +220 -0
- package/dist/importers/sync.js.map +1 -0
- package/dist/importers/twins.d.ts +10 -0
- package/dist/importers/twins.js +34 -0
- package/dist/importers/twins.js.map +1 -0
- package/dist/importers/z2m/generate.d.ts +81 -0
- package/dist/importers/z2m/generate.js +1171 -0
- package/dist/importers/z2m/generate.js.map +1 -0
- package/dist/importers/z2m/index.d.ts +5 -0
- package/dist/importers/z2m/index.js +6 -0
- package/dist/importers/z2m/index.js.map +1 -0
- package/dist/importers/z2m/source.d.ts +18 -0
- package/dist/importers/z2m/source.js +46 -0
- package/dist/importers/z2m/source.js.map +1 -0
- package/dist/importers/z2m/sync.d.ts +29 -0
- package/dist/importers/z2m/sync.js +92 -0
- package/dist/importers/z2m/sync.js.map +1 -0
- package/dist/importers/z2m/types.d.ts +72 -0
- package/dist/importers/z2m/types.js +46 -0
- package/dist/importers/z2m/types.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/log.d.ts +17 -0
- package/dist/log.js +54 -0
- package/dist/log.js.map +1 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +202 -0
- package/dist/main.js.map +1 -0
- package/dist/matter/bridge.d.ts +113 -0
- package/dist/matter/bridge.js +467 -0
- package/dist/matter/bridge.js.map +1 -0
- package/dist/matter/check.d.ts +11 -0
- package/dist/matter/check.js +116 -0
- package/dist/matter/check.js.map +1 -0
- package/dist/matter/cluster-defaults.d.ts +6 -0
- package/dist/matter/cluster-defaults.js +63 -0
- package/dist/matter/cluster-defaults.js.map +1 -0
- package/dist/matter/commissioning.d.ts +21 -0
- package/dist/matter/commissioning.js +88 -0
- package/dist/matter/commissioning.js.map +1 -0
- package/dist/matter/device-types.d.ts +44 -0
- package/dist/matter/device-types.js +230 -0
- package/dist/matter/device-types.js.map +1 -0
- package/dist/matter/ids.d.ts +31 -0
- package/dist/matter/ids.js +83 -0
- package/dist/matter/ids.js.map +1 -0
- package/dist/matter/index.d.ts +7 -0
- package/dist/matter/index.js +8 -0
- package/dist/matter/index.js.map +1 -0
- package/dist/matter/node-manager.d.ts +39 -0
- package/dist/matter/node-manager.js +161 -0
- package/dist/matter/node-manager.js.map +1 -0
- package/dist/matter/shards.d.ts +26 -0
- package/dist/matter/shards.js +93 -0
- package/dist/matter/shards.js.map +1 -0
- package/dist/model/attribute.d.ts +18 -0
- package/dist/model/attribute.js +28 -0
- package/dist/model/attribute.js.map +1 -0
- package/dist/model/catalog.d.ts +79 -0
- package/dist/model/catalog.js +223 -0
- package/dist/model/catalog.js.map +1 -0
- package/dist/model/index.d.ts +7 -0
- package/dist/model/index.js +8 -0
- package/dist/model/index.js.map +1 -0
- package/dist/model/migrate.d.ts +4 -0
- package/dist/model/migrate.js +39 -0
- package/dist/model/migrate.js.map +1 -0
- package/dist/model/options.d.ts +102 -0
- package/dist/model/options.js +88 -0
- package/dist/model/options.js.map +1 -0
- package/dist/model/presets.d.ts +37 -0
- package/dist/model/presets.js +105 -0
- package/dist/model/presets.js.map +1 -0
- package/dist/model/schema.d.ts +1747 -0
- package/dist/model/schema.js +243 -0
- package/dist/model/schema.js.map +1 -0
- package/dist/model/validate.d.ts +21 -0
- package/dist/model/validate.js +484 -0
- package/dist/model/validate.js.map +1 -0
- package/dist/mqtt/client.d.ts +38 -0
- package/dist/mqtt/client.js +94 -0
- package/dist/mqtt/client.js.map +1 -0
- package/dist/mqtt/index.d.ts +2 -0
- package/dist/mqtt/index.js +3 -0
- package/dist/mqtt/index.js.map +1 -0
- package/dist/mqtt/topic-cache.d.ts +20 -0
- package/dist/mqtt/topic-cache.js +58 -0
- package/dist/mqtt/topic-cache.js.map +1 -0
- package/dist/server/auth.d.ts +59 -0
- package/dist/server/auth.js +185 -0
- package/dist/server/auth.js.map +1 -0
- package/dist/server/catalog.d.ts +52 -0
- package/dist/server/catalog.js +96 -0
- package/dist/server/catalog.js.map +1 -0
- package/dist/server/compact.d.ts +3 -0
- package/dist/server/compact.js +105 -0
- package/dist/server/compact.js.map +1 -0
- package/dist/server/config-store.d.ts +36 -0
- package/dist/server/config-store.js +155 -0
- package/dist/server/config-store.js.map +1 -0
- package/dist/server/events.d.ts +50 -0
- package/dist/server/events.js +71 -0
- package/dist/server/events.js.map +1 -0
- package/dist/server/http.d.ts +27 -0
- package/dist/server/http.js +168 -0
- package/dist/server/http.js.map +1 -0
- package/dist/server/importers.d.ts +40 -0
- package/dist/server/importers.js +75 -0
- package/dist/server/importers.js.map +1 -0
- package/dist/server/index.d.ts +6 -0
- package/dist/server/index.js +8 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/log-buffer.d.ts +22 -0
- package/dist/server/log-buffer.js +55 -0
- package/dist/server/log-buffer.js.map +1 -0
- package/dist/server/presets.d.ts +17 -0
- package/dist/server/presets.js +55 -0
- package/dist/server/presets.js.map +1 -0
- package/dist/server/preview.d.ts +19 -0
- package/dist/server/preview.js +121 -0
- package/dist/server/preview.js.map +1 -0
- package/dist/server/server.d.ts +107 -0
- package/dist/server/server.js +810 -0
- package/dist/server/server.js.map +1 -0
- package/dist/server/update.d.ts +60 -0
- package/dist/server/update.js +191 -0
- package/dist/server/update.js.map +1 -0
- package/docs/api.md +128 -0
- package/docs/architecture.md +121 -0
- package/docs/config.md +538 -0
- package/docs/importers.md +241 -0
- package/example/mqtt2matter.json +276 -0
- package/package.json +90 -4
- package/presets/mqtt-smarthome/button.json +47 -0
- package/presets/mqtt-smarthome/contact.json +37 -0
- package/presets/mqtt-smarthome/cover.json +50 -0
- package/presets/mqtt-smarthome/dimmer.json +57 -0
- package/presets/mqtt-smarthome/humidity.json +38 -0
- package/presets/mqtt-smarthome/light.json +47 -0
- package/presets/mqtt-smarthome/occupancy.json +46 -0
- package/presets/mqtt-smarthome/switch.json +47 -0
- package/presets/mqtt-smarthome/temperature.json +38 -0
- package/presets/openbeken/color-light.json +64 -0
- package/presets/openbeken/ct-light.json +51 -0
- package/presets/openbeken/dimmer.json +47 -0
- package/presets/openbeken/humidity.json +37 -0
- package/presets/openbeken/relay.json +40 -0
- package/presets/openbeken/temperature.json +41 -0
- package/presets/shelly-gen1/dimmer.json +48 -0
- package/presets/shelly-gen1/door-window.json +43 -0
- package/presets/shelly-gen1/ht.json +43 -0
- package/presets/shelly-gen1/relay-pm.json +60 -0
- package/presets/shelly-gen1/relay.json +36 -0
- package/presets/shelly-gen1/roller.json +52 -0
- package/presets/shelly-gen2/cover.json +68 -0
- package/presets/shelly-gen2/dimmer.json +61 -0
- package/presets/shelly-gen2/ht.json +47 -0
- package/presets/shelly-gen2/i4.json +82 -0
- package/presets/shelly-gen2/switch-pm.json +101 -0
- package/presets/shelly-gen2/switch.json +47 -0
- package/presets/tasmota/climate.json +52 -0
- package/presets/tasmota/color-light.json +63 -0
- package/presets/tasmota/ct-light.json +50 -0
- package/presets/tasmota/dimmer.json +45 -0
- package/presets/tasmota/relay.json +39 -0
- package/presets/tasmota/shutter.json +46 -0
- package/presets/tasmota/temperature-humidity.json +42 -0
- package/presets/tasmota/temperature.json +32 -0
- package/presets/valetudo/vacuum.json +103 -0
- package/presets/wled/dimmer.json +46 -0
- package/presets/wled/light.json +59 -0
- package/ui/dist/assets/index-BDtT6bdH.js +10 -0
- package/ui/dist/assets/index-CHiG-aoU.css +1 -0
- package/ui/dist/index.html +18 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { LogLevel as MatterLogLevel } from '@matter/main';
|
|
2
|
+
import type { Config } from '../config/schema.ts';
|
|
3
|
+
import type { Logger } from '../log.ts';
|
|
4
|
+
import type { DeviceConfig } from '../model/schema.ts';
|
|
5
|
+
import { Bridge, type BridgeInfo, type DeviceHandle } from './bridge.ts';
|
|
6
|
+
export interface NodeManagerOptions {
|
|
7
|
+
config: Config;
|
|
8
|
+
softwareVersion: string;
|
|
9
|
+
log: Logger;
|
|
10
|
+
}
|
|
11
|
+
export declare const MATTER_LEVELS: Record<Config['log']['matter'], MatterLogLevel>;
|
|
12
|
+
/** matter.js reads the storage path from its default environment once per process */
|
|
13
|
+
export declare function prepareEnvironment(storagePath: string, matterLogLevel: Config['log']['matter']): void;
|
|
14
|
+
export declare class NodeManager {
|
|
15
|
+
readonly storagePath: string;
|
|
16
|
+
private readonly options;
|
|
17
|
+
private readonly bridges;
|
|
18
|
+
private readonly placement;
|
|
19
|
+
private shards;
|
|
20
|
+
private readonly log;
|
|
21
|
+
constructor(options: NodeManagerOptions);
|
|
22
|
+
bridge(id: string): Bridge | undefined;
|
|
23
|
+
allBridges(): Bridge[];
|
|
24
|
+
/** the device's handle, wherever it lives */
|
|
25
|
+
handle(deviceKey: string): DeviceHandle | undefined;
|
|
26
|
+
/** every device handle, keyed by device key */
|
|
27
|
+
handles(): Map<string, DeviceHandle>;
|
|
28
|
+
/** create the bridges and place the enabled devices; nothing is online before `start()` */
|
|
29
|
+
prepare(): Promise<void>;
|
|
30
|
+
private place;
|
|
31
|
+
/** add or replace a device while running: placed by the shard map, installed into its bridge at once */
|
|
32
|
+
addDevice(key: string, device: DeviceConfig): Promise<DeviceHandle | undefined>;
|
|
33
|
+
/** take a device out of its bridge; the shard map keeps the assignment for a later return */
|
|
34
|
+
removeDevice(key: string): Promise<void>;
|
|
35
|
+
/** start the bridges one after the other */
|
|
36
|
+
start(): Promise<void>;
|
|
37
|
+
stop(): Promise<void>;
|
|
38
|
+
info(): BridgeInfo[];
|
|
39
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/* The node manager: the process-wide matter.js environment (storage root, log level), n ≥ 1 bridges from
|
|
2
|
+
`config.bridges` in configuration order, and the devices placed into them through the shard map. 1.0
|
|
3
|
+
runs one bridge; nothing here assumes it. */
|
|
4
|
+
import { mkdir } from 'node:fs/promises';
|
|
5
|
+
import { join, resolve } from 'node:path';
|
|
6
|
+
import { Environment, Logger as MatterLogger, LogLevel as MatterLogLevel } from '@matter/main';
|
|
7
|
+
import { Bridge } from "./bridge.js";
|
|
8
|
+
import { CommissioningStore } from "./commissioning.js";
|
|
9
|
+
import { ShardMap } from "./shards.js";
|
|
10
|
+
export const MATTER_LEVELS = {
|
|
11
|
+
debug: MatterLogLevel.DEBUG,
|
|
12
|
+
info: MatterLogLevel.INFO,
|
|
13
|
+
notice: MatterLogLevel.NOTICE,
|
|
14
|
+
warn: MatterLogLevel.WARN,
|
|
15
|
+
error: MatterLogLevel.ERROR,
|
|
16
|
+
fatal: MatterLogLevel.FATAL,
|
|
17
|
+
};
|
|
18
|
+
let environmentPrepared = false;
|
|
19
|
+
/** matter.js reads the storage path from its default environment once per process */
|
|
20
|
+
export function prepareEnvironment(storagePath, matterLogLevel) {
|
|
21
|
+
MatterLogger.level = MATTER_LEVELS[matterLogLevel];
|
|
22
|
+
if (environmentPrepared) {
|
|
23
|
+
const current = Environment.default.vars.get('storage.path');
|
|
24
|
+
if (current !== storagePath) {
|
|
25
|
+
throw new Error(`matter.js storage is already ${String(current)}; it cannot change to ${storagePath} in this process`);
|
|
26
|
+
}
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
Environment.default.vars.set('storage.path', storagePath);
|
|
30
|
+
// the application owns SIGINT and SIGTERM: matter.js' own handler would cancel the nodes behind the back of
|
|
31
|
+
// the orderly stop, which then finds them closing, goes on and exits before their storage is closed
|
|
32
|
+
Environment.default.vars.set('runtime.signals', false);
|
|
33
|
+
environmentPrepared = true;
|
|
34
|
+
}
|
|
35
|
+
export class NodeManager {
|
|
36
|
+
storagePath;
|
|
37
|
+
options;
|
|
38
|
+
bridges = new Map();
|
|
39
|
+
placement = new Map();
|
|
40
|
+
shards;
|
|
41
|
+
log;
|
|
42
|
+
constructor(options) {
|
|
43
|
+
this.options = options;
|
|
44
|
+
this.storagePath = resolve(options.config.storage);
|
|
45
|
+
this.log = options.log;
|
|
46
|
+
}
|
|
47
|
+
bridge(id) {
|
|
48
|
+
return this.bridges.get(id);
|
|
49
|
+
}
|
|
50
|
+
allBridges() {
|
|
51
|
+
return [...this.bridges.values()];
|
|
52
|
+
}
|
|
53
|
+
/** the device's handle, wherever it lives */
|
|
54
|
+
handle(deviceKey) {
|
|
55
|
+
const bridgeId = this.placement.get(deviceKey);
|
|
56
|
+
return bridgeId === undefined ? undefined : this.bridges.get(bridgeId)?.handle(deviceKey);
|
|
57
|
+
}
|
|
58
|
+
/** every device handle, keyed by device key */
|
|
59
|
+
handles() {
|
|
60
|
+
const result = new Map();
|
|
61
|
+
for (const bridge of this.bridges.values()) {
|
|
62
|
+
for (const handle of bridge.devices()) {
|
|
63
|
+
result.set(handle.key, handle);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
/** create the bridges and place the enabled devices; nothing is online before `start()` */
|
|
69
|
+
async prepare() {
|
|
70
|
+
const { config, softwareVersion } = this.options;
|
|
71
|
+
await mkdir(this.storagePath, { recursive: true });
|
|
72
|
+
prepareEnvironment(this.storagePath, config.log.matter);
|
|
73
|
+
this.shards = await ShardMap.load(join(this.storagePath, 'shards.json'));
|
|
74
|
+
const commissioning = await CommissioningStore.load(join(this.storagePath, 'commissioning.json'));
|
|
75
|
+
let index = 0;
|
|
76
|
+
for (const [id, bridgeConfig] of Object.entries(config.bridges)) {
|
|
77
|
+
this.bridges.set(id, new Bridge({
|
|
78
|
+
id,
|
|
79
|
+
config: bridgeConfig,
|
|
80
|
+
vendorId: config.vendorId,
|
|
81
|
+
productId: (config.productId + index) & 0xffff,
|
|
82
|
+
softwareVersion,
|
|
83
|
+
commissioning: commissioning.resolve(id, {
|
|
84
|
+
passcode: bridgeConfig.passcode,
|
|
85
|
+
discriminator: bridgeConfig.discriminator,
|
|
86
|
+
}),
|
|
87
|
+
log: this.log.child(id),
|
|
88
|
+
}));
|
|
89
|
+
index++;
|
|
90
|
+
}
|
|
91
|
+
await commissioning.save();
|
|
92
|
+
for (const [key, device] of Object.entries(config.devices)) {
|
|
93
|
+
await this.place(key, device);
|
|
94
|
+
}
|
|
95
|
+
await this.shards.save();
|
|
96
|
+
}
|
|
97
|
+
async place(key, device) {
|
|
98
|
+
if (this.shards === undefined) {
|
|
99
|
+
throw new Error('prepare() first');
|
|
100
|
+
}
|
|
101
|
+
if (!device.enabled) {
|
|
102
|
+
this.log.info(`${key} is disabled`);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const order = Object.entries(this.options.config.bridges).map(([id, b]) => ({ id, maxDevices: b.maxDevices }));
|
|
106
|
+
const { bridgeId, moved } = this.shards.assign(key, order, device.bridge);
|
|
107
|
+
if (moved) {
|
|
108
|
+
this.log.warn(`${key} moved to bridge ${bridgeId}: controllers see a new device and lose its rooms and automations`);
|
|
109
|
+
}
|
|
110
|
+
const bridge = this.bridges.get(bridgeId);
|
|
111
|
+
if (bridge === undefined) {
|
|
112
|
+
// the map remembers a bridge that is no longer configured: keep the memory, use the first one
|
|
113
|
+
const fallback = this.bridges.values().next().value;
|
|
114
|
+
if (fallback === undefined) {
|
|
115
|
+
throw new Error('no bridge configured');
|
|
116
|
+
}
|
|
117
|
+
this.log.warn(`${key} is assigned to bridge "${bridgeId}", which is not configured; using "${fallback.id}" without changing the assignment`);
|
|
118
|
+
this.placement.set(key, fallback.id);
|
|
119
|
+
await fallback.addDevice(key, device);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
this.placement.set(key, bridgeId);
|
|
123
|
+
await bridge.addDevice(key, device);
|
|
124
|
+
}
|
|
125
|
+
/** add or replace a device while running: placed by the shard map, installed into its bridge at once */
|
|
126
|
+
async addDevice(key, device) {
|
|
127
|
+
if (this.shards === undefined) {
|
|
128
|
+
throw new Error('prepare() first');
|
|
129
|
+
}
|
|
130
|
+
await this.removeDevice(key);
|
|
131
|
+
await this.place(key, device);
|
|
132
|
+
await this.shards.save();
|
|
133
|
+
return this.handle(key);
|
|
134
|
+
}
|
|
135
|
+
/** take a device out of its bridge; the shard map keeps the assignment for a later return */
|
|
136
|
+
async removeDevice(key) {
|
|
137
|
+
const bridgeId = this.placement.get(key);
|
|
138
|
+
this.placement.delete(key);
|
|
139
|
+
if (bridgeId !== undefined) {
|
|
140
|
+
await this.bridges.get(bridgeId)?.removeDevice(key);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/** start the bridges one after the other */
|
|
144
|
+
async start() {
|
|
145
|
+
if (this.shards === undefined) {
|
|
146
|
+
await this.prepare();
|
|
147
|
+
}
|
|
148
|
+
for (const bridge of this.bridges.values()) {
|
|
149
|
+
await bridge.start();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async stop() {
|
|
153
|
+
for (const bridge of [...this.bridges.values()].reverse()) {
|
|
154
|
+
await bridge.stop();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
info() {
|
|
158
|
+
return this.allBridges().map((b) => b.info());
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=node-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-manager.js","sourceRoot":"","sources":["../../src/matter/node-manager.ts"],"names":[],"mappings":"AAAA;;+CAE+C;AAE/C,OAAO,EAAC,KAAK,EAAC,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAC,IAAI,EAAE,OAAO,EAAC,MAAM,WAAW,CAAC;AAExC,OAAO,EAAC,WAAW,EAAE,MAAM,IAAI,YAAY,EAAE,QAAQ,IAAI,cAAc,EAAC,MAAM,cAAc,CAAC;AAK7F,OAAO,EAAC,MAAM,EAAqC,MAAM,aAAa,CAAC;AACvE,OAAO,EAAC,kBAAkB,EAAC,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAC,QAAQ,EAAC,MAAM,aAAa,CAAC;AAQrC,MAAM,CAAC,MAAM,aAAa,GAAoD;IAC1E,KAAK,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OAAO,EAAE,CAAC;QACzB,CAAC;QACD,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;YACzC,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACzB,CAAC;IACL,CAAC;IAED,KAAK,CAAC,IAAI;QACN,KAAK,MAAM,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;YACxD,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QACxB,CAAC;IACL,CAAC;IAED,IAAI;QACA,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAClD,CAAC;CACJ"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface ShardBridge {
|
|
2
|
+
id: string;
|
|
3
|
+
/** 0 = unlimited */
|
|
4
|
+
maxDevices: number;
|
|
5
|
+
}
|
|
6
|
+
export declare class ShardMap {
|
|
7
|
+
private readonly file;
|
|
8
|
+
private readonly map;
|
|
9
|
+
private dirty;
|
|
10
|
+
constructor(file: string, entries?: Record<string, string>);
|
|
11
|
+
static load(file: string): Promise<ShardMap>;
|
|
12
|
+
get(deviceKey: string): string | undefined;
|
|
13
|
+
/** devices currently assigned to a bridge */
|
|
14
|
+
count(bridgeId: string): number;
|
|
15
|
+
/**
|
|
16
|
+
* The bridge for a device: the one configured on the device (an explicit move, recorded), else the
|
|
17
|
+
* remembered one, else the first bridge in order with room. `bridges` is in configuration order.
|
|
18
|
+
*/
|
|
19
|
+
assign(deviceKey: string, bridges: readonly ShardBridge[], explicit?: string): {
|
|
20
|
+
bridgeId: string;
|
|
21
|
+
moved: boolean;
|
|
22
|
+
};
|
|
23
|
+
/** persist when something changed; atomic through a temp file */
|
|
24
|
+
save(): Promise<void>;
|
|
25
|
+
toJSON(): Record<string, string>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/* The shard map: which bridge a device lives in. Written once when a device is first seen, persisted
|
|
2
|
+
next to matter.js' storage, never rebalanced — a device that moved between bridges would lose its
|
|
3
|
+
rooms and automations in every controller. With one bridge (1.0) every device lands in it; the map
|
|
4
|
+
exists from day one so the multi-bridge split (1.1) moves nothing. */
|
|
5
|
+
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
6
|
+
import { dirname } from 'node:path';
|
|
7
|
+
export class ShardMap {
|
|
8
|
+
file;
|
|
9
|
+
map;
|
|
10
|
+
dirty = false;
|
|
11
|
+
constructor(file, entries = {}) {
|
|
12
|
+
this.file = file;
|
|
13
|
+
this.map = new Map(Object.entries(entries));
|
|
14
|
+
}
|
|
15
|
+
static async load(file) {
|
|
16
|
+
try {
|
|
17
|
+
const text = await readFile(file, 'utf8');
|
|
18
|
+
const parsed = JSON.parse(text);
|
|
19
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
20
|
+
throw new Error('not an object');
|
|
21
|
+
}
|
|
22
|
+
const entries = {};
|
|
23
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
24
|
+
if (typeof value !== 'string') {
|
|
25
|
+
throw new Error(`"${key}" is not a bridge id`);
|
|
26
|
+
}
|
|
27
|
+
entries[key] = value;
|
|
28
|
+
}
|
|
29
|
+
return new ShardMap(file, entries);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (error.code === 'ENOENT') {
|
|
33
|
+
return new ShardMap(file);
|
|
34
|
+
}
|
|
35
|
+
throw new Error(`shard map ${file} is unreadable: ${error.message}`, { cause: error });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
get(deviceKey) {
|
|
39
|
+
return this.map.get(deviceKey);
|
|
40
|
+
}
|
|
41
|
+
/** devices currently assigned to a bridge */
|
|
42
|
+
count(bridgeId) {
|
|
43
|
+
let n = 0;
|
|
44
|
+
for (const id of this.map.values()) {
|
|
45
|
+
if (id === bridgeId) {
|
|
46
|
+
n++;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return n;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The bridge for a device: the one configured on the device (an explicit move, recorded), else the
|
|
53
|
+
* remembered one, else the first bridge in order with room. `bridges` is in configuration order.
|
|
54
|
+
*/
|
|
55
|
+
assign(deviceKey, bridges, explicit) {
|
|
56
|
+
const known = this.map.get(deviceKey);
|
|
57
|
+
if (explicit !== undefined) {
|
|
58
|
+
if (!bridges.some((b) => b.id === explicit)) {
|
|
59
|
+
throw new Error(`device "${deviceKey}" names bridge "${explicit}", which is not configured`);
|
|
60
|
+
}
|
|
61
|
+
if (known !== explicit) {
|
|
62
|
+
this.map.set(deviceKey, explicit);
|
|
63
|
+
this.dirty = true;
|
|
64
|
+
}
|
|
65
|
+
return { bridgeId: explicit, moved: known !== undefined && known !== explicit };
|
|
66
|
+
}
|
|
67
|
+
if (known !== undefined) {
|
|
68
|
+
return { bridgeId: known, moved: false };
|
|
69
|
+
}
|
|
70
|
+
const target = bridges.find((b) => b.maxDevices === 0 || this.count(b.id) < b.maxDevices) ?? bridges[bridges.length - 1];
|
|
71
|
+
if (target === undefined) {
|
|
72
|
+
throw new Error('no bridge configured');
|
|
73
|
+
}
|
|
74
|
+
this.map.set(deviceKey, target.id);
|
|
75
|
+
this.dirty = true;
|
|
76
|
+
return { bridgeId: target.id, moved: false };
|
|
77
|
+
}
|
|
78
|
+
/** persist when something changed; atomic through a temp file */
|
|
79
|
+
async save() {
|
|
80
|
+
if (!this.dirty) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
await mkdir(dirname(this.file), { recursive: true });
|
|
84
|
+
const tmp = `${this.file}.tmp`;
|
|
85
|
+
await writeFile(tmp, `${JSON.stringify(Object.fromEntries(this.map), null, 2)}\n`);
|
|
86
|
+
await rename(tmp, this.file);
|
|
87
|
+
this.dirty = false;
|
|
88
|
+
}
|
|
89
|
+
toJSON() {
|
|
90
|
+
return Object.fromEntries(this.map);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=shards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shards.js","sourceRoot":"","sources":["../../src/matter/shards.ts"],"names":[],"mappings":"AAAA;;;wEAGwE;AAExE,OAAO,EAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAC,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAQlC,MAAM,OAAO,QAAQ;IACA,IAAI,CAAS;IACb,GAAG,CAAsB;IAClC,KAAK,GAAG,KAAK,CAAC;IAEtB,YAAY,IAAY,EAAE,UAAkC,EAAE;QAC1D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IAChD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAY;QAC1B,IAAI,CAAC;YACD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAC1C,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACzC,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;gBACzE,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;YACrC,CAAC;YACD,MAAM,OAAO,GAA2B,EAAE,CAAC;YAC3C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAiC,CAAC,EAAE,CAAC;gBAC3E,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CA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C,SAAS,EAAE,IAAI,EAAC,CAAC,CAAC;QACnD,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,IAAI,MAAM,CAAC;QAC/B,MAAM,SAAS,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;QACnF,MAAM,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAED,MAAM;QACF,OAAO,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACxC,CAAC;CACJ"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface AttributeRef {
|
|
2
|
+
/** the cluster in matter.js' PascalCase, e.g. `OnOff` */
|
|
3
|
+
readonly cluster: string;
|
|
4
|
+
/** the attribute in lower camel case, e.g. `onOff` */
|
|
5
|
+
readonly attribute: string;
|
|
6
|
+
/** the behavior id matter.js uses as the state key, e.g. `onOff` */
|
|
7
|
+
readonly behaviorId: string;
|
|
8
|
+
}
|
|
9
|
+
export interface CommandRef {
|
|
10
|
+
readonly cluster: string;
|
|
11
|
+
/** the command in lower camel case, e.g. `stopMotion` */
|
|
12
|
+
readonly command: string;
|
|
13
|
+
readonly behaviorId: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function parseAttribute(text: string): AttributeRef;
|
|
16
|
+
export declare function parseCommand(text: string): CommandRef;
|
|
17
|
+
export declare function attributeKey(ref: AttributeRef): string;
|
|
18
|
+
export declare function commandKey(ref: CommandRef): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/* `Cluster.attribute` and `Cluster.command` references and matter.js' naming: the behavior id of a cluster
|
|
2
|
+
is its name in lower camel case (`OnOff` → `onOff`, `LevelControl` → `levelControl`), the attribute or
|
|
3
|
+
command name is used as is. */
|
|
4
|
+
import { ATTRIBUTE_PATTERN } from "./schema.js";
|
|
5
|
+
function behaviorIdOf(cluster) {
|
|
6
|
+
return cluster.charAt(0).toLowerCase() + cluster.slice(1);
|
|
7
|
+
}
|
|
8
|
+
export function parseAttribute(text) {
|
|
9
|
+
if (!ATTRIBUTE_PATTERN.test(text)) {
|
|
10
|
+
throw new Error(`invalid attribute reference "${text}" (expected Cluster.attribute, e.g. OnOff.onOff)`);
|
|
11
|
+
}
|
|
12
|
+
const [cluster, attribute] = text.split('.');
|
|
13
|
+
return { cluster, attribute, behaviorId: behaviorIdOf(cluster) };
|
|
14
|
+
}
|
|
15
|
+
export function parseCommand(text) {
|
|
16
|
+
if (!ATTRIBUTE_PATTERN.test(text)) {
|
|
17
|
+
throw new Error(`invalid command reference "${text}" (expected Cluster.command, e.g. WindowCovering.stopMotion)`);
|
|
18
|
+
}
|
|
19
|
+
const [cluster, command] = text.split('.');
|
|
20
|
+
return { cluster, command, behaviorId: behaviorIdOf(cluster) };
|
|
21
|
+
}
|
|
22
|
+
export function attributeKey(ref) {
|
|
23
|
+
return `${ref.cluster}.${ref.attribute}`;
|
|
24
|
+
}
|
|
25
|
+
export function commandKey(ref) {
|
|
26
|
+
return `${ref.cluster}.${ref.command}`;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=attribute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attribute.js","sourceRoot":"","sources":["../../src/model/attribute.ts"],"names":[],"mappings":"AAAA;;iCAEiC;AAEjC,OAAO,EAAC,iBAAiB,EAAC,MAAM,aAAa,CAAC;AAkB9C,SAAS,YAAY,CAAC,OAAe;IACjC,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAY;IACvC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,gCAAgC,IAAI,kDAAkD,CAAC,CAAC;IAC5G,CAAC;IACD,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAqB,CAAC;IACjE,OAAO,EAAC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,CAAC,OAAO,CAAC,EAAC,CAAC;AACnE,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,IAAY;IACrC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CACX,8BAA8B,IAAI,8DAA8D,CACnG,CAAC;IACN,CAAC;IACD,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAqB,CAAC;IAC/D,OAAO,EAAC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,YAAY,CAAC,OAAO,CAAC,EAAC,CAAC;AACjE,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,GAAiB;IAC1C,OAAO,GAAG,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,SAAS,EAAE,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,GAAe;IACtC,OAAO,GAAG,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Conformance } from '@matter/main/model';
|
|
2
|
+
export type Metatype = 'any' | 'boolean' | 'bitmap' | 'enum' | 'integer' | 'float' | 'bytes' | 'array' | 'object' | 'string' | 'date' | 'duration';
|
|
3
|
+
export interface FeatureInfo {
|
|
4
|
+
/** the specification's code, e.g. `LT` */
|
|
5
|
+
code: string;
|
|
6
|
+
/** the name matter.js and the config use, e.g. `Lighting` */
|
|
7
|
+
title: string;
|
|
8
|
+
}
|
|
9
|
+
export interface AttributeInfo {
|
|
10
|
+
/** lower camel case as matter.js names it, e.g. `currentLevel` */
|
|
11
|
+
name: string;
|
|
12
|
+
id: number;
|
|
13
|
+
metatype: Metatype;
|
|
14
|
+
nullable: boolean;
|
|
15
|
+
writable: boolean;
|
|
16
|
+
/** enum values by name (the model's PascalCase) */
|
|
17
|
+
enumMembers: ReadonlyMap<string, number> | undefined;
|
|
18
|
+
/** bitmap fields by name (lower camel, as matter.js' state object keys) with their bit */
|
|
19
|
+
bitFields: readonly {
|
|
20
|
+
name: string;
|
|
21
|
+
bit: number;
|
|
22
|
+
}[] | undefined;
|
|
23
|
+
min: number | undefined;
|
|
24
|
+
max: number | undefined;
|
|
25
|
+
/** the conformance under the cluster's feature set (titles or codes) */
|
|
26
|
+
applicability(features: Iterable<string>): Conformance.Applicability;
|
|
27
|
+
}
|
|
28
|
+
export interface CommandInfo {
|
|
29
|
+
/** lower camel case, e.g. `goToLiftPercentage` */
|
|
30
|
+
name: string;
|
|
31
|
+
id: number;
|
|
32
|
+
/** request field names in lower camel case, in order */
|
|
33
|
+
fields: readonly string[];
|
|
34
|
+
applicability(features: Iterable<string>): Conformance.Applicability;
|
|
35
|
+
}
|
|
36
|
+
export interface ClusterInfo {
|
|
37
|
+
name: string;
|
|
38
|
+
id: number;
|
|
39
|
+
/** the behavior id matter.js uses as the state key, e.g. `onOff` */
|
|
40
|
+
behaviorId: string;
|
|
41
|
+
features: readonly FeatureInfo[];
|
|
42
|
+
attributes: ReadonlyMap<string, AttributeInfo>;
|
|
43
|
+
commands: ReadonlyMap<string, CommandInfo>;
|
|
44
|
+
events: readonly string[];
|
|
45
|
+
/** `Lighting` or `LT` → `Lighting`; undefined for an unknown feature */
|
|
46
|
+
feature(nameOrCode: string): FeatureInfo | undefined;
|
|
47
|
+
}
|
|
48
|
+
export interface DeviceTypeClusterRequirement {
|
|
49
|
+
cluster: string;
|
|
50
|
+
mandatory: boolean;
|
|
51
|
+
/** feature titles the device type requires on this cluster (e.g. `Lighting` on a light's OnOff) */
|
|
52
|
+
features: readonly string[];
|
|
53
|
+
}
|
|
54
|
+
export interface DeviceTypeInfo {
|
|
55
|
+
name: string;
|
|
56
|
+
id: number;
|
|
57
|
+
revision: number;
|
|
58
|
+
classification: string;
|
|
59
|
+
/** the server clusters the device type names, mandatory and optional */
|
|
60
|
+
clusters: readonly DeviceTypeClusterRequirement[];
|
|
61
|
+
}
|
|
62
|
+
export declare function lowerCamel(name: string): string;
|
|
63
|
+
export declare function upperCamel(name: string): string;
|
|
64
|
+
/** the cluster by its PascalCase name (`OnOff`, `LevelControl`), or undefined */
|
|
65
|
+
export declare function cluster(name: string): ClusterInfo | undefined;
|
|
66
|
+
/** the device type by its name (`OnOffLight`, `PowerSource`), or undefined */
|
|
67
|
+
export declare function deviceType(name: string): DeviceTypeInfo | undefined;
|
|
68
|
+
/** every device type name the model knows, for the editor's picker */
|
|
69
|
+
export declare function deviceTypeNames(): string[];
|
|
70
|
+
export { Conformance };
|
|
71
|
+
/** command keys whose confirmation arrives on another attribute's status: decides the default of `optimistic` */
|
|
72
|
+
export declare const RELATED_STATUS: Readonly<Record<string, readonly string[]>>;
|
|
73
|
+
/** composite attributes the families own on top of the model; the value is an object of these fields */
|
|
74
|
+
export declare const COMPOSITE_ATTRIBUTES: Readonly<Record<string, {
|
|
75
|
+
cluster: string;
|
|
76
|
+
fields: readonly string[];
|
|
77
|
+
features: readonly string[];
|
|
78
|
+
description: string;
|
|
79
|
+
}>>;
|