@camstack/types 1.2.528 → 1.2.530

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 (35) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/addon.js +1 -1
  3. package/dist/addon.mjs +1 -1
  4. package/dist/capabilities/capability-definition.d.ts +15 -0
  5. package/dist/capabilities/climate-control.cap.d.ts +26 -1
  6. package/dist/capabilities/enum-sensor.cap.d.ts +1 -1
  7. package/dist/capabilities/hero-layout.cap.d.ts +158 -17
  8. package/dist/capabilities/water-heater.cap.d.ts +5 -1
  9. package/dist/device/hero/climate-view.d.ts +45 -0
  10. package/dist/device/hero/hero-contribution-kit.d.ts +27 -0
  11. package/dist/device/hero/hero-contributions-access.d.ts +2 -0
  12. package/dist/device/hero/hero-contributions-actuators.d.ts +2 -0
  13. package/dist/device/hero/hero-contributions-climate.d.ts +3 -0
  14. package/dist/device/hero/hero-contributions-devices.d.ts +2 -0
  15. package/dist/device/hero/hero-contributions-groups.d.ts +2 -0
  16. package/dist/device/hero/hero-contributions-sensors.d.ts +2 -0
  17. package/dist/device/hero/hero-contributions.d.ts +2 -5
  18. package/dist/device/hero/hero-fragment.d.ts +11 -1
  19. package/dist/device/hero/hero-look.d.ts +80 -14
  20. package/dist/device/hero/hero-model.d.ts +224 -34
  21. package/dist/device/hero/hero-row.d.ts +30 -5
  22. package/dist/device/hero/media-player-view.d.ts +6 -0
  23. package/dist/generated/addon-cap-facts.d.ts +1 -1
  24. package/dist/generated/runtime-state-durability.d.ts +6 -1
  25. package/dist/index.d.ts +1 -0
  26. package/dist/index.js +2918 -367
  27. package/dist/index.mjs +2914 -368
  28. package/dist/ir/flipper.d.ts +43 -0
  29. package/dist/ir/index.d.ts +1 -0
  30. package/dist/ir/ir-error.d.ts +1 -1
  31. package/dist/remote/flipper-ir-draft.d.ts +13 -0
  32. package/dist/remote/smartir-draft.d.ts +5 -1
  33. package/dist/{sleep-CqvzKIq2.mjs → sleep-CfYvHNFz.mjs} +16 -0
  34. package/dist/{sleep-DX_umr22.js → sleep-CqsZMKxq.js} +16 -0
  35. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_sleep = require("./sleep-DX_umr22.js");
2
+ const require_sleep = require("./sleep-CqsZMKxq.js");
3
3
  const require_event_category = require("./event-category-BC4RRerT.js");
4
4
  const require_device_type = require("./device-type-BaYa0UGS.js");
5
5
  const require_composition = require("./composition-BjHGoicU.js");
