@camstack/addon-provider-homematic 1.2.209 → 1.2.210

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 (19) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/.bundle-modules.json +11 -6
  3. package/dist/_stub.js +2791 -1972
  4. package/dist/{_virtual_mf-localSharedImportMap___mfe_internal__addon_provider_homematic_page-B8JEAJoX.mjs → _virtual_mf-localSharedImportMap___mfe_internal__addon_provider_homematic_page-DqBsgmV2.mjs} +4 -4
  5. package/dist/_virtual_mf___mfe_internal__addon_provider_homematic_page__loadShare___mf_0_camstack_mf_1_ui_mf_2_library__loadShare__.js-BkwWlzBp.mjs +26 -0
  6. package/dist/addon-provider-homematic.css +1 -1
  7. package/dist/addon.js +440 -237
  8. package/dist/addon.mjs +440 -237
  9. package/dist/{hostInit-dkdwmlIf.mjs → hostInit-Veh_hTYB.mjs} +3 -3
  10. package/dist/remoteEntry.js +1 -1
  11. package/dist/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__addon_provider_homematic_page__remoteEntry_js-D2zDM5LH.mjs → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__addon_provider_homematic_page__remoteEntry_js-B6NDlkw9.mjs} +1 -1
  12. package/dist/widgets/_stub.js +222 -48
  13. package/dist/widgets/{_virtual_mf-localSharedImportMap___mfe_internal__addon_provider_homematic_widgets-CR6dsJ2l.mjs → _virtual_mf-localSharedImportMap___mfe_internal__addon_provider_homematic_widgets-D4FsZKYN.mjs} +2 -2
  14. package/dist/widgets/_virtual_mf___mfe_internal__addon_provider_homematic_widgets__loadShare___mf_0_camstack_mf_1_ui_mf_2_library__loadShare__.js-dFo8NWrS.mjs +26 -0
  15. package/dist/widgets/{hostInit-C1PiC4_E.mjs → hostInit-xLDLUgao.mjs} +2 -2
  16. package/dist/widgets/remoteEntry.js +1 -1
  17. package/package.json +3 -3
  18. package/dist/_virtual_mf___mfe_internal__addon_provider_homematic_page__loadShare___mf_0_camstack_mf_1_ui_mf_2_library__loadShare__.js-DUSr1RDG.mjs +0 -26
  19. package/dist/widgets/_virtual_mf___mfe_internal__addon_provider_homematic_widgets__loadShare___mf_0_camstack_mf_1_ui_mf_2_library__loadShare__.js-DkWTmjd2.mjs +0 -26
package/dist/addon.js CHANGED
@@ -27025,7 +27025,12 @@ var TargetKindTextCapsSchema = object({
27025
27025
  title: boolean(),
27026
27026
  body: boolean()
27027
27027
  });
