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