@camstack/addon-provider-homematic 1.2.209 → 1.2.211

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 +13 -0
  2. package/dist/.bundle-modules.json +11 -6
  3. package/dist/_stub.js +2837 -1972
  4. package/dist/{_virtual_mf-localSharedImportMap___mfe_internal__addon_provider_homematic_page-B8JEAJoX.mjs → _virtual_mf-localSharedImportMap___mfe_internal__addon_provider_homematic_page-D5at7Q9l.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-BHT2wfZN.mjs +26 -0
  6. package/dist/addon-provider-homematic.css +1 -1
  7. package/dist/addon.js +790 -241
  8. package/dist/addon.mjs +790 -241
  9. package/dist/{hostInit-dkdwmlIf.mjs → hostInit-UNRy49MK.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-BSgPYGJt.mjs} +1 -1
  12. package/dist/widgets/_stub.js +229 -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-CTToHFHm.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-BxH-K-yr.mjs +26 -0
  15. package/dist/widgets/{hostInit-C1PiC4_E.mjs → hostInit-D-2FhaC8.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",
@@ -51910,6 +51915,7 @@ function macroOnly(macro) {
51910
51915
  };
51911
51916
  }
51912
51917
  }
51918
+ var FaultCodesSchema = array(string().min(1)).max(64);
51913
51919
  /**
51914
51920
  * Hold semantics — "for N seconds" on a leaf of the `when` tree (#498).
51915
51921
  *
@@ -52044,6 +52050,17 @@ var DeviceBecomesLeafSchema = object({
52044
52050
  path: ["value"]
52045
52051
  });
52046
52052
  });
52053
+ /**
52054
+ * A matching fault BECOMES active on a device (`device-fault.ts`): the device's
52055
+ * whole fault list is read, not only its principal code. `codes` empty = any
52056
+ * fault. Fires once per appearance; a fault already raised at start only seeds.
52057
+ */
52058
+ var DeviceFaultRaisedLeafSchema = object({
52059
+ kind: literal("device-fault-raised"),
52060
+ ...eventLeafId,
52061
+ deviceId: number$1().int().nonnegative(),
52062
+ codes: FaultCodesSchema
52063
+ });
52047
52064
  var DeviceEventLeafSchema = object({
52048
52065
  kind: literal("device-event"),
52049
52066
  ...eventLeafId,
@@ -52121,6 +52138,12 @@ var StationaryLeafSchema = object({
52121
52138
  /** `appeared`: it became parked. `departed`: the registry retired it. */
52122
52139
  phase: _enum(["appeared", "departed"])
52123
52140
  });
52141
+ /** "has a fault": a matching fault is active on the device NOW (its whole fault list). `codes` empty = any. */
52142
+ var DeviceFaultIsLeafSchema = object({
52143
+ kind: literal("device-fault-is"),
52144
+ deviceId: number$1().int().nonnegative(),
52145
+ codes: FaultCodesSchema
52146
+ });
52124
52147
  /** "is": one device field compared to one value, NOW. */
52125
52148
  var DeviceIsLeafSchema = object({
52126
52149
  kind: literal("device-is"),
@@ -52243,12 +52266,14 @@ var AutomationWhenSchema = lazy(() => discriminatedUnion("kind", [
52243
52266
  DeviceBecomesLeafSchema,
52244
52267
  DeviceEventLeafSchema,
52245
52268
  DeviceFiredLeafSchema,
52269
+ DeviceFaultRaisedLeafSchema,
52246
52270
  ScheduleLeafSchema,
52247
52271
  ManualLeafSchema,
52248
52272
  IntervalLeafSchema,
52249
52273
  DetectionLeafSchema,
52250
52274
  StationaryLeafSchema,
52251
52275
  DeviceIsLeafSchema,
52276
+ DeviceFaultIsLeafSchema,
52252
52277
  StationaryPresentLeafSchema,
52253
52278
  ExpressionLeafSchema,
52254
52279
  TimeIsLeafSchema,
@@ -52258,6 +52283,7 @@ var EVENT_KINDS = new Set([
52258
52283
  "device-becomes",
52259
52284
  "device-event",
52260
52285
  "device-fired",
52286
+ "device-fault-raised",
52261
52287
  "schedule",
52262
52288
  "manual",
52263
52289
  "interval",
@@ -52339,6 +52365,7 @@ var LEAF_WORDS = {
52339
52365
  "device-becomes": "a device value that becomes",
52340
52366
  "device-event": "a device event",
52341
52367
  "device-fired": "a device firing an event",
52368
+ "device-fault-raised": "a device fault being raised",
52342
52369
  schedule: "a schedule",
52343
52370
  manual: "a manual run",
52344
52371
  interval: "an interval",
@@ -52820,6 +52847,86 @@ var AutomationNotifyStepSchema = object({
52820
52847
  body: string().min(1, "a notification needs a message").max(NOTIFY_BODY_MAX),
52821
52848
  ...continueOnErrorShape
52822
52849
  });
52850
+ var HTTP_URL_MAX = 2e3;
52851
+ var HTTP_BODY_MAX = 16384;
52852
+ var HTTP_HEADER_VALUE_MAX = 1e3;
52853
+ var saveAsSchema = string().regex(SET_VAR_NAME_RE, "a variable name is letters, digits and _, not starting with a digit (max 40)").refine((name) => !RESERVED_RUN_VARS.includes(name), { message: `the names ${RESERVED_RUN_VARS.join(", ")} belong to the run and cannot be used` });
52854
+ var retryUntilSecondsSchema = number$1().int().min(1).max(600, `a retry window is at most 600 s`);
52855
+ /**
52856
+ * Whether a TCP port on a host answers. TCP only: an ICMP echo needs a raw
52857
+ * socket or a `ping` binary with extra privileges, and the hub image ships
52858
+ * neither for its non-root user, so it is not offered.
52859
+ *
52860
+ * Without `expect` the step wants the host REACHABLE. The result
52861
+ * (`{ reachable, rttMs, error }`) goes to the run variable `saveAs`.
52862
+ */
52863
+ var AutomationProbeStepSchema = object({
52864
+ kind: literal("probe"),
52865
+ ...stepEnabledShape,
52866
+ /** A host name or an address; may carry `{{vars.x}}` slots. */
52867
+ host: string().min(1, "a probe needs a host").max(253).regex(/^[^\s/]+$/, "a host has no spaces or slashes"),
52868
+ port: number$1().int().min(1, "a port is 1 to 65535").max(65535, "a port is 1 to 65535"),
52869
+ timeoutSeconds: number$1().int().min(1).max(30),
52870
+ expect: _enum(["reachable", "unreachable"]).optional(),
52871
+ /** Keep probing every {@link REACH_RETRY_INTERVAL_S} s until the expectation holds, for this long. */
52872
+ retryUntilSeconds: retryUntilSecondsSchema.optional(),
52873
+ saveAs: saveAsSchema.optional(),
52874
+ ...continueOnErrorShape
52875
+ }).strict();
52876
+ var HTTP_METHODS = [
52877
+ "GET",
52878
+ "POST",
52879
+ "PUT",
52880
+ "PATCH",
52881
+ "DELETE"
52882
+ ];
52883
+ /**
52884
+ * What an HTTP request must answer for the step to pass: its status, or a field
52885
+ * of the parsed JSON body, compared the way a device field is.
52886
+ */
52887
+ var AutomationHttpExpectSchema = object({
52888
+ on: _enum(["status", "json"]),
52889
+ /** A dotted path into the JSON body (`sysInfo.rawUartRemoteAddress`); needed for `json`. */
52890
+ fieldPath: string().min(1).max(200).optional(),
52891
+ operator: AutomationConditionOperatorSchema,
52892
+ value: union([
52893
+ string(),
52894
+ number$1(),
52895
+ boolean()
52896
+ ])
52897
+ }).strict().refine((expect) => expect.on !== "json" || expect.fieldPath !== void 0, {
52898
+ message: "a JSON expectation names the field it reads",
52899
+ path: ["fieldPath"]
52900
+ });
52901
+ function isHttpUrl(url) {
52902
+ if (url.includes("{{")) return /^https?:\/\/\S+$/i.test(url);
52903
+ try {
52904
+ const parsed = new URL(url);
52905
+ return parsed.protocol === "http:" || parsed.protocol === "https:";
52906
+ } catch {
52907
+ return false;
52908
+ }
52909
+ }
52910
+ /**
52911
+ * One HTTP request. Without `expect` the step wants a 2xx answer. The result
52912
+ * (`{ status, ok, json, text, error }`) goes to the run variable `saveAs`.
52913
+ * Header values are stored as typed, in plain text: they are in the recipe and
52914
+ * in the generated source, so anyone who can open the automation can read a
52915
+ * token put in one. Header values and bodies are never logged or traced.
52916
+ */
52917
+ var AutomationHttpRequestStepSchema = object({
52918
+ kind: literal("http-request"),
52919
+ ...stepEnabledShape,
52920
+ method: _enum(HTTP_METHODS),
52921
+ url: string().max(HTTP_URL_MAX).refine(isHttpUrl, "the address is an http:// or https:// URL"),
52922
+ headers: record$1(string().regex(/^[A-Za-z0-9!#$%&'*+.^_`|~-]+$/, "not a valid header name"), string().max(HTTP_HEADER_VALUE_MAX)).refine((headers) => Object.keys(headers).length <= 20, { message: `at most 20 headers` }).optional(),
52923
+ body: string().max(HTTP_BODY_MAX).optional(),
52924
+ timeoutSeconds: number$1().int().min(1).max(60),
52925
+ expect: AutomationHttpExpectSchema.optional(),
52926
+ retryUntilSeconds: retryUntilSecondsSchema.optional(),
52927
+ saveAs: saveAsSchema.optional(),
52928
+ ...continueOnErrorShape
52929
+ }).strict();
52823
52930
  var AutomationRunActionStepSchema = object({
52824
52931
  kind: literal("action"),
52825
52932
  ...stepEnabledShape,
@@ -52875,7 +52982,9 @@ var plainStepSchemas = [
52875
52982
  AutomationStopStepSchema.omit({ if: true }).strict(),
52876
52983
  AutomationSetStepSchema.omit({ if: true }).strict(),
52877
52984
  AutomationRunActionStepSchema.strict(),
52878
- AutomationNotifyStepSchema.strict()
52985
+ AutomationNotifyStepSchema.strict(),
52986
+ AutomationProbeStepSchema,
52987
+ AutomationHttpRequestStepSchema
52879
52988
  ];
52880
52989
  /**
52881
52990
  * A plain step: a flow step with no condition of its own and no step inside
@@ -52975,6 +53084,8 @@ var AutomationActionSchema = discriminatedUnion("kind", [
52975
53084
  AutomationRepeatStepSchema,
52976
53085
  AutomationRunActionStepSchema,
52977
53086
  AutomationNotifyStepSchema,
53087
+ AutomationProbeStepSchema,
53088
+ AutomationHttpRequestStepSchema,
52978
53089
  object({
52979
53090
  kind: literal("code"),
52980
53091
  ...stepEnabledShape,
@@ -53299,6 +53410,7 @@ var AutomationConditionTraceNodeSchema = object({
53299
53410
  "not",
53300
53411
  "condition",
53301
53412
  "device-is",
53413
+ "device-fault-is",
53302
53414
  "expression",
53303
53415
  "stationary-present",
53304
53416
  "time-is",
@@ -53306,6 +53418,7 @@ var AutomationConditionTraceNodeSchema = object({
53306
53418
  "device-becomes",
53307
53419
  "device-event",
53308
53420
  "device-fired",
53421
+ "device-fault-raised",
53309
53422
  "schedule",
53310
53423
  "interval",
53311
53424
  "manual",
@@ -53364,6 +53477,9 @@ var StepTraceBaseSchema = object({
53364
53477
  * (D1021): why a sentence says "—" where a number was expected. Bounded.
53365
53478
  */
53366
53479
  templates: array(string()).max(20).optional(),
53480
+ /** A probe or an HTTP request: how many tries it made, and what the last one saw (no header, no body). */
53481
+ attempts: number$1().int().optional(),
53482
+ lastAttempt: string().optional(),
53367
53483
  /**
53368
53484
  * What the step's own `if` read when the step was reached (#472): `true` the
53369
53485
  * step ran, `false` its `else` ran (or nothing did), `unknown` a state leaf
@@ -66088,9 +66204,10 @@ object({
66088
66204
  /** Longest silence a push integration may keep before the core re-reads it and asks it to resubscribe. */
66089
66205
  heartbeatMs: number$1().int().positive().optional(),
66090
66206
  /**
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).
66207
+ * Changes on every reconnect of the provider's push subscription; any change
66208
+ * makes the core read every device of the integration once (pushes lost while
66209
+ * it was down; events may be dropped, D8). It need not grow: a provider whose
66210
+ * counter restarts with its process is still understood.
66094
66211
  */
66095
66212
  connectionEpoch: number$1().int().nonnegative().optional()
66096
66213
  });
@@ -66115,15 +66232,28 @@ var DeviceStateRefreshInputSchema = object({
66115
66232
  var DeviceStateResubscribeInputSchema = object({ deviceId: number$1().int().nonnegative() });
66116
66233
  var DeviceStateRefreshResultSchema = object({ ok: literal(true) });
66117
66234
  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
- });
66235
+ var deviceStateRefreshCapability = {
66236
+ name: "device-state-refresh",
66237
+ scope: "device",
66238
+ deviceNative: true,
66239
+ mode: "singleton",
66240
+ methods: {
66241
+ refresh: method(DeviceStateRefreshInputSchema, DeviceStateRefreshResultSchema, {
66242
+ kind: "mutation",
66243
+ auth: "admin",
66244
+ notOperatorFacing: NOT_OPERATOR_FACING
66245
+ }),
66246
+ resubscribe: method(DeviceStateResubscribeInputSchema, DeviceStateRefreshResultSchema, {
66247
+ kind: "mutation",
66248
+ auth: "admin",
66249
+ notOperatorFacing: NOT_OPERATOR_FACING
66250
+ })
66251
+ },
66252
+ vocabulary: {
66253
+ noun: t("State refresh", "Aggiornamento dello stato"),
66254
+ order: 3247
66255
+ }
66256
+ };
66127
66257
  /**
66128
66258
  * Generic device-level status snapshot. Auto-registered by `BaseDevice`
66129
66259
  * for every device, regardless of provider — the kernel needs a uniform
@@ -83719,6 +83849,15 @@ var NcRuleInputSchema = object({
83719
83849
  */
83720
83850
  askVerdict: boolean().optional(),
83721
83851
  /**
83852
+ * An ALERT notification (`alert-critical`, `alert-error`, device attention)
83853
+ * carries the alert's own action — an open-URL button and, for an `invoke`
83854
+ * action, a token-authed button that runs it. Absent and `true` mean ON;
83855
+ * `false` switches it off for this rule. `.optional()`, never `.default()`
83856
+ * (a Zod default does not run on the addon cap path), so a rule authored
83857
+ * before this field keeps the action.
83858
+ */
83859
+ offerAlertAction: boolean().optional(),
83860
+ /**
83722
83861
  * Operator tags (D1054), kept on the rule like a core block's. Absent = no
83723
83862
  * tags. `.optional()`, never `.default()`: a partial `updateRule` patch that
83724
83863
  * does not name `tags` keeps the stored ones (the store merges), and an
@@ -118933,6 +119072,14 @@ object({
118933
119072
  nodeId: string().optional(),
118934
119073
  /** The alert's own action link (where the operator acts on it), when it has one. */
118935
119074
  actionUrl: string().optional(),
119075
+ /**
119076
+ * The alert's WHOLE action — label, link, navigation and `invoke` — on a
119077
+ * raised episode, so a notification can offer it (an absolute open-URL
119078
+ * button, a token-authed invoke button). `actionUrl` stays for the
119079
+ * `{{actionUrl}}` template variable. Additive: an episode published before
119080
+ * this field has none.
119081
+ */
119082
+ action: AlertActionSchema.optional(),
118936
119083
  /** A device fault episode: every active fault (`metadata.faults`), principal first. */
118937
119084
  faults: array(DeviceFaultSchema).optional(),
118938
119085
  at: number$1()
@@ -120161,6 +120308,34 @@ object({
120161
120308
  delay: number$1().nonnegative().optional(),
120162
120309
  commands: record$1(string(), unknown$1())
120163
120310
  });
120311
+ /** When a member receives: always, inside a schedule, or while an alarm panel is in a state. */
120312
+ var GroupMemberWhenSchema = discriminatedUnion("kind", [
120313
+ object({ kind: literal("always") }),
120314
+ object({
120315
+ kind: literal("schedule"),
120316
+ schedule: NcScheduleSchema
120317
+ }),
120318
+ object({
120319
+ kind: literal("alarm"),
120320
+ deviceId: number$1().int().nonnegative(),
120321
+ states: array(AlarmStateSchema).min(1)
120322
+ })
120323
+ ]);
120324
+ object({
120325
+ targetId: string().min(1),
120326
+ enabled: boolean().optional(),
120327
+ when: GroupMemberWhenSchema.optional(),
120328
+ /** Which message fields this member receives. Absent = all of them. */
120329
+ fields: array(NotificationFieldSchema).optional(),
120330
+ /** `{{title}}`, `{{body}}`, `{{priority}}` and any `{{key}}` of the notification's metadata. */
120331
+ templates: object({
120332
+ title: string().optional(),
120333
+ body: string().optional()
120334
+ }).optional(),
120335
+ minPriority: number$1().int().min(1).max(5).optional(),
120336
+ /** At most one delivery per window; a burst becomes one. 0 or absent = no throttle. */
120337
+ throttleSec: number$1().int().nonnegative().optional()
120338
+ });
120164
120339
  //#endregion
120165
120340
  //#region src/devices/hm-cold-start.ts
120166
120341
  /**
@@ -121089,6 +121264,329 @@ function buildCcuDevicesHandlers(deps) {
121089
121264
  } };
121090
121265
  }
121091
121266
  //#endregion
121267
+ //#region src/homematic-fault-mapping.ts
121268
+ /**
121269
+ * PURE mapping of what a CCU reports as faulty to `error` cap readings, with no
121270
+ * session and no I/O: the WatchDog system variables of the box, and the
121271
+ * MAINTENANCE service flags of one device.
121272
+ *
121273
+ * A reading is UNKNOWN (`active: null`, the cold slice) until the CCU has said
121274
+ * something about the flags; "no fault" is only ever written from a value that
121275
+ * was read (D315, D393).
121276
+ *
121277
+ * The cap's `label` is a plain string the provider translates, and the server
121278
+ * has no per-operator language: the label carries the English words, and the
121279
+ * Italian beside it stays in the table for the surface that can pick one.
121280
+ */
121281
+ /** The two languages of one fault, side by side so neither is forgotten. */
121282
+ function words(en, it) {
121283
+ return {
121284
+ en,
121285
+ it
121286
+ };
121287
+ }
121288
+ var SEVERITY_ORDER = {
121289
+ error: 0,
121290
+ warning: 1
121291
+ };
121292
+ function toFault(rule) {
121293
+ return {
121294
+ code: rule.key,
121295
+ label: rule.words.en,
121296
+ severity: rule.severity
121297
+ };
121298
+ }
121299
+ /** Errors first, then warnings; the order inside a tier is the rule order. */
121300
+ function rank(faults) {
121301
+ return [...faults].sort((a, b) => SEVERITY_ORDER[a.severity] - SEVERITY_ORDER[b.severity]);
121302
+ }
121303
+ function reading(faults, now) {
121304
+ const ranked = rank(faults);
121305
+ const principal = ranked[0];
121306
+ if (principal === void 0) return {
121307
+ ...ERROR_STATUS_COLD,
121308
+ active: false,
121309
+ faults: [],
121310
+ lastFetchedAt: now
121311
+ };
121312
+ return {
121313
+ active: true,
121314
+ code: principal.code,
121315
+ label: principal.label,
121316
+ severity: principal.severity,
121317
+ since: null,
121318
+ faults: ranked,
121319
+ lastFetchedAt: now
121320
+ };
121321
+ }
121322
+ function unknown(now) {
121323
+ return {
121324
+ ...ERROR_STATUS_COLD,
121325
+ lastFetchedAt: now
121326
+ };
121327
+ }
121328
+ /** A LOGIC value as the CCU hands it over: a boolean, 0/1, or its text. `null` is unread. */
121329
+ function truthy(value) {
121330
+ if (value === null) return null;
121331
+ if (typeof value === "boolean") return value;
121332
+ if (typeof value === "number") return value !== 0;
121333
+ const text = value.trim().toLowerCase();
121334
+ return text === "true" || text === "1" || text === "on" || text === "yes";
121335
+ }
121336
+ /**
121337
+ * WatchDog is part of RaspberryMatic / OpenCCU itself (since 3.59.6): it creates
121338
+ * an alarm system variable named "WatchDog: <alarm>" the first time that alarm
121339
+ * fires. The older "SV WatchDog: <alarm>" spelling is accepted too. The alarm
121340
+ * keys in {@link WATCHDOG_FAULTS} are not verified against real names, so a
121341
+ * WatchDog-prefixed variable that matches no rule is reported to the caller.
121342
+ */
121343
+ var WATCHDOG_PREFIX = /^(?:sv\s*)?watchdog\s*:\s*/i;
121344
+ var WATCHDOG_FAULTS = [
121345
+ {
121346
+ key: "hb-rf-eth-connection",
121347
+ severity: "error",
121348
+ words: words("HB-RF-ETH connection lost", "Connessione HB-RF-ETH persa")
121349
+ },
121350
+ {
121351
+ key: "low-voltage",
121352
+ severity: "error",
121353
+ words: words("CCU supply voltage low", "Tensione di alimentazione della CCU bassa")
121354
+ },
121355
+ {
121356
+ key: "rfd-restart",
121357
+ severity: "warning",
121358
+ words: words("The radio service restarted", "Il servizio radio si è riavviato")
121359
+ },
121360
+ {
121361
+ key: "regahss-restart",
121362
+ severity: "warning",
121363
+ words: words("The ReGa service restarted", "Il servizio ReGa si è riavviato")
121364
+ },
121365
+ {
121366
+ key: "no-internet",
121367
+ severity: "warning",
121368
+ words: words("The CCU has no internet", "La CCU non ha internet")
121369
+ },
121370
+ {
121371
+ key: "unclean-shutdown",
121372
+ severity: "warning",
121373
+ words: words("The CCU shut down uncleanly", "La CCU si è spenta in modo anomalo")
121374
+ }
121375
+ ];
121376
+ /** Which WatchDog fault a system variable is, or `null` when it is not one of them. */
121377
+ function watchdogRuleOf(name) {
121378
+ const key = name.trim().replace(WATCHDOG_PREFIX, "").trim().toLowerCase();
121379
+ return WATCHDOG_FAULTS.find((rule) => rule.key === key) ?? null;
121380
+ }
121381
+ /**
121382
+ * The gateway's reading from a system-variable snapshot. No WatchDog variable
121383
+ * with a value (no snapshot, no credentials, the add-on not installed) is
121384
+ * UNKNOWN, never "no fault".
121385
+ */
121386
+ function watchdogFaultReading(vars, now, onUnmatched) {
121387
+ const faults = [];
121388
+ let known = 0;
121389
+ for (const variable of vars) {
121390
+ const rule = watchdogRuleOf(variable.name);
121391
+ if (rule === null) {
121392
+ if (onUnmatched !== void 0 && WATCHDOG_PREFIX.test(variable.name.trim())) onUnmatched(variable.name);
121393
+ continue;
121394
+ }
121395
+ const on = truthy(variable.value);
121396
+ if (on === null) continue;
121397
+ known += 1;
121398
+ if (on) faults.push(toFault(rule));
121399
+ }
121400
+ if (known === 0) return unknown(now);
121401
+ return reading(faults, now);
121402
+ }
121403
+ /** Several HmIP-RF devices went unreachable together (`homematic-radio-unreachable.ts`). */
121404
+ var RADIO_UNREACHABLE_FAULT = {
121405
+ key: "radio-unreachable",
121406
+ severity: "error",
121407
+ words: words("Several radio devices became unreachable", "Più dispositivi radio non raggiungibili")
121408
+ };
121409
+ /** No radio device event for too long (`homematic-radio-silent.ts`). */
121410
+ var RADIO_SILENT_FAULT = {
121411
+ key: "radio-silent",
121412
+ severity: "error",
121413
+ words: words("No radio events received", "Nessun evento radio ricevuto")
121414
+ };
121415
+ /** A reading for one rule: raised, fine, or unknown (`null`). */
121416
+ function ruleReading(rule, active, now) {
121417
+ if (active === null) return unknown(now);
121418
+ return reading(active ? [toFault(rule)] : [], now);
121419
+ }
121420
+ /**
121421
+ * Merge the readings of several sources. A fault from any source is active
121422
+ * (one entry per code); unknown from every source is unknown; a source that
121423
+ * reads "fine" beside one that is unknown is fine.
121424
+ */
121425
+ function mergeFaultReadings(readings, now) {
121426
+ const byCode = /* @__PURE__ */ new Map();
121427
+ let known = 0;
121428
+ for (const item of readings) {
121429
+ if (item.active === null) continue;
121430
+ known += 1;
121431
+ for (const fault of item.faults ?? []) byCode.set(fault.code, fault);
121432
+ }
121433
+ if (known === 0) return unknown(now);
121434
+ return reading([...byCode.values()], now);
121435
+ }
121436
+ var MAINTENANCE_FAULTS = [
121437
+ {
121438
+ key: "UNREACH",
121439
+ severity: "error",
121440
+ words: words("Device unreachable", "Dispositivo non raggiungibile")
121441
+ },
121442
+ {
121443
+ key: "STICKY_UNREACH",
121444
+ severity: "warning",
121445
+ words: words("Device was unreachable (not acknowledged)", "Dispositivo stato non raggiungibile")
121446
+ },
121447
+ {
121448
+ key: "LOW_BAT",
121449
+ severity: "warning",
121450
+ words: words("Battery low", "Batteria scarica")
121451
+ },
121452
+ {
121453
+ key: "LOWBAT",
121454
+ severity: "warning",
121455
+ words: words("Battery low", "Batteria scarica")
121456
+ },
121457
+ {
121458
+ key: "CONFIG_PENDING",
121459
+ severity: "warning",
121460
+ words: words("Configuration pending", "Configurazione in attesa")
121461
+ },
121462
+ {
121463
+ key: "DUTY_CYCLE",
121464
+ severity: "warning",
121465
+ words: words("Radio duty cycle exhausted", "Duty cycle radio esaurito")
121466
+ }
121467
+ ];
121468
+ /** Every `ERROR_*` boolean flag the device raises is its own fault (overheat, overload, jammed…). */
121469
+ function errorFlagRule(param) {
121470
+ const name = param.slice(6).toLowerCase().replace(/_/g, " ");
121471
+ return {
121472
+ key: param,
121473
+ severity: "error",
121474
+ words: words(`Device error: ${name}`, `Errore del dispositivo: ${name}`)
121475
+ };
121476
+ }
121477
+ function maintenanceRuleOf(param, value) {
121478
+ const upper = param.toUpperCase();
121479
+ const fixed = MAINTENANCE_FAULTS.find((rule) => rule.key === upper);
121480
+ if (fixed !== void 0) return fixed;
121481
+ if (upper.startsWith("ERROR_") && typeof value === "boolean") return errorFlagRule(upper);
121482
+ return null;
121483
+ }
121484
+ /**
121485
+ * A device's reading from its MAINTENANCE channel values (parameter -> value).
121486
+ * Until a service flag has a value the reading is UNKNOWN.
121487
+ */
121488
+ function maintenanceFaultReading(values, now) {
121489
+ const faults = [];
121490
+ let known = 0;
121491
+ for (const [param, value] of values) {
121492
+ const rule = maintenanceRuleOf(param, value);
121493
+ if (rule === null) continue;
121494
+ const on = truthy(value);
121495
+ if (on === null) continue;
121496
+ known += 1;
121497
+ if (on) faults.push(toFault(rule));
121498
+ }
121499
+ if (known === 0) return unknown(now);
121500
+ return reading(faults, now);
121501
+ }
121502
+ /** Every fault the gateway can raise: WatchDog's plus the two derived from radio behaviour. */
121503
+ function gatewayFaultTypes() {
121504
+ return [
121505
+ ...WATCHDOG_FAULTS,
121506
+ RADIO_UNREACHABLE_FAULT,
121507
+ RADIO_SILENT_FAULT
121508
+ ].map(toFault);
121509
+ }
121510
+ /**
121511
+ * The faults a device's MAINTENANCE channel can raise, by their fixed flags.
121512
+ * The per-model `ERROR_*` flags are discovered from the channel, so they are
121513
+ * published when raised but not listed here.
121514
+ */
121515
+ function maintenanceFaultTypes() {
121516
+ return MAINTENANCE_FAULTS.map(toFault);
121517
+ }
121518
+ //#endregion
121519
+ //#region src/ccu/ccu-faults-actions.ts
121520
+ /** A device's MAINTENANCE channel as the parameter map the fault mapping reads. */
121521
+ function maintenanceValues(device) {
121522
+ const values = /* @__PURE__ */ new Map();
121523
+ for (const point of maintenanceChannel(device)?.dataPoints ?? []) values.set(point.parameter, point.value);
121524
+ return values;
121525
+ }
121526
+ /** When the CCU raised a fault: the timestamp of its service message of the same code, else unknown. */
121527
+ function faultSince(address, code, messages) {
121528
+ return messages.find((message) => message.address !== null && (message.address === address || message.address.startsWith(`${address}:`)) && message.type === code && message.timestamp !== null)?.timestamp ?? null;
121529
+ }
121530
+ /**
121531
+ * The active faults CamStack derives from the CCU: the same pure mapping that
121532
+ * fills a device's `error` cap, read from the facade's cached MAINTENANCE values.
121533
+ * A device whose flags the CCU has not reported is UNKNOWN: it is not a fault
121534
+ * row but is named in `unreported`, so no caller reads it as "no fault". Only the `since` lookup is best effort; the device read
121535
+ * itself throws, so the page shows its warning instead of an empty list.
121536
+ */
121537
+ function buildCcuFaultHandlers(deps) {
121538
+ return { listCcuFaults: async (input) => {
121539
+ const facade = requireFacade(deps, input.integrationId);
121540
+ const adopted = await deps.adoptedAddresses(input.integrationId);
121541
+ const messages = await facade.serviceMessages().catch((error) => {
121542
+ deps.logger.warn("listCcuFaults: service messages unreadable, fault start times omitted", { meta: {
121543
+ integrationId: input.integrationId,
121544
+ error: error instanceof Error ? error.message : String(error)
121545
+ } });
121546
+ return [];
121547
+ });
121548
+ const now = Date.now();
121549
+ const faults = [];
121550
+ const unreported = [];
121551
+ for (const device of facade.devices()) {
121552
+ const reading = maintenanceFaultReading(maintenanceValues(device), now);
121553
+ if (reading.active === null) {
121554
+ unreported.push(device.address);
121555
+ continue;
121556
+ }
121557
+ const readingFaults = reading.faults ?? [];
121558
+ const principal = readingFaults[0];
121559
+ if (reading.active !== true || principal === void 0) continue;
121560
+ const all = readingFaults.map((fault) => ({
121561
+ code: fault.code,
121562
+ label: fault.label,
121563
+ severity: fault.severity
121564
+ }));
121565
+ faults.push({
121566
+ address: device.address,
121567
+ name: device.name ?? null,
121568
+ deviceId: adopted.get(device.address) ?? null,
121569
+ severity: principal.severity,
121570
+ code: principal.code,
121571
+ label: principal.label,
121572
+ since: faultSince(device.address, principal.code, messages),
121573
+ faults: all
121574
+ });
121575
+ }
121576
+ faults.sort((a, b) => a.severity === b.severity ? 0 : a.severity === "error" ? -1 : 1);
121577
+ const reported = deps.gatewayFaults?.(input.integrationId) ?? null;
121578
+ return {
121579
+ faults,
121580
+ unreported,
121581
+ gatewayFaults: reported === null ? null : reported.map((fault) => ({
121582
+ code: fault.code,
121583
+ label: fault.label,
121584
+ severity: fault.severity
121585
+ }))
121586
+ };
121587
+ } };
121588
+ }
121589
+ //#endregion
121092
121590
  //#region src/ccu/ccu-schemas.ts
121093
121591
  /**
121094
121592
  * Wire shapes of the CCU management custom actions. Shared by the addon (handler
@@ -121555,6 +122053,29 @@ var SetValueInputSchema = IntegrationRefSchema.extend({
121555
122053
  deviceId: number$1().int().optional(),
121556
122054
  confirmed: ConfirmedSchema
121557
122055
  });
122056
+ var CcuFaultSchema = object({
122057
+ code: string(),
122058
+ label: string(),
122059
+ severity: _enum(["error", "warning"])
122060
+ });
122061
+ var CcuFaultsResultSchema = object({
122062
+ faults: array(object({
122063
+ address: string(),
122064
+ name: string().nullable(),
122065
+ /** CamStack device id when the CCU device is adopted. */
122066
+ deviceId: number$1().int().nullable(),
122067
+ severity: _enum(["error", "warning"]),
122068
+ code: string(),
122069
+ label: string(),
122070
+ /** Epoch milliseconds of the matching service message; `null` when the CCU did not say. */
122071
+ since: number$1().nullable(),
122072
+ faults: array(CcuFaultSchema)
122073
+ })),
122074
+ /** Devices whose service flags the CCU has not reported: unknown, never "no fault". */
122075
+ unreported: array(string()),
122076
+ /** What the gateway (the CCU box and its radio) reports: WatchDog, mass unreachable, radio silence. `null` is unknown (never read, or no source answered), never "none". */
122077
+ gatewayFaults: array(CcuFaultSchema).nullable().default(null)
122078
+ });
121558
122079
  //#endregion
121559
122080
  //#region src/ccu/ccu-heating-actions.ts
121560
122081
  /**
@@ -147302,6 +147823,10 @@ var homematicActions = defineCustomActions({
147302
147823
  kind: "query",
147303
147824
  auth: "admin"
147304
147825
  }),
147826
+ listCcuFaults: customAction(IntegrationRefSchema, CcuFaultsResultSchema, {
147827
+ kind: "query",
147828
+ auth: "admin"
147829
+ }),
147305
147830
  listCcuDevices: customAction(IntegrationRefSchema, CcuDevicesResultSchema, {
147306
147831
  kind: "query",
147307
147832
  auth: "admin"
@@ -147561,10 +148086,32 @@ var HmFacadeResolver = class {
147561
148086
  #sessions = /* @__PURE__ */ new Map();
147562
148087
  /** Per-integration state-change fan-out (connect, disconnect, error). */
147563
148088
  #snapshotSubs = /* @__PURE__ */ new Map();
148089
+ /** Per-integration stamps of the real radio events (`radio-silent`). */
148090
+ #radioActivity = /* @__PURE__ */ new Map();
148091
+ /** The faults the gateway device last published, for the CCU page's overview. */
148092
+ #gatewayFaults = /* @__PURE__ */ new Map();
148093
+ /** Publish the radio-event tracker of an integration (a fresh one per facade). */
148094
+ setRadioActivity(integrationId, tracker) {
148095
+ if (tracker === null) this.#radioActivity.delete(integrationId);
148096
+ else this.#radioActivity.set(integrationId, tracker);
148097
+ }
148098
+ radioActivity(integrationId) {
148099
+ return this.#radioActivity.get(integrationId) ?? null;
148100
+ }
148101
+ /** The gateway device records what it published; read by the overview, never the other way. */
148102
+ setGatewayFaults(integrationId, faults) {
148103
+ this.#gatewayFaults.set(integrationId, faults);
148104
+ }
148105
+ /** `null` is unknown: nothing was published yet, or the last reading had no answering source. */
148106
+ gatewayFaults(integrationId) {
148107
+ return this.#gatewayFaults.get(integrationId) ?? null;
148108
+ }
147564
148109
  /** Publish or remove the facade for an integration id. `null` removes the entry. */
147565
148110
  set(integrationId, facade) {
147566
148111
  if (facade === null) {
147567
148112
  this.#facades.delete(integrationId);
148113
+ this.#radioActivity.delete(integrationId);
148114
+ this.#gatewayFaults.delete(integrationId);
147568
148115
  return;
147569
148116
  }
147570
148117
  this.#facades.set(integrationId, facade);
@@ -147613,6 +148160,8 @@ var HmFacadeResolver = class {
147613
148160
  clear() {
147614
148161
  clearCcuCallLimiters();
147615
148162
  this.#facades.clear();
148163
+ this.#radioActivity.clear();
148164
+ this.#gatewayFaults.clear();
147616
148165
  this.#sessions.clear();
147617
148166
  this.#snapshotSubs.clear();
147618
148167
  clearStoredKeyLinkStates();
@@ -149293,212 +149842,6 @@ function devicePanelSection(integrationId, address) {
149293
149842
  };
149294
149843
  }
149295
149844
  //#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
149845
  //#region src/homematic-diagnostics-mapping.ts
149503
149846
  var MAINTENANCE_CHANNEL_TYPE$1 = "MAINTENANCE";
149504
149847
  /** Reachability parameters that drive the Container's `online`, not a child. */
@@ -150478,6 +150821,59 @@ function buildConnectionFormSchema() {
150478
150821
  ] };
150479
150822
  }
150480
150823
  //#endregion
150824
+ //#region src/homematic-radio-interface.ts
150825
+ /** The radio interface a data-point id belongs to, or `null`. */
150826
+ function radioInterfaceOfDataPointId(id) {
150827
+ const owner = (id.split(":")[0] ?? "").toLowerCase();
150828
+ if (owner.endsWith("-hmip-rf")) return "HmIP-RF";
150829
+ if (owner.endsWith("-bidcos-rf")) return "BidCos-RF";
150830
+ return null;
150831
+ }
150832
+ /** The radio interface of a device (all its data points share one), or `null` when it has none. */
150833
+ function radioInterfaceOfDevice(device) {
150834
+ for (const channel of device.channels) for (const point of channel.dataPoints) return radioInterfaceOfDataPointId(point.id);
150835
+ return null;
150836
+ }
150837
+ /** … each with an UNREACH start inside one window of this length. */
150838
+ var RADIO_UNREACHABLE_WINDOW_MS = 10 * 6e4;
150839
+ function unreachOf(device) {
150840
+ const point = maintenanceChannel(device)?.dataPoints.find((p) => p.parameter === "UNREACH");
150841
+ return typeof point?.value === "boolean" ? point.value : null;
150842
+ }
150843
+ /** The most UNREACH starts that fall inside any one window. */
150844
+ function largestCluster(starts) {
150845
+ const sorted = [...starts].sort((a, b) => a - b);
150846
+ let best = 0;
150847
+ let low = 0;
150848
+ for (let high = 0; high < sorted.length; high += 1) {
150849
+ while ((sorted[high] ?? 0) - (sorted[low] ?? 0) > RADIO_UNREACHABLE_WINDOW_MS) low += 1;
150850
+ best = Math.max(best, high - low + 1);
150851
+ }
150852
+ return best;
150853
+ }
150854
+ /**
150855
+ * Active when several HmIP-RF devices became UNREACH close together: enough of
150856
+ * them AND enough of the interface. A device whose UNREACH start the CCU did not
150857
+ * stamp cannot be placed in a window and is not counted. The population is the
150858
+ * HmIP-RF devices whose flag was read; none read is UNKNOWN, never "fine".
150859
+ */
150860
+ function radioUnreachableReading(devices, messages, now) {
150861
+ const starts = [];
150862
+ let population = 0;
150863
+ for (const device of devices) {
150864
+ if (radioInterfaceOfDevice(device) !== "HmIP-RF") continue;
150865
+ const unreach = unreachOf(device);
150866
+ if (unreach === null) continue;
150867
+ population += 1;
150868
+ if (!unreach) continue;
150869
+ const since = faultSince(device.address, "UNREACH", messages);
150870
+ if (since !== null) starts.push(since);
150871
+ }
150872
+ if (population === 0) return ruleReading(RADIO_UNREACHABLE_FAULT, null, now);
150873
+ const clustered = largestCluster(starts);
150874
+ return ruleReading(RADIO_UNREACHABLE_FAULT, clustered >= 3 && clustered / population >= .25, now);
150875
+ }
150876
+ //#endregion
150481
150877
  //#region src/homematic-gateway-metadata.ts
150482
150878
  /** What the CCU box is known by, as device metadata (a CCU announces no model or firmware over XML-RPC). */
150483
150879
  function gatewayMetadataPatch(input) {
@@ -150488,9 +150884,37 @@ function gatewayMetadataPatch(input) {
150488
150884
  };
150489
150885
  }
150490
150886
  //#endregion
150887
+ //#region src/homematic-state-refresh.ts
150888
+ /**
150889
+ * Homematic's side of the core state refresh (D1062): HOW to read, never WHEN.
150890
+ *
150891
+ * The CCU pushes every radio device event over the XML-RPC callback, so those
150892
+ * devices are never read on a clock. The one thing it does NOT push is its own
150893
+ * WatchDog system variables (the gateway's `error` cap): they are a snapshot the
150894
+ * gateway has to read, so the gateway registers `device-state-refresh` with
150895
+ * `push: 'none'` and the core reads it at {@link HOMEMATIC_GATEWAY_REFRESH_MS}.
150896
+ */
150897
+ /** How often the core reads the CCU's WatchDog system variables. */
150898
+ var HOMEMATIC_GATEWAY_REFRESH_MS = 3e4;
150899
+ function homematicGatewayRefreshPolicy(integrationId) {
150900
+ return {
150901
+ integrationId,
150902
+ minIntervalMs: HOMEMATIC_GATEWAY_REFRESH_MS,
150903
+ batch: false,
150904
+ push: "none"
150905
+ };
150906
+ }
150907
+ function registerHomematicStateRefresh(target) {
150908
+ target.ctx.registerNativeCap(deviceStateRefreshCapability, {
150909
+ refresh: async () => {
150910
+ await target.readFaults();
150911
+ return { ok: true };
150912
+ },
150913
+ resubscribe: async () => ({ ok: true })
150914
+ }, { stateRefresh: homematicGatewayRefreshPolicy(target.integrationId) });
150915
+ }
150916
+ //#endregion
150491
150917
  //#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
150918
  /**
150495
150919
  * The physical CCU3 / RaspberryMatic box, as a {@link DeviceType.Gateway}. Its
150496
150920
  * connection and password live on the INTEGRATION; this device follows whether
@@ -150499,8 +150923,10 @@ var WATCHDOG_POLL_MS = 3e4;
150499
150923
  *
150500
150924
  * - `device-admin-link`, the CCU's own WebUI.
150501
150925
  *
150502
- * - `error`, the faults the CCU WatchDog add-on raises as system variables
150503
- * (`homematic-fault-mapping.ts`), re-read every {@link WATCHDOG_POLL_MS}.
150926
+ * - `error`, the merge of every fault source (`homematic-fault-mapping.ts`): the
150927
+ * CCU's built-in WatchDog alarm variables, several HmIP-RF devices unreachable
150928
+ * together, and radio silence. Read by the core's `device-state-refresh` (D1062), because
150929
+ * the CCU pushes no event for them.
150504
150930
  *
150505
150931
  * There is no `reboot` and no `update`: nodehomematic has no call that restarts
150506
150932
  * the CCU, and its firmware call installs an update on a radio DEVICE by its
@@ -150515,17 +150941,23 @@ var HomematicGatewayDevice = class extends BaseDevice {
150515
150941
  snapshotUnsub = null;
150516
150942
  /** The last metadata written, so a state change that altered nothing writes nothing. */
150517
150943
  lastMetadataKey = "";
150518
- pollTimer = null;
150519
150944
  polling = false;
150520
150945
  warnedReadFailure = false;
150946
+ warnedSources = /* @__PURE__ */ new Set();
150947
+ seenUnmatchedWatchdog = /* @__PURE__ */ new Set();
150521
150948
  constructor(ctx) {
150522
150949
  const cfg = homematicGatewayDeviceSchema.parse(ctx.persistedConfig ?? {});
150523
150950
  super(ctx, homematicGatewayDeviceSchema, { type: DeviceType.Gateway });
150524
150951
  this.integrationId = cfg.integrationId;
150525
150952
  this.online = this.sessionUp();
150526
150953
  this.registerAdminLinkCap();
150527
- this.declareFaultTypes(watchdogFaultTypes());
150954
+ this.declareFaultTypes(gatewayFaultTypes());
150528
150955
  this.registerErrorCap();
150956
+ registerHomematicStateRefresh({
150957
+ ctx,
150958
+ integrationId: cfg.integrationId,
150959
+ readFaults: () => this.refreshFaults()
150960
+ });
150529
150961
  this.updateSourceInfo({
150530
150962
  id: cfg.nativeId,
150531
150963
  system: "homematic"
@@ -150538,15 +150970,9 @@ var HomematicGatewayDevice = class extends BaseDevice {
150538
150970
  if (this.sessionUp()) this.pollFaults();
150539
150971
  });
150540
150972
  await this.sync();
150541
- this.pollTimer = setInterval(() => {
150542
- this.pollFaults();
150543
- }, WATCHDOG_POLL_MS);
150544
- this.pollTimer.unref();
150545
150973
  await this.pollFaults();
150546
150974
  }
150547
150975
  async removeDevice() {
150548
- if (this.pollTimer !== null) clearInterval(this.pollTimer);
150549
- this.pollTimer = null;
150550
150976
  this.snapshotUnsub?.();
150551
150977
  this.snapshotUnsub = null;
150552
150978
  await super.removeDevice();
@@ -150555,9 +150981,79 @@ var HomematicGatewayDevice = class extends BaseDevice {
150555
150981
  return homematicFacades.getSession(this.integrationId)?.getInfo().status === "connected";
150556
150982
  }
150557
150983
  /**
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.
150984
+ * The core's read (D1062): the CCU's WatchDog system variables, published as
150985
+ * faults. It THROWS when the session is down or the CCU does not answer, so
150986
+ * the core backs the cadence off; the previous reading stands meanwhile. It
150987
+ * shares the `polling` guard with `pollFaults`: a read already in flight
150988
+ * publishes the same reading, so a second one is not started.
150989
+ */
150990
+ async refreshFaults() {
150991
+ if (this.polling) return;
150992
+ const facade = homematicFacades.get(this.integrationId);
150993
+ if (!this.sessionUp() || facade === null) throw new Error(`Homematic CCU not connected (integration ${this.integrationId})`);
150994
+ this.polling = true;
150995
+ try {
150996
+ await this.readFaultsFrom(facade);
150997
+ } finally {
150998
+ this.polling = false;
150999
+ }
151000
+ }
151001
+ async readFaultsFrom(facade) {
151002
+ await facade.refreshHub();
151003
+ const now = Date.now();
151004
+ const reading = mergeFaultReadings([
151005
+ watchdogFaultReading(facade.systemVariables(), now, (name) => this.noteUnmatchedWatchdog(name)),
151006
+ await this.readRadioUnreachable(facade, now),
151007
+ this.readRadioSilent(facade, now)
151008
+ ], now);
151009
+ if (reading.active === null) this.ctx.logger.debug("Homematic gateway: no WatchDog system variable and no other fault source readable, faults stay unknown", { tags: { deviceId: this.id } });
151010
+ homematicFacades.setGatewayFaults(this.integrationId, reading.active === null ? null : reading.faults ?? []);
151011
+ this.warnedReadFailure = false;
151012
+ await this.publishError(reading);
151013
+ }
151014
+ /** A WatchDog variable no rule knows: logged once per name so the real names get learned. */
151015
+ noteUnmatchedWatchdog(name) {
151016
+ if (this.seenUnmatchedWatchdog.has(name)) return;
151017
+ this.seenUnmatchedWatchdog.add(name);
151018
+ this.ctx.logger.debug("Homematic gateway: WatchDog variable matches no fault rule", {
151019
+ tags: { deviceId: this.id },
151020
+ meta: { variable: name }
151021
+ });
151022
+ }
151023
+ /** A source that cannot be read is unknown; the first failure is a warning, the repeats debug. */
151024
+ noteSourceFailure(source, error) {
151025
+ const log = this.warnedSources.has(source) ? this.ctx.logger.debug : this.ctx.logger.warn;
151026
+ this.warnedSources.add(source);
151027
+ log.call(this.ctx.logger, `Homematic gateway: ${source} unreadable, that source stays unknown`, {
151028
+ tags: { deviceId: this.id },
151029
+ meta: { error }
151030
+ });
151031
+ }
151032
+ /** Several HmIP-RF devices unreachable together; needs the service messages for the start times. */
151033
+ async readRadioUnreachable(facade, now) {
151034
+ try {
151035
+ const messages = await facade.serviceMessages();
151036
+ return radioUnreachableReading(facade.devices(), messages, now);
151037
+ } catch (err) {
151038
+ this.noteSourceFailure("radio unreachable check", errMsg(err));
151039
+ return ruleReading(RADIO_UNREACHABLE_FAULT, null, now);
151040
+ }
151041
+ }
151042
+ /** No real radio event for too long, from the stamps the registry's event listener keeps. */
151043
+ readRadioSilent(facade, now) {
151044
+ const tracker = homematicFacades.radioActivity(this.integrationId);
151045
+ if (tracker === null) return ruleReading(RADIO_SILENT_FAULT, null, now);
151046
+ try {
151047
+ return tracker.reading(facade.devices(), now);
151048
+ } catch (err) {
151049
+ this.noteSourceFailure("radio silence check", errMsg(err));
151050
+ return ruleReading(RADIO_SILENT_FAULT, null, now);
151051
+ }
151052
+ }
151053
+ /**
151054
+ * Read the faults when the CCU announced a new snapshot (it just reconnected
151055
+ * or changed). A read that fails changes nothing (the previous reading
151056
+ * stands), and every branch that publishes nothing leaves a line on the device.
150561
151057
  */
150562
151058
  async pollFaults() {
150563
151059
  if (this.polling) return;
@@ -150569,11 +151065,7 @@ var HomematicGatewayDevice = class extends BaseDevice {
150569
151065
  }
150570
151066
  this.polling = true;
150571
151067
  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);
151068
+ await this.readFaultsFrom(facade);
150577
151069
  } catch (err) {
150578
151070
  const log = this.warnedReadFailure ? this.ctx.logger.debug : this.ctx.logger.warn;
150579
151071
  this.warnedReadFailure = true;
@@ -151489,6 +151981,58 @@ function isConnectionArg(arg) {
151489
151981
  return typeof arg === "object" && arg !== null && "interfaceId" in arg && "state" in arg && typeof arg["state"] === "string";
151490
151982
  }
151491
151983
  //#endregion
151984
+ //#region src/homematic-radio-silent.ts
151985
+ /**
151986
+ * Feed a tracker from the library's `valueChanged`. The event's `ts` is epoch
151987
+ * milliseconds (the library stamps `Date.now()`), the unit the tracker keeps;
151988
+ * it is passed through untouched. Returns the unsubscribe function.
151989
+ */
151990
+ function attachRadioActivity(source, tracker) {
151991
+ return source.on("valueChanged", (event) => tracker.record(event.dpId, event.ts));
151992
+ }
151993
+ /**
151994
+ * Stamps the REAL device datapoint events of each radio interface (fed from the
151995
+ * library's `valueChanged`). A connection ping, an interface-level event or a
151996
+ * virtual / group device never passes {@link record}'s interface check, so none
151997
+ * of them keeps the silence alive. The reading rides the core state-refresh tick:
151998
+ * there is no timer here.
151999
+ */
152000
+ var RadioActivityTracker = class {
152001
+ #lastEventAt = /* @__PURE__ */ new Map();
152002
+ #startedAt;
152003
+ constructor(startedAt) {
152004
+ this.#startedAt = startedAt;
152005
+ }
152006
+ /** Stamp one real device event, named by its data-point id. */
152007
+ record(dataPointId, at) {
152008
+ const radio = radioInterfaceOfDataPointId(dataPointId);
152009
+ if (radio === null) return;
152010
+ if (at > (this.#lastEventAt.get(radio) ?? 0)) this.#lastEventAt.set(radio, at);
152011
+ }
152012
+ /**
152013
+ * Silent when an interface with enough devices has had no event for
152014
+ * {@link RADIO_SILENT_AFTER_MS}. Before the first event the clock runs from
152015
+ * the tracker's start, so it is UNKNOWN until that long has passed.
152016
+ */
152017
+ reading(devices, now) {
152018
+ const counts = /* @__PURE__ */ new Map();
152019
+ for (const device of devices) {
152020
+ const radio = radioInterfaceOfDevice(device);
152021
+ if (radio !== null) counts.set(radio, (counts.get(radio) ?? 0) + 1);
152022
+ }
152023
+ let judged = false;
152024
+ let silent = false;
152025
+ for (const [radio, count] of counts) {
152026
+ if (count < 5) continue;
152027
+ const last = this.#lastEventAt.get(radio);
152028
+ if (last === void 0 && now - this.#startedAt < 9e5) continue;
152029
+ judged = true;
152030
+ if (now - (last ?? this.#startedAt) >= 9e5) silent = true;
152031
+ }
152032
+ return ruleReading(RADIO_SILENT_FAULT, judged ? silent : null, now);
152033
+ }
152034
+ };
152035
+ //#endregion
151492
152036
  //#region src/homematic-client-registry.ts
151493
152037
  /**
151494
152038
  * Delays (ms) between background retries after a failed `facade.start()` (e.g.
@@ -151547,6 +152091,9 @@ var HmClientRegistry = class {
151547
152091
  const raw = new Homematic(toHomematicOptions(config));
151548
152092
  this.#facades.set(opts.id, raw);
151549
152093
  homematicFacades.set(opts.id, raw);
152094
+ const tracker = new RadioActivityTracker(Date.now());
152095
+ homematicFacades.setRadioActivity(opts.id, tracker);
152096
+ attachRadioActivity(raw, tracker);
151550
152097
  return wrapFacade(raw);
151551
152098
  }
151552
152099
  });
@@ -152467,6 +153014,7 @@ var HomematicProviderAddon = class extends BaseDeviceProvider {
152467
153014
  actionHandlers: {
152468
153015
  ...buildCcuOverviewHandlers(this.ccuActionDeps()),
152469
153016
  ...buildCcuDevicesHandlers(this.ccuActionDeps()),
153017
+ ...buildCcuFaultHandlers(this.ccuActionDeps()),
152470
153018
  ...buildCcuHeatingHandlers(this.ccuActionDeps()),
152471
153019
  ...buildCcuPairingHandlers(this.ccuActionDeps()),
152472
153020
  ...buildCcuConfigHandlers(this.ccuActionDeps()),
@@ -152563,7 +153111,8 @@ var HomematicProviderAddon = class extends BaseDeviceProvider {
152563
153111
  logger: this.ctx.logger,
152564
153112
  adoptedAddresses: (integrationId) => this.adoptedCcuAddresses(integrationId),
152565
153113
  adoptedNames: (integrationId) => this.adoptedCcuNames(integrationId),
152566
- ccuChanged: (integrationId) => homematicFacades.emitSnapshot(integrationId)
153114
+ ccuChanged: (integrationId) => homematicFacades.emitSnapshot(integrationId),
153115
+ gatewayFaults: (integrationId) => homematicFacades.gatewayFaults(integrationId)
152567
153116
  };
152568
153117
  }
152569
153118
  async onShutdown() {