mqtt2matter 0.2.0 → 0.3.1

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.
Files changed (61) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +1 -1
  3. package/dist/model/presets.d.ts +14 -1
  4. package/dist/model/presets.js +95 -17
  5. package/dist/model/presets.js.map +1 -1
  6. package/dist/server/fabrics.d.ts +42 -0
  7. package/dist/server/fabrics.js +50 -0
  8. package/dist/server/fabrics.js.map +1 -0
  9. package/dist/server/server.d.ts +19 -7
  10. package/dist/server/server.js +72 -8
  11. package/dist/server/server.js.map +1 -1
  12. package/dist/server/stats.d.ts +36 -0
  13. package/dist/server/stats.js +76 -0
  14. package/dist/server/stats.js.map +1 -0
  15. package/docs/api.md +21 -14
  16. package/docs/config.md +14 -5
  17. package/package.json +1 -1
  18. package/presets/mqtt-smarthome/button.json +1 -1
  19. package/presets/mqtt-smarthome/contact.json +1 -1
  20. package/presets/mqtt-smarthome/cover.json +1 -1
  21. package/presets/mqtt-smarthome/dimmer.json +1 -1
  22. package/presets/mqtt-smarthome/humidity.json +1 -1
  23. package/presets/mqtt-smarthome/light.json +1 -1
  24. package/presets/mqtt-smarthome/occupancy.json +1 -1
  25. package/presets/mqtt-smarthome/switch.json +1 -1
  26. package/presets/mqtt-smarthome/temperature.json +1 -1
  27. package/presets/openbeken/color-light.json +1 -1
  28. package/presets/openbeken/ct-light.json +1 -1
  29. package/presets/openbeken/dimmer.json +1 -1
  30. package/presets/openbeken/humidity.json +1 -1
  31. package/presets/openbeken/relay.json +1 -1
  32. package/presets/openbeken/temperature.json +1 -1
  33. package/presets/shelly-gen1/dimmer.json +1 -1
  34. package/presets/shelly-gen1/door-window.json +1 -1
  35. package/presets/shelly-gen1/ht.json +1 -1
  36. package/presets/shelly-gen1/relay-pm.json +1 -1
  37. package/presets/shelly-gen1/relay.json +1 -1
  38. package/presets/shelly-gen1/roller.json +1 -1
  39. package/presets/shelly-gen2/cover.json +1 -1
  40. package/presets/shelly-gen2/dimmer.json +1 -1
  41. package/presets/shelly-gen2/ht.json +1 -1
  42. package/presets/shelly-gen2/i4.json +1 -1
  43. package/presets/shelly-gen2/switch-pm.json +1 -1
  44. package/presets/shelly-gen2/switch.json +1 -1
  45. package/presets/tasmota/climate.json +1 -1
  46. package/presets/tasmota/color-light.json +1 -1
  47. package/presets/tasmota/ct-light.json +1 -1
  48. package/presets/tasmota/dimmer.json +1 -1
  49. package/presets/tasmota/relay.json +1 -1
  50. package/presets/tasmota/shutter.json +1 -1
  51. package/presets/tasmota/temperature-humidity.json +1 -1
  52. package/presets/tasmota/temperature.json +1 -1
  53. package/presets/valetudo/vacuum.json +1 -1
  54. package/presets/wled/dimmer.json +1 -1
  55. package/presets/wled/light.json +1 -1
  56. package/ui/dist/assets/index-1HdbTkGD.css +1 -0
  57. package/ui/dist/assets/index-CoG5Wu5Q.js +10 -0
  58. package/ui/dist/index.html +2 -2
  59. package/ui/dist/licenses.json +1 -0
  60. package/ui/dist/assets/index-BDtT6bdH.js +0 -10
  61. package/ui/dist/assets/index-CHiG-aoU.css +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,49 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.1