27028
- _enum([
27028
+ /**
27029
+ * The message fields a rule can author for a target (#483). Derived from a
27030
+ * kind's caps by `deliverableFields` — the ONE reading of the declaration, used
27031
+ * by the dispatcher (drop), the admin rule editor (show) and the viewer.
27032
+ */
27033
+ var NotificationFieldSchema = _enum([
27029
27034
  "title",
27030
27035
  "body",
27031
27036
  "attachments",
@@ -66088,9 +66093,10 @@ object({
66088
66093
  /** Longest silence a push integration may keep before the core re-reads it and asks it to resubscribe. */
66089
66094
  heartbeatMs: number$1().int().positive().optional(),
66090
66095
  /**
66091
- * Bumped by the provider each time its push subscription reconnected on its
66092
- * own. A change makes the core re-read every device of the integration
66093
- * (pushes lost while it was down; events may be dropped, D8).
66096
+ * Changes on every reconnect of the provider's push subscription; any change
66097
+ * makes the core read every device of the integration once (pushes lost while
66098
+ * it was down; events may be dropped, D8). It need not grow: a provider whose
66099
+ * counter restarts with its process is still understood.
66094
66100
  */
66095
66101
  connectionEpoch: number$1().int().nonnegative().optional()
66096
66102
  });
@@ -66115,15 +66121,28 @@ var DeviceStateRefreshInputSchema = object({
66115
66121
  var DeviceStateResubscribeInputSchema = object({ deviceId: number$1().int().nonnegative() });
66116
66122
  var DeviceStateRefreshResultSchema = object({ ok: literal(true) });
66117
66123
  var NOT_OPERATOR_FACING = "the core schedules state refreshes itself; an operator never asks for one";
66118
- method(DeviceStateRefreshInputSchema, DeviceStateRefreshResultSchema, {
66119
- kind: "mutation",
66120
- auth: "admin",
66121
- notOperatorFacing: NOT_OPERATOR_FACING
66122
- }), method(DeviceStateResubscribeInputSchema, DeviceStateRefreshResultSchema, {
66123
- kind: "mutation",
66124
- auth: "admin",
66125
- notOperatorFacing: NOT_OPERATOR_FACING
66126
- });
66124
+ var deviceStateRefreshCapability = {
66125
+ name: "device-state-refresh",
66126
+ scope: "device",
66127
+ deviceNative: true,
66128
+ mode: "singleton",
66129
+ methods: {
66130
+ refresh: method(DeviceStateRefreshInputSchema, DeviceStateRefreshResultSchema, {
66131
+ kind: "mutation",
66132
+ auth: "admin",
66133
+ notOperatorFacing: NOT_OPERATOR_FACING
66134
+ }),
66135
+ resubscribe: method(DeviceStateResubscribeInputSchema, DeviceStateRefreshResultSchema, {
66136
+ kind: "mutation",
66137
+ auth: "admin",
66138
+ notOperatorFacing: NOT_OPERATOR_FACING
66139
+ })
66140
+ },
66141
+ vocabulary: {
66142
+ noun: t("State refresh", "Aggiornamento dello stato"),
66143
+ order: 3247
66144
+ }
66145
+ };
66127
66146
  /**
66128
66147
  * Generic device-level status snapshot. Auto-registered by `BaseDevice`
66129
66148
  * for every device, regardless of provider — the kernel needs a uniform
@@ -83719,6 +83738,15 @@ var NcRuleInputSchema = object({
83719
83738
  */
83720
83739
  askVerdict: boolean().optional(),
83721
83740
  /**
83741
+ * An ALERT notification (`alert-critical`, `alert-error`, device attention)
83742
+ * carries the alert's own action — an open-URL button and, for an `invoke`
83743
+ * action, a token-authed button that runs it. Absent and `true` mean ON;
83744
+ * `false` switches it off for this rule. `.optional()`, never `.default()`
83745
+ * (a Zod default does not run on the addon cap path), so a rule authored
83746
+ * before this field keeps the action.
83747
+ */
83748
+ offerAlertAction: boolean().optional(),
83749
+ /**
83722
83750
  * Operator tags (D1054), kept on the rule like a core block's. Absent = no
83723
83751
  * tags. `.optional()`, never `.default()`: a partial `updateRule` patch that
83724
83752
  * does not name `tags` keeps the stored ones (the store merges), and an
@@ -118933,6 +118961,14 @@ object({
118933
118961
  nodeId: string().optional(),
118934
118962
  /** The alert's own action link (where the operator acts on it), when it has one. */
118935
118963
  actionUrl: string().optional(),
118964
+ /**
118965
+ * The alert's WHOLE action — label, link, navigation and `invoke` — on a
118966
+ * raised episode, so a notification can offer it (an absolute open-URL
118967
+ * button, a token-authed invoke button). `actionUrl` stays for the
118968
+ * `{{actionUrl}}` template variable. Additive: an episode published before
118969
+ * this field has none.
118970
+ */
118971
+ action: AlertActionSchema.optional(),
118936
118972
  /** A device fault episode: every active fault (`metadata.faults`), principal first. */
118937
118973
  faults: array(DeviceFaultSchema).optional(),
118938
118974
  at: number$1()
@@ -120161,6 +120197,34 @@ object({
120161
120197
  delay: number$1().nonnegative().optional(),
120162
120198
  commands: record$1(string(), unknown$1())
120163
120199
  });
120200
+ /** When a member receives: always, inside a schedule, or while an alarm panel is in a state. */
120201
+ var GroupMemberWhenSchema = discriminatedUnion("kind", [
120202
+ object({ kind: literal("always") }),
120203
+ object({
120204
+ kind: literal("schedule"),
120205
+ schedule: NcScheduleSchema
120206
+ }),
120207
+ object({
120208
+ kind: literal("alarm"),
120209
+ deviceId: number$1().int().nonnegative(),
120210
+ states: array(AlarmStateSchema).min(1)
120211
+ })
120212
+ ]);
120213
+ object({
120214
+ targetId: string().min(1),
120215
+ enabled: boolean().optional(),
120216
+ when: GroupMemberWhenSchema.optional(),
120217
+ /** Which message fields this member receives. Absent = all of them. */
120218
+ fields: array(NotificationFieldSchema).optional(),
120219
+ /** `{{title}}`, `{{body}}`, `{{priority}}` and any `{{key}}` of the notification's metadata. */
120220
+ templates: object({
120221
+ title: string().optional(),
120222
+ body: string().optional()
120223
+ }).optional(),
120224
+ minPriority: number$1().int().min(1).max(5).optional(),
120225
+ /** At most one delivery per window; a burst becomes one. 0 or absent = no throttle. */
120226
+ throttleSec: number$1().int().nonnegative().optional()
120227
+ });
120164
120228
  //#endregion
120165
120229
  //#region src/devices/hm-cold-start.ts
120166
120230
  /**
@@ -121089,6 +121153,277 @@ function buildCcuDevicesHandlers(deps) {
121089
121153
  } };
121090
121154
  }
121091
121155
  //#endregion
121156
+ //#region src/homematic-fault-mapping.ts
121157
+ /**
121158
+ * PURE mapping of what a CCU reports as faulty to `error` cap readings, with no
121159
+ * session and no I/O: the WatchDog system variables of the box, and the
121160
+ * MAINTENANCE service flags of one device.
121161
+ *
121162
+ * A reading is UNKNOWN (`active: null`, the cold slice) until the CCU has said
121163
+ * something about the flags; "no fault" is only ever written from a value that
121164
+ * was read (D315, D393).
121165
+ *
121166
+ * The cap's `label` is a plain string the provider translates, and the server
121167
+ * has no per-operator language: the label carries the English words, and the
121168
+ * Italian beside it stays in the table for the surface that can pick one.
121169
+ */
121170
+ /** The two languages of one fault, side by side so neither is forgotten. */
121171
+ function words(en, it) {
121172
+ return {
121173
+ en,
121174
+ it
121175
+ };
121176
+ }
121177
+ var SEVERITY_ORDER = {
121178
+ error: 0,
121179
+ warning: 1
121180
+ };
121181
+ function toFault(rule) {
121182
+ return {
121183
+ code: rule.key,
121184
+ label: rule.words.en,
121185
+ severity: rule.severity
121186
+ };
121187
+ }
121188
+ /** Errors first, then warnings; the order inside a tier is the rule order. */
121189
+ function rank(faults) {
121190
+ return [...faults].sort((a, b) => SEVERITY_ORDER[a.severity] - SEVERITY_ORDER[b.severity]);
121191
+ }
121192
+ function reading(faults, now) {
121193
+ const ranked = rank(faults);
121194
+ const principal = ranked[0];
121195
+ if (principal === void 0) return {
121196
+ ...ERROR_STATUS_COLD,
121197
+ active: false,
121198
+ faults: [],
121199
+ lastFetchedAt: now
121200
+ };
121201
+ return {
121202
+ active: true,
121203
+ code: principal.code,
121204
+ label: principal.label,
121205
+ severity: principal.severity,
121206
+ since: null,
121207
+ faults: ranked,
121208
+ lastFetchedAt: now
121209
+ };
121210
+ }
121211
+ function unknown(now) {
121212
+ return {
121213
+ ...ERROR_STATUS_COLD,
121214
+ lastFetchedAt: now
121215
+ };
121216
+ }
121217
+ /** A LOGIC value as the CCU hands it over: a boolean, 0/1, or its text. `null` is unread. */
121218
+ function truthy(value) {
121219
+ if (value === null) return null;
121220
+ if (typeof value === "boolean") return value;
121221
+ if (typeof value === "number") return value !== 0;
121222
+ const text = value.trim().toLowerCase();
121223
+ return text === "true" || text === "1" || text === "on" || text === "yes";
121224
+ }
121225
+ /** The WatchDog add-on names its variables "SV WatchDog: <key>". */
121226
+ var WATCHDOG_PREFIX = /^sv\s*watchdog\s*:\s*/i;
121227
+ var WATCHDOG_FAULTS = [
121228
+ {
121229
+ key: "hb-rf-eth-connection",
121230
+ severity: "error",
121231
+ words: words("HB-RF-ETH connection lost", "Connessione HB-RF-ETH persa")
121232
+ },
121233
+ {
121234
+ key: "low-voltage",
121235
+ severity: "error",
121236
+ words: words("CCU supply voltage low", "Tensione di alimentazione della CCU bassa")
121237
+ },
121238
+ {
121239
+ key: "rfd-restart",
121240
+ severity: "warning",
121241
+ words: words("The radio service restarted", "Il servizio radio si è riavviato")
121242
+ },
121243
+ {
121244
+ key: "regahss-restart",
121245
+ severity: "warning",
121246
+ words: words("The ReGa service restarted", "Il servizio ReGa si è riavviato")
121247
+ },
121248
+ {
121249
+ key: "no-internet",
121250
+ severity: "warning",
121251
+ words: words("The CCU has no internet", "La CCU non ha internet")
121252
+ },
121253
+ {
121254
+ key: "unclean-shutdown",
121255
+ severity: "warning",
121256
+ words: words("The CCU shut down uncleanly", "La CCU si è spenta in modo anomalo")
121257
+ }
121258
+ ];
121259
+ /** Which WatchDog fault a system variable is, or `null` when it is not one of them. */
121260
+ function watchdogRuleOf(name) {
121261
+ const key = name.trim().replace(WATCHDOG_PREFIX, "").trim().toLowerCase();
121262
+ return WATCHDOG_FAULTS.find((rule) => rule.key === key) ?? null;
121263
+ }
121264
+ /**
121265
+ * The gateway's reading from a system-variable snapshot. No WatchDog variable
121266
+ * with a value (no snapshot, no credentials, the add-on not installed) is
121267
+ * UNKNOWN, never "no fault".
121268
+ */
121269
+ function watchdogFaultReading(vars, now) {
121270
+ const faults = [];
121271
+ let known = 0;
121272
+ for (const variable of vars) {
121273
+ const rule = watchdogRuleOf(variable.name);
121274
+ if (rule === null) continue;
121275
+ const on = truthy(variable.value);
121276
+ if (on === null) continue;
121277
+ known += 1;
121278
+ if (on) faults.push(toFault(rule));
121279
+ }
121280
+ if (known === 0) return unknown(now);
121281
+ return reading(faults, now);
121282
+ }
121283
+ var MAINTENANCE_FAULTS = [
121284
+ {
121285
+ key: "UNREACH",
121286
+ severity: "error",
121287
+ words: words("Device unreachable", "Dispositivo non raggiungibile")
121288
+ },
121289
+ {
121290
+ key: "STICKY_UNREACH",
121291
+ severity: "warning",
121292
+ words: words("Device was unreachable (not acknowledged)", "Dispositivo stato non raggiungibile")
121293
+ },
121294
+ {
121295
+ key: "LOW_BAT",
121296
+ severity: "warning",
121297
+ words: words("Battery low", "Batteria scarica")
121298
+ },
121299
+ {
121300
+ key: "LOWBAT",
121301
+ severity: "warning",
121302
+ words: words("Battery low", "Batteria scarica")
121303
+ },
121304
+ {
121305
+ key: "CONFIG_PENDING",
121306
+ severity: "warning",
121307
+ words: words("Configuration pending", "Configurazione in attesa")
121308
+ },
121309
+ {
121310
+ key: "DUTY_CYCLE",
121311
+ severity: "warning",
121312
+ words: words("Radio duty cycle exhausted", "Duty cycle radio esaurito")
121313
+ }
121314
+ ];
121315
+ /** Every `ERROR_*` boolean flag the device raises is its own fault (overheat, overload, jammed…). */
121316
+ function errorFlagRule(param) {
121317
+ const name = param.slice(6).toLowerCase().replace(/_/g, " ");
121318
+ return {
121319
+ key: param,
121320
+ severity: "error",
121321
+ words: words(`Device error: ${name}`, `Errore del dispositivo: ${name}`)
121322
+ };
121323
+ }
121324
+ function maintenanceRuleOf(param, value) {
121325
+ const upper = param.toUpperCase();
121326
+ const fixed = MAINTENANCE_FAULTS.find((rule) => rule.key === upper);
121327
+ if (fixed !== void 0) return fixed;
121328
+ if (upper.startsWith("ERROR_") && typeof value === "boolean") return errorFlagRule(upper);
121329
+ return null;
121330
+ }
121331
+ /**
121332
+ * A device's reading from its MAINTENANCE channel values (parameter -> value).
121333
+ * Until a service flag has a value the reading is UNKNOWN.
121334
+ */
121335
+ function maintenanceFaultReading(values, now) {
121336
+ const faults = [];
121337
+ let known = 0;
121338
+ for (const [param, value] of values) {
121339
+ const rule = maintenanceRuleOf(param, value);
121340
+ if (rule === null) continue;
121341
+ const on = truthy(value);
121342
+ if (on === null) continue;
121343
+ known += 1;
121344
+ if (on) faults.push(toFault(rule));
121345
+ }
121346
+ if (known === 0) return unknown(now);
121347
+ return reading(faults, now);
121348
+ }
121349
+ /** The faults the CCU box can raise: its WatchDog variables. */
121350
+ function watchdogFaultTypes() {
121351
+ return WATCHDOG_FAULTS.map(toFault);
121352
+ }
121353
+ /**
121354
+ * The faults a device's MAINTENANCE channel can raise, by their fixed flags.
121355
+ * The per-model `ERROR_*` flags are discovered from the channel, so they are
121356
+ * published when raised but not listed here.
121357
+ */
121358
+ function maintenanceFaultTypes() {
121359
+ return MAINTENANCE_FAULTS.map(toFault);
121360
+ }
121361
+ //#endregion
121362
+ //#region src/ccu/ccu-faults-actions.ts
121363
+ /** A device's MAINTENANCE channel as the parameter map the fault mapping reads. */
121364
+ function maintenanceValues(device) {
121365
+ const values = /* @__PURE__ */ new Map();
121366
+ for (const point of maintenanceChannel(device)?.dataPoints ?? []) values.set(point.parameter, point.value);
121367
+ return values;
121368
+ }
121369
+ /** When the CCU raised a fault: the timestamp of its service message of the same code, else unknown. */
121370
+ function faultSince(address, code, messages) {
121371
+ return messages.find((message) => message.address !== null && (message.address === address || message.address.startsWith(`${address}:`)) && message.type === code && message.timestamp !== null)?.timestamp ?? null;
121372
+ }
121373
+ /**
121374
+ * The active faults CamStack derives from the CCU: the same pure mapping that
121375
+ * fills a device's `error` cap, read from the facade's cached MAINTENANCE values.
121376
+ * A device whose flags the CCU has not reported is UNKNOWN: it is not a fault
121377
+ * row but is named in `unreported`, so no caller reads it as "no fault". Only the `since` lookup is best effort; the device read
121378
+ * itself throws, so the page shows its warning instead of an empty list.
121379
+ */
121380
+ function buildCcuFaultHandlers(deps) {
121381
+ return { listCcuFaults: async (input) => {
121382
+ const facade = requireFacade(deps, input.integrationId);
121383
+ const adopted = await deps.adoptedAddresses(input.integrationId);
121384
+ const messages = await facade.serviceMessages().catch((error) => {
121385
+ deps.logger.warn("listCcuFaults: service messages unreadable, fault start times omitted", { meta: {
121386
+ integrationId: input.integrationId,
121387
+ error: error instanceof Error ? error.message : String(error)
121388
+ } });
121389
+ return [];
121390
+ });
121391
+ const now = Date.now();
121392
+ const faults = [];
121393
+ const unreported = [];
121394
+ for (const device of facade.devices()) {
121395
+ const reading = maintenanceFaultReading(maintenanceValues(device), now);
121396
+ if (reading.active === null) {
121397
+ unreported.push(device.address);
121398
+ continue;
121399
+ }
121400
+ const readingFaults = reading.faults ?? [];
121401
+ const principal = readingFaults[0];
121402
+ if (reading.active !== true || principal === void 0) continue;
121403
+ const all = readingFaults.map((fault) => ({
121404
+ code: fault.code,
121405
+ label: fault.label,
121406
+ severity: fault.severity
121407
+ }));
121408
+ faults.push({
121409
+ address: device.address,
121410
+ name: device.name ?? null,
121411
+ deviceId: adopted.get(device.address) ?? null,
121412
+ severity: principal.severity,
121413
+ code: principal.code,
121414
+ label: principal.label,
121415
+ since: faultSince(device.address, principal.code, messages),
121416
+ faults: all
121417
+ });
121418
+ }
121419
+ faults.sort((a, b) => a.severity === b.severity ? 0 : a.severity === "error" ? -1 : 1);
121420
+ return {
121421
+ faults,
121422
+ unreported
121423
+ };
121424
+ } };
121425
+ }
121426
+ //#endregion
121092
121427
  //#region src/ccu/ccu-schemas.ts
121093
121428
  /**
121094
121429
  * Wire shapes of the CCU management custom actions. Shared by the addon (handler
@@ -121555,6 +121890,27 @@ var SetValueInputSchema = IntegrationRefSchema.extend({
121555
121890
  deviceId: number$1().int().optional(),
121556
121891
  confirmed: ConfirmedSchema
121557
121892
  });
121893
+ var CcuFaultSchema = object({
121894
+ code: string(),
121895
+ label: string(),
121896
+ severity: _enum(["error", "warning"])
121897
+ });
121898
+ var CcuFaultsResultSchema = object({
121899
+ faults: array(object({
121900
+ address: string(),
121901
+ name: string().nullable(),
121902
+ /** CamStack device id when the CCU device is adopted. */
121903
+ deviceId: number$1().int().nullable(),
121904
+ severity: _enum(["error", "warning"]),
121905
+ code: string(),
121906
+ label: string(),
121907
+ /** Epoch milliseconds of the matching service message; `null` when the CCU did not say. */
121908
+ since: number$1().nullable(),
121909
+ faults: array(CcuFaultSchema)
121910
+ })),
121911
+ /** Devices whose service flags the CCU has not reported: unknown, never "no fault". */
121912
+ unreported: array(string())
121913
+ });
121558
121914
  //#endregion
121559
121915
  //#region src/ccu/ccu-heating-actions.ts
121560
121916
  /**
@@ -147302,6 +147658,10 @@ var homematicActions = defineCustomActions({
147302
147658
  kind: "query",
147303
147659
  auth: "admin"
147304
147660
  }),
147661
+ listCcuFaults: customAction(IntegrationRefSchema, CcuFaultsResultSchema, {
147662
+ kind: "query",
147663
+ auth: "admin"
147664
+ }),
147305
147665
  listCcuDevices: customAction(IntegrationRefSchema, CcuDevicesResultSchema, {
147306
147666
  kind: "query",
147307
147667
  auth: "admin"
@@ -149293,212 +149653,6 @@ function devicePanelSection(integrationId, address) {
149293
149653
  };
149294
149654
  }
149295
149655
  //#endregion
149296
- //#region src/homematic-fault-mapping.ts
149297
- /**
149298
- * PURE mapping of what a CCU reports as faulty to `error` cap readings, with no
149299
- * session and no I/O: the WatchDog system variables of the box, and the
149300
- * MAINTENANCE service flags of one device.
149301
- *
149302
- * A reading is UNKNOWN (`active: null`, the cold slice) until the CCU has said
149303
- * something about the flags; "no fault" is only ever written from a value that
149304
- * was read (D315, D393).
149305
- *
149306
- * The cap's `label` is a plain string the provider translates, and the server
149307
- * has no per-operator language: the label carries the English words, and the
149308
- * Italian beside it stays in the table for the surface that can pick one.
149309
- */
149310
- /** The two languages of one fault, side by side so neither is forgotten. */
149311
- function words(en, it) {
149312
- return {
149313
- en,
149314
- it
149315
- };
149316
- }
149317
- var SEVERITY_ORDER = {
149318
- error: 0,
149319
- warning: 1
149320
- };
149321
- function toFault(rule) {
149322
- return {
149323
- code: rule.key,
149324
- label: rule.words.en,
149325
- severity: rule.severity
149326
- };
149327
- }
149328
- /** Errors first, then warnings; the order inside a tier is the rule order. */
149329
- function rank(faults) {
149330
- return [...faults].sort((a, b) => SEVERITY_ORDER[a.severity] - SEVERITY_ORDER[b.severity]);
149331
- }
149332
- function reading(faults, now) {
149333
- const ranked = rank(faults);
149334
- const principal = ranked[0];
149335
- if (principal === void 0) return {
149336
- ...ERROR_STATUS_COLD,
149337
- active: false,
149338
- faults: [],
149339
- lastFetchedAt: now
149340
- };
149341
- return {
149342
- active: true,
149343
- code: principal.code,
149344
- label: principal.label,
149345
- severity: principal.severity,
149346
- since: null,
149347
- faults: ranked,
149348
- lastFetchedAt: now
149349
- };
149350
- }
149351
- function unknown(now) {
149352
- return {
149353
- ...ERROR_STATUS_COLD,
149354
- lastFetchedAt: now
149355
- };
149356
- }
149357
- /** A LOGIC value as the CCU hands it over: a boolean, 0/1, or its text. `null` is unread. */
149358
- function truthy(value) {
149359
- if (value === null) return null;
149360
- if (typeof value === "boolean") return value;
149361
- if (typeof value === "number") return value !== 0;
149362
- const text = value.trim().toLowerCase();
149363
- return text === "true" || text === "1" || text === "on" || text === "yes";
149364
- }
149365
- /** The WatchDog add-on names its variables "SV WatchDog: <key>". */
149366
- var WATCHDOG_PREFIX = /^sv\s*watchdog\s*:\s*/i;
149367
- var WATCHDOG_FAULTS = [
149368
- {
149369
- key: "hb-rf-eth-connection",
149370
- severity: "error",
149371
- words: words("HB-RF-ETH connection lost", "Connessione HB-RF-ETH persa")
149372
- },
149373
- {
149374
- key: "low-voltage",
149375
- severity: "error",
149376
- words: words("CCU supply voltage low", "Tensione di alimentazione della CCU bassa")
149377
- },
149378
- {
149379
- key: "rfd-restart",
149380
- severity: "warning",
149381
- words: words("The radio service restarted", "Il servizio radio si è riavviato")
149382
- },
149383
- {
149384
- key: "regahss-restart",
149385
- severity: "warning",
149386
- words: words("The ReGa service restarted", "Il servizio ReGa si è riavviato")
149387
- },
149388
- {
149389
- key: "no-internet",
149390
- severity: "warning",
149391
- words: words("The CCU has no internet", "La CCU non ha internet")
149392
- },
149393
- {
149394
- key: "unclean-shutdown",
149395
- severity: "warning",
149396
- words: words("The CCU shut down uncleanly", "La CCU si è spenta in modo anomalo")
149397
- }
149398
- ];
149399
- /** Which WatchDog fault a system variable is, or `null` when it is not one of them. */
149400
- function watchdogRuleOf(name) {
149401
- const key = name.trim().replace(WATCHDOG_PREFIX, "").trim().toLowerCase();
149402
- return WATCHDOG_FAULTS.find((rule) => rule.key === key) ?? null;
149403
- }
149404
- /**
149405
- * The gateway's reading from a system-variable snapshot. No WatchDog variable
149406
- * with a value (no snapshot, no credentials, the add-on not installed) is
149407
- * UNKNOWN, never "no fault".
149408
- */
149409
- function watchdogFaultReading(vars, now) {
149410
- const faults = [];
149411
- let known = 0;
149412
- for (const variable of vars) {
149413
- const rule = watchdogRuleOf(variable.name);
149414
- if (rule === null) continue;
149415
- const on = truthy(variable.value);
149416
- if (on === null) continue;
149417
- known += 1;
149418
- if (on) faults.push(toFault(rule));
149419
- }
149420
- if (known === 0) return unknown(now);
149421
- return reading(faults, now);
149422
- }
149423
- var MAINTENANCE_FAULTS = [
149424
- {
149425
- key: "UNREACH",
149426
- severity: "error",
149427
- words: words("Device unreachable", "Dispositivo non raggiungibile")
149428
- },
149429
- {
149430
- key: "STICKY_UNREACH",
149431
- severity: "warning",
149432
- words: words("Device was unreachable (not acknowledged)", "Dispositivo stato non raggiungibile")
149433
- },
149434
- {
149435
- key: "LOW_BAT",
149436
- severity: "warning",
149437
- words: words("Battery low", "Batteria scarica")
149438
- },
149439
- {
149440
- key: "LOWBAT",
149441
- severity: "warning",
149442
- words: words("Battery low", "Batteria scarica")
149443
- },
149444
- {
149445
- key: "CONFIG_PENDING",
149446
- severity: "warning",
149447
- words: words("Configuration pending", "Configurazione in attesa")
149448
- },
149449
- {
149450
- key: "DUTY_CYCLE",
149451
- severity: "warning",
149452
- words: words("Radio duty cycle exhausted", "Duty cycle radio esaurito")
149453
- }
149454
- ];
149455
- /** Every `ERROR_*` boolean flag the device raises is its own fault (overheat, overload, jammed…). */
149456
- function errorFlagRule(param) {
149457
- const name = param.slice(6).toLowerCase().replace(/_/g, " ");
149458
- return {
149459
- key: param,
149460
- severity: "error",
149461
- words: words(`Device error: ${name}`, `Errore del dispositivo: ${name}`)
149462
- };
149463
- }
149464
- function maintenanceRuleOf(param, value) {
149465
- const upper = param.toUpperCase();
149466
- const fixed = MAINTENANCE_FAULTS.find((rule) => rule.key === upper);
149467
- if (fixed !== void 0) return fixed;
149468
- if (upper.startsWith("ERROR_") && typeof value === "boolean") return errorFlagRule(upper);
149469
- return null;
149470
- }
149471
- /**
149472
- * A device's reading from its MAINTENANCE channel values (parameter -> value).
149473
- * Until a service flag has a value the reading is UNKNOWN.
149474
- */
149475
- function maintenanceFaultReading(values, now) {
149476
- const faults = [];
149477
- let known = 0;
149478
- for (const [param, value] of values) {
149479
- const rule = maintenanceRuleOf(param, value);
149480
- if (rule === null) continue;
149481
- const on = truthy(value);
149482
- if (on === null) continue;
149483
- known += 1;
149484
- if (on) faults.push(toFault(rule));
149485
- }
149486
- if (known === 0) return unknown(now);
149487
- return reading(faults, now);
149488
- }
149489
- /** The faults the CCU box can raise: its WatchDog variables. */
149490
- function watchdogFaultTypes() {
149491
- return WATCHDOG_FAULTS.map(toFault);
149492
- }
149493
- /**
149494
- * The faults a device's MAINTENANCE channel can raise, by their fixed flags.
149495
- * The per-model `ERROR_*` flags are discovered from the channel, so they are
149496
- * published when raised but not listed here.
149497
- */
149498
- function maintenanceFaultTypes() {
149499
- return MAINTENANCE_FAULTS.map(toFault);
149500
- }
149501
- //#endregion
149502
149656
  //#region src/homematic-diagnostics-mapping.ts
149503
149657
  var MAINTENANCE_CHANNEL_TYPE$1 = "MAINTENANCE";
149504
149658
  /** Reachability parameters that drive the Container's `online`, not a child. */
@@ -150488,9 +150642,37 @@ function gatewayMetadataPatch(input) {
150488
150642
  };
150489
150643
  }