@@ -1435,7 +1435,7 @@ function rowSchemaOf(itemFields) {
1435
1435
  * adapter's own parse accepts, because the form already validated its shape. The body is loose, so a key
1436
1436
  * the schema does not know (the owner of a personal target) survives a write.
1437
1437
  */
1438
- function fieldsOf(descriptor) {
1438
+ function fieldsOf$1(descriptor) {
1439
1439
  const shape = {};
1440
1440
  const secretArrayKeys = {};
1441
1441
  for (const section of descriptor.configSchema.sections) for (const field of section.fields) switch (field.type) {
@@ -1464,7 +1464,7 @@ function fieldsOf(descriptor) {
1464
1464
  }
1465
1465
  /** The record kind of one target kind, derived from its descriptor. */
1466
1466
  function defineNotificationTargetKind(descriptor) {
1467
- const { shape, secretArrayKeys } = fieldsOf(descriptor);
1467
+ const { shape, secretArrayKeys } = fieldsOf$1(descriptor);
1468
1468
  return require_sleep.defineEntryKind(notificationTargetKindName(descriptor.kind), {
1469
1469
  title: `${descriptor.label} notification targets`,
1470
1470
  schema: TargetBodyBaseSchema.extend(shape),
@@ -1691,7 +1691,7 @@ function buildNotificationTargetInstances(records, spec) {
1691
1691
  }
1692
1692
  /** The secret keys of a kind's body: the descriptor's `password` fields (top level). */
1693
1693
  function secretKeysOf(descriptor) {
1694
- const { shape } = fieldsOf(descriptor);
1694
+ const { shape } = fieldsOf$1(descriptor);
1695
1695
  return Object.keys(shape).filter((key) => {
1696
1696
  const meta = zod.z.globalRegistry.get(shape[key] ?? zod.z.unknown());
1697
1697
  return typeof meta === "object" && meta !== null && Reflect.get(meta, "secret") === true;
@@ -41648,6 +41648,12 @@ var ClimateControlStatusSchema = zod.z.object({
41648
41648
  maxTemp: zod.z.number().nullable().optional().meta(require_sleep.readingMeta("temperature")),
41649
41649
  /** Setpoint granularity, Celsius (0.5, 1). Absent / null = not reported. */
41650
41650
  tempStep: zod.z.number().positive().nullable().optional().meta(require_sleep.readingMeta("temperature")),
41651
+ /**
41652
+ * The last non-off mode the device reported. Kept by the device-state mirror on every
41653
+ * write (providers never set it), so "turn on" can return to it. Absent until the device
41654
+ * has reported a running mode.
41655
+ */
41656
+ lastActiveMode: HvacModeSchema.exclude(["off"]).optional(),
41651
41657
  /** Ms epoch when the slice was last updated (push or command). */
41652
41658
  lastFetchedAt: zod.z.number()
41653
41659
  });
@@ -41732,7 +41738,8 @@ var climateControlCapability = {
41732
41738
  * See `RuntimeStateDurability`. Enforced by
41733
41739
  * `scripts/check-runtime-state-durability.ts`.
41734
41740
  */
41735
- durability: "session",
41741
+ durability: "restored",
41742
+ restoredStateFields: ["lastActiveMode"],
41736
41743
  /**
41737
41744
  * History (D850): recorded series. Celsius by contract; setpoints keep every change (`minIntervalMs: 0`).
41738
41745
  */
@@ -43087,7 +43094,7 @@ function irSourceProblem(source) {
43087
43094
  throw err;
43088
43095
  }
43089
43096
  }
43090
- function same(a, b) {
43097
+ function same$1(a, b) {
43091
43098
  return a.trim().toLowerCase() === b.trim().toLowerCase();
43092
43099
  }
43093
43100
  /** The `digits` source that declares this channel number, or null. */
@@ -43101,7 +43108,7 @@ function findChannelSource(sources, number) {
43101
43108
  * the number reach the same source; nothing else is guessed.
43102
43109
  */
43103
43110
  function resolveRemoteSource(sources, query) {
43104
- const byName = sources.find((source) => same(source.name, query));
43111
+ const byName = sources.find((source) => same$1(source.name, query));
43105
43112
  if (byName !== void 0) return byName;
43106
43113
  const byId = sources.find((source) => source.id === query.trim());
43107
43114
  if (byId !== void 0) return byId;
@@ -53602,7 +53609,7 @@ var enumSensorCapability = {
53602
53609
  } } },
53603
53610
  /** Clock fields: written, but excluded from the compare that decides
53604
53611
  * whether persisting is worth a SQLite commit. */
53605
- volatileStateFields: ["lastFetchedAt"]
53612
+ volatileStateFields: ["lastFetchedAt", "timestamp"]
53606
53613
  };
53607
53614
  //#endregion
53608
53615
  //#region src/capabilities/event-emitter.cap.ts
@@ -55273,22 +55280,51 @@ var HERO_ROW_IDS = [
55273
55280
  "volume",
55274
55281
  "source",
55275
55282
  "contact",
55276
- "motion-trigger"
55283
+ "motion-trigger",
55284
+ "lock",
55285
+ "alarm",
55286
+ "fan",
55287
+ "vacuum",
55288
+ "mower",
55289
+ "feeder",
55290
+ "fountain",
55291
+ "pump-cycle",
55292
+ "automation",
55293
+ "script",
55294
+ "do-not-disturb",
55295
+ "brightness",
55296
+ "color",
55297
+ "cover",
55298
+ "valve",
55299
+ "humidifier",
55300
+ "update",
55301
+ "button",
55302
+ "climate-mode",
55303
+ "climate-fan",
55304
+ "setpoint",
55305
+ "channel",
55306
+ "control"
55277
55307
  ];
55278
55308
  var HeroRowIdSchema = zod.z.enum(HERO_ROW_IDS);
55279
- /** Argument values an action carries; the device id is added by the renderer. */
55280
- var HeroArgsSchema = zod.z.record(zod.z.string(), zod.z.union([
55309
+ var HeroArgValueSchema = zod.z.lazy(() => zod.z.union([
55281
55310
  zod.z.string(),
55282
55311
  zod.z.number(),
55283
- zod.z.boolean()
55312
+ zod.z.boolean(),
55313
+ zod.z.record(zod.z.string(), HeroArgValueSchema)
55284
55314
  ]));
55315
+ var HeroArgsSchema = zod.z.record(zod.z.string(), HeroArgValueSchema);
55285
55316
  /** A cap method called on the hero's device. */
55286
55317
  var HeroCallSchema = zod.z.object({
55287
55318
  cap: zod.z.string(),
55288
55319
  method: zod.z.string(),
55289
55320
  args: HeroArgsSchema
55290
55321
  });
55291
- var HeroConfirmSchema = zod.z.enum(["off-while-running"]);
55322
+ var HeroConfirmSchema = zod.z.enum([
55323
+ "off-while-running",
55324
+ "unlock",
55325
+ "install",
55326
+ "press"
55327
+ ]);
55292
55328
  var HeroActionSchema = zod.z.object({
55293
55329
  /** Unique within the model; the `gated` list and the specs name it. */
55294
55330
  id: zod.z.string(),
@@ -55384,7 +55420,11 @@ var HeroConsumptionSlotSchema = zod.z.discriminatedUnion("kind", [zod.z.object({
55384
55420
  })]);
55385
55421
  var HeroOwnPowerSlotSchema = zod.z.object({
55386
55422
  /** Which cap the power is switched through; the renderer never needs it. */
55387
- source: zod.z.enum(["switch", "media-player"]),
55423
+ source: zod.z.enum([
55424
+ "switch",
55425
+ "media-player",
55426
+ "climate-control"
55427
+ ]),
55388
55428
  /** `null` = unknown, never off. */
55389
55429
  on: zod.z.boolean().nullable(),
55390
55430
  assumed: zod.z.boolean(),
@@ -55421,7 +55461,23 @@ var HeroFactSchema = zod.z.object({
55421
55461
  "remaining",
55422
55462
  "volume",
55423
55463
  "source",
55424
- "consumables"
55464
+ "consumables",
55465
+ "since",
55466
+ "speed",
55467
+ "progress",
55468
+ "level",
55469
+ "last-run",
55470
+ "event",
55471
+ "members",
55472
+ "failures",
55473
+ "reading",
55474
+ "climate",
55475
+ "temperature",
55476
+ "humidity",
55477
+ "pressure",
55478
+ "air-quality",
55479
+ "illuminance",
55480
+ "valve"
55425
55481
  ]),
55426
55482
  icon: IconKeySchema.nullable(),
55427
55483
  text: HeroTextSchema,
@@ -88080,6 +88136,11 @@ var WaterHeaterStatusSchema = zod.z.object({
88080
88136
  minTemp: zod.z.number().nullable().meta(require_sleep.readingMeta("temperature")),
88081
88137
  /** HA `max_temp` attribute. Null when not reported. */
88082
88138
  maxTemp: zod.z.number().nullable().meta(require_sleep.readingMeta("temperature")),
88139
+ /**
88140
+ * The last operation mode other than `off` the device reported. Kept by the device-state
88141
+ * mirror on every write (providers never set it), so "turn on" can return to it.
88142
+ */
88143
+ lastActiveMode: zod.z.string().optional(),
88083
88144
  /** Ms epoch when the slice was last updated. */
88084
88145
  lastChangedAt: zod.z.number()
88085
88146
  });
@@ -88127,7 +88188,8 @@ var waterHeaterCapability = {
88127
88188
  * See `RuntimeStateDurability`. Enforced by
88128
88189
  * `scripts/check-runtime-state-durability.ts`.
88129
88190
  */
88130
- durability: "session",
88191
+ durability: "restored",
88192
+ restoredStateFields: ["lastActiveMode"],
88131
88193
  /**
88132
88194
  * History (D850): recorded series. The schema carries no unit; providers publish Celsius. Setpoint keeps every change.
88133
88195
  */
@@ -93504,7 +93566,7 @@ function resolveAll(table, target, skipped) {
93504
93566
  * command SmartIR knows fills its role; a source, or any command it does not
93505
93567
  * know, becomes a custom button named as the file spells it.
93506
93568
  */
93507
- function smartIrDraft(table, target) {
93569
+ function smartIrDraft(table, target, options = {}) {
93508
93570
  const skipped = [];
93509
93571
  const commands = resolveAll(table, target, skipped);
93510
93572
  const bindings = {};
@@ -93537,9 +93599,16 @@ function smartIrDraft(table, target) {
93537
93599
  continue;
93538
93600
  }
93539
93601
  if (command.name === "on" || command.name === "off") continue;
93540
- const role = KNOWN_KEY_ROLES[command.name];
93541
- if (role !== void 0) bindings[role] = bindingOf(command);
93542
- else addCustom(command, "");
93602
+ const role = options.roleOf?.(command.name) ?? KNOWN_KEY_ROLES[command.name];
93603
+ if (role === void 0) addCustom(command, "");
93604
+ else if (bindings[role] !== void 0) skipped.push({
93605
+ name: command.name,
93606
+ reason: `duplicate of the ${role} button already bound`
93607
+ });
93608
+ else {
93609
+ bindings[role] = bindingOf(command);
93610
+ if (role === "power") mode = "toggle";
93611
+ }
93543
93612
  }
93544
93613
  return {
93545
93614
  bindings,
@@ -93549,6 +93618,273 @@ function smartIrDraft(table, target) {
93549
93618
  };
93550
93619
  }
93551
93620
  //#endregion
93621
+ //#region src/ir/flipper.ts
93622
+ /**
93623
+ * The Flipper `.ir` signals file: a header, then one block per button
93624
+ * separated by `#`. A block is either a PARSED code (protocol, address,
93625
+ * command) or a RAW train (frequency, duty cycle, alternating durations).
93626
+ * Parsed codes are encoded here for the protocols whose frame is proven;
93627
+ * every other protocol is reported per button, never dropped silently.
93628
+ */
93629
+ var FILETYPE = "IR signals file";
93630
+ function malformed(message) {
93631
+ return new IrCodecError("flipper-malformed", message);
93632
+ }
93633
+ function fieldsOf(block) {
93634
+ const fields = /* @__PURE__ */ new Map();
93635
+ for (const line of block) {
93636
+ const colon = line.indexOf(":");
93637
+ if (colon <= 0) continue;
93638
+ fields.set(line.slice(0, colon).trim().toLowerCase(), line.slice(colon + 1).trim());
93639
+ }
93640
+ return fields;
93641
+ }
93642
+ function need(fields, key, name) {
93643
+ const value = fields.get(key);
93644
+ if (value === void 0 || value === "") throw malformed(`Button "${name}" has no ${key}`);
93645
+ return value;
93646
+ }
93647
+ function littleEndian(hex, what, name) {
93648
+ const bytes = hex.split(/\s+/);
93649
+ let value = 0;
93650
+ bytes.forEach((byte, index) => {
93651
+ if (!/^[0-9a-fA-F]{1,2}$/.test(byte)) throw malformed(`Button "${name}" has a bad ${what}`);
93652
+ value += Number.parseInt(byte, 16) * 256 ** index;
93653
+ });
93654
+ return value;
93655
+ }
93656
+ function buttonOf(block) {
93657
+ const fields = fieldsOf(block);
93658
+ const name = need(fields, "name", "?");
93659
+ const type = need(fields, "type", name);
93660
+ if (type === "parsed") return {
93661
+ type,
93662
+ name,
93663
+ protocol: need(fields, "protocol", name),
93664
+ address: littleEndian(need(fields, "address", name), "address", name),
93665
+ command: littleEndian(need(fields, "command", name), "command", name)
93666
+ };
93667
+ if (type === "raw") {
93668
+ const data = need(fields, "data", name).split(/\s+/).map((v) => Number(v));
93669
+ if (data.some((v) => !Number.isInteger(v) || v <= 0)) throw malformed(`Button "${name}" has bad raw data`);
93670
+ return {
93671
+ type,
93672
+ name,
93673
+ frequency: Number(need(fields, "frequency", name)),
93674
+ dutyCycle: Number(fields.get("duty_cycle") ?? "0.33"),
93675
+ data
93676
+ };
93677
+ }
93678
+ throw malformed(`Button "${name}" has unknown type "${type}"`);
93679
+ }
93680
+ /** Parse a `.ir` file. Throws `IrCodecError` (`flipper-malformed`). */
93681
+ function parseFlipperIr(text) {
93682
+ const lines = text.split(/\r?\n/);
93683
+ if (fieldsOf(lines.slice(0, 3)).get("filetype") !== FILETYPE) throw malformed("Not a Flipper IR signals file");
93684
+ const blocks = [[]];
93685
+ for (const line of lines.slice(1)) {
93686
+ if (line.trim().startsWith("#")) {
93687
+ if ((blocks.at(-1) ?? []).some((l) => l.trim().toLowerCase().startsWith("name:"))) blocks.push([]);
93688
+ continue;
93689
+ }
93690
+ blocks.at(-1)?.push(line);
93691
+ }
93692
+ return { buttons: blocks.filter((b) => b.some((l) => l.trim().toLowerCase().startsWith("name:"))).map(buttonOf) };
93693
+ }
93694
+ var CARRIER_HZ = 38e3;
93695
+ var BIT_MARK_US$1 = 560;
93696
+ var ONE_SPACE_US$1 = 1690;
93697
+ var ZERO_SPACE_US$1 = 560;
93698
+ /** Bytes sent in order, each byte LSB first, closed by a stop mark. */
93699
+ function frame(headerMark, headerSpace, bytes) {
93700
+ const body = bytes.flatMap((byte) => Array.from({ length: 8 }, (_, bit) => [BIT_MARK_US$1, -(Math.floor(byte / 2 ** bit) % 2 === 1 ? ONE_SPACE_US$1 : ZERO_SPACE_US$1)]).flat());
93701
+ return [
93702
+ headerMark,
93703
+ -headerSpace,
93704
+ ...body,
93705
+ BIT_MARK_US$1,
93706
+ -560
93707
+ ];
93708
+ }
93709
+ function fits(value, bits, what, protocol) {
93710
+ if (value >= 2 ** bits) throw new IrCodecError("flipper-malformed", `${protocol} ${what} does not fit in ${bits} bits`);
93711
+ }
93712
+ var lo = (v) => v % 256;
93713
+ var hi = (v) => Math.floor(v / 256) % 256;
93714
+ /** Protocols this encoder emits: NEC, NECext and Samsung32. Any other throws, naming the protocol. */
93715
+ function encodeFlipperParsed(code) {
93716
+ const { protocol, address, command } = code;
93717
+ if (protocol === "NEC") {
93718
+ fits(address, 8, "address", protocol);
93719
+ fits(command, 8, "command", protocol);
93720
+ return {
93721
+ timings: frame(9e3, 4500, [
93722
+ address,
93723
+ 255 - address,
93724
+ command,
93725
+ 255 - command
93726
+ ]),
93727
+ carrierHz: CARRIER_HZ
93728
+ };
93729
+ }
93730
+ if (protocol === "NECext") {
93731
+ fits(address, 16, "address", protocol);
93732
+ fits(command, 16, "command", protocol);
93733
+ return {
93734
+ timings: frame(9e3, 4500, [
93735
+ lo(address),
93736
+ hi(address),
93737
+ lo(command),
93738
+ hi(command)
93739
+ ]),
93740
+ carrierHz: CARRIER_HZ
93741
+ };
93742
+ }
93743
+ if (protocol === "Samsung32") {
93744
+ fits(address, 16, "address", protocol);
93745
+ fits(command, 8, "command", protocol);
93746
+ return {
93747
+ timings: frame(4500, 4500, [
93748
+ ...address > 255 ? [lo(address), hi(address)] : [address, address],
93749
+ command,
93750
+ 255 - command
93751
+ ]),
93752
+ carrierHz: CARRIER_HZ
93753
+ };
93754
+ }
93755
+ throw new IrCodecError("flipper-malformed", `${protocol} protocol is not supported`);
93756
+ }
93757
+ function rawTimings(data) {
93758
+ return data.map((value, index) => index % 2 === 0 ? value : -value);
93759
+ }
93760
+ /**
93761
+ * The file as a command table (every button a `raw` payload carrying its
93762
+ * carrier), plus the buttons that could not be encoded, named with the reason.
93763
+ */
93764
+ function flipperIrTable(file) {
93765
+ const commands = [];
93766
+ const skipped = [];
93767
+ for (const button of file.buttons) try {
93768
+ if (button.type === "raw") commands.push({
93769
+ name: button.name,
93770
+ group: "command",
93771
+ payload: {
93772
+ kind: "raw",
93773
+ timings: rawTimings(button.data),
93774
+ settings: {
93775
+ carrierHz: Math.round(button.frequency),
93776
+ dutyCyclePercent: Math.min(100, Math.max(1, Math.round(button.dutyCycle * 100)))
93777
+ }
93778
+ }
93779
+ });
93780
+ else {
93781
+ const { timings, carrierHz } = encodeFlipperParsed(button);
93782
+ commands.push({
93783
+ name: button.name,
93784
+ group: "command",
93785
+ payload: {
93786
+ kind: "raw",
93787
+ timings,
93788
+ settings: { carrierHz }
93789
+ }
93790
+ });
93791
+ }
93792
+ } catch (err) {
93793
+ if (!(err instanceof IrCodecError)) throw err;
93794
+ skipped.push({
93795
+ name: button.name,
93796
+ group: "command",
93797
+ reason: err.message
93798
+ });
93799
+ }
93800
+ return {
93801
+ table: {
93802
+ commands,
93803
+ interCommandDelayMs: 500
93804
+ },
93805
+ skipped
93806
+ };
93807
+ }
93808
+ //#endregion
93809
+ //#region src/remote/flipper-ir-draft.ts
93810
+ /**
93811
+ * Turns a Flipper `.ir` file into the same draft of the `remote`
93812
+ * configuration a SmartIR file produces (`smartIrDraft`), with Flipper's
93813
+ * button names mapped to roles. Names the table does not know (an app such as
93814
+ * "Netflix") become custom buttons named as the file spells them; a button
93815
+ * whose protocol cannot be encoded comes back in `skipped` with the reason.
93816
+ * PURE and browser-safe, like the SmartIR path.
93817
+ */
93818
+ var NAME_ROLES = {
93819
+ power: "power",
93820
+ pwr: "power",
93821
+ poweron: "power_on",
93822
+ on: "power_on",
93823
+ poweroff: "power_off",
93824
+ off: "power_off",
93825
+ volup: "volume_up",
93826
+ volumeup: "volume_up",
93827
+ voldown: "volume_down",
93828
+ volumedown: "volume_down",
93829
+ vol: "volume_up",
93830
+ mute: "mute",
93831
+ chup: "channel_up",
93832
+ channelup: "channel_up",
93833
+ chnext: "channel_up",
93834
+ channelnext: "channel_up",
93835
+ chdown: "channel_down",
93836
+ channeldown: "channel_down",
93837
+ chprev: "channel_down",
93838
+ channelprev: "channel_down",
93839
+ up: "up",
93840
+ down: "down",
93841
+ left: "left",
93842
+ right: "right",
93843
+ ok: "ok",
93844
+ enter: "ok",
93845
+ select: "ok",
93846
+ back: "back",
93847
+ return: "back",
93848
+ home: "home",
93849
+ menu: "menu",
93850
+ info: "info",
93851
+ guide: "guide",
93852
+ exit: "exit",
93853
+ input: "input",
93854
+ source: "input",
93855
+ play: "play",
93856
+ pause: "pause",
93857
+ playpause: "play_pause",
93858
+ stop: "stop",
93859
+ next: "next",
93860
+ previous: "previous",
93861
+ prev: "previous",
93862
+ ff: "fast_forward",
93863
+ fastforward: "fast_forward",
93864
+ rew: "rewind",
93865
+ rewind: "rewind"
93866
+ };
93867
+ var DIGIT_PREFIXES = /^(?:num|number|digit|key|btn)/;
93868
+ /** The role a Flipper button name fills, or undefined when it is not a known one. */
93869
+ function flipperRole(name) {
93870
+ const squashed = name.toLowerCase().replace(/\+/g, "up").replace(/-/g, "down").replace(/[^a-z0-9]/g, "");
93871
+ const fixed = NAME_ROLES[squashed];
93872
+ if (fixed !== void 0) return fixed;
93873
+ const digit = squashed.replace(DIGIT_PREFIXES, "");
93874
+ return /^[0-9]$/.test(digit) ? `digit_${digit}` : void 0;
93875
+ }
93876
+ function flipperIrDraft(file, target) {
93877
+ const { table, skipped } = flipperIrTable(file);
93878
+ const draft = smartIrDraft(table, target, { roleOf: flipperRole });
93879
+ return {
93880
+ ...draft,
93881
+ skipped: [...skipped.map((s) => ({
93882
+ name: s.name,
93883
+ reason: s.reason
93884
+ })), ...draft.skipped]
93885
+ };
93886
+ }
93887
+ //#endregion
93552
93888
  //#region src/running-state/from-operation.ts
93553
93889
  function programStartFromRemaining(running, remainingSeconds, fetchedAt) {
93554
93890
  if (!running || remainingSeconds === null || remainingSeconds === void 0) return null;
@@ -94213,7 +94549,7 @@ var ACTUATOR_TEMPLATE_IDS = [
94213
94549
  "media-player",
94214
94550
  "climate"
94215
94551
  ];
94216
- function row$1(cap, method, requires = null, confirm = false) {
94552
+ function row$2(cap, method, requires = null, confirm = false) {
94217
94553
  return {
94218
94554
  cap,
94219
94555
  method,
@@ -94223,41 +94559,41 @@ function row$1(cap, method, requires = null, confirm = false) {
94223
94559
  }
94224
94560
  /** The first row's cap is the type's own: always offered, members without it are skipped. */
94225
94561
  var ACTUATOR_METHODS = {
94226
- switch: [row$1("switch", "setState")],
94562
+ switch: [row$2("switch", "setState")],
94227
94563
  light: [
94228
- row$1("switch", "setState"),
94229
- row$1("brightness", "setBrightness"),
94230
- row$1("color", "setColor")
94564
+ row$2("switch", "setState"),
94565
+ row$2("brightness", "setBrightness"),
94566
+ row$2("color", "setColor")
94231
94567
  ],
94232
94568
  fan: [
94233
- row$1("switch", "setState"),
94234
- row$1("fan-control", "setPercentage", require_device_type.DeviceFeature.FanSpeed),
94235
- row$1("fan-control", "setPreset", require_device_type.DeviceFeature.FanPreset),
94236
- row$1("fan-control", "setDirection", require_device_type.DeviceFeature.FanDirection),
94237
- row$1("fan-control", "setOscillating", require_device_type.DeviceFeature.FanOscillating)
94569
+ row$2("switch", "setState"),
94570
+ row$2("fan-control", "setPercentage", require_device_type.DeviceFeature.FanSpeed),
94571
+ row$2("fan-control", "setPreset", require_device_type.DeviceFeature.FanPreset),
94572
+ row$2("fan-control", "setDirection", require_device_type.DeviceFeature.FanDirection),
94573
+ row$2("fan-control", "setOscillating", require_device_type.DeviceFeature.FanOscillating)
94238
94574
  ],
94239
94575
  cover: [
94240
- row$1("cover", "open"),
94241
- row$1("cover", "close"),
94242
- row$1("cover", "stop", require_device_type.DeviceFeature.CoverStoppable),
94243
- row$1("cover", "setPosition", require_device_type.DeviceFeature.CoverPositionable),
94244
- row$1("cover", "setTiltPosition", require_device_type.DeviceFeature.CoverTilt)
94576
+ row$2("cover", "open"),
94577
+ row$2("cover", "close"),
94578
+ row$2("cover", "stop", require_device_type.DeviceFeature.CoverStoppable),
94579
+ row$2("cover", "setPosition", require_device_type.DeviceFeature.CoverPositionable),
94580
+ row$2("cover", "setTiltPosition", require_device_type.DeviceFeature.CoverTilt)
94245
94581
  ],
94246
94582
  valve: [
94247
- row$1("valve", "open"),
94248
- row$1("valve", "close"),
94249
- row$1("valve", "setPosition", require_device_type.DeviceFeature.ValvePositionable)
94583
+ row$2("valve", "open"),
94584
+ row$2("valve", "close"),
94585
+ row$2("valve", "setPosition", require_device_type.DeviceFeature.ValvePositionable)
94250
94586
  ],
94251
- lock: [row$1("lock-control", "lock"), row$1("lock-control", "unlock", null, true)],
94587
+ lock: [row$2("lock-control", "lock"), row$2("lock-control", "unlock", null, true)],
94252
94588
  "media-player": [
94253
- row$1("media-player", "play"),
94254
- row$1("media-player", "pause"),
94255
- row$1("media-player", "setVolume", require_device_type.DeviceFeature.MediaPlayerVolume)
94589
+ row$2("media-player", "play"),
94590
+ row$2("media-player", "pause"),
94591
+ row$2("media-player", "setVolume", require_device_type.DeviceFeature.MediaPlayerVolume)
94256
94592
  ],
94257
94593
  climate: [
94258
- row$1("climate-control", "setMode"),
94259
- row$1("climate-control", "setTarget"),
94260
- row$1("climate-control", "setFanMode", require_device_type.DeviceFeature.ClimateFanMode)
94594
+ row$2("climate-control", "setMode"),
94595
+ row$2("climate-control", "setTarget"),
94596
+ row$2("climate-control", "setFanMode", require_device_type.DeviceFeature.ClimateFanMode)
94261
94597
  ]
94262
94598
  };
94263
94599
  function actuatorMethodRow(templateId, cap, method) {
@@ -99834,191 +100170,7 @@ function resolveMutate(router, method) {
99834
100170
  return typeof mutate === "function" ? mutate : null;
99835
100171
  }
99836
100172
  //#endregion
99837
- //#region src/device/hero/media-player-view.ts
99838
- /** The position to show at `nowMs`: the reported one, advanced while playing when it is stamped. */
99839
- function projectedPositionMs(status, nowMs) {
99840
- if (status.position === null) return null;
99841
- const stamp = status.positionUpdatedAt;
99842
- if (status.state !== "playing" || typeof stamp !== "number") return status.position;
99843
- const advanced = status.position + Math.max(0, nowMs - stamp);
99844
- return status.duration !== null && status.duration > 0 ? Math.min(advanced, status.duration) : advanced;
99845
- }
99846
- /**
99847
- * The optimistic patch for a seek. A status that carries `positionUpdatedAt` is stamped
99848
- * too: the projection advances from the stamp, so leaving the old one would show a
99849
- * position past the target.
99850
- */
99851
- function seekPatch(status, positionMs, nowMs) {
99852
- return typeof status.positionUpdatedAt === "number" ? {
99853
- position: positionMs,
99854
- positionUpdatedAt: nowMs
99855
- } : { position: positionMs };
99856
- }
99857
- /** True when the status carries a stamp the position can be advanced from. */
99858
- function isPositionTicking(status) {
99859
- return status !== void 0 && status.state === "playing" && status.position !== null && typeof status.positionUpdatedAt === "number";
99860
- }
99861
- var NO_TRANSPORT = {
99862
- playPause: false,
99863
- previous: false,
99864
- next: false,
99865
- stop: false
99866
- };
99867
- /** Whether the status carries any activity the device actually reported. */
99868
- function runningOf$1(state) {
99869
- switch (state) {
99870
- case "playing":
99871
- case "paused":
99872
- case "buffering":
99873
- case "idle": return state;
99874
- case void 0: return "unknown";
99875
- default: return "none";
99876
- }
99877
- }
99878
- function artworkOf(status) {
99879
- const url = status.currentMedia?.imageUrl?.trim() ?? "";
99880
- return url === "" ? null : url;
99881
- }
99882
- function powerOf(state) {
99883
- if (state === void 0) return "unknown";
99884
- if (state === "off") return "off";
99885
- if (state === "standby") return "standby";
99886
- return "on";
99887
- }
99888
- /**
99889
- * A slice from before `assumedFields` existed (stateSource assumed, no list)
99890
- * means the whole state is a guess; with a list, only the named fields are.
99891
- */
99892
- function isAssumed(status, field) {
99893
- if (status.stateSource !== "assumed") return false;
99894
- const listed = status.assumedFields ?? [];
99895
- return listed.length === 0 || listed.includes(field);
99896
- }
99897
- var UNKNOWN_VIEW = {
99898
- power: "unknown",
99899
- runningReading: "unknown",
99900
- running: "unknown",
99901
- stateAssumed: false,
99902
- canSwitchPower: false,
99903
- transport: NO_TRANSPORT,
99904
- seek: false,
99905
- volume: "none",
99906
- volumeKnown: false,
99907
- muteKnown: false,
99908
- artworkUrl: null,
99909
- mute: false,
99910
- source: null,
99911
- shuffle: false,
99912
- repeat: false,
99913
- shuffleReadOnly: false,
99914
- repeatReadOnly: false,
99915
- nowPlaying: null
99916
- };
99917
- function nowPlayingOf(status) {
99918
- if (status === void 0) return null;
99919
- const media = status.currentMedia;
99920
- const title = media?.title.trim() ?? "";
99921
- const subtitle = [media?.artist, media?.album].map((part) => part?.trim() ?? "").filter((part) => part !== "").join(" · ");
99922
- const artworkUrl = artworkOf(status);
99923
- const source = typeof status.source === "string" ? status.source.trim() : "";
99924
- const hasDuration = status.position !== null && status.duration !== null && status.duration > 0;
99925
- if (title === "" && subtitle === "" && artworkUrl === null) return null;
99926
- return {
99927
- title: title === "" ? null : title,
99928
- subtitle: subtitle === "" ? null : subtitle,
99929
- artworkUrl,
99930
- source: source === "" ? null : source,
99931
- progress: hasDuration && status.position !== null && status.duration !== null ? {
99932
- positionMs: status.position,
99933
- durationMs: status.duration
99934
- } : null
99935
- };
99936
- }
99937
- function readingOf(running) {
99938
- if (running === true) return "running";
99939
- if (running === false) return "idle";
99940
- return "unknown";
99941
- }
99942
- function deriveMediaPlayerView(status, features, extras = {}) {
99943
- return {
99944
- ...derivePowerGatedView(status, features, extras),
99945
- nowPlaying: nowPlayingOf(status),
99946
- shuffleReadOnly: status !== void 0 && status.shuffle !== null && !(features?.includes(require_device_type.DeviceFeature.MediaPlayerShuffle) ?? false),
99947
- repeatReadOnly: status !== void 0 && status.repeat !== null && !(features?.includes(require_device_type.DeviceFeature.MediaPlayerRepeat) ?? false)
99948
- };
99949
- }
99950
- function derivePowerGatedView(status, features, extras) {
99951
- const runningReading = readingOf(extras.running);
99952
- const view = deriveFromStatus(status, features);
99953
- const guessed = status === void 0 || status.state === void 0 || view.stateAssumed;
99954
- if (runningReading === "unknown" || !guessed) return {
99955
- ...view,
99956
- runningReading
99957
- };
99958
- if (runningReading === "idle") return {
99959
- ...UNKNOWN_VIEW,
99960
- power: "off",
99961
- running: "none",
99962
- canSwitchPower: view.canSwitchPower,
99963
- runningReading
99964
- };
99965
- return {
99966
- ...status === void 0 ? view : deriveFromStatus(status.state === void 0 || status.state === "off" || status.state === "standby" ? {
99967
- ...status,
99968
- state: "on"
99969
- } : status, features),
99970
- power: "on",
99971
- stateAssumed: false,
99972
- runningReading
99973
- };
99974
- }
99975
- function deriveFromStatus(status, features) {
99976
- const has = (f) => features?.includes(f) ?? false;
99977
- const canSwitchPower = has(require_device_type.DeviceFeature.MediaPlayerPower);
99978
- if (status === void 0 || status.state === void 0) return {
99979
- ...UNKNOWN_VIEW,
99980
- canSwitchPower
99981
- };
99982
- const power = powerOf(status.state);
99983
- const running = runningOf$1(status.state);
99984
- const base = {
99985
- ...UNKNOWN_VIEW,
99986
- power,
99987
- running,
99988
- stateAssumed: isAssumed(status, "state"),
99989
- canSwitchPower
99990
- };
99991
- if (power !== "on") return base;
99992
- const hasTransportFeature = has(require_device_type.DeviceFeature.MediaPlayerNext) || has(require_device_type.DeviceFeature.MediaPlayerPrevious) || has(require_device_type.DeviceFeature.MediaPlayerStop) || has(require_device_type.DeviceFeature.MediaPlayerSeek);
99993
- const volume = has(require_device_type.DeviceFeature.MediaPlayerVolume) ? "slider" : has(require_device_type.DeviceFeature.MediaPlayerVolumeStep) ? "steps" : "none";
99994
- const sourceName = typeof status.source === "string" ? status.source.trim() : "";
99995
- const options = status.availableSources ?? [];
99996
- const hasSource = sourceName !== "" || options.length > 0;
99997
- return {
99998
- ...base,
99999
- transport: {
100000
- playPause: running !== "none" || hasTransportFeature,
100001
- previous: has(require_device_type.DeviceFeature.MediaPlayerPrevious),
100002
- next: has(require_device_type.DeviceFeature.MediaPlayerNext),
100003
- stop: has(require_device_type.DeviceFeature.MediaPlayerStop)
100004
- },
100005
- seek: has(require_device_type.DeviceFeature.MediaPlayerSeek) && status.duration !== null && status.duration > 0,
100006
- volume,
100007
- mute: has(require_device_type.DeviceFeature.MediaPlayerMute) || volume === "slider" && status.isMuted !== null,
100008
- volumeKnown: status.volumeLevel !== null,
100009
- muteKnown: status.isMuted !== null,
100010
- artworkUrl: artworkOf(status),
100011
- source: hasSource ? {
100012
- current: sourceName,
100013
- options,
100014
- selectable: has(require_device_type.DeviceFeature.MediaPlayerSelectSource) && options.length > 1
100015
- } : null,
100016
- shuffle: has(require_device_type.DeviceFeature.MediaPlayerShuffle) && status.shuffle !== null,
100017
- repeat: has(require_device_type.DeviceFeature.MediaPlayerRepeat) && status.repeat !== null
100018
- };
100019
- }
100020
- //#endregion
100021
- //#region src/device/hero/hero-contributions.ts
100173
+ //#region src/device/hero/hero-contribution-kit.ts
100022
100174
  /** Parses the raw slice with the cap's own schema; `undefined` when it does not parse. */
100023
100175
  function contribution(cap, schema, build) {
100024
100176
  return {
@@ -100047,11 +100199,16 @@ var asAction = (a) => ({
100047
100199
  kind: "action",
100048
100200
  action: a
100049
100201
  });
100050
- function reading(source, state, assumed = false) {
100051
- return {
100202
+ function reading(source, state, assumed = false, title) {
100203
+ return title === void 0 ? {
100052
100204
  source,
100053
100205
  state,
100054
100206
  assumed
100207
+ } : {
100208
+ source,
100209
+ state,
100210
+ assumed,
100211
+ title
100055
100212
  };
100056
100213
  }
100057
100214
  function fact(id, icon, text, tone = "muted") {
@@ -100062,6 +100219,1840 @@ function fact(id, icon, text, tone = "muted") {
100062
100219
  tone
100063
100220
  };
100064
100221
  }
100222
+ function row$1(id, icon, status, controls = []) {
100223
+ return {
100224
+ id,
100225
+ icon,
100226
+ status,
100227
+ controls: [...controls]
100228
+ };
100229
+ }
100230
+ /** "5 min" / "3 h" / "2 d" since `at`; `null` when the moment is unknown (0) or in the future. */
100231
+ function elapsedText(at, now) {
100232
+ if (at <= 0 || at > now) return null;
100233
+ const min = Math.floor((now - at) / 6e4);
100234
+ if (min < 1) return require_sleep.t("just now", "adesso");
100235
+ if (min < 60) return require_sleep.t(`${min} min ago`, `${min} min fa`);
100236
+ const h = Math.floor(min / 60);
100237
+ if (h < 48) return require_sleep.t(`${h} h ago`, `${h} h fa`);
100238
+ const d = Math.floor(h / 24);
100239
+ return require_sleep.t(`${d} d ago`, `${d} g fa`);
100240
+ }
100241
+ /** Joins words with " · ", skipping what is not there. */
100242
+ function joinText(parts) {
100243
+ const present = parts.filter((p) => p !== null);
100244
+ if (present.length === 0) return null;
100245
+ return require_sleep.t(present.map((p) => p.en).join(" · "), present.map((p) => p.it).join(" · "));
100246
+ }
100247
+ //#endregion
100248
+ //#region src/device/hero/hero-contributions-access.ts
100249
+ /**
100250
+ * What the access and automation caps add to a hero (D1023): a lock, an alarm
100251
+ * panel, an automation, a script and a media player's do-not-disturb. Every
100252
+ * contribution is typed against the cap's own status schema; a slice that does
100253
+ * not parse reads as "not answered" and the state is `unknown`, never `off`
100254
+ * (D315/D393). Nothing is guessed: with an unknown state the actions the cap
100255
+ * offers are offered separately.
100256
+ */
100257
+ var LOCK_WORDS = {
100258
+ locked: {
100259
+ state: "on",
100260
+ title: require_sleep.t("Locked", "Chiusa"),
100261
+ door: "closed"
100262
+ },
100263
+ unlocked: {
100264
+ state: "standby",
100265
+ title: require_sleep.t("Unlocked", "Aperta"),
100266
+ door: "open"
100267
+ },
100268
+ locking: {
100269
+ state: "running",
100270
+ title: require_sleep.t("Locking", "In chiusura"),
100271
+ door: "closed"
100272
+ },
100273
+ unlocking: {
100274
+ state: "running",
100275
+ title: require_sleep.t("Unlocking", "In apertura"),
100276
+ door: "open"
100277
+ },
100278
+ jammed: {
100279
+ state: "alert",
100280
+ title: require_sleep.t("Jammed", "Bloccata"),
100281
+ door: null
100282
+ },
100283
+ "door-open": {
100284
+ state: "standby",
100285
+ title: require_sleep.t("Door open", "Porta aperta"),
100286
+ door: "open"
100287
+ }
100288
+ };
100289
+ var lockAction = (primary) => action("lock.lock", require_sleep.t("Lock", "Chiudi"), "lock", "lock-control", "lock", {}, primary ? "primary" : "normal");
100290
+ var unlockAction = (primary) => action("lock.unlock", require_sleep.t("Unlock", "Apri"), "lock-open", "lock-control", "unlock", {}, primary ? "primary" : "normal", "unlock");
100291
+ function lockControls(state, latch) {
100292
+ const open = asAction(action("lock.open", require_sleep.t("Open latch", "Apri il chiavistello"), "door-open", "lock-control", "open", {}, "normal", "unlock"));
100293
+ switch (state) {
100294
+ case "locked": return [asAction(unlockAction(true)), ...latch ? [open] : []];
100295
+ case "unlocked": return [asAction(lockAction(true)), ...latch ? [open] : []];
100296
+ case "jammed": return [asAction(unlockAction(false)), asAction(lockAction(false))];
100297
+ case null: return [asAction(lockAction(false)), asAction(unlockAction(false))];
100298
+ default: return [];
100299
+ }
100300
+ }
100301
+ var lockContribution = contribution("lock-control", LockControlStatusSchema, (slice, ctx) => {
100302
+ const state = slice?.state ?? null;
100303
+ const words = state === null ? null : LOCK_WORDS[state];
100304
+ const since = slice === void 0 ? null : elapsedText(slice.lastChangedAt, ctx.now);
100305
+ const title = words?.title ?? require_sleep.t("Unknown", "Sconosciuto");
100306
+ return {
100307
+ reading: reading("lock-control", words?.state ?? "unknown", false, words?.title),
100308
+ rows: [row$1("lock", state === "locked" || state === "locking" ? "lock" : "lock-open", joinText([title, since]), lockControls(state, ctx.features.includes(require_device_type.DeviceFeature.LockOpen)))],
100309
+ ...since === null || words === null ? {} : { facts: [fact("since", "clock", since, "muted")] },
100310
+ ...words?.door == null ? {} : { scene: { mode: words.door } }
100311
+ };
100312
+ });
100313
+ var ALARM_WORDS = {
100314
+ disarmed: {
100315
+ state: "off",
100316
+ title: require_sleep.t("Disarmed", "Disinserito")
100317
+ },
100318
+ armed_home: {
100319
+ state: "on",
100320
+ title: require_sleep.t("Armed home", "Inserito in casa")
100321
+ },
100322
+ armed_away: {
100323
+ state: "on",
100324
+ title: require_sleep.t("Armed away", "Inserito fuori casa")
100325
+ },
100326
+ armed_night: {
100327
+ state: "on",
100328
+ title: require_sleep.t("Armed night", "Inserito notte")
100329
+ },
100330
+ armed_vacation: {
100331
+ state: "on",
100332
+ title: require_sleep.t("Armed vacation", "Inserito vacanza")
100333
+ },
100334
+ armed_custom_bypass: {
100335
+ state: "on",
100336
+ title: require_sleep.t("Armed with bypass", "Inserito con esclusioni")
100337
+ },
100338
+ arming: {
100339
+ state: "standby",
100340
+ title: require_sleep.t("Arming", "Inserimento")
100341
+ },
100342
+ disarming: {
100343
+ state: "standby",
100344
+ title: require_sleep.t("Disarming", "Disinserimento")
100345
+ },
100346
+ pending: {
100347
+ state: "standby",
100348
+ title: require_sleep.t("Entry delay", "Ritardo di ingresso")
100349
+ },
100350
+ triggered: {
100351
+ state: "alert",
100352
+ title: require_sleep.t("Triggered", "Allarme in corso")
100353
+ }
100354
+ };
100355
+ var ARM_LABELS = {
100356
+ home: require_sleep.t("Arm home", "Inserisci in casa"),
100357
+ away: require_sleep.t("Arm away", "Inserisci fuori casa"),
100358
+ night: require_sleep.t("Arm night", "Inserisci notte"),
100359
+ vacation: require_sleep.t("Arm vacation", "Inserisci vacanza"),
100360
+ custom_bypass: require_sleep.t("Arm with bypass", "Inserisci con esclusioni")
100361
+ };
100362
+ var ALARM_MODES = [
100363
+ "home",
100364
+ "away",
100365
+ "night",
100366
+ "vacation",
100367
+ "custom_bypass"
100368
+ ];
100369
+ function alarmControls(state, modes, requiresCode) {
100370
+ if (requiresCode) return [];
100371
+ const disarm = asAction(action("alarm.disarm", require_sleep.t("Disarm", "Disinserisci"), "shield-off", "alarm-panel", "disarm", {}, "primary"));
100372
+ const arm = (primaryFirst) => modes.map((mode, i) => asAction(action(`alarm.arm.${mode}`, ARM_LABELS[mode], "shield-check", "alarm-panel", "arm", { mode }, primaryFirst && i === 0 ? "primary" : "normal")));
100373
+ switch (state) {
100374
+ case "disarmed": return arm(true);
100375
+ case "arming":
100376
+ case "disarming": return [];
100377
+ case null: return [];
100378
+ default: return [disarm];
100379
+ }
100380
+ }
100381
+ var ACCESS_FAMILY_CONTRIBUTIONS = {
100382
+ "lock-control": lockContribution,
100383
+ "alarm-panel": contribution("alarm-panel", AlarmPanelStatusSchema, (slice, ctx) => {
100384
+ const state = slice?.state ?? null;
100385
+ const words = state === null ? null : ALARM_WORDS[state];
100386
+ const since = slice === void 0 ? null : elapsedText(slice.lastChangedAt, ctx.now);
100387
+ const modes = slice === void 0 ? ALARM_MODES : slice.availableModes;
100388
+ return {
100389
+ reading: reading("alarm-panel", words?.state ?? "unknown", false, words?.title),
100390
+ rows: [row$1("alarm", state === "triggered" ? "shield-alert" : state === "disarmed" ? "shield-off" : "shield-check", joinText([words?.title ?? require_sleep.t("Unknown", "Sconosciuto"), since]), alarmControls(state, modes, slice?.requiresCode ?? false))],
100391
+ ...since === null || words === null ? {} : { facts: [fact("since", "clock", since, state === "triggered" ? "danger" : "muted")] }
100392
+ };
100393
+ }),
100394
+ "automation-control": contribution("automation-control", AutomationControlStatusSchema, (slice, ctx) => {
100395
+ const failed = slice?.lastError != null;
100396
+ const state = slice === void 0 ? "unknown" : failed ? "alert" : slice.isRunning ? "running" : slice.enabled ? "on" : "off";
100397
+ const title = slice === void 0 ? void 0 : failed ? require_sleep.t("Failed", "In errore") : slice.isRunning ? require_sleep.t("Running", "In esecuzione") : slice.enabled ? require_sleep.t("Enabled", "Attiva") : require_sleep.t("Disabled", "Disattivata");
100398
+ const last = slice === void 0 ? null : elapsedText(slice.lastTriggeredAt, ctx.now);
100399
+ const run = action("automation.run", require_sleep.t("Run now", "Esegui ora"), "play", "automation-control", "trigger", {}, "primary");
100400
+ const toggle = {
100401
+ kind: "toggle",
100402
+ id: "automation.enabled",
100403
+ label: require_sleep.t("Enabled", "Attiva"),
100404
+ on: slice?.enabled ?? null,
100405
+ turnOn: action("automation.enable", require_sleep.t("Enable", "Attiva"), "play", "automation-control", "enable"),
100406
+ turnOff: action("automation.disable", require_sleep.t("Disable", "Disattiva"), "square", "automation-control", "disable")
100407
+ };
100408
+ return {
100409
+ reading: reading("automation-control", state, false, title),
100410
+ rows: [row$1("automation", "workflow", joinText([
100411
+ title ?? require_sleep.t("Unknown", "Sconosciuto"),
100412
+ last === null ? null : require_sleep.t(`Ran ${last.en}`, `Eseguita ${last.it}`),
100413
+ slice?.lastError == null ? null : require_sleep.t(slice.lastError, slice.lastError)
100414
+ ]), [asAction(run), toggle])],
100415
+ ...last === null ? {} : { facts: [fact("last-run", "clock", last, failed ? "danger" : "muted")] }
100416
+ };
100417
+ }),
100418
+ "script-runner": contribution("script-runner", ScriptRunnerStatusSchema, (slice, ctx) => {
100419
+ const failed = slice?.lastRunSuccess === false;
100420
+ const state = slice === void 0 ? "unknown" : slice.isRunning ? "running" : failed ? "alert" : "idle";
100421
+ const title = slice === void 0 ? void 0 : slice.isRunning ? require_sleep.t("Running", "In esecuzione") : failed ? require_sleep.t("Failed", "In errore") : require_sleep.t("Ready", "Pronto");
100422
+ const last = slice === void 0 ? null : elapsedText(slice.lastRunAt, ctx.now);
100423
+ const control = slice?.isRunning === true ? action("script.stop", require_sleep.t("Stop", "Ferma"), "square", "script-runner", "stop", {}, "primary") : action("script.run", require_sleep.t("Run", "Esegui"), "play", "script-runner", "run", {}, "primary");
100424
+ return {
100425
+ reading: reading("script-runner", state, false, title),
100426
+ rows: [row$1("script", "scroll-text", joinText([
100427
+ title ?? require_sleep.t("Unknown", "Sconosciuto"),
100428
+ last === null ? null : require_sleep.t(`Ran ${last.en}`, `Eseguito ${last.it}`),
100429
+ slice?.lastError == null ? null : require_sleep.t(slice.lastError, slice.lastError)
100430
+ ]), [asAction(control)])],
100431
+ ...last === null ? {} : { facts: [fact("last-run", "clock", last, failed ? "danger" : "muted")] }
100432
+ };
100433
+ }),
100434
+ "do-not-disturb": contribution("do-not-disturb", DoNotDisturbStatusSchema, (slice) => {
100435
+ const on = slice?.enabled ?? null;
100436
+ return { rows: [row$1("do-not-disturb", "bell-off", on === null ? require_sleep.t("Unknown", "Sconosciuto") : on ? require_sleep.t("Do not disturb on", "Non disturbare attivo") : require_sleep.t("Do not disturb off", "Non disturbare spento"), [{
100437
+ kind: "toggle",
100438
+ id: "do-not-disturb.toggle",
100439
+ label: require_sleep.t("Do not disturb", "Non disturbare"),
100440
+ on,
100441
+ turnOn: action("do-not-disturb.on", require_sleep.t("Turn on", "Attiva"), "bell-off", "do-not-disturb", "setEnabled", { enabled: true }),
100442
+ turnOff: action("do-not-disturb.off", require_sleep.t("Turn off", "Disattiva"), "bell", "do-not-disturb", "setEnabled", { enabled: false })
100443
+ }])] };
100444
+ })
100445
+ };
100446
+ //#endregion
100447
+ //#region src/device/hero/hero-contributions-devices.ts
100448
+ /**
100449
+ * What the household-device caps add to a hero (D1023): a fan, a robot vacuum,
100450
+ * a robot mower, a pet feeder, a pet fountain and its pump cycle. Typed against
100451
+ * each cap's own status schema; a slice that does not parse is "not answered"
100452
+ * (`unknown`, never `off`, D315/D393). A measurement the device did not report
100453
+ * is absent from the facts, never a zero (D393).
100454
+ */
100455
+ var has$3 = (ctx, f) => ctx.features.includes(f);
100456
+ var unknownText = require_sleep.t("Unknown", "Sconosciuto");
100457
+ var pct$1 = (n) => require_sleep.t(`${Math.round(n)}%`, `${Math.round(n)}%`);
100458
+ var unit = (n) => Math.min(1, Math.max(0, n / 100));
100459
+ /** Battery as a fact, unless the device is also bound to the `battery` cap (it already says so). */
100460
+ function ownBattery(level, ctx) {
100461
+ if (level === null || ctx.caps.includes("battery")) return [];
100462
+ const tone = level <= 20 ? "danger" : level <= 40 ? "warning" : "success";
100463
+ return [fact("battery", "battery", require_sleep.t(`Battery ${Math.round(level)}%`, `Batteria ${Math.round(level)}%`), tone)];
100464
+ }
100465
+ var fanContribution = contribution("fan-control", FanControlStatusSchema, (slice, ctx) => {
100466
+ const speed = slice?.speed ?? null;
100467
+ const state = speed === null ? "unknown" : speed > 0 ? "running" : "off";
100468
+ const controls = [];
100469
+ if (speed !== null || has$3(ctx, require_device_type.DeviceFeature.FanSpeed)) controls.push({
100470
+ kind: "slider",
100471
+ id: "fan.speed",
100472
+ label: require_sleep.t("Speed", "Velocità"),
100473
+ value: speed,
100474
+ min: 0,
100475
+ max: 100,
100476
+ step: slice?.percentageStep ?? 1,
100477
+ unit: "%",
100478
+ call: {
100479
+ cap: "fan-control",
100480
+ method: "setPercentage",
100481
+ args: {}
100482
+ },
100483
+ valueArg: "speed"
100484
+ });
100485
+ if (slice !== void 0 && slice.availablePresets.length > 0) controls.push({
100486
+ kind: "picker",
100487
+ id: "fan.preset",
100488
+ label: require_sleep.t("Mode", "Modalità"),
100489
+ current: slice.preset === "" ? null : slice.preset,
100490
+ options: [...slice.availablePresets],
100491
+ call: {
100492
+ cap: "fan-control",
100493
+ method: "setPreset",
100494
+ args: {}
100495
+ },
100496
+ valueArg: "preset"
100497
+ });
100498
+ if (slice?.oscillating != null || has$3(ctx, require_device_type.DeviceFeature.FanOscillating)) controls.push({
100499
+ kind: "toggle",
100500
+ id: "fan.oscillating",
100501
+ label: require_sleep.t("Oscillate", "Oscilla"),
100502
+ on: slice?.oscillating ?? null,
100503
+ turnOn: action("fan.oscillate.on", require_sleep.t("Oscillate", "Oscilla"), "refresh-cw", "fan-control", "setOscillating", { oscillating: true }),
100504
+ turnOff: action("fan.oscillate.off", require_sleep.t("Hold still", "Fermo"), "square", "fan-control", "setOscillating", { oscillating: false })
100505
+ });
100506
+ if (slice?.direction != null || has$3(ctx, require_device_type.DeviceFeature.FanDirection)) controls.push({
100507
+ kind: "picker",
100508
+ id: "fan.direction",
100509
+ label: require_sleep.t("Direction", "Direzione"),
100510
+ current: slice?.direction ?? null,
100511
+ options: ["forward", "reverse"],
100512
+ call: {
100513
+ cap: "fan-control",
100514
+ method: "setDirection",
100515
+ args: {}
100516
+ },
100517
+ valueArg: "direction"
100518
+ });
100519
+ const speedText = speed === null ? null : pct$1(speed);
100520
+ const preset = slice?.preset ?? "";
100521
+ const status = speed === null ? unknownText : joinText([speed === 0 ? require_sleep.t("Off", "Spento") : require_sleep.t(`Speed ${speed}%`, `Velocità ${speed}%`), preset === "" ? null : require_sleep.t(preset, preset)]);
100522
+ return {
100523
+ reading: reading("fan-control", state),
100524
+ rows: [{
100525
+ id: "fan",
100526
+ icon: "fan",
100527
+ status,
100528
+ controls
100529
+ }],
100530
+ ...speedText === null ? {} : {
100531
+ facts: [fact("speed", "fan", speedText, speed === 0 ? "muted" : "primary")],
100532
+ tiles: { right: [{
100533
+ label: require_sleep.t("Speed", "Velocità"),
100534
+ value: speedText
100535
+ }] },
100536
+ scene: { level: unit(speed ?? 0) }
100537
+ }
100538
+ };
100539
+ });
100540
+ var VACUUM_WORDS = {
100541
+ idle: {
100542
+ state: "idle",
100543
+ title: require_sleep.t("Idle", "Inattivo")
100544
+ },
100545
+ cleaning: {
100546
+ state: "running",
100547
+ title: require_sleep.t("Cleaning", "Pulisce")
100548
+ },
100549
+ paused: {
100550
+ state: "standby",
100551
+ title: require_sleep.t("Paused", "In pausa")
100552
+ },
100553
+ returning: {
100554
+ state: "running",
100555
+ title: require_sleep.t("Returning to base", "Torna alla base")
100556
+ },
100557
+ docked: {
100558
+ state: "idle",
100559
+ title: require_sleep.t("Docked", "In base")
100560
+ },
100561
+ drying: {
100562
+ state: "running",
100563
+ title: require_sleep.t("Drying", "Asciuga")
100564
+ },
100565
+ error: {
100566
+ state: "alert",
100567
+ title: require_sleep.t("Error", "Errore")
100568
+ }
100569
+ };
100570
+ function robotAction(cap, prefix, id, en, it, icon, method, primary = false) {
100571
+ return asAction(action(`${prefix}.${id}`, require_sleep.t(en, it), icon, cap, method, {}, primary ? "primary" : "normal"));
100572
+ }
100573
+ var vac = (id, en, it, icon, method, primary = false) => robotAction("vacuum-control", "vacuum", id, en, it, icon, method, primary);
100574
+ function vacuumControls(state) {
100575
+ const start = (primary) => vac("start", "Start", "Avvia", "play", "start", primary);
100576
+ const resume = vac("resume", "Resume", "Riprendi", "play", "start", true);
100577
+ const pause = (primary) => vac("pause", "Pause", "Pausa", "pause", "pause", primary);
100578
+ const base = vac("base", "Return to base", "Torna alla base", "house", "returnToBase");
100579
+ switch (state) {
100580
+ case "cleaning": return [pause(true), base];
100581
+ case "paused": return [resume, base];
100582
+ case "returning":
100583
+ case "drying": return [vac("stop", "Stop", "Ferma", "square", "stop")];
100584
+ case "idle": return [start(true), base];
100585
+ case "docked": return [start(true)];
100586
+ case "error": return [base];
100587
+ case null: return [
100588
+ start(false),
100589
+ pause(false),
100590
+ base
100591
+ ];
100592
+ }
100593
+ }
100594
+ var vacuumContribution = contribution("vacuum-control", VacuumControlStatusSchema, (slice, ctx) => {
100595
+ const state = slice?.state ?? null;
100596
+ const words = state === null ? null : VACUUM_WORDS[state];
100597
+ const title = state === "error" && slice?.errorLabel ? require_sleep.t(slice.errorLabel, slice.errorLabel) : words?.title;
100598
+ const controls = vacuumControls(state);
100599
+ if (slice !== void 0 && slice.availableFanSpeeds.length > 0) controls.push({
100600
+ kind: "picker",
100601
+ id: "vacuum.suction",
100602
+ label: require_sleep.t("Suction", "Aspirazione"),
100603
+ current: slice.fanSpeed,
100604
+ options: [...slice.availableFanSpeeds],
100605
+ call: {
100606
+ cap: "vacuum-control",
100607
+ method: "setFanSpeed",
100608
+ args: {}
100609
+ },
100610
+ valueArg: "speed"
100611
+ });
100612
+ if (state !== null) controls.push(vac("locate", "Locate", "Trova", "map-pin", "locate"));
100613
+ const progress = state === "cleaning" ? slice?.progress ?? null : null;
100614
+ return {
100615
+ reading: reading("vacuum-control", words?.state ?? "unknown", false, title),
100616
+ rows: [{
100617
+ id: "vacuum",
100618
+ icon: "bot",
100619
+ status: title ?? unknownText,
100620
+ controls
100621
+ }],
100622
+ facts: [...ownBattery(slice?.batteryLevel ?? null, ctx), ...progress === null ? [] : [fact("progress", "activity", pct$1(progress), "primary")]],
100623
+ ...progress === null ? {} : {
100624
+ tiles: { right: [{
100625
+ label: require_sleep.t("Progress", "Avanzamento"),
100626
+ value: pct$1(progress)
100627
+ }] },
100628
+ scene: { level: unit(progress) }
100629
+ }
100630
+ };
100631
+ });
100632
+ var MOWER_WORDS = {
100633
+ idle: {
100634
+ state: "idle",
100635
+ title: require_sleep.t("Idle", "Inattivo")
100636
+ },
100637
+ mowing: {
100638
+ state: "running",
100639
+ title: require_sleep.t("Mowing", "Taglia")
100640
+ },
100641
+ paused: {
100642
+ state: "standby",
100643
+ title: require_sleep.t("Paused", "In pausa")
100644
+ },
100645
+ docked: {
100646
+ state: "idle",
100647
+ title: require_sleep.t("Docked", "In base")
100648
+ },
100649
+ error: {
100650
+ state: "alert",
100651
+ title: require_sleep.t("Error", "Errore")
100652
+ }
100653
+ };
100654
+ var mow = (id, en, it, icon, method, primary = false) => robotAction("lawn-mower-control", "mower", id, en, it, icon, method, primary);
100655
+ function mowerControls(activity) {
100656
+ const start = (primary) => mow("start", "Start mowing", "Avvia il taglio", "play", "startMowing", primary);
100657
+ const pause = (primary) => mow("pause", "Pause", "Pausa", "pause", "pause", primary);
100658
+ const dock = mow("dock", "Return to base", "Torna alla base", "house", "dock");
100659
+ switch (activity) {
100660
+ case "mowing": return [pause(true), dock];
100661
+ case "paused": return [mow("resume", "Resume", "Riprendi", "play", "startMowing", true), dock];
100662
+ case "idle": return [start(true), dock];
100663
+ case "docked": return [start(true)];
100664
+ case "error": return [dock];
100665
+ case null: return [
100666
+ start(false),
100667
+ pause(false),
100668
+ dock
100669
+ ];
100670
+ }
100671
+ }
100672
+ var mowerContribution = contribution("lawn-mower-control", LawnMowerControlStatusSchema, (slice, ctx) => {
100673
+ const activity = slice?.activity ?? null;
100674
+ const words = activity === null ? null : MOWER_WORDS[activity];
100675
+ const title = activity === "error" && slice?.currentCodeLabel ? require_sleep.t(slice.currentCodeLabel, slice.currentCodeLabel) : words?.title;
100676
+ const progress = activity === "mowing" ? slice?.progress ?? null : null;
100677
+ return {
100678
+ reading: reading("lawn-mower-control", words?.state ?? "unknown", false, title),
100679
+ rows: [{
100680
+ id: "mower",
100681
+ icon: "sprout",
100682
+ status: title ?? unknownText,
100683
+ controls: mowerControls(activity)
100684
+ }],
100685
+ facts: [...ownBattery(slice?.batteryLevel ?? null, ctx), ...progress === null ? [] : [fact("progress", "activity", pct$1(progress), "primary")]],
100686
+ ...progress === null ? {} : {
100687
+ tiles: { right: [{
100688
+ label: require_sleep.t("Progress", "Avanzamento"),
100689
+ value: pct$1(progress)
100690
+ }] },
100691
+ scene: { level: unit(progress) }
100692
+ }
100693
+ };
100694
+ });
100695
+ function feederWords(slice) {
100696
+ if (slice === void 0) return null;
100697
+ if (slice.status === "offline") return {
100698
+ state: "offline",
100699
+ title: require_sleep.t("Offline", "Non raggiungibile")
100700
+ };
100701
+ if (slice.error !== null) return {
100702
+ state: "alert",
100703
+ title: require_sleep.t(slice.error, slice.error)
100704
+ };
100705
+ if (slice.feeding) return {
100706
+ state: "running",
100707
+ title: require_sleep.t("Dispensing", "Eroga")
100708
+ };
100709
+ if (slice.eating) return {
100710
+ state: "running",
100711
+ title: require_sleep.t("Pet is eating", "Sta mangiando")
100712
+ };
100713
+ if (slice.lowFood) return {
100714
+ state: "standby",
100715
+ title: require_sleep.t("Food is low", "Cibo in esaurimento")
100716
+ };
100717
+ return {
100718
+ state: "idle",
100719
+ title: require_sleep.t("Ready", "Pronto")
100720
+ };
100721
+ }
100722
+ /** The manual portion the card offers: the last one given, else the hardware minimum. */
100723
+ function feedArgs(slice) {
100724
+ if (slice.isDualHopper) return {
100725
+ hopper1: slice.lastFeedHopper1 ?? 4,
100726
+ hopper2: slice.lastFeedHopper2 ?? 4
100727
+ };
100728
+ return { grams: slice.lastFeedGrams ?? 4 };
100729
+ }
100730
+ function feederControls(slice) {
100731
+ return [
100732
+ asAction(slice.feeding ? action("feeder.cancel", require_sleep.t("Cancel", "Annulla"), "square", "pet-feeder", "cancelFeed", {}, "primary") : action("feeder.feed", slice.isDualHopper ? require_sleep.t("Feed", "Eroga") : require_sleep.t(`Feed ${slice.lastFeedGrams ?? 4} g`, `Eroga ${slice.lastFeedGrams ?? 4} g`), "bone", "pet-feeder", "feed", feedArgs(slice), "primary")),
100733
+ asAction(action("feeder.call", require_sleep.t("Call pet", "Chiama"), "volume-2", "pet-feeder", "callPet")),
100734
+ {
100735
+ kind: "toggle",
100736
+ id: "feeder.child-lock",
100737
+ label: require_sleep.t("Child lock", "Blocco bambini"),
100738
+ on: slice.childLock,
100739
+ turnOn: action("feeder.child-lock.on", require_sleep.t("Lock", "Blocca"), "lock", "pet-feeder", "setChildLock", { on: true }),
100740
+ turnOff: action("feeder.child-lock.off", require_sleep.t("Unlock", "Sblocca"), "lock-open", "pet-feeder", "setChildLock", { on: false })
100741
+ }
100742
+ ];
100743
+ }
100744
+ var feederContribution = contribution("pet-feeder", PetFeederStatusSchema, (slice, ctx) => {
100745
+ const words = feederWords(slice);
100746
+ const last = slice?.lastFeedGrams ?? null;
100747
+ return {
100748
+ reading: reading("pet-feeder", words?.state ?? "unknown", false, words?.title),
100749
+ rows: [{
100750
+ id: "feeder",
100751
+ icon: "bone",
100752
+ status: words?.title ?? unknownText,
100753
+ controls: slice === void 0 ? [] : feederControls(slice)
100754
+ }],
100755
+ facts: [
100756
+ ...slice?.lowFood === true ? [fact("level", "bone", require_sleep.t("Food low", "Cibo in esaurimento"), "warning")] : [],
100757
+ ...last === null ? [] : [fact("last-run", "clock", require_sleep.t(`Last ${last} g`, `Ultimo ${last} g`))],
100758
+ ...ownBattery(slice?.powerSource === "battery" ? slice.batteryPower : null, ctx)
100759
+ ],
100760
+ ...last === null ? {} : { tiles: { right: [{
100761
+ label: require_sleep.t("Last portion", "Ultima porzione"),
100762
+ value: require_sleep.t(`${last} g`, `${last} g`)
100763
+ }] } }
100764
+ };
100765
+ });
100766
+ var fountainContribution = contribution("pet-fountain", PetFountainStatusSchema, (slice) => {
100767
+ const pump = slice?.pumpRunning ?? null;
100768
+ const fault = slice?.error ?? null;
100769
+ const empty = slice?.empty === true;
100770
+ const state = slice === void 0 ? "unknown" : fault !== null || empty ? "alert" : pump === null ? "unknown" : pump ? "running" : "off";
100771
+ const title = slice === void 0 ? void 0 : fault !== null ? require_sleep.t(fault, fault) : empty ? require_sleep.t("Tank empty", "Serbatoio vuoto") : pump === null ? void 0 : pump ? require_sleep.t("Pump running", "Pompa attiva") : require_sleep.t("Pump off", "Pompa spenta");
100772
+ const level = slice?.waterLevel ?? null;
100773
+ const control = {
100774
+ kind: "toggle",
100775
+ id: "fountain.pump",
100776
+ label: require_sleep.t("Pump", "Pompa"),
100777
+ on: pump,
100778
+ turnOn: action("fountain.pump.on", require_sleep.t("Pump on", "Accendi la pompa"), "droplets", "pet-fountain", "setPump", { on: true }, "primary"),
100779
+ turnOff: action("fountain.pump.off", require_sleep.t("Pump off", "Spegni la pompa"), "square", "pet-fountain", "setPump", { on: false })
100780
+ };
100781
+ return {
100782
+ reading: reading("pet-fountain", state, false, title),
100783
+ rows: [{
100784
+ id: "fountain",
100785
+ icon: "droplets",
100786
+ status: title ?? unknownText,
100787
+ controls: slice === void 0 ? [] : [control]
100788
+ }],
100789
+ ...level === null ? {} : {
100790
+ facts: [fact("level", "droplets", require_sleep.t(`Water ${Math.round(level)}%`, `Acqua ${Math.round(level)}%`), level <= 20 ? "warning" : "primary")],
100791
+ tiles: { right: [{
100792
+ label: require_sleep.t("Water", "Acqua"),
100793
+ value: pct$1(level)
100794
+ }] },
100795
+ scene: { level: unit(level) }
100796
+ }
100797
+ };
100798
+ });
100799
+ var minutesOf = (seconds) => Math.max(0, Math.round(seconds / 60));
100800
+ var DEVICES_FAMILY_CONTRIBUTIONS = {
100801
+ "fan-control": fanContribution,
100802
+ "vacuum-control": vacuumContribution,
100803
+ "lawn-mower-control": mowerContribution,
100804
+ "pet-feeder": feederContribution,
100805
+ "pet-fountain": fountainContribution,
100806
+ "pump-cycle": contribution("pump-cycle", PumpCycleStatusSchema, (slice) => {
100807
+ const enabled = slice?.enabled ?? null;
100808
+ const cycle = slice?.onTime != null && slice.offTime != null ? require_sleep.t(`${minutesOf(slice.onTime)} min on · ${minutesOf(slice.offTime)} min off`, `${minutesOf(slice.onTime)} min acceso · ${minutesOf(slice.offTime)} min spento`) : null;
100809
+ return { rows: [row$1("pump-cycle", "timer", enabled === null ? unknownText : enabled ? joinText([require_sleep.t("Cycling", "A cicli"), cycle]) : require_sleep.t("Runs continuously", "Sempre attiva"), [{
100810
+ kind: "toggle",
100811
+ id: "pump-cycle.enabled",
100812
+ label: require_sleep.t("Pump cycle", "Ciclo pompa"),
100813
+ on: enabled,
100814
+ turnOn: action("pump-cycle.on", require_sleep.t("Cycle the pump", "Attiva il ciclo"), "timer", "pump-cycle", "setEnabled", { on: true }),
100815
+ turnOff: action("pump-cycle.off", require_sleep.t("Run continuously", "Sempre attiva"), "timer-off", "pump-cycle", "setEnabled", { on: false })
100816
+ }])] };
100817
+ })
100818
+ };
100819
+ //#endregion
100820
+ //#region src/device/hero/hero-contributions-actuators.ts
100821
+ /**
100822
+ * What the moving and dimming caps add to a hero (D1023): a light's brightness
100823
+ * and colour, a cover, a valve and a humidifier. Moving a cover or a valve is
100824
+ * an ACTION the person presses, never a toggle that fires by itself; a slice
100825
+ * that does not parse reads `unknown`, never closed or off (D315/D393).
100826
+ */
100827
+ var has$2 = (ctx, f) => ctx.features.includes(f);
100828
+ var pct = (n) => require_sleep.t(`${Math.round(n)}%`, `${Math.round(n)}%`);
100829
+ var brightnessContribution = contribution("brightness", BrightnessStatusSchema, (slice) => {
100830
+ const level = slice?.level ?? null;
100831
+ return {
100832
+ ...level === null ? {} : { reading: reading("brightness", level > 0 ? "on" : "off") },
100833
+ ...level === null ? {} : {
100834
+ facts: [fact("level", "sun-dim", pct(level), level > 0 ? "primary" : "muted")],
100835
+ scene: { level: level / 100 }
100836
+ },
100837
+ rows: [row$1("brightness", "sun-dim", level === null ? null : require_sleep.t(`Brightness ${Math.round(level)}%`, `Luminosità ${Math.round(level)}%`), [{
100838
+ kind: "slider",
100839
+ id: "brightness.level",
100840
+ label: require_sleep.t("Brightness", "Luminosità"),
100841
+ value: level,
100842
+ min: 0,
100843
+ max: 100,
100844
+ step: 1,
100845
+ unit: "%",
100846
+ call: {
100847
+ cap: "brightness",
100848
+ method: "setBrightness",
100849
+ args: {}
100850
+ },
100851
+ valueArg: "level"
100852
+ }])]
100853
+ };
100854
+ });
100855
+ /**
100856
+ * Preset colours as actions: `setColor` takes a nested `{ mode, … }` argument, which a
100857
+ * hero action carries (D1023). Only the modes the bulb declares are offered, each a
100858
+ * valid `setColor` input; a bulb that declares none is shown, not set.
100859
+ */
100860
+ var WHITE_PRESETS = [
100861
+ {
100862
+ id: "color.warm",
100863
+ en: "Warm white",
100864
+ it: "Bianco caldo",
100865
+ icon: "sun",
100866
+ mired: 370
100867
+ },
100868
+ {
100869
+ id: "color.neutral",
100870
+ en: "Neutral white",
100871
+ it: "Bianco neutro",
100872
+ icon: "lightbulb",
100873
+ mired: 250
100874
+ },
100875
+ {
100876
+ id: "color.cool",
100877
+ en: "Cool white",
100878
+ it: "Bianco freddo",
100879
+ icon: "snowflake",
100880
+ mired: 154
100881
+ }
100882
+ ];
100883
+ var HUE_PRESETS = [
100884
+ {
100885
+ id: "color.red",
100886
+ en: "Red",
100887
+ it: "Rosso",
100888
+ hue: 0
100889
+ },
100890
+ {
100891
+ id: "color.amber",
100892
+ en: "Amber",
100893
+ it: "Ambra",
100894
+ hue: 40
100895
+ },
100896
+ {
100897
+ id: "color.green",
100898
+ en: "Green",
100899
+ it: "Verde",
100900
+ hue: 120
100901
+ },
100902
+ {
100903
+ id: "color.cyan",
100904
+ en: "Cyan",
100905
+ it: "Ciano",
100906
+ hue: 180
100907
+ },
100908
+ {
100909
+ id: "color.blue",
100910
+ en: "Blue",
100911
+ it: "Blu",
100912
+ hue: 240
100913
+ },
100914
+ {
100915
+ id: "color.purple",
100916
+ en: "Purple",
100917
+ it: "Viola",
100918
+ hue: 280
100919
+ }
100920
+ ];
100921
+ function colorControls(ctx, current) {
100922
+ const controls = [];
100923
+ if (has$2(ctx, require_device_type.DeviceFeature.LightColorMired)) for (const p of WHITE_PRESETS) controls.push(asAction(action(p.id, require_sleep.t(p.en, p.it), p.icon, "color", "setColor", { color: {
100924
+ mode: "mired",
100925
+ colorTemperature: p.mired
100926
+ } })));
100927
+ if (has$2(ctx, require_device_type.DeviceFeature.LightColorHsv)) {
100928
+ const s = current?.s ?? 100;
100929
+ const v = current?.v ?? 100;
100930
+ for (const p of HUE_PRESETS) controls.push(asAction(action(p.id, require_sleep.t(p.en, p.it), "palette", "color", "setColor", { color: {
100931
+ mode: "hsv",
100932
+ hsv: {
100933
+ h: p.hue,
100934
+ s,
100935
+ v
100936
+ }
100937
+ } })));
100938
+ }
100939
+ return controls;
100940
+ }
100941
+ var colorContribution = contribution("color", ColorStatusSchema, (slice, ctx) => {
100942
+ let words = null;
100943
+ if (slice !== void 0) {
100944
+ if (slice.mode === "mired" && slice.colorTemperature !== void 0 && slice.colorTemperature > 0) {
100945
+ const kelvin = Math.round(1e6 / slice.colorTemperature);
100946
+ words = require_sleep.t(`${kelvin} K`, `${kelvin} K`);
100947
+ } else if (slice.mode === "rgb" && slice.rgb !== void 0) {
100948
+ const c = `RGB ${slice.rgb.r}, ${slice.rgb.g}, ${slice.rgb.b}`;
100949
+ words = require_sleep.t(c, c);
100950
+ } else if (slice.mode === "hsv" && slice.hsv !== void 0) words = require_sleep.t(`Hue ${Math.round(slice.hsv.h)}°`, `Tonalità ${Math.round(slice.hsv.h)}°`);
100951
+ }
100952
+ return {
100953
+ ...words === null ? {} : { facts: [fact("reading", "palette", words)] },
100954
+ rows: [row$1("color", "palette", words, colorControls(ctx, slice?.mode === "hsv" && slice.hsv !== void 0 ? slice.hsv : null))]
100955
+ };
100956
+ });
100957
+ function travelWords(state, position) {
100958
+ const partial = position !== null && position > 0 && position < 100;
100959
+ const at = position === null ? null : Math.round(position);
100960
+ switch (state) {
100961
+ case "open": return {
100962
+ state: "on",
100963
+ title: partial ? require_sleep.t(`${at}% open`, `Aperto al ${at}%`) : require_sleep.t("Open", "Aperto"),
100964
+ mode: "open"
100965
+ };
100966
+ case "closed": return {
100967
+ state: "off",
100968
+ title: require_sleep.t("Closed", "Chiuso"),
100969
+ mode: "closed"
100970
+ };
100971
+ case "opening": return {
100972
+ state: "running",
100973
+ title: require_sleep.t("Opening", "In apertura"),
100974
+ mode: "open"
100975
+ };
100976
+ case "closing": return {
100977
+ state: "running",
100978
+ title: require_sleep.t("Closing", "In chiusura"),
100979
+ mode: "closed"
100980
+ };
100981
+ case "stopped": return {
100982
+ state: "idle",
100983
+ title: at === null ? require_sleep.t("Stopped", "Fermo") : require_sleep.t(`Stopped at ${at}%`, `Fermo al ${at}%`),
100984
+ mode: position === null ? null : position > 0 ? "open" : "closed"
100985
+ };
100986
+ }
100987
+ }
100988
+ /** Open / stop / close are actions; the one that makes sense next carries the emphasis. */
100989
+ function travelActions(s, state, moving) {
100990
+ const emphasis = (wanted) => wanted ? "primary" : "normal";
100991
+ const open = action(`${s.cap}.open`, require_sleep.t("Open", "Apri"), "arrow-up", s.cap, "open", {}, emphasis(state === "closed" || state === "closing"));
100992
+ const stop = action(`${s.cap}.stop`, require_sleep.t("Stop", "Ferma"), "square", s.cap, "stop", {}, emphasis(moving));
100993
+ const close = action(`${s.cap}.close`, require_sleep.t("Close", "Chiudi"), "arrow-down", s.cap, "close", {}, emphasis(state === "open" || state === "opening"));
100994
+ return s.stoppable || moving ? [
100995
+ open,
100996
+ stop,
100997
+ close
100998
+ ] : [open, close];
100999
+ }
101000
+ function positionSlider(s, position) {
101001
+ return {
101002
+ kind: "slider",
101003
+ id: `${s.cap}.position`,
101004
+ label: require_sleep.t("Position", "Posizione"),
101005
+ value: position,
101006
+ min: 0,
101007
+ max: 100,
101008
+ step: 1,
101009
+ unit: "%",
101010
+ call: {
101011
+ cap: s.cap,
101012
+ method: "setPosition",
101013
+ args: {}
101014
+ },
101015
+ valueArg: "position"
101016
+ };
101017
+ }
101018
+ function travelFragment(s, state, position, tilt, ctx) {
101019
+ if (state === void 0) return {
101020
+ reading: reading(s.source, "unknown"),
101021
+ rows: [row$1(s.rowId, "arrow-up", null, travelActions(s, void 0, false).map(asAction))]
101022
+ };
101023
+ const words = travelWords(state, position);
101024
+ const controls = travelActions(s, state, state === "opening" || state === "closing").map(asAction);
101025
+ if (position !== null || s.positionable) controls.push(positionSlider(s, position));
101026
+ if (s.cap === "cover" && (tilt !== null || has$2(ctx, require_device_type.DeviceFeature.CoverTilt))) controls.push({
101027
+ kind: "slider",
101028
+ id: "cover.tilt",
101029
+ label: require_sleep.t("Tilt", "Inclinazione"),
101030
+ value: tilt,
101031
+ min: 0,
101032
+ max: 100,
101033
+ step: 1,
101034
+ unit: "%",
101035
+ call: {
101036
+ cap: "cover",
101037
+ method: "setTiltPosition",
101038
+ args: {}
101039
+ },
101040
+ valueArg: "tiltPosition"
101041
+ });
101042
+ return {
101043
+ reading: reading(s.source, words.state, false, words.title),
101044
+ ...position === null ? {} : { facts: [fact("level", "arrow-up-down", pct(position))] },
101045
+ scene: {
101046
+ ...words.mode === null ? {} : { mode: words.mode },
101047
+ ...position === null ? {} : { level: position / 100 }
101048
+ },
101049
+ rows: [row$1(s.rowId, "arrow-up-down", joinText([words.title, position !== null && state !== "open" ? pct(position) : null]), controls)]
101050
+ };
101051
+ }
101052
+ var ACTUATORS_FAMILY_CONTRIBUTIONS = {
101053
+ brightness: brightnessContribution,
101054
+ color: colorContribution,
101055
+ cover: contribution("cover", CoverStatusSchema, (slice, ctx) => travelFragment({
101056
+ cap: "cover",
101057
+ rowId: "cover",
101058
+ source: "cover",
101059
+ stoppable: has$2(ctx, require_device_type.DeviceFeature.CoverStoppable),
101060
+ positionable: has$2(ctx, require_device_type.DeviceFeature.CoverPositionable)
101061
+ }, slice?.state, slice?.position ?? null, slice?.tiltPosition ?? null, ctx)),
101062
+ valve: contribution("valve", ValveStatusSchema, (slice, ctx) => travelFragment({
101063
+ cap: "valve",
101064
+ rowId: "valve",
101065
+ source: "valve",
101066
+ stoppable: false,
101067
+ positionable: has$2(ctx, require_device_type.DeviceFeature.ValvePositionable)
101068
+ }, slice?.state, slice?.position ?? null, null, ctx)),
101069
+ humidifier: contribution("humidifier", HumidifierStatusSchema, (slice) => {
101070
+ if (slice === void 0) return { reading: reading("humidifier", "unknown") };
101071
+ const action_ = slice.action;
101072
+ let state = "off";
101073
+ let title = require_sleep.t("Off", "Spento");
101074
+ if (slice.on) if (action_ === "humidifying") {
101075
+ state = "running";
101076
+ title = require_sleep.t("Humidifying", "Umidifica");
101077
+ } else if (action_ === "drying") {
101078
+ state = "running";
101079
+ title = require_sleep.t("Drying", "Deumidifica");
101080
+ } else if (action_ === "idle") {
101081
+ state = "idle";
101082
+ title = require_sleep.t("Idle", "In attesa");
101083
+ } else {
101084
+ state = "on";
101085
+ title = require_sleep.t("On", "Acceso");
101086
+ }
101087
+ const controls = [{
101088
+ kind: "toggle",
101089
+ id: "humidifier.power",
101090
+ label: require_sleep.t("Power", "Accensione"),
101091
+ on: slice.on,
101092
+ turnOn: action("humidifier.on", require_sleep.t("Turn on", "Accendi"), "power", "humidifier", "setOn", { on: true }),
101093
+ turnOff: action("humidifier.off", require_sleep.t("Turn off", "Spegni"), "power-off", "humidifier", "setOn", { on: false })
101094
+ }];
101095
+ if (slice.targetHumidity !== null) controls.push({
101096
+ kind: "slider",
101097
+ id: "humidifier.target",
101098
+ label: require_sleep.t("Target", "Obiettivo"),
101099
+ value: slice.targetHumidity,
101100
+ min: slice.minHumidity ?? 0,
101101
+ max: slice.maxHumidity ?? 100,
101102
+ step: 1,
101103
+ unit: "%",
101104
+ call: {
101105
+ cap: "humidifier",
101106
+ method: "setTargetHumidity",
101107
+ args: {}
101108
+ },
101109
+ valueArg: "humidity"
101110
+ });
101111
+ if (slice.availableModes.length > 0) controls.push({
101112
+ kind: "picker",
101113
+ id: "humidifier.mode",
101114
+ label: require_sleep.t("Mode", "Modalità"),
101115
+ current: slice.mode,
101116
+ options: [...slice.availableModes],
101117
+ call: {
101118
+ cap: "humidifier",
101119
+ method: "setMode",
101120
+ args: {}
101121
+ },
101122
+ valueArg: "mode"
101123
+ });
101124
+ const now = slice.currentHumidity;
101125
+ return {
101126
+ reading: reading("humidifier", state, false, title),
101127
+ ...now === null ? {} : { facts: [fact("level", "droplets", pct(now), "info")] },
101128
+ ...slice.targetHumidity === null ? {} : { tiles: { right: [{
101129
+ label: require_sleep.t("Target", "Obiettivo"),
101130
+ value: pct(slice.targetHumidity)
101131
+ }] } },
101132
+ ...now === null ? {} : { scene: { level: now / 100 } },
101133
+ rows: [row$1("humidifier", "droplets", joinText([title, slice.mode === null ? null : require_sleep.t(slice.mode, slice.mode)]), controls)]
101134
+ };
101135
+ })
101136
+ };
101137
+ var GROUPS_FAMILY_CONTRIBUTIONS = {
101138
+ "group-active": contribution("group-active", GroupActiveSchema, (slice) => {
101139
+ if (slice === void 0) return { reading: reading("group-active", "unknown") };
101140
+ return { reading: reading("group-active", slice.active ? "on" : "off", false, slice.active ? require_sleep.t("Active", "Attivo") : require_sleep.t("Inactive", "Non attivo")) };
101141
+ }),
101142
+ "group-status": contribution("group-status", GroupStatusSchema, (slice) => {
101143
+ if (slice === void 0) return {};
101144
+ const text = slice.excluded === 0 ? require_sleep.t(`${slice.total} members`, `${slice.total} membri`) : require_sleep.t(`${slice.included} of ${slice.total} reporting`, `${slice.included} di ${slice.total} rispondono`);
101145
+ return {
101146
+ facts: [fact("members", "users", text, slice.excluded === 0 ? "muted" : "warning")],
101147
+ tiles: { left: [{
101148
+ label: require_sleep.t("Members", "Membri"),
101149
+ value: text
101150
+ }] }
101151
+ };
101152
+ }),
101153
+ "group-commands": contribution("group-commands", GroupCommandsSchema, (slice) => {
101154
+ if (slice === void 0) return {};
101155
+ const failed = slice.results.filter((r) => !r.ok).length;
101156
+ if (failed === 0) return {};
101157
+ const total = slice.results.length;
101158
+ return { facts: [fact("failures", "triangle-alert", require_sleep.t(`${failed} of ${total} failed`, `${failed} di ${total} falliti`), "danger")] };
101159
+ }),
101160
+ "event-emitter": contribution("event-emitter", EventEmitterStatusSchema, (slice, ctx) => {
101161
+ if (slice === void 0) return { reading: reading("event-emitter", "unknown") };
101162
+ const last = slice.lastEvent;
101163
+ const ago = last === null ? null : elapsedText(last.timestamp, ctx.now);
101164
+ return {
101165
+ reading: reading("event-emitter", "idle", false, require_sleep.t("Listening", "In ascolto")),
101166
+ ...last === null ? {} : { facts: [fact("event", "radio-tower", ago === null ? require_sleep.t(last.eventType, last.eventType) : require_sleep.t(`${last.eventType} · ${ago.en}`, `${last.eventType} · ${ago.it}`), "primary")] },
101167
+ tiles: { right: [{
101168
+ label: require_sleep.t("Events", "Eventi"),
101169
+ value: require_sleep.t(`${slice.eventCountSinceStart}`, `${slice.eventCountSinceStart}`)
101170
+ }] }
101171
+ };
101172
+ })
101173
+ };
101174
+ //#endregion
101175
+ //#region src/device/hero/hero-contributions-sensors.ts
101176
+ /**
101177
+ * What the sensing caps add to a hero (D1023): the alarm sensors (smoke, flood,
101178
+ * gas, tamper, vibration), motion, presence, the doorbell, the generic binary
101179
+ * and meter, the weather station, a firmware update, an image and the two
101180
+ * caps a person acts on directly (a button, a control).
101181
+ *
101182
+ * A sensor's title is its READING ("Clear" / "Detected"), never a power word:
101183
+ * the generic On / Off belong to something that can be switched. A slice that
101184
+ * does not parse is "not answered" and reads `unknown`, never clear (D315/D393);
101185
+ * a measurement the device did not report is absent, never a zero (D393).
101186
+ */
101187
+ /** The recency of a transition as the top line's "since" fact; absent when never observed. */
101188
+ function sinceFact(at, now, tone = "muted") {
101189
+ if (at === null) return [];
101190
+ const ago = elapsedText(at, now);
101191
+ return ago === null ? [] : [fact("since", "clock", ago, tone)];
101192
+ }
101193
+ function detection(spec) {
101194
+ return contribution(spec.cap, spec.schema, (slice, ctx) => {
101195
+ if (slice === void 0) return { reading: reading(spec.source, "unknown") };
101196
+ const tripped = spec.flag(slice);
101197
+ const changed = spec.changedAt(slice);
101198
+ return {
101199
+ reading: reading(spec.source, tripped ? spec.yesState : "idle", false, tripped ? spec.words.yes : spec.words.no),
101200
+ facts: sinceFact(changed === 0 ? null : changed, ctx.now, tripped ? "danger" : "muted")
101201
+ };
101202
+ });
101203
+ }
101204
+ var detected = {
101205
+ yes: require_sleep.t("Detected", "Rilevato"),
101206
+ no: require_sleep.t("Clear", "Libero")
101207
+ };
101208
+ var smokeContribution = detection({
101209
+ cap: "smoke",
101210
+ source: "smoke",
101211
+ schema: SmokeStatusSchema,
101212
+ words: {
101213
+ yes: require_sleep.t("Smoke detected", "Fumo rilevato"),
101214
+ no: require_sleep.t("Clear", "Nessun fumo")
101215
+ },
101216
+ yesState: "alert",
101217
+ flag: (s) => s.detected,
101218
+ changedAt: (s) => s.lastChangedAt
101219
+ });
101220
+ var floodContribution = detection({
101221
+ cap: "flood",
101222
+ source: "flood",
101223
+ schema: FloodStatusSchema,
101224
+ words: {
101225
+ yes: require_sleep.t("Leak detected", "Perdita rilevata"),
101226
+ no: require_sleep.t("Dry", "Asciutto")
101227
+ },
101228
+ yesState: "alert",
101229
+ flag: (s) => s.flooded,
101230
+ changedAt: (s) => s.lastChangedAt
101231
+ });
101232
+ var gasContribution = detection({
101233
+ cap: "gas",
101234
+ source: "gas",
101235
+ schema: GasStatusSchema,
101236
+ words: {
101237
+ yes: require_sleep.t("Gas detected", "Gas rilevato"),
101238
+ no: require_sleep.t("Clear", "Nessun gas")
101239
+ },
101240
+ yesState: "alert",
101241
+ flag: (s) => s.detected,
101242
+ changedAt: (s) => s.lastChangedAt
101243
+ });
101244
+ var tamperContribution = detection({
101245
+ cap: "tamper",
101246
+ source: "tamper",
101247
+ schema: TamperStatusSchema,
101248
+ words: {
101249
+ yes: require_sleep.t("Tampered", "Manomesso"),
101250
+ no: require_sleep.t("Secure", "Integro")
101251
+ },
101252
+ yesState: "alert",
101253
+ flag: (s) => s.tampered,
101254
+ changedAt: (s) => s.lastChangedAt
101255
+ });
101256
+ var vibrationContribution = detection({
101257
+ cap: "vibration",
101258
+ source: "vibration",
101259
+ schema: VibrationStatusSchema,
101260
+ words: {
101261
+ yes: require_sleep.t("Vibration", "Vibrazione"),
101262
+ no: require_sleep.t("Still", "Fermo")
101263
+ },
101264
+ yesState: "on",
101265
+ flag: (s) => s.detected,
101266
+ changedAt: (s) => s.lastChangedAt
101267
+ });
101268
+ var binaryContribution = detection({
101269
+ cap: "binary",
101270
+ source: "binary",
101271
+ schema: BinaryStatusSchema,
101272
+ words: {
101273
+ yes: require_sleep.t("Active", "Attivo"),
101274
+ no: require_sleep.t("Inactive", "Inattivo")
101275
+ },
101276
+ yesState: "on",
101277
+ flag: (s) => s.on,
101278
+ changedAt: (s) => s.lastChangedAt
101279
+ });
101280
+ var motionContribution = contribution("motion", MotionStatusSchema, (slice, ctx) => {
101281
+ if (slice === void 0) return { reading: reading("motion", "unknown") };
101282
+ const last = slice.lastDetectedAt;
101283
+ const ago = last === null ? null : elapsedText(last, ctx.now);
101284
+ return {
101285
+ reading: reading("motion", slice.detected ? "on" : "idle", false, slice.detected ? detected.yes : require_sleep.t("Clear", "Nessun movimento")),
101286
+ ...ago === null ? {} : { facts: [fact("since", "clock", require_sleep.t(`Last motion ${ago.en}`, `Ultimo movimento ${ago.it}`), slice.detected ? "primary" : "muted")] }
101287
+ };
101288
+ });
101289
+ var presenceContribution = contribution("presence", PresenceStatusSchema, (slice, ctx) => {
101290
+ if (slice === void 0) return { reading: reading("presence", "unknown") };
101291
+ const zone = slice.state;
101292
+ const home = zone === "home";
101293
+ const away = zone === "not_home";
101294
+ const title = home ? require_sleep.t("Home", "A casa") : away ? require_sleep.t("Away", "Fuori casa") : require_sleep.t(zone, zone);
101295
+ const facts = [];
101296
+ if (slice.location !== null && slice.location !== "") facts.push(fact("reading", "map-pin", require_sleep.t(slice.location, slice.location)));
101297
+ facts.push(...sinceFact(slice.lastChangedAt === 0 ? null : slice.lastChangedAt, ctx.now));
101298
+ return {
101299
+ reading: reading("presence", away ? "off" : "on", false, title),
101300
+ facts
101301
+ };
101302
+ });
101303
+ /** A ring this recent still reads as "ringing". */
101304
+ var RINGING_MS = 3e4;
101305
+ var doorbellContribution = contribution("doorbell", DoorbellStatusSchema, (slice, ctx) => {
101306
+ if (slice === void 0) return { reading: reading("doorbell", "unknown") };
101307
+ const last = slice.lastPressedAt;
101308
+ const ago = last === null ? null : elapsedText(last, ctx.now);
101309
+ const ringing = last !== null && ctx.now >= last && ctx.now - last < RINGING_MS;
101310
+ const title = ringing ? require_sleep.t("Ringing", "Suona") : ago === null ? require_sleep.t("No ring yet", "Nessun squillo") : require_sleep.t(`Last ring ${ago.en}`, `Ultimo squillo ${ago.it}`);
101311
+ const count = slice.pressCountSinceStart;
101312
+ return {
101313
+ ...ctx.caps.includes("motion") && !ringing ? {} : { reading: reading("doorbell", ringing ? "on" : "idle", false, title) },
101314
+ facts: [...ctx.caps.includes("motion") && !ringing ? [fact("event", "bell", title)] : [], ...count > 0 ? [fact("event", "bell-ring", require_sleep.t(`${count} ring${count === 1 ? "" : "s"}`, `${count} squilli`))] : []]
101315
+ };
101316
+ });
101317
+ var number = (n) => `${Number(n.toFixed(2))}`;
101318
+ var meterContribution = contribution("meter", MeterStatusSchema, (slice, ctx) => {
101319
+ if (slice === void 0 || slice.value === null) return { reading: reading("meter", "unknown") };
101320
+ const value = number(slice.value);
101321
+ return {
101322
+ reading: reading("meter", "idle", false, require_sleep.t(value, value)),
101323
+ facts: sinceFact(slice.lastFetchedAt === 0 ? null : slice.lastFetchedAt, ctx.now)
101324
+ };
101325
+ });
101326
+ var CONDITION_WORDS = {
101327
+ sunny: require_sleep.t("Sunny", "Soleggiato"),
101328
+ "clear-night": require_sleep.t("Clear night", "Notte serena"),
101329
+ cloudy: require_sleep.t("Cloudy", "Nuvoloso"),
101330
+ partlycloudy: require_sleep.t("Partly cloudy", "Parzialmente nuvoloso"),
101331
+ rainy: require_sleep.t("Rain", "Pioggia"),
101332
+ pouring: require_sleep.t("Heavy rain", "Pioggia forte"),
101333
+ snowy: require_sleep.t("Snow", "Neve"),
101334
+ "snowy-rainy": require_sleep.t("Sleet", "Nevischio"),
101335
+ fog: require_sleep.t("Fog", "Nebbia"),
101336
+ windy: require_sleep.t("Windy", "Ventoso"),
101337
+ "windy-variant": require_sleep.t("Windy", "Ventoso"),
101338
+ lightning: require_sleep.t("Thunderstorm", "Temporale"),
101339
+ "lightning-rainy": require_sleep.t("Thunderstorm", "Temporale"),
101340
+ hail: require_sleep.t("Hail", "Grandine"),
101341
+ exceptional: require_sleep.t("Exceptional", "Eccezionale")
101342
+ };
101343
+ var weatherContribution = contribution("weather", WeatherStatusSchema, (slice, ctx) => {
101344
+ if (slice === void 0) return { reading: reading("weather", "unknown") };
101345
+ const { condition, temperature, humidity, pressure, windSpeed } = slice;
101346
+ const celsius = temperature === null ? null : `${number(temperature)}°C`;
101347
+ const word = condition === null ? null : CONDITION_WORDS[condition] ?? require_sleep.t(condition, condition);
101348
+ const title = word ?? (celsius === null ? null : require_sleep.t(celsius, celsius));
101349
+ if (title === null) return { reading: reading("weather", "unknown") };
101350
+ const facts = [];
101351
+ if (celsius !== null && word !== null) facts.push(fact("reading", "thermometer", require_sleep.t(celsius, celsius), "primary"));
101352
+ if (humidity !== null) facts.push(fact("reading", "droplets", require_sleep.t(`${Math.round(humidity)}%`, `${Math.round(humidity)}%`)));
101353
+ if (windSpeed !== null) facts.push(fact("reading", "wind", require_sleep.t(`${number(windSpeed)} m/s`, `${number(windSpeed)} m/s`)));
101354
+ if (pressure !== null) facts.push(fact("reading", "gauge", require_sleep.t(`${Math.round(pressure)} hPa`, `${Math.round(pressure)} hPa`)));
101355
+ facts.push(...sinceFact(slice.lastFetchedAt === 0 ? null : slice.lastFetchedAt, ctx.now));
101356
+ const left = [];
101357
+ if (humidity !== null) left.push({
101358
+ label: require_sleep.t("Humidity", "Umidità"),
101359
+ value: require_sleep.t(`${Math.round(humidity)}%`, `${Math.round(humidity)}%`)
101360
+ });
101361
+ if (pressure !== null) left.push({
101362
+ label: require_sleep.t("Pressure", "Pressione"),
101363
+ value: require_sleep.t(`${Math.round(pressure)} hPa`, `${Math.round(pressure)} hPa`)
101364
+ });
101365
+ const right = windSpeed === null ? [] : [{
101366
+ label: require_sleep.t("Wind", "Vento"),
101367
+ value: require_sleep.t(`${number(windSpeed)} m/s`, `${number(windSpeed)} m/s`)
101368
+ }];
101369
+ return {
101370
+ reading: reading("weather", "on", false, title),
101371
+ facts,
101372
+ tiles: {
101373
+ left,
101374
+ right
101375
+ }
101376
+ };
101377
+ });
101378
+ var updateContribution = contribution("update", UpdateStatusSchema, (slice) => {
101379
+ if (slice === void 0) return { reading: reading("update", "unknown") };
101380
+ const { currentVersion, availableVersion, inProgress, updatable } = slice;
101381
+ const pending = availableVersion !== null && availableVersion !== "" && availableVersion !== currentVersion;
101382
+ if (!pending && currentVersion === null && !inProgress) return { reading: reading("update", "unknown") };
101383
+ const state = inProgress ? "running" : pending ? "standby" : "idle";
101384
+ const title = inProgress ? require_sleep.t("Updating", "Aggiornamento in corso") : pending ? require_sleep.t("Update available", "Aggiornamento disponibile") : require_sleep.t("Up to date", "Aggiornato");
101385
+ const versions = currentVersion === null ? pending ? require_sleep.t(`${availableVersion}`, `${availableVersion}`) : null : pending ? require_sleep.t(`${currentVersion} → ${availableVersion}`, `${currentVersion} → ${availableVersion}`) : require_sleep.t(`Version ${currentVersion}`, `Versione ${currentVersion}`);
101386
+ const install = pending && updatable && !inProgress ? [asAction(action("update.install", require_sleep.t("Install", "Installa"), "download", "update", "installUpdate", {}, "primary", "install"))] : [];
101387
+ return {
101388
+ reading: reading("update", state, false, title),
101389
+ facts: versions === null ? [] : [fact("reading", "download", versions, pending ? "warning" : "muted")],
101390
+ rows: [row$1("update", "download", versions, install)]
101391
+ };
101392
+ });
101393
+ var imageContribution = contribution("image", ImageStatusSchema, (slice, ctx) => {
101394
+ if (slice === void 0) return { reading: reading("image", "unknown") };
101395
+ if (slice.url === null) return { reading: reading("image", "idle", false, require_sleep.t("No image yet", "Nessuna immagine")) };
101396
+ const ago = slice.lastUpdated === null ? null : elapsedText(slice.lastUpdated, ctx.now);
101397
+ return {
101398
+ reading: reading("image", "on", false, ago === null ? require_sleep.t("Image", "Immagine") : require_sleep.t(`Updated ${ago.en}`, `Aggiornata ${ago.it}`)),
101399
+ artworkUrl: slice.url
101400
+ };
101401
+ });
101402
+ /** A button has no state to read: it is always ready, so it is never `unknown`. */
101403
+ var buttonContribution = {
101404
+ cap: "button",
101405
+ contribute: () => ({
101406
+ reading: reading("button", "idle", false, require_sleep.t("Ready", "Pronto")),
101407
+ rows: [row$1("button", "pointer", null, [asAction(action("button.press", require_sleep.t("Press", "Premi"), "pointer", "button", "press", {}, "primary", "press"))])]
101408
+ })
101409
+ };
101410
+ var controlContribution = contribution("control", ControlStatusSchema, (slice, ctx) => {
101411
+ if (slice === void 0) return { reading: reading("control", "unknown") };
101412
+ const text = typeof slice.value === "number" ? number(slice.value) : slice.value;
101413
+ return {
101414
+ reading: reading("control", "on", false, require_sleep.t(text, text)),
101415
+ facts: sinceFact(slice.lastChangedAt === 0 ? null : slice.lastChangedAt, ctx.now),
101416
+ rows: controlRows(slice)
101417
+ };
101418
+ });
101419
+ var CONTROL_LABEL = require_sleep.t("Value", "Valore");
101420
+ /** A number with known bounds is a slider, a choice a picker; text and dates stay read-only. */
101421
+ function controlRows(slice) {
101422
+ if (slice.kind === "numeric" && typeof slice.value === "number") {
101423
+ if (slice.min === void 0 || slice.max === void 0) return [];
101424
+ return [row$1("control", "sliders-horizontal", null, [{
101425
+ kind: "slider",
101426
+ id: "control.value",
101427
+ label: CONTROL_LABEL,
101428
+ value: slice.value,
101429
+ min: slice.min,
101430
+ max: slice.max,
101431
+ step: slice.step ?? 1,
101432
+ unit: "",
101433
+ call: {
101434
+ cap: "control",
101435
+ method: "setValue",
101436
+ args: { control: { kind: "numeric" } }
101437
+ },
101438
+ valueArg: "control.value"
101439
+ }])];
101440
+ }
101441
+ if (slice.kind === "select" && typeof slice.value === "string") return [row$1("control", "sliders-horizontal", null, [{
101442
+ kind: "picker",
101443
+ id: "control.value",
101444
+ label: CONTROL_LABEL,
101445
+ current: slice.value,
101446
+ options: slice.options,
101447
+ call: {
101448
+ cap: "control",
101449
+ method: "setValue",
101450
+ args: { control: { kind: "select" } }
101451
+ },
101452
+ valueArg: "control.value"
101453
+ }])];
101454
+ return [];
101455
+ }
101456
+ var SENSORS_FAMILY_CONTRIBUTIONS = {
101457
+ smoke: smokeContribution,
101458
+ flood: floodContribution,
101459
+ gas: gasContribution,
101460
+ tamper: tamperContribution,
101461
+ vibration: vibrationContribution,
101462
+ binary: binaryContribution,
101463
+ motion: motionContribution,
101464
+ presence: presenceContribution,
101465
+ doorbell: doorbellContribution,
101466
+ meter: meterContribution,
101467
+ weather: weatherContribution,
101468
+ update: updateContribution,
101469
+ image: imageContribution,
101470
+ button: buttonContribution,
101471
+ control: controlContribution
101472
+ };
101473
+ //#endregion
101474
+ //#region src/device/hero/climate-view.ts
101475
+ var MODE_LABEL = {
101476
+ off: require_sleep.t("Off", "Spento"),
101477
+ heat: require_sleep.t("Heating", "Riscalda"),
101478
+ cool: require_sleep.t("Cooling", "Freddo"),
101479
+ auto: require_sleep.t("Auto", "Auto"),
101480
+ heat_cool: require_sleep.t("Heat/Cool", "Caldo/Freddo"),
101481
+ fan_only: require_sleep.t("Fan only", "Solo ventola"),
101482
+ dry: require_sleep.t("Drying", "Deumidifica")
101483
+ };
101484
+ var SCENE_MODE = {
101485
+ off: null,
101486
+ heat: "heat",
101487
+ cool: "cool",
101488
+ auto: "auto",
101489
+ heat_cool: "auto",
101490
+ fan_only: "fan",
101491
+ dry: "dry"
101492
+ };
101493
+ /** Without a remembered mode, "turn on" picks the first of these the device accepts. */
101494
+ var ON_MODE_PREFERENCE = [
101495
+ "auto",
101496
+ "heat_cool",
101497
+ "heat",
101498
+ "cool"
101499
+ ];
101500
+ /** 22 -> "22", 22.3 -> "22.3": a trailing zero is noise on a thermostat. */
101501
+ function formatDegrees(value) {
101502
+ return `${Number(value.toFixed(1))}°`;
101503
+ }
101504
+ /** "Turn on" returns to the mode the device last ran when it still accepts it, else the fixed order. */
101505
+ function onModeOf(available, last) {
101506
+ const candidates = available.filter((m) => m !== "off");
101507
+ if (last !== void 0 && candidates.includes(last)) return last;
101508
+ for (const preferred of ON_MODE_PREFERENCE) if (candidates.includes(preferred)) return preferred;
101509
+ return candidates[0] ?? null;
101510
+ }
101511
+ function deriveClimateView(slice) {
101512
+ const range = rangeFrom(slice.minTemp, slice.maxTemp, slice.tempStep);
101513
+ const level = levelWithin(slice.target, range);
101514
+ return {
101515
+ mode: slice.mode,
101516
+ isOff: slice.mode === "off",
101517
+ modeLabel: MODE_LABEL[slice.mode],
101518
+ target: slice.target,
101519
+ measured: slice.currentTemp,
101520
+ targetRange: slice.targetLow !== null && slice.targetHigh !== null ? {
101521
+ low: slice.targetLow,
101522
+ high: slice.targetHigh
101523
+ } : null,
101524
+ targetHumidity: slice.targetHumidity,
101525
+ humidity: slice.currentHumidity,
101526
+ range,
101527
+ availableModes: slice.availableModes,
101528
+ sceneMode: SCENE_MODE[slice.mode],
101529
+ level,
101530
+ onMode: onModeOf(slice.availableModes, slice.lastActiveMode)
101531
+ };
101532
+ }
101533
+ /** "22° (22.3°)": the setpoint and, in brackets, what is measured. The mode is the headline, not repeated here. */
101534
+ function thermalStatusText(target, measured) {
101535
+ const goal = target === null ? "" : typeof target === "string" ? target : formatDegrees(target);
101536
+ const now = measured === null ? "" : formatDegrees(measured);
101537
+ const temps = goal !== "" && now !== "" ? `${goal} (${now})` : goal !== "" ? goal : now;
101538
+ return temps === "" ? null : require_sleep.t(temps, temps);
101539
+ }
101540
+ function climateStatusText(view) {
101541
+ const range = view.targetRange;
101542
+ return thermalStatusText(view.target !== null ? view.target : range === null ? null : `${Number(range.low.toFixed(1))}–${formatDegrees(range.high)}`, view.measured);
101543
+ }
101544
+ /** The setpoint inside its range, 0..1. */
101545
+ function levelWithin(value, range) {
101546
+ if (value === null || range === null) return null;
101547
+ return Math.min(1, Math.max(0, (value - range.min) / (range.max - range.min)));
101548
+ }
101549
+ function rangeFrom(min, max, step) {
101550
+ if (min === null || min === void 0) return null;
101551
+ if (max === null || max === void 0 || max <= min) return null;
101552
+ return {
101553
+ min,
101554
+ max,
101555
+ step: step ?? 1
101556
+ };
101557
+ }
101558
+ //#endregion
101559
+ //#region src/device/hero/hero-contributions-climate.ts
101560
+ /**
101561
+ * The climate family's contributions to a hero (D1023): `climate-control`,
101562
+ * `water-heater`, `heating-valve`, and the read-only sensors. Capabilities
101563
+ * contribute, types never do (D14). A slice that is absent or does not parse is
101564
+ * "not answered": the state reads unknown, no row is drawn (D315, D393).
101565
+ */
101566
+ var same = (text) => require_sleep.t(text, text);
101567
+ function tile(en, it, value) {
101568
+ return {
101569
+ label: require_sleep.t(en, it),
101570
+ value: same(value)
101571
+ };
101572
+ }
101573
+ function setpointSlider(id, cap, method, valueArg, value, range) {
101574
+ return {
101575
+ kind: "slider",
101576
+ id,
101577
+ label: require_sleep.t("Target", "Obiettivo"),
101578
+ value,
101579
+ min: range.min,
101580
+ max: range.max,
101581
+ step: range.step,
101582
+ unit: "°",
101583
+ call: {
101584
+ cap,
101585
+ method,
101586
+ args: {}
101587
+ },
101588
+ valueArg
101589
+ };
101590
+ }
101591
+ function setpointRow(status, slider) {
101592
+ return slider === null ? [] : [{
101593
+ id: "setpoint",
101594
+ icon: "thermometer",
101595
+ status,
101596
+ controls: [slider]
101597
+ }];
101598
+ }
101599
+ var climateContribution = contribution("climate-control", ClimateControlStatusSchema, (slice, ctx) => {
101600
+ if (slice === void 0) return { reading: reading("climate-control", "unknown") };
101601
+ const view = deriveClimateView(slice);
101602
+ const status = climateStatusText(view);
101603
+ const facts = [];
101604
+ if (status !== null) facts.push(fact("climate", "thermometer", status));
101605
+ if (view.humidity !== null) facts.push(fact("humidity", "droplets", same(`${Math.round(view.humidity)}%`)));
101606
+ if (view.targetHumidity !== null) facts.push(fact("humidity", "droplets", same(`→ ${Math.round(view.targetHumidity)}%`)));
101607
+ const left = [];
101608
+ const right = [];
101609
+ if (view.measured !== null) left.push(tile("Indoor", "In casa", formatDegrees(view.measured)));
101610
+ if (view.humidity !== null) left.push(tile("Humidity", "Umidità", `${Math.round(view.humidity)}%`));
101611
+ const modeControls = [{
101612
+ kind: "picker",
101613
+ id: "climate.mode",
101614
+ label: require_sleep.t("Mode", "Modalità"),
101615
+ current: view.mode,
101616
+ options: [...view.availableModes],
101617
+ call: {
101618
+ cap: "climate-control",
101619
+ method: "setMode",
101620
+ args: {}
101621
+ },
101622
+ valueArg: "mode"
101623
+ }];
101624
+ if (slice.availablePresets.length > 0) modeControls.push({
101625
+ kind: "picker",
101626
+ id: "climate.preset",
101627
+ label: require_sleep.t("Preset", "Preset"),
101628
+ current: slice.preset === "" ? null : slice.preset,
101629
+ options: [...slice.availablePresets],
101630
+ call: {
101631
+ cap: "climate-control",
101632
+ method: "setPreset",
101633
+ args: {}
101634
+ },
101635
+ valueArg: "preset"
101636
+ });
101637
+ const fanControls = [];
101638
+ if (slice.availableFanModes.length > 0) fanControls.push({
101639
+ kind: "picker",
101640
+ id: "climate.fan",
101641
+ label: require_sleep.t("Fan", "Ventola"),
101642
+ current: slice.fanMode === "" ? null : slice.fanMode,
101643
+ options: [...slice.availableFanModes],
101644
+ call: {
101645
+ cap: "climate-control",
101646
+ method: "setFanMode",
101647
+ args: {}
101648
+ },
101649
+ valueArg: "fanMode"
101650
+ });
101651
+ const swing = (id, en, it, method, on, feature) => ctx.features.includes(feature) ? [{
101652
+ kind: "toggle",
101653
+ id,
101654
+ label: require_sleep.t(en, it),
101655
+ on,
101656
+ turnOn: action(`${id}.on`, require_sleep.t(en, it), "wind", "climate-control", method, { on: true }),
101657
+ turnOff: action(`${id}.off`, require_sleep.t(en, it), "wind", "climate-control", method, { on: false })
101658
+ }] : [];
101659
+ fanControls.push(...swing("climate.swing-vertical", "Swing vertical", "Oscillazione verticale", "setSwingVertical", slice.swingVertical, require_device_type.DeviceFeature.ClimateSwingVertical), ...swing("climate.swing-horizontal", "Swing horizontal", "Oscillazione orizzontale", "setSwingHorizontal", slice.swingHorizontal, require_device_type.DeviceFeature.ClimateSwingHorizontal));
101660
+ const rows = [{
101661
+ id: "climate-mode",
101662
+ icon: "thermometer",
101663
+ status: view.modeLabel,
101664
+ controls: modeControls
101665
+ }];
101666
+ if (fanControls.length > 0) rows.push({
101667
+ id: "climate-fan",
101668
+ icon: "fan",
101669
+ status: slice.fanMode === "" ? null : same(slice.fanMode),
101670
+ controls: fanControls
101671
+ });
101672
+ rows.push(...setpointRow(view.target === null ? null : same(formatDegrees(view.target)), view.range === null || view.target === null ? null : setpointSlider("climate.target", "climate-control", "setTarget", "target", view.target, view.range)));
101673
+ const sceneMode = view.sceneMode;
101674
+ return {
101675
+ reading: reading("climate-control", view.isOff ? "off" : "on"),
101676
+ title: view.modeLabel,
101677
+ facts,
101678
+ ...left.length === 0 && right.length === 0 ? {} : { tiles: {
101679
+ left,
101680
+ right
101681
+ } },
101682
+ scene: {
101683
+ ...sceneMode === null ? {} : { mode: sceneMode },
101684
+ ...view.level === null ? {} : { level: view.level }
101685
+ },
101686
+ ...view.onMode === null ? {} : { ownPower: {
101687
+ source: "climate-control",
101688
+ on: !view.isOff,
101689
+ assumed: false,
101690
+ turnOn: action("own-power.on", require_sleep.t("Turn on", "Accendi"), "power", "climate-control", "setMode", { mode: view.onMode }),
101691
+ turnOff: action("own-power.off", require_sleep.t("Turn off", "Spegni"), "power-off", "climate-control", "setMode", { mode: "off" })
101692
+ } },
101693
+ rows
101694
+ };
101695
+ });
101696
+ var WATER_ON_PREFERENCE = [
101697
+ "eco",
101698
+ "electric",
101699
+ "heat_pump",
101700
+ "performance"
101701
+ ];
101702
+ function capitalised(word) {
101703
+ return same(word.charAt(0).toUpperCase() + word.slice(1).replace(/_/g, " "));
101704
+ }
101705
+ var waterHeaterContribution = contribution("water-heater", WaterHeaterStatusSchema, (slice) => {
101706
+ if (slice === void 0 || slice.operationMode === null) return { reading: reading("climate-control", "unknown") };
101707
+ const isOff = slice.operationMode === "off";
101708
+ const label = capitalised(slice.operationMode);
101709
+ const status = thermalStatusText(slice.targetTemp, slice.currentTemp);
101710
+ const range = rangeFrom(slice.minTemp, slice.maxTemp, 1);
101711
+ const candidates = slice.availableModes.filter((m) => m !== "off");
101712
+ const last = slice.lastActiveMode;
101713
+ const onMode = last !== void 0 && candidates.includes(last) ? last : WATER_ON_PREFERENCE.find((m) => candidates.includes(m)) ?? candidates[0] ?? null;
101714
+ const modeControls = [{
101715
+ kind: "picker",
101716
+ id: "water-heater.mode",
101717
+ label: require_sleep.t("Mode", "Modalità"),
101718
+ current: slice.operationMode,
101719
+ options: [...slice.availableModes],
101720
+ call: {
101721
+ cap: "water-heater",
101722
+ method: "setOperationMode",
101723
+ args: {}
101724
+ },
101725
+ valueArg: "mode"
101726
+ }];
101727
+ if (slice.away !== null) modeControls.push({
101728
+ kind: "toggle",
101729
+ id: "water-heater.away",
101730
+ label: require_sleep.t("Away", "Assente"),
101731
+ on: slice.away,
101732
+ turnOn: action("water-heater.away.on", require_sleep.t("Away", "Assente"), "house", "water-heater", "setAway", { on: true }),
101733
+ turnOff: action("water-heater.away.off", require_sleep.t("Away", "Assente"), "house", "water-heater", "setAway", { on: false })
101734
+ });
101735
+ const rows = [{
101736
+ id: "climate-mode",
101737
+ icon: "flame",
101738
+ status: label,
101739
+ controls: modeControls
101740
+ }, ...setpointRow(slice.targetTemp === null ? null : same(formatDegrees(slice.targetTemp)), range === null || slice.targetTemp === null ? null : setpointSlider("water-heater.target", "water-heater", "setTargetTemp", "temp", slice.targetTemp, range))];
101741
+ const level = levelWithin(slice.targetTemp, range);
101742
+ return {
101743
+ reading: reading("climate-control", isOff ? "off" : "on"),
101744
+ title: label,
101745
+ facts: status === null ? [] : [fact("climate", "flame", status)],
101746
+ ...slice.currentTemp === null ? {} : { tiles: { left: [tile("Water", "Acqua", formatDegrees(slice.currentTemp))] } },
101747
+ scene: {
101748
+ ...isOff ? {} : { mode: "heat" },
101749
+ ...level === null ? {} : { level }
101750
+ },
101751
+ ...onMode === null ? {} : { ownPower: {
101752
+ source: "climate-control",
101753
+ on: !isOff,
101754
+ assumed: false,
101755
+ turnOn: action("own-power.on", require_sleep.t("Turn on", "Accendi"), "power", "water-heater", "setOperationMode", { mode: onMode }),
101756
+ turnOff: action("own-power.off", require_sleep.t("Turn off", "Spegni"), "power-off", "water-heater", "setOperationMode", { mode: "off" })
101757
+ } },
101758
+ rows
101759
+ };
101760
+ });
101761
+ var heatingValveContribution = contribution("heating-valve", HeatingValveStatusSchema, (slice) => {
101762
+ const position = slice?.position ?? null;
101763
+ if (position === null) return { reading: reading("sensor", "unknown") };
101764
+ const text = same(`${Math.round(position)}%`);
101765
+ return {
101766
+ reading: reading("sensor", position > 0 ? "running" : "idle"),
101767
+ facts: [fact("valve", "gauge", require_sleep.t(`Valve ${text.en}`, `Valvola ${text.it}`))],
101768
+ tiles: { right: [tile("Valve", "Valvola", text.en)] },
101769
+ scene: { level: position / 100 }
101770
+ };
101771
+ });
101772
+ /** One reading fact plus its tile; a value that did not answer says nothing and the state stays unknown. */
101773
+ function sensorFragment(value, id, icon, en, it, text) {
101774
+ if (value === null) return { reading: reading("sensor", "unknown") };
101775
+ return {
101776
+ reading: reading("sensor", "on"),
101777
+ title: same(text),
101778
+ facts: [fact(id, icon, same(text))],
101779
+ tiles: { right: [tile(en, it, text)] }
101780
+ };
101781
+ }
101782
+ var temperatureContribution = contribution("temperature-sensor", TemperatureSensorStatusSchema, (slice) => sensorFragment(slice?.temperature ?? null, "temperature", "thermometer", "Temperature", "Temperatura", formatDegrees(slice?.temperature ?? 0)));
101783
+ var humidityContribution = contribution("humidity-sensor", HumiditySensorStatusSchema, (slice) => sensorFragment(slice?.humidity ?? null, "humidity", "droplets", "Humidity", "Umidità", `${Math.round(slice?.humidity ?? 0)}%`));
101784
+ var pressureContribution = contribution("pressure-sensor", PressureSensorStatusSchema, (slice) => sensorFragment(slice?.pressure ?? null, "pressure", "gauge", "Pressure", "Pressione", `${Math.round(slice?.pressure ?? 0)} hPa`));
101785
+ var illuminanceContribution = contribution("ambient-light-sensor", AmbientLightSensorStatusSchema, (slice) => sensorFragment(slice?.illuminance ?? null, "illuminance", "sun", "Light", "Luce", `${Math.round(slice?.illuminance ?? 0)} lx`));
101786
+ var numericContribution = contribution("numeric-sensor", NumericSensorStatusSchema, (slice) => sensorFragment(slice?.value ?? null, "reading", "gauge", "Value", "Valore", String(Number((slice?.value ?? 0).toFixed(2)))));
101787
+ var enumContribution = contribution("enum-sensor", EnumSensorStatusSchema, (slice) => {
101788
+ if (slice === void 0 || slice.value === "") return { reading: reading("sensor", "unknown") };
101789
+ if (slice.timestamp === true) return { reading: reading("sensor", "on") };
101790
+ return sensorFragment(slice.value, "reading", "gauge", "State", "Stato", slice.value);
101791
+ });
101792
+ /** Index bands: the headline of an air-quality sensor is a word, not a number. */
101793
+ function airQualityWord(aqi) {
101794
+ if (aqi <= 50) return require_sleep.t("Good", "Buona");
101795
+ if (aqi <= 100) return require_sleep.t("Moderate", "Discreta");
101796
+ if (aqi <= 150) return require_sleep.t("Poor", "Scadente");
101797
+ return require_sleep.t("Unhealthy", "Malsana");
101798
+ }
101799
+ /** The climate family, in the order their fragments are merged (a valve's level outranks a setpoint's). */
101800
+ var CLIMATE_FAMILY_CONTRIBUTIONS = {
101801
+ "heating-valve": heatingValveContribution,
101802
+ "climate-control": climateContribution,
101803
+ "water-heater": waterHeaterContribution,
101804
+ "temperature-sensor": temperatureContribution,
101805
+ "humidity-sensor": humidityContribution,
101806
+ "pressure-sensor": pressureContribution,
101807
+ "air-quality-sensor": contribution("air-quality-sensor", AirQualitySensorStatusSchema, (slice) => {
101808
+ if (slice === void 0) return { reading: reading("sensor", "unknown") };
101809
+ const parts = [];
101810
+ if (slice.aqi !== void 0) parts.push({
101811
+ label: "AQI",
101812
+ value: String(Math.round(slice.aqi))
101813
+ });
101814
+ if (slice.co2 !== void 0) parts.push({
101815
+ label: "CO₂",
101816
+ value: `${Math.round(slice.co2)} ppm`
101817
+ });
101818
+ if (slice.pm25 !== void 0) parts.push({
101819
+ label: "PM2.5",
101820
+ value: `${Math.round(slice.pm25)} µg/m³`
101821
+ });
101822
+ if (slice.voc !== void 0) parts.push({
101823
+ label: "VOC",
101824
+ value: `${Math.round(slice.voc)} ppb`
101825
+ });
101826
+ if (slice.pm10 !== void 0) parts.push({
101827
+ label: "PM10",
101828
+ value: `${Math.round(slice.pm10)} µg/m³`
101829
+ });
101830
+ if (parts.length === 0) return { reading: reading("sensor", "unknown") };
101831
+ return {
101832
+ reading: reading("sensor", "on"),
101833
+ ...slice.aqi === void 0 ? {} : { title: airQualityWord(slice.aqi) },
101834
+ facts: parts.map((p) => fact("air-quality", "wind", same(`${p.label} ${p.value}`))),
101835
+ tiles: { right: parts.slice(0, 2).map((p) => tile(p.label, p.label, p.value)) }
101836
+ };
101837
+ }),
101838
+ "carbon-monoxide": contribution("carbon-monoxide", CarbonMonoxideStatusSchema, (slice) => {
101839
+ if (slice === void 0) return { reading: reading("sensor", "unknown") };
101840
+ return {
101841
+ reading: reading("sensor", slice.detected ? "alert" : "idle"),
101842
+ title: slice.detected ? require_sleep.t("CO detected", "CO rilevato") : require_sleep.t("Air clear", "Aria libera"),
101843
+ facts: [fact("reading", slice.detected ? "triangle-alert" : "shield-check", slice.detected ? require_sleep.t("CO detected", "CO rilevato") : require_sleep.t("Air clear", "Aria libera"), slice.detected ? "danger" : "muted")]
101844
+ };
101845
+ }),
101846
+ "ambient-light-sensor": illuminanceContribution,
101847
+ "numeric-sensor": numericContribution,
101848
+ "enum-sensor": enumContribution
101849
+ };
101850
+ //#endregion
101851
+ //#region src/device/hero/media-player-view.ts
101852
+ /** The position to show at `nowMs`: the reported one, advanced while playing when it is stamped. */
101853
+ function projectedPositionMs(status, nowMs) {
101854
+ if (status.position === null) return null;
101855
+ const stamp = status.positionUpdatedAt;
101856
+ if (status.state !== "playing" || typeof stamp !== "number") return status.position;
101857
+ const advanced = status.position + Math.max(0, nowMs - stamp);
101858
+ return status.duration !== null && status.duration > 0 ? Math.min(advanced, status.duration) : advanced;
101859
+ }
101860
+ /**
101861
+ * The optimistic patch for a seek. A status that carries `positionUpdatedAt` is stamped
101862
+ * too: the projection advances from the stamp, so leaving the old one would show a
101863
+ * position past the target.
101864
+ */
101865
+ function seekPatch(status, positionMs, nowMs) {
101866
+ return typeof status.positionUpdatedAt === "number" ? {
101867
+ position: positionMs,
101868
+ positionUpdatedAt: nowMs
101869
+ } : { position: positionMs };
101870
+ }
101871
+ /** True when the status carries a stamp the position can be advanced from. */
101872
+ function isPositionTicking(status) {
101873
+ return status !== void 0 && status.state === "playing" && status.position !== null && typeof status.positionUpdatedAt === "number";
101874
+ }
101875
+ var NO_TRANSPORT = {
101876
+ playPause: false,
101877
+ previous: false,
101878
+ next: false,
101879
+ stop: false
101880
+ };
101881
+ /** Whether the status carries any activity the device actually reported. */
101882
+ function runningOf$1(state) {
101883
+ switch (state) {
101884
+ case "playing":
101885
+ case "paused":
101886
+ case "buffering":
101887
+ case "idle": return state;
101888
+ case void 0: return "unknown";
101889
+ default: return "none";
101890
+ }
101891
+ }
101892
+ function artworkOf(status) {
101893
+ const url = status.currentMedia?.imageUrl?.trim() ?? "";
101894
+ return url === "" ? null : url;
101895
+ }
101896
+ function powerOf(state) {
101897
+ if (state === void 0) return "unknown";
101898
+ if (state === "off") return "off";
101899
+ if (state === "standby") return "standby";
101900
+ return "on";
101901
+ }
101902
+ /**
101903
+ * A slice from before `assumedFields` existed (stateSource assumed, no list)
101904
+ * means the whole state is a guess; with a list, only the named fields are.
101905
+ */
101906
+ function isAssumed(status, field) {
101907
+ if (status.stateSource !== "assumed") return false;
101908
+ const listed = status.assumedFields ?? [];
101909
+ return listed.length === 0 || listed.includes(field);
101910
+ }
101911
+ var UNKNOWN_VIEW = {
101912
+ power: "unknown",
101913
+ runningReading: "unknown",
101914
+ running: "unknown",
101915
+ stateAssumed: false,
101916
+ canSwitchPower: false,
101917
+ transport: NO_TRANSPORT,
101918
+ seek: false,
101919
+ volume: "none",
101920
+ volumeKnown: false,
101921
+ muteKnown: false,
101922
+ artworkUrl: null,
101923
+ mute: false,
101924
+ source: null,
101925
+ channel: null,
101926
+ shuffle: false,
101927
+ repeat: false,
101928
+ shuffleReadOnly: false,
101929
+ repeatReadOnly: false,
101930
+ nowPlaying: null
101931
+ };
101932
+ function nowPlayingOf(status) {
101933
+ if (status === void 0) return null;
101934
+ const media = status.currentMedia;
101935
+ const title = media?.title.trim() ?? "";
101936
+ const subtitle = [media?.artist, media?.album].map((part) => part?.trim() ?? "").filter((part) => part !== "").join(" · ");
101937
+ const artworkUrl = artworkOf(status);
101938
+ const source = typeof status.source === "string" ? status.source.trim() : "";
101939
+ const hasDuration = status.position !== null && status.duration !== null && status.duration > 0;
101940
+ if (title === "" && subtitle === "" && artworkUrl === null) return null;
101941
+ return {
101942
+ title: title === "" ? null : title,
101943
+ subtitle: subtitle === "" ? null : subtitle,
101944
+ artworkUrl,
101945
+ source: source === "" ? null : source,
101946
+ progress: hasDuration && status.position !== null && status.duration !== null ? {
101947
+ positionMs: status.position,
101948
+ durationMs: status.duration
101949
+ } : null
101950
+ };
101951
+ }
101952
+ function readingOf(running) {
101953
+ if (running === true) return "running";
101954
+ if (running === false) return "idle";
101955
+ return "unknown";
101956
+ }
101957
+ function deriveMediaPlayerView(status, features, extras = {}) {
101958
+ return {
101959
+ ...derivePowerGatedView(status, features, extras),
101960
+ nowPlaying: nowPlayingOf(status),
101961
+ shuffleReadOnly: status !== void 0 && status.shuffle !== null && !(features?.includes(require_device_type.DeviceFeature.MediaPlayerShuffle) ?? false),
101962
+ repeatReadOnly: status !== void 0 && status.repeat !== null && !(features?.includes(require_device_type.DeviceFeature.MediaPlayerRepeat) ?? false)
101963
+ };
101964
+ }
101965
+ function derivePowerGatedView(status, features, extras) {
101966
+ const runningReading = readingOf(extras.running);
101967
+ const view = deriveFromStatus(status, features);
101968
+ const guessed = status === void 0 || status.state === void 0 || view.stateAssumed;
101969
+ if (runningReading === "unknown" || !guessed) return {
101970
+ ...view,
101971
+ runningReading
101972
+ };
101973
+ if (runningReading === "idle") return {
101974
+ ...UNKNOWN_VIEW,
101975
+ power: "off",
101976
+ running: "none",
101977
+ canSwitchPower: view.canSwitchPower,
101978
+ runningReading
101979
+ };
101980
+ return {
101981
+ ...status === void 0 ? view : deriveFromStatus(status.state === void 0 || status.state === "off" || status.state === "standby" ? {
101982
+ ...status,
101983
+ state: "on"
101984
+ } : status, features),
101985
+ power: "on",
101986
+ stateAssumed: false,
101987
+ runningReading
101988
+ };
101989
+ }
101990
+ /** The channel being watched: only a media item the device itself calls a channel. */
101991
+ function channelOf(status) {
101992
+ const media = status.currentMedia;
101993
+ if (media === null || media === void 0 || media.type !== "channel") return null;
101994
+ const title = media.title.trim();
101995
+ return title === "" ? null : title;
101996
+ }
101997
+ function deriveFromStatus(status, features) {
101998
+ const has = (f) => features?.includes(f) ?? false;
101999
+ const canSwitchPower = has(require_device_type.DeviceFeature.MediaPlayerPower);
102000
+ if (status === void 0 || status.state === void 0) return {
102001
+ ...UNKNOWN_VIEW,
102002
+ canSwitchPower
102003
+ };
102004
+ const power = powerOf(status.state);
102005
+ const running = runningOf$1(status.state);
102006
+ const base = {
102007
+ ...UNKNOWN_VIEW,
102008
+ power,
102009
+ running,
102010
+ stateAssumed: isAssumed(status, "state"),
102011
+ canSwitchPower
102012
+ };
102013
+ if (power !== "on") return base;
102014
+ const hasTransportFeature = has(require_device_type.DeviceFeature.MediaPlayerNext) || has(require_device_type.DeviceFeature.MediaPlayerPrevious) || has(require_device_type.DeviceFeature.MediaPlayerStop) || has(require_device_type.DeviceFeature.MediaPlayerSeek);
102015
+ const volume = has(require_device_type.DeviceFeature.MediaPlayerVolume) ? "slider" : has(require_device_type.DeviceFeature.MediaPlayerVolumeStep) ? "steps" : "none";
102016
+ const sourceName = typeof status.source === "string" ? status.source.trim() : "";
102017
+ const options = status.availableSources ?? [];
102018
+ const hasSource = sourceName !== "" || options.length > 0;
102019
+ return {
102020
+ ...base,
102021
+ transport: {
102022
+ playPause: running !== "none" || hasTransportFeature,
102023
+ previous: has(require_device_type.DeviceFeature.MediaPlayerPrevious),
102024
+ next: has(require_device_type.DeviceFeature.MediaPlayerNext),
102025
+ stop: has(require_device_type.DeviceFeature.MediaPlayerStop)
102026
+ },
102027
+ seek: has(require_device_type.DeviceFeature.MediaPlayerSeek) && status.duration !== null && status.duration > 0,
102028
+ volume,
102029
+ mute: has(require_device_type.DeviceFeature.MediaPlayerMute) || volume === "slider" && status.isMuted !== null,
102030
+ volumeKnown: status.volumeLevel !== null,
102031
+ muteKnown: status.isMuted !== null,
102032
+ artworkUrl: artworkOf(status),
102033
+ source: hasSource ? {
102034
+ current: sourceName,
102035
+ options,
102036
+ selectable: has(require_device_type.DeviceFeature.MediaPlayerSelectSource) && options.length > 1
102037
+ } : null,
102038
+ channel: has(require_device_type.DeviceFeature.MediaPlayerChannelStep) ? { current: channelOf(status) } : null,
102039
+ shuffle: has(require_device_type.DeviceFeature.MediaPlayerShuffle) && status.shuffle !== null,
102040
+ repeat: has(require_device_type.DeviceFeature.MediaPlayerRepeat) && status.repeat !== null
102041
+ };
102042
+ }
102043
+ //#endregion
102044
+ //#region src/device/hero/hero-contributions.ts
102045
+ /**
102046
+ * What each capability contributes to a hero (D1023). The map is typed against
102047
+ * the cap's own status schema: a slice is parsed at the boundary, and one that
102048
+ * does not parse reads as "not answered", never as a value.
102049
+ *
102050
+ * Capabilities contribute, device types never do (D14): nothing here looks at a
102051
+ * vendor. A type only chooses which ROWS its layout carries and how it looks.
102052
+ * `HERO_CAP_COVERAGE` (the second file of this directory) says, for every
102053
+ * device cap, whether it contributes and why it does not; the guard
102054
+ * `scripts/check-cap-hero-contributions.ts` keeps it complete.
102055
+ */
100065
102056
  function minutesLeft(seconds) {
100066
102057
  const m = Math.ceil(seconds / 60);
100067
102058
  return require_sleep.t(`${m} min left`, `${m} min rimanenti`);
@@ -100419,6 +102410,15 @@ var HERO_CAP_CONTRIBUTIONS = [
100419
102410
  status: null,
100420
102411
  controls: volume
100421
102412
  });
102413
+ if (view.channel !== null) {
102414
+ const channel = view.channel.current;
102415
+ rows.push({
102416
+ id: "channel",
102417
+ icon: "tv",
102418
+ status: channel === null ? null : require_sleep.t(channel, channel),
102419
+ controls: [asAction(action("channel.down", require_sleep.t("Channel down", "Canale giù"), "chevron-down", "media-player", "channelDown")), asAction(action("channel.up", require_sleep.t("Channel up", "Canale su"), "chevron-up", "media-player", "channelUp"))]
102420
+ });
102421
+ }
100422
102422
  if (view.source !== null) {
100423
102423
  const current = view.source.current === "" ? null : view.source.current;
100424
102424
  rows.push({
@@ -100479,7 +102479,13 @@ var HERO_CAP_CONTRIBUTIONS = [
100479
102479
  powerSourceContribution,
100480
102480
  remoteContribution,
100481
102481
  consumablesContribution,
100482
- dishwasherContribution
102482
+ dishwasherContribution,
102483
+ ...Object.values(ACCESS_FAMILY_CONTRIBUTIONS),
102484
+ ...Object.values(DEVICES_FAMILY_CONTRIBUTIONS),
102485
+ ...Object.values(GROUPS_FAMILY_CONTRIBUTIONS),
102486
+ ...Object.values(ACTUATORS_FAMILY_CONTRIBUTIONS),
102487
+ ...Object.values(SENSORS_FAMILY_CONTRIBUTIONS),
102488
+ ...Object.values(CLIMATE_FAMILY_CONTRIBUTIONS)
100483
102489
  ];
100484
102490
  //#endregion
100485
102491
  //#region src/device/hero/hero-layout.ts
@@ -100500,7 +102506,9 @@ var MEDIA_PLAYER_LAYOUT = { rows: [
100500
102506
  "now-playing",
100501
102507
  "playback",
100502
102508
  "volume",
100503
- "source"
102509
+ "channel",
102510
+ "source",
102511
+ "do-not-disturb"
100504
102512
  ] };
100505
102513
  var APPLIANCE_LAYOUT = { rows: ["cycle"] };
100506
102514
  /** Its Home Connect PowerState is a secondary row action, never the own-power slot. */
@@ -100509,40 +102517,66 @@ var DISHWASHER_LAYOUT = { rows: [
100509
102517
  "program",
100510
102518
  "appliance-power"
100511
102519
  ] };
102520
+ var CLIMATE_LAYOUT = { rows: [
102521
+ "climate-mode",
102522
+ "climate-fan",
102523
+ "setpoint"
102524
+ ] };
100512
102525
  var SWITCH_LAYOUT = { rows: ["motion-trigger"] };
102526
+ var LOCK_LAYOUT = { rows: ["lock"] };
102527
+ var ALARM_LAYOUT = { rows: ["alarm"] };
102528
+ var FAN_LAYOUT = { rows: ["fan"] };
102529
+ var VACUUM_LAYOUT = { rows: ["vacuum"] };
102530
+ var MOWER_LAYOUT = { rows: ["mower"] };
102531
+ var FEEDER_LAYOUT = { rows: ["feeder"] };
102532
+ var FOUNTAIN_LAYOUT = { rows: ["fountain", "pump-cycle"] };
102533
+ var AUTOMATION_LAYOUT = { rows: ["automation"] };
102534
+ var SCRIPT_LAYOUT = { rows: ["script"] };
102535
+ var LIGHT_LAYOUT = { rows: [
102536
+ "brightness",
102537
+ "color",
102538
+ "contact",
102539
+ "motion-trigger"
102540
+ ] };
102541
+ var COVER_LAYOUT = { rows: ["cover"] };
102542
+ var VALVE_LAYOUT = { rows: ["valve"] };
102543
+ var HUMIDIFIER_LAYOUT = { rows: ["humidifier"] };
102544
+ var UPDATE_LAYOUT = { rows: ["update"] };
102545
+ var CONTROL_LAYOUT = { rows: ["control"] };
102546
+ var BUTTON_LAYOUT = { rows: ["button"] };
100513
102547
  var HERO_LAYOUT_BY_TYPE = {
100514
102548
  [require_device_type.DeviceType.Camera]: HERO_LAYOUT_DEFAULT,
100515
102549
  [require_device_type.DeviceType.Hub]: HERO_LAYOUT_DEFAULT,
100516
- [require_device_type.DeviceType.Light]: HERO_LAYOUT_DEFAULT,
102550
+ [require_device_type.DeviceType.Light]: LIGHT_LAYOUT,
100517
102551
  [require_device_type.DeviceType.Siren]: HERO_LAYOUT_DEFAULT,
100518
102552
  [require_device_type.DeviceType.Switch]: SWITCH_LAYOUT,
100519
102553
  [require_device_type.DeviceType.Sensor]: HERO_LAYOUT_DEFAULT,
100520
- [require_device_type.DeviceType.Thermostat]: HERO_LAYOUT_DEFAULT,
100521
- [require_device_type.DeviceType.Climate]: HERO_LAYOUT_DEFAULT,
100522
- [require_device_type.DeviceType.Button]: HERO_LAYOUT_DEFAULT,
102554
+ [require_device_type.DeviceType.Thermostat]: CLIMATE_LAYOUT,
102555
+ [require_device_type.DeviceType.Climate]: CLIMATE_LAYOUT,
102556
+ [require_device_type.DeviceType.Button]: BUTTON_LAYOUT,
100523
102557
  [require_device_type.DeviceType.EventEmitter]: HERO_LAYOUT_DEFAULT,
100524
- [require_device_type.DeviceType.Update]: HERO_LAYOUT_DEFAULT,
102558
+ [require_device_type.DeviceType.Update]: UPDATE_LAYOUT,
100525
102559
  [require_device_type.DeviceType.Generic]: HERO_LAYOUT_DEFAULT,
100526
102560
  [require_device_type.DeviceType.Notifier]: HERO_LAYOUT_DEFAULT,
100527
- [require_device_type.DeviceType.Script]: HERO_LAYOUT_DEFAULT,
100528
- [require_device_type.DeviceType.Automation]: HERO_LAYOUT_DEFAULT,
100529
- [require_device_type.DeviceType.Lock]: HERO_LAYOUT_DEFAULT,
100530
- [require_device_type.DeviceType.Cover]: HERO_LAYOUT_DEFAULT,
100531
- [require_device_type.DeviceType.Valve]: HERO_LAYOUT_DEFAULT,
100532
- [require_device_type.DeviceType.Humidifier]: HERO_LAYOUT_DEFAULT,
100533
- [require_device_type.DeviceType.WaterHeater]: HERO_LAYOUT_DEFAULT,
100534
- [require_device_type.DeviceType.Fan]: HERO_LAYOUT_DEFAULT,
102561
+ [require_device_type.DeviceType.Script]: SCRIPT_LAYOUT,
102562
+ [require_device_type.DeviceType.Automation]: AUTOMATION_LAYOUT,
102563
+ [require_device_type.DeviceType.Lock]: LOCK_LAYOUT,
102564
+ [require_device_type.DeviceType.Cover]: COVER_LAYOUT,
102565
+ [require_device_type.DeviceType.Valve]: VALVE_LAYOUT,
102566
+ [require_device_type.DeviceType.Humidifier]: HUMIDIFIER_LAYOUT,
102567
+ [require_device_type.DeviceType.WaterHeater]: CLIMATE_LAYOUT,
102568
+ [require_device_type.DeviceType.Fan]: FAN_LAYOUT,
100535
102569
  [require_device_type.DeviceType.MediaPlayer]: MEDIA_PLAYER_LAYOUT,
100536
- [require_device_type.DeviceType.AlarmPanel]: HERO_LAYOUT_DEFAULT,
100537
- [require_device_type.DeviceType.Control]: HERO_LAYOUT_DEFAULT,
102570
+ [require_device_type.DeviceType.AlarmPanel]: ALARM_LAYOUT,
102571
+ [require_device_type.DeviceType.Control]: CONTROL_LAYOUT,
100538
102572
  [require_device_type.DeviceType.Presence]: HERO_LAYOUT_DEFAULT,
100539
102573
  [require_device_type.DeviceType.Weather]: HERO_LAYOUT_DEFAULT,
100540
- [require_device_type.DeviceType.Vacuum]: HERO_LAYOUT_DEFAULT,
100541
- [require_device_type.DeviceType.LawnMower]: HERO_LAYOUT_DEFAULT,
102574
+ [require_device_type.DeviceType.Vacuum]: VACUUM_LAYOUT,
102575
+ [require_device_type.DeviceType.LawnMower]: MOWER_LAYOUT,
100542
102576
  [require_device_type.DeviceType.Container]: HERO_LAYOUT_DEFAULT,
100543
102577
  [require_device_type.DeviceType.Image]: HERO_LAYOUT_DEFAULT,
100544
- [require_device_type.DeviceType.PetFeeder]: HERO_LAYOUT_DEFAULT,
100545
- [require_device_type.DeviceType.PetFountain]: HERO_LAYOUT_DEFAULT,
102578
+ [require_device_type.DeviceType.PetFeeder]: FEEDER_LAYOUT,
102579
+ [require_device_type.DeviceType.PetFountain]: FOUNTAIN_LAYOUT,
100546
102580
  [require_device_type.DeviceType.Dishwasher]: DISHWASHER_LAYOUT,
100547
102581
  [require_device_type.DeviceType.Washer]: APPLIANCE_LAYOUT,
100548
102582
  [require_device_type.DeviceType.Heater]: HEATER_LAYOUT,
@@ -100731,25 +102765,413 @@ var DISHWASHER_LOOK = lookOf({
100731
102765
  idle: INFO,
100732
102766
  standby: WARN
100733
102767
  });
100734
- var LEAK_LOOK = lookOf({
100735
- icon: "droplets",
102768
+ /** A sensor that reads Clear or Detected: calm when clear, an alarm when it trips. */
102769
+ function sensorLook(icon, alertIcon = icon) {
102770
+ return lookOf({
102771
+ icon,
102772
+ on: [
102773
+ "primary",
102774
+ "glow",
102775
+ "halo"
102776
+ ],
102777
+ off: MUTED,
102778
+ running: [
102779
+ "primary",
102780
+ "glow",
102781
+ "halo"
102782
+ ],
102783
+ idle: [
102784
+ "success",
102785
+ "plain",
102786
+ "none"
102787
+ ],
102788
+ standby: WARN,
102789
+ alert: look(alertIcon, "danger", "alert-wash", "pulse")
102790
+ });
102791
+ }
102792
+ var LEAK_LOOK = sensorLook("droplets");
102793
+ var SMOKE_LOOK = sensorLook("flame");
102794
+ var GAS_LOOK = sensorLook("wind");
102795
+ var TAMPER_LOOK = sensorLook("shield-alert");
102796
+ var VIBRATION_LOOK = sensorLook("vibrate");
102797
+ var MOTION_LOOK = sensorLook("radar", "triangle-alert");
102798
+ var DOORBELL_LOOK = sensorLook("bell-ring");
102799
+ /** A camera is a camera: never a power glyph, whatever its motion reads. */
102800
+ var CAMERA_LOOK = sensorLook("video", "triangle-alert");
102801
+ /** A bulb glows while lit. */
102802
+ var LIGHT_LOOK = lookOf({
102803
+ icon: "lightbulb",
100736
102804
  on: [
100737
- "danger",
102805
+ "warning",
102806
+ "glow",
102807
+ "glow"
102808
+ ],
102809
+ off: MUTED,
102810
+ running: [
102811
+ "warning",
102812
+ "glow",
102813
+ "glow"
102814
+ ],
102815
+ idle: INFO,
102816
+ standby: WARN
102817
+ });
102818
+ /** Closed is a position, not an absence of power: the blind keeps its glyph and goes quiet. */
102819
+ var COVER_LOOK = lookOf({
102820
+ icon: "blinds",
102821
+ on: [
102822
+ "primary",
102823
+ "plain",
102824
+ "none"
102825
+ ],
102826
+ off: MUTED,
102827
+ running: [
102828
+ "primary",
102829
+ "plain",
102830
+ "pulse"
102831
+ ],
102832
+ idle: INFO,
102833
+ standby: WARN
102834
+ });
102835
+ var VALVE_LOOK = lookOf({
102836
+ icon: "droplet",
102837
+ on: [
102838
+ "primary",
100738
102839
  "water",
100739
102840
  "wave"
100740
102841
  ],
100741
102842
  off: MUTED,
100742
102843
  running: [
100743
- "danger",
102844
+ "primary",
100744
102845
  "water",
102846
+ "pulse"
102847
+ ],
102848
+ idle: INFO,
102849
+ standby: WARN
102850
+ });
102851
+ var HUMIDIFIER_LOOK = lookOf({
102852
+ icon: "droplets",
102853
+ on: [
102854
+ "info",
102855
+ "mist",
102856
+ "breathe"
102857
+ ],
102858
+ off: MUTED,
102859
+ running: [
102860
+ "info",
102861
+ "mist",
100745
102862
  "wave"
100746
102863
  ],
100747
102864
  idle: INFO,
100748
- standby: WARN,
100749
- alert: look("droplets", "danger", "alert-wash", "pulse")
102865
+ standby: WARN
100750
102866
  });
100751
- var SMOKE_LOOK = lookOf({
100752
- icon: "flame",
102867
+ var CONTROL_LOOK = lookOf({
102868
+ icon: "sliders-horizontal",
102869
+ on: [
102870
+ "primary",
102871
+ "plain",
102872
+ "none"
102873
+ ],
102874
+ off: MUTED,
102875
+ running: [
102876
+ "primary",
102877
+ "plain",
102878
+ "pulse"
102879
+ ],
102880
+ idle: INFO,
102881
+ standby: WARN
102882
+ });
102883
+ var PRESENCE_LOOK = lookOf({
102884
+ icon: "map-pin",
102885
+ on: [
102886
+ "success",
102887
+ "plain",
102888
+ "none"
102889
+ ],
102890
+ off: MUTED,
102891
+ running: [
102892
+ "primary",
102893
+ "plain",
102894
+ "pulse"
102895
+ ],
102896
+ idle: INFO,
102897
+ standby: WARN
102898
+ });
102899
+ var WEATHER_LOOK = lookOf({
102900
+ icon: "cloud-sun",
102901
+ on: [
102902
+ "info",
102903
+ "sky",
102904
+ "none"
102905
+ ],
102906
+ off: MUTED,
102907
+ running: [
102908
+ "info",
102909
+ "sky",
102910
+ "none"
102911
+ ],
102912
+ idle: INFO,
102913
+ standby: WARN
102914
+ });
102915
+ /** An update waits (warning), runs (pulse) or is done (calm). */
102916
+ var UPDATE_LOOK = lookOf({
102917
+ icon: "download",
102918
+ on: [
102919
+ "success",
102920
+ "plain",
102921
+ "none"
102922
+ ],
102923
+ off: MUTED,
102924
+ running: [
102925
+ "primary",
102926
+ "plain",
102927
+ "pulse"
102928
+ ],
102929
+ idle: [
102930
+ "success",
102931
+ "plain",
102932
+ "none"
102933
+ ],
102934
+ standby: [
102935
+ "warning",
102936
+ "plain",
102937
+ "pulse"
102938
+ ]
102939
+ });
102940
+ var BUTTON_LOOK = lookOf({
102941
+ icon: "pointer",
102942
+ on: [
102943
+ "primary",
102944
+ "plain",
102945
+ "none"
102946
+ ],
102947
+ off: MUTED,
102948
+ running: [
102949
+ "primary",
102950
+ "plain",
102951
+ "pulse"
102952
+ ],
102953
+ idle: INFO,
102954
+ standby: WARN
102955
+ });
102956
+ var IMAGE_LOOK = lookOf({
102957
+ icon: "image",
102958
+ on: [
102959
+ "primary",
102960
+ "plain",
102961
+ "none"
102962
+ ],
102963
+ off: MUTED,
102964
+ running: [
102965
+ "primary",
102966
+ "plain",
102967
+ "pulse"
102968
+ ],
102969
+ idle: INFO,
102970
+ standby: WARN
102971
+ });
102972
+ /** A lock is secure when locked, and says so when it is not. */
102973
+ var LOCK_LOOK = {
102974
+ ...lookOf({
102975
+ icon: "lock",
102976
+ on: [
102977
+ "success",
102978
+ "plain",
102979
+ "none"
102980
+ ],
102981
+ off: MUTED,
102982
+ running: [
102983
+ "primary",
102984
+ "plain",
102985
+ "pulse"
102986
+ ],
102987
+ idle: INFO,
102988
+ standby: WARN
102989
+ }),
102990
+ standby: look("lock-open", "warning", "plain", "none"),
102991
+ off: look("lock-open", "muted", "plain", "none")
102992
+ };
102993
+ /** The shield glows while armed, blinks red in alarm and goes quiet when disarmed. */
102994
+ var ALARM_LOOK = {
102995
+ ...lookOf({
102996
+ icon: "shield-check",
102997
+ on: [
102998
+ "success",
102999
+ "glow",
103000
+ "halo"
103001
+ ],
103002
+ off: MUTED,
103003
+ running: [
103004
+ "primary",
103005
+ "plain",
103006
+ "pulse"
103007
+ ],
103008
+ idle: INFO,
103009
+ standby: WARN
103010
+ }),
103011
+ off: look("shield-off", "muted", "plain", "none"),
103012
+ standby: look("shield", "warning", "plain", "pulse"),
103013
+ alert: look("shield-alert", "danger", "alert-wash", "blink")
103014
+ };
103015
+ /** Blades turn only while air moves. */
103016
+ var FAN_LOOK = lookOf({
103017
+ icon: "fan",
103018
+ on: [
103019
+ "success",
103020
+ "plain",
103021
+ "none"
103022
+ ],
103023
+ off: MUTED,
103024
+ running: [
103025
+ "primary",
103026
+ "mist",
103027
+ "spin"
103028
+ ],
103029
+ idle: INFO,
103030
+ standby: WARN
103031
+ });
103032
+ var VACUUM_LOOK = lookOf({
103033
+ icon: "bot",
103034
+ on: [
103035
+ "success",
103036
+ "plain",
103037
+ "none"
103038
+ ],
103039
+ off: MUTED,
103040
+ running: [
103041
+ "primary",
103042
+ "plain",
103043
+ "pulse"
103044
+ ],
103045
+ idle: INFO,
103046
+ standby: WARN
103047
+ });
103048
+ var MOWER_LOOK = lookOf({
103049
+ icon: "sprout",
103050
+ on: [
103051
+ "success",
103052
+ "plain",
103053
+ "none"
103054
+ ],
103055
+ off: MUTED,
103056
+ running: [
103057
+ "primary",
103058
+ "plain",
103059
+ "pulse"
103060
+ ],
103061
+ idle: INFO,
103062
+ standby: WARN
103063
+ });
103064
+ var FEEDER_LOOK = lookOf({
103065
+ icon: "bone",
103066
+ on: [
103067
+ "success",
103068
+ "plain",
103069
+ "none"
103070
+ ],
103071
+ off: MUTED,
103072
+ running: [
103073
+ "primary",
103074
+ "plain",
103075
+ "pulse"
103076
+ ],
103077
+ idle: INFO,
103078
+ standby: WARN
103079
+ });
103080
+ var FOUNTAIN_LOOK = lookOf({
103081
+ icon: "droplets",
103082
+ on: [
103083
+ "success",
103084
+ "plain",
103085
+ "none"
103086
+ ],
103087
+ off: MUTED,
103088
+ running: [
103089
+ "primary",
103090
+ "water",
103091
+ "wave"
103092
+ ],
103093
+ idle: INFO,
103094
+ standby: WARN
103095
+ });
103096
+ var AUTOMATION_LOOK = lookOf({
103097
+ icon: "workflow",
103098
+ on: [
103099
+ "success",
103100
+ "plain",
103101
+ "none"
103102
+ ],
103103
+ off: MUTED,
103104
+ running: [
103105
+ "primary",
103106
+ "plain",
103107
+ "pulse"
103108
+ ],
103109
+ idle: INFO,
103110
+ standby: WARN
103111
+ });
103112
+ var SCRIPT_LOOK = lookOf({
103113
+ icon: "scroll-text",
103114
+ on: [
103115
+ "success",
103116
+ "plain",
103117
+ "none"
103118
+ ],
103119
+ off: MUTED,
103120
+ running: [
103121
+ "primary",
103122
+ "plain",
103123
+ "pulse"
103124
+ ],
103125
+ idle: INFO,
103126
+ standby: WARN
103127
+ });
103128
+ var EVENT_EMITTER_LOOK = lookOf({
103129
+ icon: "radio-tower",
103130
+ on: [
103131
+ "success",
103132
+ "plain",
103133
+ "none"
103134
+ ],
103135
+ off: MUTED,
103136
+ running: [
103137
+ "primary",
103138
+ "plain",
103139
+ "pulse"
103140
+ ],
103141
+ idle: INFO,
103142
+ standby: WARN
103143
+ });
103144
+ /** A reading device: the value is the headline, the look only says what kind of reading it is. */
103145
+ function readingLook(icon, tone) {
103146
+ return lookOf({
103147
+ icon,
103148
+ on: [
103149
+ tone,
103150
+ "plain",
103151
+ "none"
103152
+ ],
103153
+ off: MUTED,
103154
+ running: [
103155
+ tone,
103156
+ "plain",
103157
+ "none"
103158
+ ],
103159
+ idle: [
103160
+ tone,
103161
+ "plain",
103162
+ "none"
103163
+ ],
103164
+ standby: MUTED
103165
+ });
103166
+ }
103167
+ var READING_SENSOR_LOOK = readingLook("gauge", "info");
103168
+ var TEMPERATURE_LOOK = readingLook("thermometer", "info");
103169
+ var HUMIDITY_LOOK = readingLook("droplets", "info");
103170
+ var AIR_QUALITY_LOOK = readingLook("wind", "success");
103171
+ var LIGHT_SENSOR_LOOK = readingLook("sun", "warning");
103172
+ /** Carbon monoxide: calm is a shield, detected is the alarm. */
103173
+ var CO_LOOK = lookOf({
103174
+ icon: "shield-check",
100753
103175
  on: [
100754
103176
  "danger",
100755
103177
  "alert-wash",
@@ -100761,43 +103183,109 @@ var SMOKE_LOOK = lookOf({
100761
103183
  "alert-wash",
100762
103184
  "pulse"
100763
103185
  ],
103186
+ idle: [
103187
+ "success",
103188
+ "plain",
103189
+ "none"
103190
+ ],
103191
+ standby: MUTED,
103192
+ alert: look("triangle-alert", "danger", "alert-wash", "pulse")
103193
+ });
103194
+ /** Heating and cooling devices: the mode (see {@link HERO_MODE_LOOK}) picks the picture while on. */
103195
+ var THERMOSTAT_LOOK = lookOf({
103196
+ icon: "thermometer",
103197
+ on: [
103198
+ "primary",
103199
+ "plain",
103200
+ "none"
103201
+ ],
103202
+ off: MUTED,
103203
+ running: [
103204
+ "warning",
103205
+ "heat-rise",
103206
+ "rise"
103207
+ ],
103208
+ idle: INFO,
103209
+ standby: MUTED
103210
+ });
103211
+ var CLIMATE_LOOK = lookOf({
103212
+ icon: "snowflake",
103213
+ on: [
103214
+ "primary",
103215
+ "plain",
103216
+ "none"
103217
+ ],
103218
+ off: MUTED,
103219
+ running: [
103220
+ "primary",
103221
+ "plain",
103222
+ "none"
103223
+ ],
103224
+ idle: INFO,
103225
+ standby: MUTED
103226
+ });
103227
+ var WATER_HEATER_LOOK = lookOf({
103228
+ icon: "thermometer-sun",
103229
+ on: [
103230
+ "warning",
103231
+ "heat-rise",
103232
+ "rise"
103233
+ ],
103234
+ off: MUTED,
103235
+ running: [
103236
+ "warning",
103237
+ "heat-rise",
103238
+ "rise"
103239
+ ],
100764
103240
  idle: INFO,
100765
- standby: WARN,
100766
- alert: look("flame", "danger", "alert-wash", "pulse")
103241
+ standby: MUTED
100767
103242
  });
103243
+ /** What a climate device draws while it is on, by mode: warm air rises, cold falls, drops dry, the fan spins. */
103244
+ var HERO_MODE_LOOK = {
103245
+ heat: look("flame", "warning", "heat-rise", "rise"),
103246
+ cool: look("snowflake", "info", "cool-fall", "fall"),
103247
+ dry: look("droplets", "info", "water", "wave"),
103248
+ fan: look("fan", "primary", "plain", "spin"),
103249
+ auto: look("thermometer", "success", "glow", "glow"),
103250
+ playing: null,
103251
+ paused: null,
103252
+ open: null,
103253
+ closed: null
103254
+ };
103255
+ var MODE_LOOK_TYPES = [require_device_type.DeviceType.Climate, require_device_type.DeviceType.Thermostat];
100768
103256
  var HERO_LOOK_BY_TYPE = {
100769
- [require_device_type.DeviceType.Camera]: HERO_LOOK_DEFAULT,
103257
+ [require_device_type.DeviceType.Camera]: CAMERA_LOOK,
100770
103258
  [require_device_type.DeviceType.Hub]: HERO_LOOK_DEFAULT,
100771
- [require_device_type.DeviceType.Light]: HERO_LOOK_DEFAULT,
103259
+ [require_device_type.DeviceType.Light]: LIGHT_LOOK,
100772
103260
  [require_device_type.DeviceType.Siren]: HERO_LOOK_DEFAULT,
100773
103261
  [require_device_type.DeviceType.Switch]: SWITCH_LOOK,
100774
- [require_device_type.DeviceType.Sensor]: HERO_LOOK_DEFAULT,
100775
- [require_device_type.DeviceType.Thermostat]: HERO_LOOK_DEFAULT,
100776
- [require_device_type.DeviceType.Climate]: HERO_LOOK_DEFAULT,
100777
- [require_device_type.DeviceType.Button]: HERO_LOOK_DEFAULT,
100778
- [require_device_type.DeviceType.EventEmitter]: HERO_LOOK_DEFAULT,
100779
- [require_device_type.DeviceType.Update]: HERO_LOOK_DEFAULT,
103262
+ [require_device_type.DeviceType.Sensor]: READING_SENSOR_LOOK,
103263
+ [require_device_type.DeviceType.Thermostat]: THERMOSTAT_LOOK,
103264
+ [require_device_type.DeviceType.Climate]: CLIMATE_LOOK,
103265
+ [require_device_type.DeviceType.Button]: BUTTON_LOOK,
103266
+ [require_device_type.DeviceType.EventEmitter]: EVENT_EMITTER_LOOK,
103267
+ [require_device_type.DeviceType.Update]: UPDATE_LOOK,
100780
103268
  [require_device_type.DeviceType.Generic]: HERO_LOOK_DEFAULT,
100781
103269
  [require_device_type.DeviceType.Notifier]: HERO_LOOK_DEFAULT,
100782
- [require_device_type.DeviceType.Script]: HERO_LOOK_DEFAULT,
100783
- [require_device_type.DeviceType.Automation]: HERO_LOOK_DEFAULT,
100784
- [require_device_type.DeviceType.Lock]: HERO_LOOK_DEFAULT,
100785
- [require_device_type.DeviceType.Cover]: HERO_LOOK_DEFAULT,
100786
- [require_device_type.DeviceType.Valve]: HERO_LOOK_DEFAULT,
100787
- [require_device_type.DeviceType.Humidifier]: HERO_LOOK_DEFAULT,
100788
- [require_device_type.DeviceType.WaterHeater]: HERO_LOOK_DEFAULT,
100789
- [require_device_type.DeviceType.Fan]: HERO_LOOK_DEFAULT,
103270
+ [require_device_type.DeviceType.Script]: SCRIPT_LOOK,
103271
+ [require_device_type.DeviceType.Automation]: AUTOMATION_LOOK,
103272
+ [require_device_type.DeviceType.Lock]: LOCK_LOOK,
103273
+ [require_device_type.DeviceType.Cover]: COVER_LOOK,
103274
+ [require_device_type.DeviceType.Valve]: VALVE_LOOK,
103275
+ [require_device_type.DeviceType.Humidifier]: HUMIDIFIER_LOOK,
103276
+ [require_device_type.DeviceType.WaterHeater]: WATER_HEATER_LOOK,
103277
+ [require_device_type.DeviceType.Fan]: FAN_LOOK,
100790
103278
  [require_device_type.DeviceType.MediaPlayer]: MEDIA_PLAYER_LOOK,
100791
- [require_device_type.DeviceType.AlarmPanel]: HERO_LOOK_DEFAULT,
100792
- [require_device_type.DeviceType.Control]: HERO_LOOK_DEFAULT,
100793
- [require_device_type.DeviceType.Presence]: HERO_LOOK_DEFAULT,
100794
- [require_device_type.DeviceType.Weather]: HERO_LOOK_DEFAULT,
100795
- [require_device_type.DeviceType.Vacuum]: HERO_LOOK_DEFAULT,
100796
- [require_device_type.DeviceType.LawnMower]: HERO_LOOK_DEFAULT,
103279
+ [require_device_type.DeviceType.AlarmPanel]: ALARM_LOOK,
103280
+ [require_device_type.DeviceType.Control]: CONTROL_LOOK,
103281
+ [require_device_type.DeviceType.Presence]: PRESENCE_LOOK,
103282
+ [require_device_type.DeviceType.Weather]: WEATHER_LOOK,
103283
+ [require_device_type.DeviceType.Vacuum]: VACUUM_LOOK,
103284
+ [require_device_type.DeviceType.LawnMower]: MOWER_LOOK,
100797
103285
  [require_device_type.DeviceType.Container]: HERO_LOOK_DEFAULT,
100798
- [require_device_type.DeviceType.Image]: HERO_LOOK_DEFAULT,
100799
- [require_device_type.DeviceType.PetFeeder]: HERO_LOOK_DEFAULT,
100800
- [require_device_type.DeviceType.PetFountain]: HERO_LOOK_DEFAULT,
103286
+ [require_device_type.DeviceType.Image]: IMAGE_LOOK,
103287
+ [require_device_type.DeviceType.PetFeeder]: FEEDER_LOOK,
103288
+ [require_device_type.DeviceType.PetFountain]: FOUNTAIN_LOOK,
100801
103289
  [require_device_type.DeviceType.Dishwasher]: DISHWASHER_LOOK,
100802
103290
  [require_device_type.DeviceType.Washer]: WASHER_LOOK,
100803
103291
  [require_device_type.DeviceType.Heater]: HEATER_LOOK,
@@ -100809,12 +103297,12 @@ var HERO_LOOK_BY_ROLE = {
100809
103297
  [require_device_type.DeviceRole.Siren]: "inherit",
100810
103298
  [require_device_type.DeviceRole.Floodlight]: "inherit",
100811
103299
  [require_device_type.DeviceRole.Spotlight]: "inherit",
100812
- [require_device_type.DeviceRole.PirSensor]: "inherit",
103300
+ [require_device_type.DeviceRole.PirSensor]: MOTION_LOOK,
100813
103301
  [require_device_type.DeviceRole.Chime]: "inherit",
100814
103302
  [require_device_type.DeviceRole.Autotrack]: "inherit",
100815
103303
  [require_device_type.DeviceRole.Nightvision]: "inherit",
100816
103304
  [require_device_type.DeviceRole.PrivacyMask]: "inherit",
100817
- [require_device_type.DeviceRole.Doorbell]: "inherit",
103305
+ [require_device_type.DeviceRole.Doorbell]: DOORBELL_LOOK,
100818
103306
  [require_device_type.DeviceRole.CoverBlind]: "inherit",
100819
103307
  [require_device_type.DeviceRole.CoverShutter]: "inherit",
100820
103308
  [require_device_type.DeviceRole.CoverAwning]: "inherit",
@@ -100825,21 +103313,21 @@ var HERO_LOOK_BY_ROLE = {
100825
103313
  [require_device_type.DeviceRole.CoverWindow]: "inherit",
100826
103314
  [require_device_type.DeviceRole.BinaryHelper]: "inherit",
100827
103315
  [require_device_type.DeviceRole.Outlet]: "inherit",
100828
- [require_device_type.DeviceRole.MotionSensor]: "inherit",
103316
+ [require_device_type.DeviceRole.MotionSensor]: MOTION_LOOK,
100829
103317
  [require_device_type.DeviceRole.ContactSensor]: "inherit",
100830
103318
  [require_device_type.DeviceRole.LeakSensor]: LEAK_LOOK,
100831
103319
  [require_device_type.DeviceRole.SmokeSensor]: SMOKE_LOOK,
100832
- [require_device_type.DeviceRole.COSensor]: "inherit",
100833
- [require_device_type.DeviceRole.GasSensor]: "inherit",
100834
- [require_device_type.DeviceRole.TamperSensor]: "inherit",
100835
- [require_device_type.DeviceRole.VibrationSensor]: "inherit",
103320
+ [require_device_type.DeviceRole.COSensor]: CO_LOOK,
103321
+ [require_device_type.DeviceRole.GasSensor]: GAS_LOOK,
103322
+ [require_device_type.DeviceRole.TamperSensor]: TAMPER_LOOK,
103323
+ [require_device_type.DeviceRole.VibrationSensor]: VIBRATION_LOOK,
100836
103324
  [require_device_type.DeviceRole.ConnectivitySensor]: "inherit",
100837
103325
  [require_device_type.DeviceRole.SoundSensor]: "inherit",
100838
103326
  [require_device_type.DeviceRole.BinarySensor]: "inherit",
100839
- [require_device_type.DeviceRole.TemperatureSensor]: "inherit",
100840
- [require_device_type.DeviceRole.HumiditySensor]: "inherit",
100841
- [require_device_type.DeviceRole.AmbientLightSensor]: "inherit",
100842
- [require_device_type.DeviceRole.PressureSensor]: "inherit",
103327
+ [require_device_type.DeviceRole.TemperatureSensor]: TEMPERATURE_LOOK,
103328
+ [require_device_type.DeviceRole.HumiditySensor]: HUMIDITY_LOOK,
103329
+ [require_device_type.DeviceRole.AmbientLightSensor]: LIGHT_SENSOR_LOOK,
103330
+ [require_device_type.DeviceRole.PressureSensor]: READING_SENSOR_LOOK,
100843
103331
  [require_device_type.DeviceRole.WindSensor]: "inherit",
100844
103332
  [require_device_type.DeviceRole.RainSensor]: "inherit",
100845
103333
  [require_device_type.DeviceRole.UvSensor]: "inherit",
@@ -100849,7 +103337,7 @@ var HERO_LOOK_BY_ROLE = {
100849
103337
  [require_device_type.DeviceRole.EnergySensor]: "inherit",
100850
103338
  [require_device_type.DeviceRole.VoltageSensor]: "inherit",
100851
103339
  [require_device_type.DeviceRole.CurrentSensor]: "inherit",
100852
- [require_device_type.DeviceRole.AirQualitySensor]: "inherit",
103340
+ [require_device_type.DeviceRole.AirQualitySensor]: AIR_QUALITY_LOOK,
100853
103341
  [require_device_type.DeviceRole.BatterySensor]: "inherit",
100854
103342
  [require_device_type.DeviceRole.NumericSensor]: "inherit",
100855
103343
  [require_device_type.DeviceRole.EnumSensor]: "inherit",
@@ -100871,10 +103359,17 @@ function isDeviceType(type) {
100871
103359
  function isDeviceRole(role) {
100872
103360
  return Object.values(require_device_type.DeviceRole).includes(role);
100873
103361
  }
100874
- /** The look of a (role, type) pair, for a state. Role beats type beats the generic default. */
100875
- function resolveHeroLook(role, type, state) {
103362
+ /**
103363
+ * The look of a (role, type) pair, for a state. Role beats type beats the generic default.
103364
+ * A climate device that is on draws its MODE (`mode` is the scene's); a role never loses to it.
103365
+ */
103366
+ function resolveHeroLook(role, type, state, mode = null) {
100876
103367
  const byRole = role !== null && isDeviceRole(role) ? HERO_LOOK_BY_ROLE[role] : void 0;
100877
103368
  if (byRole !== void 0 && byRole !== "inherit") return byRole[state];
103369
+ if (mode !== null && (state === "on" || state === "running") && MODE_LOOK_TYPES.includes(type)) {
103370
+ const byMode = HERO_MODE_LOOK[mode];
103371
+ if (byMode !== null) return byMode;
103372
+ }
100878
103373
  return ((isDeviceType(type) ? HERO_LOOK_BY_TYPE[type] : void 0) ?? HERO_LOOK_DEFAULT)[state];
100879
103374
  }
100880
103375
  /** Every look the model declares, for the exhaustiveness guard and its spec. */
@@ -100888,7 +103383,11 @@ function allHeroLooks() {
100888
103383
  //#endregion
100889
103384
  //#region src/device/hero/own-power.ts
100890
103385
  /** The media player's offer outranks a bound switch: the player's own state is the device's. */
100891
- var OWN_POWER_SOURCE_ORDER = ["media-player", "switch"];
103386
+ var OWN_POWER_SOURCE_ORDER = [
103387
+ "media-player",
103388
+ "climate-control",
103389
+ "switch"
103390
+ ];
100892
103391
  function resolveOwnPower(offers) {
100893
103392
  for (const source of OWN_POWER_SOURCE_ORDER) {
100894
103393
  const offer = offers.find((o) => o.source === source);
@@ -100912,9 +103411,41 @@ function resolveOwnPower(offers) {
100912
103411
  var STATE_SOURCE_ORDER = [
100913
103412
  "media-player",
100914
103413
  "dishwasher",
103414
+ "lock-control",
103415
+ "alarm-panel",
103416
+ "vacuum-control",
103417
+ "lawn-mower-control",
103418
+ "fan-control",
103419
+ "pet-feeder",
103420
+ "pet-fountain",
103421
+ "automation-control",
103422
+ "script-runner",
103423
+ "event-emitter",
100915
103424
  "running-state",
100916
103425
  "switch",
100917
- "contact"
103426
+ "contact",
103427
+ "group-active",
103428
+ "cover",
103429
+ "valve",
103430
+ "humidifier",
103431
+ "brightness",
103432
+ "smoke",
103433
+ "flood",
103434
+ "gas",
103435
+ "tamper",
103436
+ "vibration",
103437
+ "doorbell",
103438
+ "motion",
103439
+ "presence",
103440
+ "update",
103441
+ "weather",
103442
+ "image",
103443
+ "control",
103444
+ "meter",
103445
+ "binary",
103446
+ "button",
103447
+ "climate-control",
103448
+ "sensor"
100918
103449
  ];
100919
103450
  var STATE_TEXT = {
100920
103451
  on: require_sleep.t("On", "Acceso"),
@@ -100927,6 +103458,10 @@ var STATE_TEXT = {
100927
103458
  unknown: require_sleep.t("Unknown", "Sconosciuto")
100928
103459
  };
100929
103460
  function pickReading(readings) {
103461
+ for (const source of STATE_SOURCE_ORDER) {
103462
+ const alarm = readings.find((r) => r.source === source && r.state === "alert");
103463
+ if (alarm !== void 0) return alarm;
103464
+ }
100930
103465
  for (const source of STATE_SOURCE_ORDER) {
100931
103466
  const found = readings.find((r) => r.source === source && r.state !== "unknown");
100932
103467
  if (found !== void 0) return found;
@@ -100941,21 +103476,25 @@ function runningOf(input) {
100941
103476
  function stateOf(input, readings) {
100942
103477
  if (!input.device.online) return {
100943
103478
  state: "offline",
100944
- assumed: false
103479
+ assumed: false,
103480
+ title: STATE_TEXT.offline
100945
103481
  };
100946
103482
  const picked = pickReading(readings);
100947
103483
  if (picked === null) return {
100948
103484
  state: "unknown",
100949
- assumed: false
103485
+ assumed: false,
103486
+ title: STATE_TEXT.unknown
100950
103487
  };
100951
103488
  const switchOff = readings.some((r) => r.source === "switch" && r.state === "off");
100952
103489
  if (picked.source === "running-state" && picked.state === "idle" && switchOff) return {
100953
103490
  state: "off",
100954
- assumed: false
103491
+ assumed: false,
103492
+ title: STATE_TEXT.off
100955
103493
  };
100956
103494
  return {
100957
103495
  state: picked.state,
100958
- assumed: picked.assumed
103496
+ assumed: picked.assumed,
103497
+ title: picked.title ?? STATE_TEXT[picked.state]
100959
103498
  };
100960
103499
  }
100961
103500
  function provenanceOf(cap, fragment) {
@@ -101004,15 +103543,17 @@ function buildHeroModel(input) {
101004
103543
  features: input.features,
101005
103544
  now: input.now,
101006
103545
  running: runningOf(input),
101007
- remoteCommands: input.remoteCommands
103546
+ remoteCommands: input.remoteCommands,
103547
+ caps: input.caps
101008
103548
  };
101009
103549
  const contributed = HERO_CAP_CONTRIBUTIONS.filter((c) => input.caps.includes(c.cap)).map((c) => ({
101010
103550
  cap: c.cap,
101011
103551
  fragment: c.contribute(input.slices[c.cap], ctx)
101012
103552
  }));
101013
103553
  const fragments = contributed.map((c) => c.fragment);
101014
- const { state, assumed } = stateOf(input, fragments.flatMap((f) => f.reading === void 0 ? [] : [f.reading]));
101015
- const look = resolveHeroLook(device.role, device.type, state);
103554
+ const { state, assumed, title } = stateOf(input, fragments.flatMap((f) => f.reading === void 0 ? [] : [f.reading]));
103555
+ const scene = sceneOf(device.role, device.type, fragments);
103556
+ const look = resolveHeroLook(device.role, device.type, state, scene.mode);
101016
103557
  const artworkUrl = fragments.find((f) => f.artworkUrl !== void 0)?.artworkUrl;
101017
103558
  const background = artworkUrl === void 0 || state === "offline" ? {
101018
103559
  kind: "state",
@@ -101036,7 +103577,8 @@ function buildHeroModel(input) {
101036
103577
  const powerSupply = fragments.find((f) => f.powerSupply !== void 0)?.powerSupply ?? null;
101037
103578
  const remote = fragments.find((f) => f.remote !== void 0)?.remote ?? null;
101038
103579
  const badges = fragments.flatMap((f) => f.badges ?? []);
101039
- const facts = fragments.flatMap((f) => f.facts ?? []);
103580
+ const headline = state === "offline" || state === "unknown" ? void 0 : fragments.find((f) => f.title !== void 0)?.title;
103581
+ const facts = fragments.flatMap((f) => f.facts ?? []).filter((f) => headline === void 0 || f.text.en !== headline.en);
101040
103582
  const sideTiles = {
101041
103583
  left: tilesOf(fragments, "left"),
101042
103584
  right: tilesOf(fragments, "right")
@@ -101058,10 +103600,10 @@ function buildHeroModel(input) {
101058
103600
  stateAssumed: assumed,
101059
103601
  look,
101060
103602
  background,
101061
- scene: sceneOf(device.role, device.type, fragments),
103603
+ scene,
101062
103604
  facts,
101063
103605
  sideTiles,
101064
- title: STATE_TEXT[state],
103606
+ title: headline ?? title,
101065
103607
  badges,
101066
103608
  remote,
101067
103609
  consumables: fragments.find((f) => f.consumables !== void 0)?.consumables ?? null,
@@ -101089,28 +103631,28 @@ var LATER_PHASE = "a hero fact, contributed when its type migrates to the templa
101089
103631
  var NOT_A_HERO_FACT = "plumbing or configuration; reachable from the device page tabs";
101090
103632
  var HERO_CAP_COVERAGE = {
101091
103633
  accessories: { none: NOT_A_HERO_FACT },
101092
- "air-quality-sensor": { none: LATER_PHASE },
101093
- "alarm-panel": { none: LATER_PHASE },
101094
- "ambient-light-sensor": { none: LATER_PHASE },
103634
+ "air-quality-sensor": "contributes",
103635
+ "alarm-panel": "contributes",
103636
+ "ambient-light-sensor": "contributes",
101095
103637
  "audio-analysis": { none: NOT_A_HERO_FACT },
101096
103638
  "audio-metrics": { none: NOT_A_HERO_FACT },
101097
- "automation-control": { none: LATER_PHASE },
103639
+ "automation-control": "contributes",
101098
103640
  battery: "contributes",
101099
- binary: { none: LATER_PHASE },
101100
- brightness: { none: LATER_PHASE },
101101
- button: { none: LATER_PHASE },
103641
+ binary: "contributes",
103642
+ brightness: "contributes",
103643
+ button: "contributes",
101102
103644
  "camera-credentials": { none: NOT_A_HERO_FACT },
101103
103645
  "camera-grid-layout": { none: NOT_A_HERO_FACT },
101104
103646
  "camera-pipeline-config": { none: NOT_A_HERO_FACT },
101105
103647
  "camera-streams": { none: NOT_A_HERO_FACT },
101106
- "carbon-monoxide": { none: LATER_PHASE },
101107
- "climate-control": { none: LATER_PHASE },
101108
- color: { none: LATER_PHASE },
103648
+ "carbon-monoxide": "contributes",
103649
+ "climate-control": "contributes",
103650
+ color: "contributes",
101109
103651
  connectivity: { none: NOT_A_HERO_FACT },
101110
103652
  consumables: "contributes",
101111
103653
  contact: "contributes",
101112
- control: { none: LATER_PHASE },
101113
- cover: { none: LATER_PHASE },
103654
+ control: "contributes",
103655
+ cover: "contributes",
101114
103656
  "day-night": { none: NOT_A_HERO_FACT },
101115
103657
  "detection-pipeline": { none: NOT_A_HERO_FACT },
101116
103658
  "device-admin-link": { none: NOT_A_HERO_FACT },
@@ -101121,29 +103663,29 @@ var HERO_CAP_COVERAGE = {
101121
103663
  "device-transitions": { none: "audit log of what changed and who asked; reachable from the device page history" },
101122
103664
  "device-status": { none: NOT_A_HERO_FACT },
101123
103665
  dishwasher: "contributes",
101124
- "do-not-disturb": { none: LATER_PHASE },
101125
- doorbell: { none: LATER_PHASE },
101126
- "enum-sensor": { none: LATER_PHASE },
101127
- "event-emitter": { none: LATER_PHASE },
101128
- "fan-control": { none: LATER_PHASE },
103666
+ "do-not-disturb": "contributes",
103667
+ doorbell: "contributes",
103668
+ "enum-sensor": "contributes",
103669
+ "event-emitter": "contributes",
103670
+ "fan-control": "contributes",
101129
103671
  "feature-probe": { none: NOT_A_HERO_FACT },
101130
- flood: { none: LATER_PHASE },
101131
- gas: { none: LATER_PHASE },
101132
- "group-active": { none: LATER_PHASE },
101133
- "group-commands": { none: LATER_PHASE },
101134
- "group-status": { none: LATER_PHASE },
101135
- "heating-valve": { none: LATER_PHASE },
101136
- humidifier: { none: LATER_PHASE },
101137
- "humidity-sensor": { none: LATER_PHASE },
101138
- image: { none: LATER_PHASE },
103672
+ flood: "contributes",
103673
+ gas: "contributes",
103674
+ "group-active": "contributes",
103675
+ "group-commands": "contributes",
103676
+ "group-status": "contributes",
103677
+ "heating-valve": "contributes",
103678
+ humidifier: "contributes",
103679
+ "humidity-sensor": "contributes",
103680
+ image: "contributes",
101139
103681
  "image-settings": { none: NOT_A_HERO_FACT },
101140
103682
  intercom: { none: NOT_A_HERO_FACT },
101141
- "ir-transmitter": { none: LATER_PHASE },
101142
- "lawn-mower-control": { none: LATER_PHASE },
101143
- "lock-control": { none: LATER_PHASE },
103683
+ "ir-transmitter": { none: "a transport on a board: it sends raw timings for a remote and reports no state (D957); the appliance it drives shows its own state and the remote button" },
103684
+ "lawn-mower-control": "contributes",
103685
+ "lock-control": "contributes",
101144
103686
  "media-player": "contributes",
101145
- meter: { none: LATER_PHASE },
101146
- motion: { none: LATER_PHASE },
103687
+ meter: "contributes",
103688
+ motion: "contributes",
101147
103689
  "motion-detection": { none: NOT_A_HERO_FACT },
101148
103690
  "motion-trigger": "contributes",
101149
103691
  "motion-zones": { none: NOT_A_HERO_FACT },
@@ -101151,19 +103693,19 @@ var HERO_CAP_COVERAGE = {
101151
103693
  navigation: { none: NOT_A_HERO_FACT },
101152
103694
  "network-link": "contributes",
101153
103695
  notifier: { none: NOT_A_HERO_FACT },
101154
- "numeric-sensor": { none: LATER_PHASE },
103696
+ "numeric-sensor": "contributes",
101155
103697
  osd: { none: NOT_A_HERO_FACT },
101156
- "pet-feeder": { none: LATER_PHASE },
101157
- "pet-fountain": { none: LATER_PHASE },
103698
+ "pet-feeder": "contributes",
103699
+ "pet-fountain": "contributes",
101158
103700
  "pipeline-analytics": { none: NOT_A_HERO_FACT },
101159
103701
  "power-meter": "contributes",
101160
103702
  "power-source": "contributes",
101161
- presence: { none: LATER_PHASE },
101162
- "pressure-sensor": { none: LATER_PHASE },
103703
+ presence: "contributes",
103704
+ "pressure-sensor": "contributes",
101163
103705
  "privacy-mask": { none: NOT_A_HERO_FACT },
101164
103706
  ptz: { none: NOT_A_HERO_FACT },
101165
103707
  "ptz-autotrack": { none: NOT_A_HERO_FACT },
101166
- "pump-cycle": { none: LATER_PHASE },
103708
+ "pump-cycle": "contributes",
101167
103709
  reboot: { none: NOT_A_HERO_FACT },
101168
103710
  recording: { none: NOT_A_HERO_FACT },
101169
103711
  "recording-onboard": { none: NOT_A_HERO_FACT },
@@ -101171,23 +103713,23 @@ var HERO_CAP_COVERAGE = {
101171
103713
  remote: "contributes",
101172
103714
  "running-state": "contributes",
101173
103715
  "scene-monitor": { none: NOT_A_HERO_FACT },
101174
- "script-runner": { none: LATER_PHASE },
101175
- smoke: { none: LATER_PHASE },
103716
+ "script-runner": "contributes",
103717
+ smoke: "contributes",
101176
103718
  snapshot: { none: NOT_A_HERO_FACT },
101177
103719
  "stream-catalog": { none: NOT_A_HERO_FACT },
101178
103720
  "stream-params": { none: NOT_A_HERO_FACT },
101179
103721
  "stream-signals": { none: NOT_A_HERO_FACT },
101180
103722
  switch: "contributes",
101181
- tamper: { none: LATER_PHASE },
101182
- "temperature-sensor": { none: LATER_PHASE },
103723
+ tamper: "contributes",
103724
+ "temperature-sensor": "contributes",
101183
103725
  "timed-run": "contributes",
101184
- update: { none: LATER_PHASE },
101185
- "vacuum-control": { none: LATER_PHASE },
101186
- valve: { none: LATER_PHASE },
101187
- vibration: { none: LATER_PHASE },
103726
+ update: "contributes",
103727
+ "vacuum-control": "contributes",
103728
+ valve: "contributes",
103729
+ vibration: "contributes",
101188
103730
  videoclips: { none: NOT_A_HERO_FACT },
101189
- "water-heater": { none: LATER_PHASE },
101190
- weather: { none: LATER_PHASE },
103731
+ "water-heater": "contributes",
103732
+ weather: "contributes",
101191
103733
  "webrtc-session": { none: NOT_A_HERO_FACT },
101192
103734
  "zone-analytics": { none: NOT_A_HERO_FACT },
101193
103735
  "zone-rules": { none: NOT_A_HERO_FACT },
@@ -117118,7 +119660,7 @@ function getCapsByProviderKind(kind) {
117118
119660
  //#region src/generated/runtime-state-durability.ts
117119
119661
  /**
117120
119662
  * Per-cap runtime-state policy, projected from every `*.cap.ts` that declares
117121
- * `runtimeState`. 81 caps: 39 `restored`, 42 `session`.
119663
+ * `runtimeState`. 81 caps: 41 `restored`, 40 `session`.
117122
119664
  *
117123
119665
  * A cap absent from this map has no runtime-state slice at all. A cap PRESENT
117124
119666
  * with `durability: 'session'` has one and has decided not to keep it.
@@ -117165,8 +119707,9 @@ var RUNTIME_STATE_POLICY = {
117165
119707
  volatileFields: ["lastChangedAt"]
117166
119708
  },
117167
119709
  "climate-control": {
117168
- durability: "session",
117169
- volatileFields: []
119710
+ durability: "restored",
119711
+ volatileFields: [],
119712
+ restoredFields: ["lastActiveMode"]
117170
119713
  },
117171
119714
  "color": {
117172
119715
  durability: "session",
@@ -117218,7 +119761,7 @@ var RUNTIME_STATE_POLICY = {
117218
119761
  },
117219
119762
  "enum-sensor": {
117220
119763
  durability: "restored",
117221
- volatileFields: ["lastFetchedAt"]
119764
+ volatileFields: ["lastFetchedAt", "timestamp"]
117222
119765
  },
117223
119766
  "event-emitter": {
117224
119767
  durability: "session",
@@ -117429,8 +119972,9 @@ var RUNTIME_STATE_POLICY = {
117429
119972
  volatileFields: ["lastChangedAt"]
117430
119973
  },
117431
119974
  "water-heater": {
117432
- durability: "session",
117433
- volatileFields: []
119975
+ durability: "restored",
119976
+ volatileFields: [],
119977
+ restoredFields: ["lastActiveMode"]
117434
119978
  },
117435
119979
  "weather": {
117436
119980
  durability: "session",
@@ -117476,6 +120020,7 @@ var RESTORED_CAP_NAMES = [
117476
120020
  "battery",
117477
120021
  "binary",
117478
120022
  "carbon-monoxide",
120023
+ "climate-control",
117479
120024
  "connectivity",
117480
120025
  "consumables",
117481
120026
  "contact",
@@ -117507,6 +120052,7 @@ var RESTORED_CAP_NAMES = [
117507
120052
  "tamper",
117508
120053
  "temperature-sensor",
117509
120054
  "vibration",
120055
+ "water-heater",
117510
120056
  "zone-rules",
117511
120057
  "zones"
117512
120058
  ];
@@ -133392,6 +135938,7 @@ exports.emitDownForOwnedCaps = require_sleep.emitDownForOwnedCaps;
133392
135938
  exports.emitReadiness = require_sleep.emitReadiness;
133393
135939
  exports.emitsCollectionSelector = emitsCollectionSelector;
133394
135940
  exports.encodeCardsToComposition = encodeCardsToComposition;
135941
+ exports.encodeFlipperParsed = encodeFlipperParsed;
133395
135942
  exports.encodeProfileFromStreamShape = encodeProfileFromStreamShape;
133396
135943
  exports.encodeSamsung = encodeSamsung;
133397
135944
  exports.encodeVectorBase64 = encodeVectorBase64;
@@ -133467,6 +136014,9 @@ exports.findTimezone = findTimezone;
133467
136014
  exports.findVocabAction = require_sleep.findVocabAction;
133468
136015
  exports.flattenNestedRecords = flattenNestedRecords;
133469
136016
  exports.flattenPortsOver = flattenPortsOver;
136017
+ exports.flipperIrDraft = flipperIrDraft;
136018
+ exports.flipperIrTable = flipperIrTable;
136019
+ exports.flipperRole = flipperRole;
133470
136020
  exports.floodCapability = floodCapability;
133471
136021
  exports.foldSnapshotByFunction = foldSnapshotByFunction;
133472
136022
  exports.followSwitchRunningFeature = followSwitchRunningFeature;
@@ -133847,6 +136397,7 @@ exports.parseColorInput = parseColorInput;
133847
136397
  exports.parseCredentialScopes = parseCredentialScopes;
133848
136398
  exports.parseDeviceEnrollmentLink = parseDeviceEnrollmentLink;
133849
136399
  exports.parseExpression = require_composition.parseExpression;
136400
+ exports.parseFlipperIr = parseFlipperIr;
133850
136401
  exports.parseJsonArray = require_sleep.parseJsonArray;
133851
136402
  exports.parseJsonObject = require_sleep.parseJsonObject;
133852
136403
  exports.parseJsonUnknown = require_sleep.parseJsonUnknown;