4
+
5
+ - **Fixed: creating a device from a preset replaced the device created before.** The dialog derived the key from
6
+ the device name, the presets' default names were generic ("Switch"), and `PUT /api/devices/:key` creates or
7
+ replaces — so the second device silently took the first one's place. Now the suggested key is never one a
8
+ device has (`switch`, `switch-2`, `switch-3`, …), a taken key is named and refused in the preset dialog, the
9
+ create dialog and the duplicate prompt, and the UI creates through the new `POST /api/devices` (`{key, device}`,
10
+ `409` when the key exists), which can never replace a device; `PUT` stays for edits.
11
+ - **Presets name the device after what identifies it** instead of a generic "Switch", "Relay" or "Light": the
12
+ mqtt-smarthome item with its slashes as spaces (`kitchen/light` → "kitchen light"), the Tasmota topic, the Shelly device id or MQTT prefix, the WLED topic,
13
+ the OpenBeken client, the Valetudo identifier — with the channel or relay index where the preset is one channel
14
+ of a device (`shellyplus2pm-… 1`, `plug-1 2`, `obk-th temperature`). A preset's default may reference other
15
+ variables (`"%item%"`), `%item|words%` with the value's slashes as spaces. In the dialog the name follows those
16
+ fields while you type, until you edit it yourself; a cleared name follows again.
17
+ - **Preset format**: a variable's `default` may reference other variables (`"default": "%topic% %index%"`);
18
+ where no value is given, the references are resolved from the other values and the result trimmed. A
19
+ reference to an undeclared variable or a cycle is a preset problem. An addition: every preset that was valid
20
+ stays valid and yields the same device.
21
+
22
+ ## 0.3.0
23
+
24
+ - The Presets page has a search box: every word must occur in a preset's name, vendor, id or description
25
+ ("shelly cover", "tasmota sensor"); the toolbar shows how many of the presets match.
26
+ - **A new top bar**: on the right, the GitHub link, **§** for the licences, the version, the statistics and a
27
+ gear for the Configuration page (no longer a tab).
28
+ - The **version** is a button with a popup: installed and latest version, "check for updates", "update to
29
+ vX" and the restart (they were the Version section of the Configuration page); a dot on the version says
30
+ an update is published.
31
+ - The **statistics** popup shows uptime, CPU, memory (RSS and heap), event loop utilisation and lag
32
+ (mean/max), devices, endpoints, bridges paired, controllers (fabrics), MQTT topics and MQTT messages per
33
+ second — from the new `GET /api/stats`, averaged over a 5-second window, polled only while the popup is
34
+ open.
35
+ - The **licences** dialog lists mqtt2matter's own licence and NOTICE and the licence of every third-party
36
+ package that ships — the runtime dependencies and what the UI bundle contains, with their licence texts.
37
+ The build generates the list (`ui/dist/licenses.json`) from `node_modules`; nothing is kept by hand.
38
+ - **Language and theme** moved to the top of the Configuration page ("Display"); they are still kept per
39
+ browser.
40
+ - **The fabrics on the Bridges page** say which controller each one belongs to — Apple Home, Apple Keychain (the
41
+ companion fabric Apple adds when the bridge is paired from Apple Home, with a hint saying so), Google Home,
42
+ Amazon Alexa, Home Assistant, SmartThings, Aqara, IKEA, Hue and more, by the root vendor id as the CSA's ledger
43
+ lists it — with the fabric's label, index and id, the bridge's and the controller's node ids, the compressed
44
+ fabric id, the active sessions and subscriptions, and the last contact. `GET /api/bridges` carries the new
45
+ fields.
46
+
3
47
  ## 0.2.0
4
48
 
5
49
  - **Presets for the mqtt-smarthome convention**: switch, light, dimmer, cover, contact, occupancy,
package/README.md CHANGED
@@ -129,7 +129,7 @@ is none, writes the unit and enables and starts it; running it again rewrites th
129
129
  say, or after an update that needs a new unit). `--install --dry-run` shows what it would write.
130
130
  `mqtt2matter --uninstall` removes the service and keeps the configuration and the storage.
131
131
 
132
- **Restart and update from the UI** (Configuration → Version) work under this service. A restart exits with code
132
+ **Restart and update from the UI** (the version number in the top bar) work under this service. A restart exits with code
133
133
  75, which the unit restarts on (`RestartForceExitStatus=75`) and counts as a clean stop
134
134
  (`SuccessExitStatus=75`). An update installs the registry's latest `mqtt2matter` the way it was installed,
135
135
  globally with npm — which the service user may not do: the UI only writes
@@ -1,6 +1,10 @@
1
1
  import { z } from 'zod';