150490
150644
  //#endregion
150645
+ //#region src/homematic-state-refresh.ts
150646
+ /**
150647
+ * Homematic's side of the core state refresh (D1062): HOW to read, never WHEN.
150648
+ *
150649
+ * The CCU pushes every radio device event over the XML-RPC callback, so those
150650
+ * devices are never read on a clock. The one thing it does NOT push is its own
150651
+ * WatchDog system variables (the gateway's `error` cap): they are a snapshot the
150652
+ * gateway has to read, so the gateway registers `device-state-refresh` with
150653
+ * `push: 'none'` and the core reads it at {@link HOMEMATIC_GATEWAY_REFRESH_MS}.
150654
+ */
150655
+ /** How often the core reads the CCU's WatchDog system variables. */
150656
+ var HOMEMATIC_GATEWAY_REFRESH_MS = 3e4;
150657
+ function homematicGatewayRefreshPolicy(integrationId) {
150658
+ return {
150659
+ integrationId,
150660
+ minIntervalMs: HOMEMATIC_GATEWAY_REFRESH_MS,
150661
+ batch: false,
150662
+ push: "none"
150663
+ };
150664
+ }
150665
+ function registerHomematicStateRefresh(target) {
150666
+ target.ctx.registerNativeCap(deviceStateRefreshCapability, {
150667
+ refresh: async () => {
150668
+ await target.readFaults();
150669
+ return { ok: true };
150670
+ },
150671
+ resubscribe: async () => ({ ok: true })
150672
+ }, { stateRefresh: homematicGatewayRefreshPolicy(target.integrationId) });
150673
+ }
150674
+ //#endregion
150491
150675
  //#region src/devices/homematic-gateway-device.ts