2
2
  import { type DeviceConfig } from './schema.ts';
3
3
  export declare const PLACEHOLDER_PATTERN: RegExp;
4
+ /** a reference in a default: `%name%`, or `%name|words%` for the value with its slashes as spaces */
5
+ export declare const DEFAULT_REFERENCE_PATTERN: RegExp;
6
+ /** a referenced value as a default takes it: `words` turns `kitchen/ceiling` into `kitchen ceiling` */
7
+ export declare function referenceValue(value: string, modifier: string | undefined): string;
4
8
  export declare const PresetVariableSchema: z.ZodObject<{
5
9
  label: z.ZodString;
6
10
  description: z.ZodOptional<z.ZodString>;
@@ -28,8 +32,17 @@ export declare class PresetError extends Error {
28
32
  }
29
33
  /** the placeholders a preset's device template uses */
30
34
  export declare function placeholdersOf(preset: Preset): string[];
31
- /** parse a preset file's JSON; every placeholder must be declared in `variables` */
35
+ /**
36
+ * parse a preset file's JSON; every placeholder must be declared in `variables`, and a default may reference
37
+ * only declared variables, without a cycle
38
+ */
32
39
  export declare function parsePreset(raw: unknown): Preset;
40
+ /**
41
+ * The value of every variable: the given one, else its default with the references to other variables
42
+ * resolved the same way and the result trimmed, else empty for an optional one. A variable without a value,
43
+ * a default or `optional` is missing.
44
+ */
45
+ export declare function presetValues(preset: Preset, values: Record<string, string>): Record<string, string>;
33
46
  /**
34
47
  * The device entry a preset yields for the user's values. Values are substituted into the JSON text, so
35
48
  * they are escaped as JSON strings; a placeholder that forms a whole JSON string stays a string.
@@ -3,15 +3,24 @@
3
3
  values. The format is fixed here; the shipped presets for Tasmota, Shelly and ESPHome come later and
4
4
  users add their own as JSON files. A placeholder is `%name%`; `variables` declares each with a label
5
5
  and a default, so an editor can ask for them. Substitution is textual over the JSON of the template,
6
- so a placeholder can stand in a topic, a payload or a template string alike. */
6
+ so a placeholder can stand in a topic, a payload or a template string alike. A default may itself
7
+ name other variables (`"default": "%item%"`, `"%item|words%"` with the value's slashes as spaces): it is
8
+ resolved from their values when no value is given, so a device's default name can be what identifies it. */
7
9
  import { z } from 'zod';
8
10
  import { DeviceSchema } from "./schema.js";
9
11
  export const PLACEHOLDER_PATTERN = /%([A-Za-z_][A-Za-z0-9_]*)%/g;
12
+ /** a reference in a default: `%name%`, or `%name|words%` for the value with its slashes as spaces */
13
+ export const DEFAULT_REFERENCE_PATTERN = /%([A-Za-z_][A-Za-z0-9_]*)(?:\|(words))?%/g;
14
+ /** a referenced value as a default takes it: `words` turns `kitchen/ceiling` into `kitchen ceiling` */
15
+ export function referenceValue(value, modifier) {
16
+ return modifier === 'words' ? value.replace(/\//g, ' ').replace(/\s+/g, ' ').trim() : value;
17
+ }
10
18
  export const PresetVariableSchema = z
11
19
  .object({
12
20
  /** what the editor asks for */
13
21
  label: z.string().min(1),
14
22
  description: z.string().optional(),
23
+ /** may reference other variables (`%item%`): resolved from their values, then trimmed */
15
24
  default: z.string().optional(),
16
25
  /** no default and not optional: the user must fill it */
17
26
  optional: z.boolean().default(false),
@@ -49,7 +58,14 @@ export function placeholdersOf(preset) {
49
58
  }
50
59
  return [...names].sort();
51
60
  }
52
- /** parse a preset file's JSON; every placeholder must be declared in `variables` */
61
+ /** the variables a default references */
62
+ function referencesOf(text) {
63
+ return [...text.matchAll(DEFAULT_REFERENCE_PATTERN)].map((match) => match[1] ?? '');
64
+ }
65
+ /**
66
+ * parse a preset file's JSON; every placeholder must be declared in `variables`, and a default may reference
67
+ * only declared variables, without a cycle
68
+ */
53
69
  export function parsePreset(raw) {
54
70
  const result = PresetSchema.safeParse(raw);
55
71
  if (!result.success) {
@@ -60,33 +76,95 @@ export function parsePreset(raw) {
60
76
  if (undeclared.length > 0) {
61
77
  throw new PresetError(`preset ${preset.id}: placeholders without a variable: ${undeclared.join(', ')}`);
62
78
  }
79
+ for (const [name, variable] of Object.entries(preset.variables)) {
80
+ const references = referencesOf(variable.default ?? '');
81
+ const unknown = references.filter((ref) => !(ref in preset.variables));
82
+ if (unknown.length > 0) {
83
+ throw new PresetError(`preset ${preset.id}: the default of ${name} references undeclared variables: ${unknown.join(', ')}`);
84
+ }
85
+ }
86
+ const cycle = defaultCycle(preset);
87
+ if (cycle !== undefined) {
88
+ throw new PresetError(`preset ${preset.id}: the defaults reference each other in a cycle: ${cycle.join(' → ')}`);
89
+ }
63
90
  return preset;
64
91
  }
65
- function escapeForJson(value) {
66
- return JSON.stringify(value).slice(1, -1);
92
+ /** the first cycle among the defaults' references, as the names on it */
93
+ function defaultCycle(preset) {
94
+ const done = new Set();
95
+ const visit = (name, path) => {
96
+ const at = path.indexOf(name);
97
+ if (at >= 0) {
98
+ return [...path.slice(at), name];
99
+ }
100
+ if (done.has(name)) {
101
+ return undefined;
102
+ }
103
+ for (const ref of referencesOf(preset.variables[name]?.default ?? '')) {
104
+ const found = visit(ref, [...path, name]);
105
+ if (found !== undefined) {
106
+ return found;
107
+ }
108
+ }
109
+ done.add(name);
110
+ return undefined;
111
+ };
112
+ for (const name of Object.keys(preset.variables)) {
113
+ const found = visit(name, []);
114
+ if (found !== undefined) {
115
+ return found;
116
+ }
117
+ }
118
+ return undefined;
67
119
  }
68
120
  /**
69
- * The device entry a preset yields for the user's values. Values are substituted into the JSON text, so
70
- * they are escaped as JSON strings; a placeholder that forms a whole JSON string stays a string.
121
+ * The value of every variable: the given one, else its default with the references to other variables
122
+ * resolved the same way and the result trimmed, else empty for an optional one. A variable without a value,
123
+ * a default or `optional` is missing.
71
124
  */
72
- export function applyPreset(preset, values) {
125
+ export function presetValues(preset, values) {
73
126
  const missing = [];
74
- const filled = {};
75
- for (const [name, variable] of Object.entries(preset.variables)) {
76
- const value = values[name] ?? variable.default;
77
- if (value === undefined) {
78
- if (!variable.optional) {
79
- missing.push(name);
80
- }
81
- filled[name] = '';
127
+ const resolved = new Map();
128
+ const resolve = (name) => {
129
+ const known = resolved.get(name);
130
+ if (known !== undefined) {
131
+ return known;
132
+ }
133
+ const variable = preset.variables[name];
134
+ const given = values[name];
135
+ let value;
136
+ if (given !== undefined) {
137
+ value = given;
138
+ }
139
+ else if (variable?.default !== undefined) {
140
+ value = variable.default
141
+ .replace(DEFAULT_REFERENCE_PATTERN, (_m, ref, modifier) => referenceValue(resolve(ref), modifier))
142
+ .trim();
82
143
  }
83
144
  else {
84
- filled[name] = value;
145
+ if (variable !== undefined && !variable.optional) {
146
+ missing.push(name);
147
+ }
148
+ value = '';
85
149
  }
86
- }
150
+ resolved.set(name, value);
151
+ return value;
152
+ };
153
+ const filled = Object.fromEntries(Object.keys(preset.variables).map((name) => [name, resolve(name)]));
87
154
  if (missing.length > 0) {
88
155
  throw new PresetError(`preset ${preset.id}: missing values for ${missing.join(', ')}`);
89
156
  }
157
+ return filled;
158
+ }
159
+ function escapeForJson(value) {
160
+ return JSON.stringify(value).slice(1, -1);
161
+ }
162
+ /**
163
+ * The device entry a preset yields for the user's values. Values are substituted into the JSON text, so
164
+ * they are escaped as JSON strings; a placeholder that forms a whole JSON string stays a string.
165
+ */
166
+ export function applyPreset(preset, values) {
167
+ const filled = presetValues(preset, values);
90
168
  const text = JSON.stringify(preset.device).replace(PLACEHOLDER_PATTERN, (_m, name) => escapeForJson(filled[name] ?? ''));
91
169
  let raw;
92
170
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"presets.js","sourceRo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AC;IAC3B,OAAO,EAAC,GAAG,MAAM,EAAE,MAAM,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAC,EAAC,CAAC;AACjG,CAAC"}
@@ -0,0 +1,42 @@
1
+ /** root vendor id → the controller's name */
2
+ export declare const CONTROLLERS: ReadonlyMap<number, string>;
3
+ export declare function controllerName(vendorId: number): string | undefined;
4
+ /** a fabric as matter.js' FabricManager has it (the fields read here) */
5
+ export interface FabricSource {
6
+ fabricIndex: number;
7
+ fabricId: bigint | number;
8
+ nodeId: bigint | number;
9
+ rootNodeId: bigint | number;
10
+ rootVendorId: number;
11
+ globalId: bigint | number;
12
+ label: string;
13
+ }
14
+ /** a session as matter.js' SessionsBehavior has it (the fields read here) */
15
+ export interface SessionSource {
16
+ fabric?: {
17
+ fabricIndex: number;
18
+ } | undefined;
19
+ isPeerActive: boolean;
20
+ lastInteractionTimestamp: number | undefined;
21
+ numberOfActiveSubscriptions: number;
22
+ }
23
+ export interface FabricJson {
24
+ index: number;
25
+ label: string;
26
+ vendorId: number;
27
+ /** the controller, when the vendor id is a known one */
28
+ vendorName: string | undefined;
29
+ /** the bridge's node id in this fabric */
30
+ nodeId: string;
31
+ /** the controller's own node id (the root's) */
32
+ rootNodeId: string;
33
+ fabricId: string;
34
+ /** the compressed fabric id, hex: the first half of the bridge's operational mDNS name in this fabric */
35
+ compressedFabricId: string;
36
+ /** sessions of the controller whose peer is active */
37
+ sessions: number;
38
+ subscriptions: number;
39
+ /** ms since the epoch: the last interaction over any session of this fabric */
40
+ lastInteraction: number | undefined;
41
+ }
42
+ export declare function fabricJson(fabric: FabricSource, sessions: readonly SessionSource[]): FabricJson;
@@ -0,0 +1,50 @@
1
+ /* What the Bridges page shows of a fabric: the controller by its root vendor id, the ids, and the
2
+ sessions matter.js holds for it. A fabric is one controller's (one ecosystem's) pairing of the bridge;
3
+ the vendor id of its root certificate names the ecosystem. The table holds the controllers people pair
4
+ bridges with; every id is the one the CSA's Distributed Compliance Ledger lists for that vendor. */
5
+ /** root vendor id → the controller's name */
6
+ export const CONTROLLERS = new Map([
7
+ [0x1349, 'Apple Home'],
8
+ // Apple adds a second fabric for the iCloud Keychain when the bridge is paired from Apple Home
9
+ [0x1384, 'Apple Keychain'],
10
+ [0x6006, 'Google Home'],
11
+ [0x1217, 'Amazon Alexa'],
12
+ [0x134b, 'Home Assistant'],
13
+ [0x110a, 'Samsung SmartThings'],
14
+ [0x115f, 'Aqara'],
15
+ [0x117c, 'IKEA'],
16
+ [0x100b, 'Philips Hue (Signify)'],
17
+ [0x125d, 'Tuya'],
18
+ [0x126e, 'Xiaomi'],
19
+ [0x1286, 'eWeLink (CoolKit)'],
20
+ [0x1490, 'Shelly'],
21
+ [0x1488, 'Flic'],
22
+ // the test vendor ids of the specification: chip-tool, matter.js' own controller, development builds
23
+ [0xfff1, 'Test vendor'],
24
+ [0xfff2, 'Test vendor'],
25
+ [0xfff3, 'Test vendor'],
26
+ [0xfff4, 'Test vendor'],
27
+ ]);
28
+ export function controllerName(vendorId) {
29
+ return CONTROLLERS.get(vendorId);
30
+ }
31
+ const hex16 = (value) => BigInt(value).toString(16).toUpperCase().padStart(16, '0');
32
+ export function fabricJson(fabric, sessions) {
33
+ const own = sessions.filter((s) => s.fabric?.fabricIndex === fabric.fabricIndex);
34
+ const active = own.filter((s) => s.isPeerActive);
35
+ const last = own.map((s) => s.lastInteractionTimestamp ?? 0).reduce((a, b) => Math.max(a, b), 0);
36
+ return {
37
+ index: fabric.fabricIndex,
38
+ label: fabric.label,
39
+ vendorId: fabric.rootVendorId,
40
+ vendorName: controllerName(fabric.rootVendorId),
41
+ nodeId: String(fabric.nodeId),
42
+ rootNodeId: String(fabric.rootNodeId),
43
+ fabricId: String(fabric.fabricId),
44
+ compressedFabricId: hex16(fabric.globalId),
45
+ sessions: active.length,
46
+ subscriptions: own.reduce((sum, s) => sum + s.numberOfActiveSubscriptions, 0),
47
+ lastInteraction: last > 0 ? last : undefined,
48
+ };
49
+ }
50
+ //# sourceMappingURL=fabrics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fabrics.js","sourceRoot":"","sources":["../../src/server/fabrics.ts"],"names":[],"mappings":"AAAA;;;sGAGsG;AAEtG,6CAA6C;AAC7C,MAAM,CAAC,MAAM,WAAW,GAAgC,IAAI,GAAG,CAAC;IAC5D,CAAC,MAAM,EAAE,YAAY,CAAC;IACtB,+FAA+F;IAC/F,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAC1B,CAAC,MAAM,EAAE,aAAa,CAAC;IACvB,CAAC,MAAM,EAAE,cAAc,CAAC;IACxB,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAC1B,CAAC,MAAM,EAAE,qBAAqB,CAAC;IAC/B,CAAC,MAAM,EAAE,OAAO,CAAC;IACjB,CAAC,MAAM,EAAE,MAAM,CAAC;IAChB,CAAC,MAAM,EAAE,uBAAuB,CAAC;IACjC,CAAC,MAAM,EAAE,MAAM,CAAC;IAChB,CAAC,MAAM,EAAE,QAAQ,CAAC;IAClB,CAAC,MAAM,EAAE,mBAAmB,CAAC;IAC7B,CAAC,MAAM,EAAE,QAAQ,CAAC;IAClB,CAAC,MAAM,EAAE,MAAM,CAAC;IAChB,qGAAqG;IACrG,CAAC,MAAM,EAAE,aAAa,CAAC;IACvB,CAAC,MAAM,EAAE,aAAa,CAAC;IACvB,CAAC,MAAM,EAAE,aAAa,CAAC;IACvB,CAAC,MAAM,EAAE,aAAa,CAAC;CAC1B,CAAC,CAAC;AAEH,MAAM,UAAU,cAAc,CAAC,QAAgB;IAC3C,OAAO,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC;AAyCD,MAAM,KAAK,GAAG,CAAC,KAAsB,EAAU,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EA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CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;KAC/C,CAAC;AACN,CAAC"}
@@ -2,10 +2,12 @@ import type { App } from '../app.ts';
2
2
  import type { Logger } from '../log.ts';
3
3
  import { type DeviceConfig } from '../model/schema.ts';
4
4
  import type { ConfigStore } from './config-store.ts';
5
+ import { type FabricJson } from './fabrics.ts';
5
6
  import { Auth } from './auth.ts';
6
7
  import { Updater } from './update.ts';
7
8
  import type { Importer } from './importers.ts';
8
9
  import type { LogBuffer } from './log-buffer.ts';
10
+ import { type RuntimeFigures } from './stats.ts';
9
11
  export interface ServerOptions {
10
12
  app: App;
11
13
  store: ConfigStore;
@@ -52,16 +54,21 @@ export interface BridgeJson {
52
54
  qrPairingCode: string;
53
55
  } | undefined;
54
56
  devices: number;
55
- fabrics: {
56
- index: number;
57
- label: string;
58
- vendorId: number;
59
- nodeId: string;
60
- fabricId: string;
61
- }[];
57
+ fabrics: FabricJson[];
62
58
  /** 0 closed, 1 enhanced, 2 basic (the AdministratorCommissioning window status) */
63
59
  windowStatus: number;
64
60
  }
61
+ export interface StatsJson extends RuntimeFigures {
62
+ devices: number;
63
+ endpoints: number;
64
+ bridges: number;
65
+ bridgesCommissioned: number;
66
+ /** the controllers paired, over all bridges */
67
+ fabrics: number;
68
+ mqttConnected: boolean;
69
+ /** the topics in the cache (everything the bridge subscribed to and saw) */
70
+ mqttTopics: number;
71
+ }
65
72
  /** the package's `ui/dist`, from `src/server/` or `dist/server/` alike */
66
73
  export declare const UI_DIST: string;
67
74
  export declare class Server {
@@ -77,6 +84,7 @@ export declare class Server {
77
84
  private readonly startedAt;
78
85
  private readonly auth;
79
86
  private readonly updater;
87
+ private readonly stats;
80
88
  constructor(options: ServerOptions);
81
89
  /** the bound port */
82
90
  get port(): number;
@@ -94,6 +102,10 @@ export declare class Server {
94
102
  /** save a device (compact in the file, parsed in the app), build it, tell the clients */
95
103
  private saveDevice;
96
104
  private removeDevice;
105
+ /** the statistics popup: the process figures and what the bridge holds; cheap, no Matter round trip */
106
+ private statsJson;
107
+ /** the sessions matter.js holds on a bridge node; none while the node is not up */
108
+ private sessionsOf;
97
109
  private bridgesJson;
98
110
  private bridgeNode;
99
111
  private importers;
@@ -14,11 +14,13 @@ import { validateDevice } from "../model/validate.js";
14
14
  import { catalogJson, clusterJson } from "./catalog.js";
15
15
  import { compactDevice } from "./compact.js";
16
16
  import { EventHub } from "./events.js";
17
+ import { fabricJson } from "./fabrics.js";
17
18
  import { AuthConfigSchema } from "../config/schema.js";
18
19
  import { Auth, hashPassword } from "./auth.js";
19
20
  import { HttpError, Router, sendJson, serveStatic } from "./http.js";
20
21
  import { Updater } from "./update.js";
21
22
  import { loadPresets } from "./presets.js";
23
+ import { RuntimeStats } from "./stats.js";
22
24
  import { previewCommand, previewStatus } from "./preview.js";
23
25
  /** the package's `ui/dist`, from `src/server/` or `dist/server/` alike */
24
26
  export const UI_DIST = resolve(new URL('../../ui/dist', import.meta.url).pathname);
@@ -52,6 +54,7 @@ export class Server {
52
54
  startedAt = Date.now();
53
55
  auth;
54
56
  updater;
57
+ stats = new RuntimeStats();
55
58
  constructor(options) {
56
59
  this.options = options;
57
60
  this.app = options.app;
@@ -96,6 +99,7 @@ export class Server {
96
99
  }
97
100
  });
98
101
  this.routes();
102
+ this.stats.start();
99
103
  }
100
104
  /** the bound port */
101
105
  get port() {
@@ -135,6 +139,7 @@ export class Server {
135
139
  importer.load(this.app.mqtt.cache);
136
140
  }
137
141
  const onMessage = (topic, payload, retain) => {
142
+ this.stats.count();
138
143
  this.hub.broadcast({
139
144
  type: 'mqtt',
140
145
  topic,
@@ -189,6 +194,7 @@ export class Server {
189
194
  }
190
195
  }
191
196
  async close() {
197
+ this.stats.stop();
192
198
  for (const off of this.unsubscribe.splice(0)) {
193
199
  off();
194
200
  }
@@ -345,18 +351,63 @@ export class Server {
345
351
  this.hub.broadcast({ type: 'devices' });
346
352
  }
347
353
  // ── bridges ────────────────────────────────────────────────────────────────────────────────────
354
+ /** the statistics popup: the process figures and what the bridge holds; cheap, no Matter round trip */
355
+ statsJson() {
356
+ const devices = Object.values(this.app.config.devices);
357
+ const bridges = this.app.nodes.allBridges();
358
+ let fabrics = 0;
359
+ for (const bridge of bridges) {
360
+ const node = bridge.serverNode;
361
+ if (node !== undefined) {
362
+ try {
363
+ fabrics += node.env.get(FabricManager).length;
364
+ }
365
+ catch {
366
+ // the node is not up yet
367
+ }
368
+ }
369
+ }
370
+ return {
371
+ ...this.stats.figures(),
372
+ devices: devices.length,
373
+ endpoints: devices.reduce((sum, device) => sum + device.endpoints.length, 0),
374
+ bridges: bridges.length,
375
+ bridgesCommissioned: bridges.filter((bridge) => bridge.info().commissioned).length,
376
+ fabrics,
377
+ mqttConnected: this.app.mqtt.connected,
378
+ mqttTopics: this.app.mqtt.cache.size,
379
+ };
380
+ }
381
+ /** the sessions matter.js holds on a bridge node; none while the node is not up */
382
+ sessionsOf(node) {
383
+ try {
384
+ return Object.values(node.state.sessions.sessions).map((session) => ({
385
+ fabric: session.fabric === undefined ? undefined : { fabricIndex: Number(session.fabric.fabricIndex) },
386
+ isPeerActive: session.isPeerActive,
387
+ lastInteractionTimestamp: session.lastInteractionTimestamp,
388
+ numberOfActiveSubscriptions: session.numberOfActiveSubscriptions,
389
+ }));
390
+ }
391
+ catch {
392
+ return [];
393
+ }
394
+ }
348
395
  bridgesJson() {
349
396
  return this.app.nodes.allBridges().map((bridge) => {
350
397
  const node = bridge.serverNode;
351
- const fabrics = node === undefined
352
- ? []
353
- : node.env.get(FabricManager).map((f) => ({
354
- index: Number(f.fabricIndex),
398
+ let fabrics = [];
399
+ if (node !== undefined) {
400
+ const sessions = this.sessionsOf(node);
401
+ fabrics = node.env.get(FabricManager).map((f) => fabricJson({
402
+ fabricIndex: Number(f.fabricIndex),
403
+ fabricId: f.fabricId,
404
+ nodeId: f.nodeId,
405
+ rootNodeId: f.rootNodeId,
406
+ rootVendorId: f.rootVendorId,
407
+ globalId: f.globalId,
355
408
  label: f.label,
356
- vendorId: f.rootVendorId,
357
- nodeId: String(f.nodeId),
358
- fabricId: String(f.fabricId),
359
- }));
409
+ }, sessions));
410
+ }
360
411
  let windowStatus = 0;
361
412
  if (node !== undefined) {
362
413
  try {
@@ -509,6 +560,7 @@ export class Server {
509
560
  importers: this.importers().map((i) => i.kind),
510
561
  update: this.updater.known,
511
562
  }));
563
+ r.add('GET', '/api/stats', () => this.statsJson());
512
564
  r.add('GET', '/api/update', async (request) => {
513
565
  await this.updater.check(request.query.get('check') === '1');
514
566
  return await this.updater.status();
@@ -559,6 +611,18 @@ export class Server {
559
611
  });
560
612
  this.authRoutes();
561
613
  r.add('GET', '/api/devices', () => this.listDevices());
614
+ r.add('POST', '/api/devices', async (request, response) => {
615
+ // create only: an existing key is 409, so no client replaces a device by accident (PUT does)
616
+ const b = body(request);
617
+ const key = b.key;
618
+ if (typeof key !== 'string' || key === '') {
619
+ throw new HttpError(400, 'expected {key, device}');
620
+ }
621
+ if (this.app.config.devices[key] !== undefined) {
622
+ throw new HttpError(409, `a device with the key ${key} exists already`, { key });
623
+ }
624
+ sendJson(response, 201, await this.saveDevice(key, b.device));
625
+ });
562
626
  r.add('GET', '/api/devices/:key', (request) => this.deviceJson(request.params.key ?? ''));
563
627
  r.add('PUT', '/api/devices/:key', async (request) => {
564
628
  return await this.saveDevice(request.params.key ?? '', request.body);