150492
- /** How often the CCU system variables are re-read: they are a snapshot, the CCU pushes no event for them. */
150493
- var WATCHDOG_POLL_MS = 3e4;
150494
150676
  /**
150495
150677
  * The physical CCU3 / RaspberryMatic box, as a {@link DeviceType.Gateway}. Its
150496
150678
  * connection and password live on the INTEGRATION; this device follows whether
@@ -150500,7 +150682,8 @@ var WATCHDOG_POLL_MS = 3e4;
150500
150682
  * - `device-admin-link`, the CCU's own WebUI.
150501
150683
  *
150502
150684
  * - `error`, the faults the CCU WatchDog add-on raises as system variables
150503
- * (`homematic-fault-mapping.ts`), re-read every {@link WATCHDOG_POLL_MS}.
150685
+ * (`homematic-fault-mapping.ts`), read by the core's `device-state-refresh` (D1062),
150686
+ * because the CCU pushes no event for them.
150504
150687
  *
150505
150688
  * There is no `reboot` and no `update`: nodehomematic has no call that restarts
150506
150689
  * the CCU, and its firmware call installs an update on a radio DEVICE by its
@@ -150515,7 +150698,6 @@ var HomematicGatewayDevice = class extends BaseDevice {
150515
150698
  snapshotUnsub = null;
150516
150699
  /** The last metadata written, so a state change that altered nothing writes nothing. */
150517
150700
  lastMetadataKey = "";
150518
- pollTimer = null;
150519
150701
  polling = false;
150520
150702
  warnedReadFailure = false;
150521
150703
  constructor(ctx) {
@@ -150526,6 +150708,11 @@ var HomematicGatewayDevice = class extends BaseDevice {
150526
150708
  this.registerAdminLinkCap();
150527
150709
  this.declareFaultTypes(watchdogFaultTypes());
150528
150710
  this.registerErrorCap();
150711
+ registerHomematicStateRefresh({
150712
+ ctx,
150713
+ integrationId: cfg.integrationId,
150714
+ readFaults: () => this.refreshFaults()
150715
+ });
150529
150716
  this.updateSourceInfo({
150530
150717
  id: cfg.nativeId,
150531
150718
  system: "homematic"
@@ -150538,15 +150725,9 @@ var HomematicGatewayDevice = class extends BaseDevice {
150538
150725
  if (this.sessionUp()) this.pollFaults();
150539
150726
  });
150540
150727
  await this.sync();
150541
- this.pollTimer = setInterval(() => {
150542
- this.pollFaults();
150543
- }, WATCHDOG_POLL_MS);
150544
- this.pollTimer.unref();
150545
150728
  await this.pollFaults();
150546
150729
  }
150547
150730
  async removeDevice() {
150548
- if (this.pollTimer !== null) clearInterval(this.pollTimer);
150549
- this.pollTimer = null;
150550
150731
  this.snapshotUnsub?.();
150551
150732
  this.snapshotUnsub = null;
150552
150733
  await super.removeDevice();
@@ -150555,9 +150736,34 @@ var HomematicGatewayDevice = class extends BaseDevice {
150555
150736
  return homematicFacades.getSession(this.integrationId)?.getInfo().status === "connected";
150556
150737
  }
150557
150738
  /**
150558
- * Read the CCU's WatchDog system variables and publish them as faults. A read
150559
- * that fails changes nothing (the previous reading stands), and every branch
150560
- * that publishes nothing leaves a line on the device.
150739
+ * The core's read (D1062): the CCU's WatchDog system variables, published as
150740
+ * faults. It THROWS when the session is down or the CCU does not answer, so
150741
+ * the core backs the cadence off; the previous reading stands meanwhile. It
150742
+ * shares the `polling` guard with `pollFaults`: a read already in flight
150743
+ * publishes the same reading, so a second one is not started.
150744
+ */
150745
+ async refreshFaults() {
150746
+ if (this.polling) return;
150747
+ const facade = homematicFacades.get(this.integrationId);
150748
+ if (!this.sessionUp() || facade === null) throw new Error(`Homematic CCU not connected (integration ${this.integrationId})`);
150749
+ this.polling = true;
150750
+ try {
150751
+ await this.readFaultsFrom(facade);
150752
+ } finally {
150753
+ this.polling = false;
150754
+ }
150755
+ }
150756
+ async readFaultsFrom(facade) {
150757
+ await facade.refreshHub();
150758
+ const reading = watchdogFaultReading(facade.systemVariables(), Date.now());
150759
+ if (reading.active === null) this.ctx.logger.debug("Homematic gateway: no WatchDog system variable readable on the CCU, faults stay unknown", { tags: { deviceId: this.id } });
150760
+ this.warnedReadFailure = false;
150761
+ await this.publishError(reading);
150762
+ }
150763
+ /**
150764
+ * Read the faults when the CCU announced a new snapshot (it just reconnected
150765
+ * or changed). A read that fails changes nothing (the previous reading
150766
+ * stands), and every branch that publishes nothing leaves a line on the device.
150561
150767
  */
150562
150768
  async pollFaults() {
150563
150769
  if (this.polling) return;
@@ -150569,11 +150775,7 @@ var HomematicGatewayDevice = class extends BaseDevice {
150569
150775
  }
150570
150776
  this.polling = true;
150571
150777
  try {
150572
- await facade.refreshHub();
150573
- const reading = watchdogFaultReading(facade.systemVariables(), Date.now());
150574
- if (reading.active === null) this.ctx.logger.debug("Homematic gateway: no WatchDog system variable readable on the CCU, faults stay unknown", { tags });
150575
- this.warnedReadFailure = false;
150576
- await this.publishError(reading);
150778
+ await this.readFaultsFrom(facade);
150577
150779
  } catch (err) {
150578
150780
  const log = this.warnedReadFailure ? this.ctx.logger.debug : this.ctx.logger.warn;
150579
150781
  this.warnedReadFailure = true;
@@ -152467,6 +152669,7 @@ var HomematicProviderAddon = class extends BaseDeviceProvider {
152467
152669
  actionHandlers: {
152468
152670
  ...buildCcuOverviewHandlers(this.ccuActionDeps()),
152469
152671
  ...buildCcuDevicesHandlers(this.ccuActionDeps()),
152672
+ ...buildCcuFaultHandlers(this.ccuActionDeps()),
152470
152673
  ...buildCcuHeatingHandlers(this.ccuActionDeps()),
152471
152674
  ...buildCcuPairingHandlers(this.ccuActionDeps()),
152472
152675
  ...buildCcuConfigHandlers(this.ccuActionDeps()),