@avantics/node-red-home-automation 5.0.0 → 6.1.0

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 (91) hide show
  1. package/README.md +413 -77
  2. package/contract-examples/room-lighting.mjs +39 -27
  3. package/dist/lib/activity-lighting-controller.d.ts +7 -2
  4. package/dist/lib/activity-lighting-controller.js +75 -16
  5. package/dist/lib/avr-controller.d.ts +2 -2
  6. package/dist/lib/avr-controller.js +21 -26
  7. package/dist/lib/circadian-policy.d.ts +47 -0
  8. package/dist/lib/circadian-policy.js +111 -0
  9. package/dist/lib/circadian-publishing.d.ts +33 -0
  10. package/dist/lib/circadian-publishing.js +154 -0
  11. package/dist/lib/circadian-schedule.d.ts +4 -0
  12. package/dist/lib/circadian-schedule.js +12 -0
  13. package/dist/lib/command-echo.d.ts +8 -1
  14. package/dist/lib/command-echo.js +37 -6
  15. package/dist/lib/cover-controller.js +4 -0
  16. package/dist/lib/denon-protocol.js +3 -2
  17. package/dist/lib/enable-input.d.ts +3 -0
  18. package/dist/lib/enable-input.js +18 -0
  19. package/dist/lib/house-schedule.js +2 -2
  20. package/dist/lib/light-contract.d.ts +53 -0
  21. package/dist/lib/light-contract.js +11 -0
  22. package/dist/lib/motion-policy.d.ts +0 -1
  23. package/dist/lib/motion-policy.js +9 -8
  24. package/dist/lib/motion-publishing.js +2 -1
  25. package/dist/lib/mqtt-message.d.ts +6 -0
  26. package/dist/lib/mqtt-message.js +21 -0
  27. package/dist/lib/room-controller.d.ts +41 -27
  28. package/dist/lib/room-controller.js +422 -213
  29. package/dist/lib/room-holds.d.ts +34 -0
  30. package/dist/lib/room-holds.js +66 -0
  31. package/dist/lib/room-lighting-discovery.d.ts +0 -14
  32. package/dist/lib/room-lighting-discovery.js +19 -125
  33. package/dist/lib/room-publishing.d.ts +7 -12
  34. package/dist/lib/room-publishing.js +65 -125
  35. package/dist/lib/shelly-cover.d.ts +2 -4
  36. package/dist/lib/shelly-cover.js +30 -70
  37. package/dist/lib/shelly-gen2.d.ts +25 -0
  38. package/dist/lib/shelly-gen2.js +58 -0
  39. package/dist/lib/shelly-switch.d.ts +95 -0
  40. package/dist/lib/shelly-switch.js +237 -0
  41. package/dist/lib/theatre-state-contract.js +12 -4
  42. package/dist/lib/z2m-cover.d.ts +49 -0
  43. package/dist/lib/z2m-cover.js +120 -0
  44. package/dist/lib/z2m-light-adapter.d.ts +62 -0
  45. package/dist/lib/z2m-light-adapter.js +195 -0
  46. package/dist/lib/z2m-light.d.ts +2 -2
  47. package/dist/lib/z2m-light.js +11 -14
  48. package/dist/nodes/activity-lighting-controller.html +15 -6
  49. package/dist/nodes/activity-lighting-controller.js +21 -0
  50. package/dist/nodes/adapter.d.ts +5 -1
  51. package/dist/nodes/adapter.js +35 -2
  52. package/dist/nodes/avr-controller.html +20 -18
  53. package/dist/nodes/avr-controller.js +5 -5
  54. package/dist/nodes/circadian-policy.d.ts +3 -0
  55. package/dist/nodes/circadian-policy.html +145 -0
  56. package/dist/nodes/circadian-policy.js +162 -0
  57. package/dist/nodes/cover-controller.html +9 -3
  58. package/dist/nodes/cover-controller.js +1 -1
  59. package/dist/nodes/display-mode-controller.html +14 -17
  60. package/dist/nodes/display-mode-controller.js +4 -1
  61. package/dist/nodes/house-schedule-mqtt.html +5 -0
  62. package/dist/nodes/house-schedule-mqtt.js +1 -1
  63. package/dist/nodes/house-schedule.html +3 -3
  64. package/dist/nodes/motion-policy.html +10 -2
  65. package/dist/nodes/motion-policy.js +4 -1
  66. package/dist/nodes/occupancy-fusion.html +5 -0
  67. package/dist/nodes/occupancy-fusion.js +1 -1
  68. package/dist/nodes/refused-enable.d.ts +7 -0
  69. package/dist/nodes/refused-enable.js +24 -0
  70. package/dist/nodes/room-controller.html +232 -85
  71. package/dist/nodes/room-controller.js +71 -97
  72. package/dist/nodes/shelly-switch.d.ts +3 -0
  73. package/dist/nodes/shelly-switch.html +87 -0
  74. package/dist/nodes/shelly-switch.js +48 -0
  75. package/dist/nodes/theatre-state-contract.html +9 -3
  76. package/dist/nodes/theatre-state-contract.js +1 -1
  77. package/dist/nodes/z2m-cover.d.ts +3 -0
  78. package/dist/nodes/z2m-cover.html +68 -0
  79. package/dist/nodes/z2m-cover.js +41 -0
  80. package/dist/nodes/z2m-light.d.ts +3 -0
  81. package/dist/nodes/z2m-light.html +76 -0
  82. package/dist/nodes/z2m-light.js +51 -0
  83. package/examples/Cover control.json +28 -71
  84. package/examples/Home theatre activity.json +53 -19
  85. package/examples/House schedule.json +106 -24
  86. package/examples/Room lighting.json +57 -25
  87. package/examples/Shelly cover.json +5 -16
  88. package/examples/Shelly switch.json +197 -0
  89. package/package.json +12 -4
  90. package/dist/lib/room-schedule.d.ts +0 -8
  91. package/dist/lib/room-schedule.js +0 -41
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.circadianRetainedTopics = exports.circadianStoppingOutputs = exports.circadianAvailabilityTopic = exports.circadianTimeTopic = exports.circadianSwitchTopic = void 0;
4
+ exports.circadianDiscovery = circadianDiscovery;
5
+ exports.roomCircadianDiscoveryTopics = roomCircadianDiscoveryTopics;
6
+ exports.circadianStateTopics = circadianStateTopics;
7
+ exports.circadianStateOutputs = circadianStateOutputs;
8
+ exports.circadianStartingOutputs = circadianStartingOutputs;
9
+ exports.circadianInbound = circadianInbound;
10
+ const ha_discovery_1 = require("./ha-discovery");
11
+ const publishing_node_1 = require("./publishing-node");
12
+ const topic_names_1 = require("./topic-names");
13
+ const circadianSwitchTopic = (area, which, end) => (0, topic_names_1.homeTopic)(area, which, end);
14
+ exports.circadianSwitchTopic = circadianSwitchTopic;
15
+ const circadianTimeTopic = (area, which, end) => (0, topic_names_1.homeTopic)(area, which, end);
16
+ exports.circadianTimeTopic = circadianTimeTopic;
17
+ const circadianAvailabilityTopic = (area) => (0, topic_names_1.homeTopic)(area, "circadian", "availability");
18
+ exports.circadianAvailabilityTopic = circadianAvailabilityTopic;
19
+ const DEVICE = { kind: "circadian", label: "Circadian Lighting", model: "Circadian lighting policy" };
20
+ const TIMES = [
21
+ ["wake-time", "wake_time", "Wake time", "mdi:weather-sunset-up"],
22
+ ["bed-time", "bed_time", "Bed time", "mdi:weather-night"]
23
+ ];
24
+ function circadianDiscovery(config) {
25
+ const availability = (0, exports.circadianAvailabilityTopic)(config.area);
26
+ const toggle = (which, id, name, icon) => (0, publishing_node_1.discoveryEntry)(config, DEVICE, availability, {
27
+ component: "switch", id, name, fields: {
28
+ icon,
29
+ command_topic: (0, exports.circadianSwitchTopic)(config.area, which, "set"),
30
+ state_topic: (0, exports.circadianSwitchTopic)(config.area, which, "state"),
31
+ payload_on: "ON",
32
+ payload_off: "OFF",
33
+ optimistic: false
34
+ }
35
+ });
36
+ return [
37
+ toggle("circadian", "circadian_lighting", "Circadian lighting", "mdi:clock-time-seven-outline"),
38
+ toggle("sleep", "sleep", "Sleep", "mdi:sleep"),
39
+ ...(config.timesFrom === "house" ? [] : TIMES.map(([which, id, name, icon]) => (0, publishing_node_1.discoveryEntry)(config, DEVICE, availability, {
40
+ component: "time", id, name, fields: {
41
+ icon,
42
+ command_topic: (0, exports.circadianTimeTopic)(config.area, which, "set"),
43
+ state_topic: (0, exports.circadianTimeTopic)(config.area, which, "state"),
44
+ entity_category: "config"
45
+ }
46
+ })))
47
+ ];
48
+ }
49
+ // The discovery topics of the circadian, sleep, wake and bed entities a room
50
+ // controller published under the area scheme before 6.0, which the policy
51
+ // clears before announcing its own, so Home Assistant can give the new
52
+ // entities the old entity IDs. (A room named after its node ID clears its
53
+ // own, at its start.)
54
+ function roomCircadianDiscoveryTopics(config, idScheme = "area", nodeId) {
55
+ const owner = { area: config.area, discoveryPrefix: config.discoveryPrefix, idScheme, nodeId };
56
+ return [
57
+ (0, ha_discovery_1.discoveryEntity)(owner, "switch", "circadian_lighting").topic,
58
+ (0, ha_discovery_1.discoveryEntity)(owner, "switch", "sleep").topic,
59
+ (0, ha_discovery_1.discoveryEntity)(owner, "time", "wake_time").topic,
60
+ (0, ha_discovery_1.discoveryEntity)(owner, "time", "bed_time").topic
61
+ ];
62
+ }
63
+ // The state topics the policy publishes, which a room controller with the
64
+ // same area must never clear.
65
+ function circadianStateTopics(area) {
66
+ return [
67
+ (0, exports.circadianSwitchTopic)(area, "circadian", "state"),
68
+ (0, exports.circadianSwitchTopic)(area, "sleep", "state"),
69
+ (0, exports.circadianTimeTopic)(area, "wake-time", "state"),
70
+ (0, exports.circadianTimeTopic)(area, "bed-time", "state")
71
+ ];
72
+ }
73
+ // "HH:MM:SS", as Home Assistant's time entity reads it.
74
+ function timeState(time) {
75
+ return time + ":00";
76
+ }
77
+ function circadianStateOutputs(config, state) {
78
+ if (!(0, publishing_node_1.publishesState)(config))
79
+ return [];
80
+ const outputs = [
81
+ (0, publishing_node_1.retainedText)((0, exports.circadianSwitchTopic)(config.area, "circadian", "state"), state.enabled ? "ON" : "OFF"),
82
+ (0, publishing_node_1.retainedText)((0, exports.circadianSwitchTopic)(config.area, "sleep", "state"), state.sleeping ? "ON" : "OFF")
83
+ ];
84
+ if (config.timesFrom !== "house") {
85
+ outputs.push((0, publishing_node_1.retainedText)((0, exports.circadianTimeTopic)(config.area, "wake-time", "state"), timeState(state.schedule.wakeTime)), (0, publishing_node_1.retainedText)((0, exports.circadianTimeTopic)(config.area, "bed-time", "state"), timeState(state.schedule.bedTime)));
86
+ }
87
+ return outputs;
88
+ }
89
+ const circadian = (0, publishing_node_1.publishingNode)({
90
+ entries: circadianDiscovery,
91
+ availabilityTopic: exports.circadianAvailabilityTopic,
92
+ stateTopics: (config) => circadianStateTopics(config.area).filter((topic) => config.timesFrom !== "house" || !/\/(wake|bed)-time\/state$/.test(topic)),
93
+ stateOutputs: circadianStateOutputs
94
+ });
95
+ // What it publishes as the flows start and at its startup message. First,
96
+ // with discovery on, the circadian, sleep, wake and bed entries older room
97
+ // controllers published before 6.0 under its area, cleared: those named
98
+ // after the area, and those named after each room node with its area
99
+ // (`roomNodeIds`, found in the flows, migrated or not). Then its own entries,
100
+ // availability and state, in the same batch, so Home Assistant always
101
+ // removes the old entities before it sees the new ones and can give them the
102
+ // old entity IDs. Following a house, its own time entities are cleared too.
103
+ function circadianStartingOutputs(config, state, roomNodeIds = []) {
104
+ return [...circadianClears(config, roomNodeIds), ...circadian.starting(config, state)];
105
+ }
106
+ function circadianClears(config, roomNodeIds) {
107
+ if (!(0, publishing_node_1.publishesDiscovery)(config))
108
+ return [];
109
+ const topics = [
110
+ ...roomCircadianDiscoveryTopics(config),
111
+ ...roomNodeIds.flatMap((nodeId) => roomCircadianDiscoveryTopics(config, "node", nodeId))
112
+ ];
113
+ if (config.timesFrom === "house") {
114
+ topics.push(...circadianDiscovery({ ...config, timesFrom: "own" }).map(({ topic }) => topic).filter((topic) => /\/time\//.test(topic)));
115
+ }
116
+ return [...new Set(topics)].map((topic) => (0, publishing_node_1.retainedText)(topic, ""));
117
+ }
118
+ exports.circadianStoppingOutputs = circadian.stopping;
119
+ exports.circadianRetainedTopics = circadian.retainedTopics;
120
+ // MQTT the policy reads, as its own events: ON or OFF on the circadian and
121
+ // sleep set topics, and a time on its own wake and bed set topics. Read only
122
+ // while it publishes; retained messages and other payloads are ignored with a
123
+ // trace. Anything else is not for these topics.
124
+ function circadianInbound(msg, config) {
125
+ if (!(0, publishing_node_1.publishesState)(config) || typeof msg.topic !== "string")
126
+ return null;
127
+ const area = config.area;
128
+ const sets = [
129
+ [(0, exports.circadianSwitchTopic)(area, "circadian", "set"), "circadian-set", (text) => onOff("circadian", text), "not-on-or-off"],
130
+ [(0, exports.circadianSwitchTopic)(area, "sleep", "set"), "sleep-set", (text) => onOff("sleep", text), "not-on-or-off"]
131
+ ];
132
+ if (config.timesFrom !== "house") {
133
+ sets.push([(0, exports.circadianTimeTopic)(area, "wake-time", "set"), "wake-time-set", (text) => time("wakeTime", text), "not-a-time"], [(0, exports.circadianTimeTopic)(area, "bed-time", "set"), "bed-time-set", (text) => time("bedTime", text), "not-a-time"]);
134
+ }
135
+ const set = sets.find(([topic]) => topic === msg.topic);
136
+ if (!set)
137
+ return null;
138
+ const [, name, read, invalid] = set;
139
+ const ignored = (reason, details = {}) => ({ event: { kind: "ignored" }, traces: [{ event: name, outcome: "ignored", reason, details }] });
140
+ if (msg.retain === true)
141
+ return ignored("retained-message");
142
+ const text = typeof msg.payload === "string" ? msg.payload.trim() : "";
143
+ const event = read(text);
144
+ return event ? { event, traces: [] } : ignored(invalid, { payload: text });
145
+ }
146
+ function onOff(kind, text) {
147
+ const requested = text.toUpperCase();
148
+ return requested === "ON" || requested === "OFF" ? { kind, enabled: requested === "ON" } : null;
149
+ }
150
+ function time(key, text) {
151
+ const value = (0, ha_discovery_1.timeEntityValue)(text);
152
+ return value === null ? null : { kind: "schedule", [key]: value };
153
+ }
154
+ //# sourceMappingURL=circadian-publishing.js.map
@@ -9,3 +9,7 @@ export interface DaySchedule {
9
9
  export declare function clockMinutes(value: unknown): number | null;
10
10
  export declare function resolveSchedule(wakeTime?: unknown, bedTime?: unknown): DaySchedule;
11
11
  export declare function scheduleLevel(now: Date, wakeTime: string, bedTime: string): number;
12
+ export declare function requestedSchedule(current: DaySchedule, event: {
13
+ wakeTime?: unknown;
14
+ bedTime?: unknown;
15
+ }): DaySchedule | null;
@@ -4,6 +4,7 @@ exports.DEFAULT_BED_TIME = exports.DEFAULT_WAKE_TIME = exports.WIND_DOWN_MINUTES
4
4
  exports.clockMinutes = clockMinutes;
5
5
  exports.resolveSchedule = resolveSchedule;
6
6
  exports.scheduleLevel = scheduleLevel;
7
+ exports.requestedSchedule = requestedSchedule;
7
8
  // A daily wake and bed schedule, and how far into the day a given moment is.
8
9
  // Pure: it knows nothing about lights, and takes the time it is asked about.
9
10
  // After waking, the day level rises over this long; before bed it winds down
@@ -60,4 +61,15 @@ function scheduleLevel(now, wakeTime, bedTime) {
60
61
  const untilBed = awakeMinutes - sinceWake;
61
62
  return untilBed < windDown ? ease(untilBed / windDown) : 1;
62
63
  }
64
+ // New times from a "schedule" message, each "HH:MM", with a time left out
65
+ // staying as it is; null if they aren't valid, different times.
66
+ function requestedSchedule(current, event) {
67
+ const next = {
68
+ wakeTime: typeof event.wakeTime === "string" ? event.wakeTime.trim() : current.wakeTime,
69
+ bedTime: typeof event.bedTime === "string" ? event.bedTime.trim() : current.bedTime
70
+ };
71
+ const wake = clockMinutes(next.wakeTime);
72
+ const bed = clockMinutes(next.bedTime);
73
+ return wake === null || bed === null || wake === bed ? null : next;
74
+ }
63
75
  //# sourceMappingURL=circadian-schedule.js.map
@@ -6,10 +6,17 @@ export interface ExpectedCommand {
6
6
  on?: boolean;
7
7
  power?: boolean;
8
8
  echoed?: boolean;
9
+ id?: string;
10
+ tentative?: boolean;
9
11
  }
10
12
  export declare function parsePayload(payload: unknown): unknown;
11
13
  export declare function fingerprint(payload: unknown): string;
12
- export declare function rememberCommand(queue: ExpectedCommand[] | undefined, payload: unknown, nowMs: number): ExpectedCommand[];
14
+ export declare function rememberCommand(queue: ExpectedCommand[] | undefined, payload: unknown, nowMs: number, { id, tentative }?: {
15
+ id?: string;
16
+ tentative?: boolean;
17
+ }): ExpectedCommand[];
18
+ export declare function commandSent(queue: ExpectedCommand[] | undefined, id: string, nowMs: number): ExpectedCommand[];
19
+ export declare function commandSkipped(queue: ExpectedCommand[] | undefined, id: string, nowMs: number): ExpectedCommand[];
13
20
  export type StateReportVerdict = "confirms" | "stale" | "external";
14
21
  export declare function checkStateReport(queue: ExpectedCommand[] | undefined, observedOn: boolean, nowMs: number): {
15
22
  queue: ExpectedCommand[];
@@ -4,6 +4,8 @@ exports.ECHO_QUEUE_LIMIT = exports.ECHO_WINDOW_MS = void 0;
4
4
  exports.parsePayload = parsePayload;
5
5
  exports.fingerprint = fingerprint;
6
6
  exports.rememberCommand = rememberCommand;
7
+ exports.commandSent = commandSent;
8
+ exports.commandSkipped = commandSkipped;
7
9
  exports.checkStateReport = checkStateReport;
8
10
  exports.checkCommandEcho = checkCommandEcho;
9
11
  // Telling the room controller's own light commands from other people's.
@@ -39,10 +41,23 @@ function fingerprint(payload) {
39
41
  function live(queue, nowMs) {
40
42
  return (queue || []).filter((entry) => entry.expires > nowMs).map((entry) => ({ ...entry }));
41
43
  }
42
- // Remember a command just sent.
43
- function rememberCommand(queue, payload, nowMs) {
44
+ // At most ECHO_QUEUE_LIMIT entries, tentative ones aside: the oldest go.
45
+ function trimmed(queue) {
46
+ let excess = queue.filter((entry) => entry.tentative !== true).length - exports.ECHO_QUEUE_LIMIT;
47
+ return queue.filter((entry) => {
48
+ if (excess > 0 && entry.tentative !== true) {
49
+ excess -= 1;
50
+ return false;
51
+ }
52
+ return true;
53
+ });
54
+ }
55
+ // Remember a command just sent: with an id, the room's own; tentative for a
56
+ // restyle its adapter may skip.
57
+ function rememberCommand(queue, payload, nowMs, { id, tentative = false } = {}) {
44
58
  const next = live(queue, nowMs);
45
- const entry = { fingerprint: fingerprint(payload), expires: nowMs + exports.ECHO_WINDOW_MS };
59
+ const entry = { fingerprint: fingerprint(payload), expires: nowMs + exports.ECHO_WINDOW_MS,
60
+ ...(id !== undefined ? { id } : {}), ...(tentative ? { tentative: true } : {}) };
46
61
  const requested = payload && typeof payload === "object"
47
62
  ? String(payload.state || "").toUpperCase()
48
63
  : "";
@@ -51,14 +66,30 @@ function rememberCommand(queue, payload, nowMs) {
51
66
  entry.power = entry.on;
52
67
  }
53
68
  next.push(entry);
54
- return next.slice(-exports.ECHO_QUEUE_LIMIT);
69
+ return trimmed(next);
70
+ }
71
+ // A tentative command its adapter sent after all: now an ordinary entry.
72
+ function commandSent(queue, id, nowMs) {
73
+ return trimmed(live(queue, nowMs).map((entry) => {
74
+ if (entry.id !== id)
75
+ return entry;
76
+ const { tentative: _tentative, ...sent } = entry;
77
+ return sent;
78
+ }));
79
+ }
80
+ // A tentative command its adapter skipped: as if never sent.
81
+ function commandSkipped(queue, id, nowMs) {
82
+ return live(queue, nowMs).filter((entry) => entry.id !== id);
55
83
  }
56
84
  function checkStateReport(queue, observedOn, nowMs) {
57
85
  const next = live(queue, nowMs);
58
- const latest = next.filter((entry) => entry.on !== undefined).at(-1);
86
+ // A tentative restyle isn't pending until its adapter says it sent it: a
87
+ // skipped one was never sent, so it must never make a report stale.
88
+ const pending = next.filter((entry) => entry.on !== undefined && entry.tentative !== true);
89
+ const latest = pending.at(-1);
59
90
  const verdict = latest === undefined ? "external" : latest.on === observedOn ? "confirms" : "stale";
60
91
  if (verdict === "confirms") {
61
- for (const entry of next)
92
+ for (const entry of pending)
62
93
  delete entry.on;
63
94
  }
64
95
  return { queue: next, verdict };
@@ -232,6 +232,10 @@ function transitionCover(saved, msg, suppliedConfig = {}, nowValue = new Date())
232
232
  trace("intent", "accepted", null, { kind: intent.kind, position, generation: intent.generation });
233
233
  }
234
234
  function acceptObservation(observation) {
235
+ // A cover that reports no position at all is the other cover type.
236
+ if (observation.position === undefined && ("state" in observation || observation.motion !== undefined)) {
237
+ throw new Error("observed cover reading has no position: for a cover that reports none, set the cover node's Cover to \"Open, close and stop only\"");
238
+ }
235
239
  const devicePosition = validPosition(observation.position, "observed cover position");
236
240
  if (observation.motion !== undefined && !Object.hasOwn(MOTIONS, observation.motion)) {
237
241
  throw new Error("unknown observed cover motion");
@@ -52,8 +52,9 @@ function parseVolume(raw) {
52
52
  const denon = raw.length === 2 ? Number(raw) : Number(raw.slice(0, 2)) + Number(raw.slice(2)) / 10;
53
53
  return denon - DENON_ZERO_DB;
54
54
  }
55
- // A volume request's value from before 5.0, in the receiver's own 0-98:
56
- // absolute values convert to dB; relative ones are already a change in dB.
55
+ // A volume in the receiver's own 0-98 as dB: absolute values convert,
56
+ // relative ones are already a change in dB. Used only for a receiver state
57
+ // saved before 5.0, restored once (see createAvrState).
57
58
  function legacyVolumeDb(value, mode) {
58
59
  return mode === "absolute" ? value - DENON_ZERO_DB : value;
59
60
  }
@@ -0,0 +1,3 @@
1
+ export declare const NOT_TRUE_OR_FALSE = "not-true-or-false";
2
+ export declare function enableValue(value: unknown): boolean | null;
3
+ export declare function describeValue(value: unknown): string;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NOT_TRUE_OR_FALSE = void 0;
4
+ exports.enableValue = enableValue;
5
+ exports.describeValue = describeValue;
6
+ // An enable, sleep or pause input from a flow: true or false only. Anything
7
+ // else, such as "on" or "ON" (accepted before 6.0), is refused and traced,
8
+ // never read as off. Home Assistant's ON and OFF reach a node through its
9
+ // set topics, which translate them to true or false.
10
+ exports.NOT_TRUE_OR_FALSE = "not-true-or-false";
11
+ function enableValue(value) {
12
+ return typeof value === "boolean" ? value : null;
13
+ }
14
+ // A refused value as it can be shown in a trace and a warning.
15
+ function describeValue(value) {
16
+ return typeof value === "string" ? JSON.stringify(value) : String(value);
17
+ }
18
+ //# sourceMappingURL=enable-input.js.map
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.houseScheduleInUse = houseScheduleInUse;
4
4
  exports.transitionHouseSchedule = transitionHouseSchedule;
5
- const room_schedule_1 = require("./room-schedule");
5
+ const circadian_schedule_1 = require("./circadian-schedule");
6
6
  const settings_1 = require("./settings");
7
7
  // The times in use: each saved time while its setting is unchanged.
8
8
  function houseScheduleInUse(saved, setting) {
@@ -15,7 +15,7 @@ function transitionHouseSchedule(saved, event, setting) {
15
15
  const state = { schedule: houseScheduleInUse(saved, setting), scheduleSetting: { ...setting } };
16
16
  const traces = [];
17
17
  let changed = false;
18
- const next = (0, room_schedule_1.requestedSchedule)(state.schedule, event);
18
+ const next = (0, circadian_schedule_1.requestedSchedule)(state.schedule, event);
19
19
  if (!next) {
20
20
  traces.push({ event: "schedule", outcome: "ignored", reason: "invalid-times", details: { wakeTime: event.wakeTime, bedTime: event.bedTime } });
21
21
  }
@@ -0,0 +1,53 @@
1
+ export interface LightCommandMessage {
2
+ kind: "command";
3
+ target: string;
4
+ state: "ON" | "OFF";
5
+ brightnessPct?: number;
6
+ colorTempKelvin?: number;
7
+ transitionSeconds?: number;
8
+ extra?: Record<string, unknown>;
9
+ restyle?: boolean;
10
+ source: string;
11
+ id: string;
12
+ }
13
+ export interface LightObserveMessage {
14
+ kind: "observe";
15
+ target: string;
16
+ }
17
+ export type LightRoomMessage = LightCommandMessage | LightObserveMessage;
18
+ export type LightField = "brightness" | "colorTemp";
19
+ export type LightReading = {
20
+ kind: "observed";
21
+ target: string;
22
+ on: boolean;
23
+ brightnessPct?: number;
24
+ colorTempKelvin?: number;
25
+ fields: LightField[];
26
+ showsLast: boolean;
27
+ observedAt: string;
28
+ } | {
29
+ kind: "external";
30
+ target: string;
31
+ state: string;
32
+ setsValues: boolean;
33
+ observedAt: string;
34
+ } | {
35
+ kind: "echo-changed";
36
+ target: string;
37
+ id: string | null;
38
+ state: string;
39
+ } | {
40
+ kind: "skipped";
41
+ target: string;
42
+ id: string;
43
+ observedAt: string;
44
+ } | {
45
+ kind: "sent";
46
+ target: string;
47
+ id: string;
48
+ } | {
49
+ kind: "availability";
50
+ target: string;
51
+ online: boolean;
52
+ };
53
+ export declare function isLightReading(value: unknown): value is LightReading;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isLightReading = isLightReading;
4
+ function isLightReading(value) {
5
+ if (!value || typeof value !== "object")
6
+ return false;
7
+ const reading = value;
8
+ return typeof reading.target === "string" &&
9
+ ["observed", "external", "echo-changed", "skipped", "sent", "availability"].includes(String(reading.kind));
10
+ }
11
+ //# sourceMappingURL=light-contract.js.map
@@ -47,7 +47,6 @@ export type MotionEffect = {
47
47
  kind: "send";
48
48
  message: LightingIntent;
49
49
  };
50
- export declare function booleanOn(value: unknown): boolean;
51
50
  export declare function normaliseMotionConfig(raw: {
52
51
  onTargets?: unknown;
53
52
  offTargets?: unknown;
@@ -1,16 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DEFAULT_MAX_PAUSE_SECONDS = void 0;
4
- exports.booleanOn = booleanOn;
5
4
  exports.normaliseMotionConfig = normaliseMotionConfig;
6
5
  exports.createMotionState = createMotionState;
7
6
  exports.lightingIntent = lightingIntent;
8
7
  exports.transitionMotion = transitionMotion;
8
+ const enable_input_1 = require("./enable-input");
9
9
  const settings_1 = require("./settings");
10
10
  exports.DEFAULT_MAX_PAUSE_SECONDS = 600;
11
- function booleanOn(value) {
12
- return value === true || (typeof value === "string" && value.toLowerCase() === "on");
13
- }
14
11
  function finiteNumber(value) {
15
12
  const number = Number(value);
16
13
  return Number.isFinite(number) ? number : null;
@@ -118,9 +115,13 @@ function transitionMotion(saved, input, config, globalEnabled, now = Date.now())
118
115
  }
119
116
  const source = input.source;
120
117
  const payload = input.payload;
121
- if (source === "global-enabled") {
118
+ if ((source === "global-enabled" || source === "area-enabled" || source === "pause") && (0, enable_input_1.enableValue)(payload) === null) {
119
+ // Refused, never read as off: the node warns and says so on its status.
120
+ trace(source === "pause" ? "pause" : "enabled", "ignored", enable_input_1.NOT_TRUE_OR_FALSE, { source, payload: (0, enable_input_1.describeValue)(payload) });
121
+ }
122
+ else if (source === "global-enabled") {
122
123
  const previous = nextGlobalEnabled;
123
- nextGlobalEnabled = booleanOn(payload);
124
+ nextGlobalEnabled = payload === true;
124
125
  if (previous !== nextGlobalEnabled) {
125
126
  trace("enabled", "changed", null, { scope: "global", enabled: nextGlobalEnabled });
126
127
  }
@@ -136,7 +137,7 @@ function transitionMotion(saved, input, config, globalEnabled, now = Date.now())
136
137
  trace("pause", "ignored", "owner-required");
137
138
  }
138
139
  else {
139
- const pause = payload === true || booleanOn(payload);
140
+ const pause = payload === true;
140
141
  const held = state.pausedBy.some((entry) => entry.owner === owner);
141
142
  const others = state.pausedBy.filter((entry) => entry.owner !== owner);
142
143
  const until = now + (config.maxPauseSeconds ?? exports.DEFAULT_MAX_PAUSE_SECONDS) * 1000;
@@ -148,7 +149,7 @@ function transitionMotion(saved, input, config, globalEnabled, now = Date.now())
148
149
  }
149
150
  else if (source === "area-enabled") {
150
151
  const previous = state.areaEnabled;
151
- state.areaEnabled = booleanOn(payload);
152
+ state.areaEnabled = payload === true;
152
153
  if (previous !== state.areaEnabled) {
153
154
  trace("enabled", "changed", null, { scope: "area", enabled: state.areaEnabled });
154
155
  }
@@ -82,7 +82,8 @@ function motionInbound(msg, config) {
82
82
  const requested = text.toUpperCase();
83
83
  if (requested !== "ON" && requested !== "OFF")
84
84
  return ignored("not-on-or-off", { payload: text });
85
- return { input: { source: "area-enabled", payload: requested }, traces: [] };
85
+ // Home Assistant's ON and OFF, as the node's own true and false.
86
+ return { input: { source: "area-enabled", payload: requested === "ON" }, traces: [] };
86
87
  }
87
88
  const seconds = text === "" ? NaN : Number(text);
88
89
  if (!Number.isFinite(seconds) || seconds < 0 || seconds > exports.MAX_DELAY_SECONDS)
@@ -0,0 +1,6 @@
1
+ export interface MqttPublication {
2
+ topic: string;
3
+ payload: string;
4
+ }
5
+ export declare function parsedPayload(payload: unknown): unknown;
6
+ export declare function isObject(value: unknown): value is Record<string, unknown>;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parsedPayload = parsedPayload;
4
+ exports.isObject = isObject;
5
+ // An MQTT in node may hand over a parsed object, a string or a Buffer;
6
+ // JSON text is parsed, anything else is returned as it is.
7
+ function parsedPayload(payload) {
8
+ const text = Buffer.isBuffer(payload) ? payload.toString("utf8") : payload;
9
+ if (typeof text !== "string")
10
+ return text;
11
+ try {
12
+ return JSON.parse(text);
13
+ }
14
+ catch {
15
+ return text;
16
+ }
17
+ }
18
+ function isObject(value) {
19
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
20
+ }
21
+ //# sourceMappingURL=mqtt-message.js.map
@@ -1,25 +1,30 @@
1
1
  import type { TraceEntry } from "./bounded-trace";
2
- import type { CircadianLighting } from "./circadian";
3
- import type { DaySchedule } from "./circadian-schedule";
4
- import { type LightCommand, type LightReport } from "./z2m-light";
2
+ import type { LightStyle } from "./light-styling";
3
+ import { type LightField, type LightRoomMessage } from "./light-contract";
4
+ import { type LightHold } from "./room-holds";
5
5
  import { type ExpectedCommand } from "./command-echo";
6
6
  export { fingerprint, parsePayload, type ExpectedCommand } from "./command-echo";
7
7
  export interface RoomTarget {
8
8
  id: string;
9
- stateTopic: string;
10
- commandTopic: string;
9
+ onOffOnly?: boolean;
11
10
  }
12
11
  export interface RoomConfig {
13
12
  area: string;
14
13
  displayName: string;
15
14
  targets: RoomTarget[];
16
- initialSleep: boolean;
17
- refreshTransitionSeconds: number;
18
15
  initialTransitionSeconds: number;
19
- lighting: CircadianLighting;
20
- schedule?: DaySchedule;
21
16
  }
22
- export interface RoomObservation extends LightReport {
17
+ export interface RoomStyle {
18
+ values: LightStyle | null;
19
+ transitionSeconds: number;
20
+ until: string;
21
+ source: string;
22
+ }
23
+ export interface RoomObservation {
24
+ on: boolean;
25
+ brightnessPct?: number;
26
+ colorTempKelvin?: number;
27
+ fields?: LightField[];
23
28
  observedAt: string;
24
29
  }
25
30
  export type TargetControlState = "in-control" | "overridden" | "manual";
@@ -29,20 +34,26 @@ export type TargetControl = {
29
34
  state: "overridden";
30
35
  owner: string;
31
36
  };
32
- export declare const LEGACY_LIGHT_UNITS = "legacy-light-units";
37
+ export type { HeldSpec, LightHold } from "./room-holds";
38
+ export declare const REMOVED_LIGHT_UNITS = "removed-light-units";
33
39
  export declare const INVALID_LIGHT_VALUES = "invalid-light-values";
40
+ export declare const ON_OFF_ONLY = "on-off-only";
41
+ export declare const MOVED_CIRCADIAN_SETTINGS: readonly ["houseSchedule", "wakeTime", "bedTime", "maxBrightnessPct", "maxColorTempKelvin", "sleepBrightnessPct", "sleepColorTempKelvin", "refreshTransitionSeconds", "refreshSeconds", "initialSleep", "latitude", "longitude", "minBrightnessPct", "minColorTempKelvin"];
42
+ export declare function movedCircadianSettings(config: Record<string, unknown>): string[];
43
+ export declare function targetsWithTopics(targets: unknown): string[];
44
+ export declare const MOVED_TO_CIRCADIAN = "moved-to-circadian";
34
45
  export interface RoomState {
35
46
  observed: Record<string, RoomObservation>;
36
47
  desired: Record<string, boolean>;
37
48
  control: Record<string, TargetControl>;
49
+ holds: Record<string, LightHold>;
38
50
  expected: Record<string, ExpectedCommand[]>;
39
- circadianEnabled: boolean;
40
- sleeping: boolean;
41
- schedule: DaySchedule;
42
- scheduleSetting: DaySchedule;
51
+ style: RoomStyle | null;
43
52
  personAt: Record<string, number>;
44
53
  untold: string[];
45
54
  restyledAt: Record<string, number>;
55
+ available: Record<string, boolean>;
56
+ commandSeq: number;
46
57
  }
47
58
  export interface LightingEvent {
48
59
  kind?: string;
@@ -57,15 +68,15 @@ export interface LightingEvent {
57
68
  person?: boolean;
58
69
  owner?: string;
59
70
  source?: string;
60
- refresh?: boolean;
61
71
  retained?: boolean;
62
- enabled?: boolean;
63
72
  vacantSince?: string;
64
- wakeTime?: string;
65
- bedTime?: string;
73
+ transitionSeconds?: number;
74
+ until?: string;
75
+ takeBack?: boolean;
66
76
  }
67
77
  export interface RoomMessage {
68
78
  lighting?: LightingEvent;
79
+ light?: unknown;
69
80
  topic?: string;
70
81
  payload?: unknown;
71
82
  retain?: boolean;
@@ -74,25 +85,28 @@ export interface RoomOutput {
74
85
  topic: string;
75
86
  payload: unknown;
76
87
  retain: boolean;
77
- lighting_command?: {
78
- area: string;
79
- target: string;
80
- source: string;
81
- };
82
88
  }
83
89
  export declare function createRoomState(config: RoomConfig, saved?: Partial<RoomState> & {
84
90
  manual?: Record<string, boolean>;
85
91
  }): RoomState;
86
- export declare function adaptivePayload(lightState: string, isRefresh: boolean, sleeping: boolean, now: Date, config: RoomConfig): LightCommand;
92
+ export declare function intentValues(values: Record<string, unknown>): {
93
+ brightnessPct: number | undefined;
94
+ colorTempKelvin: number | undefined;
95
+ extra: Record<string, unknown>;
96
+ removed: string[];
97
+ invalid: string[];
98
+ };
87
99
  export declare function transitionRoom(saved: Partial<RoomState> | undefined, msg: RoomMessage, config: RoomConfig, nowValue?: Date | string | number): {
88
100
  state: RoomState;
89
101
  outputs: RoomOutput[];
102
+ commands: LightRoomMessage[];
90
103
  traces: TraceEntry<Record<string, unknown>>[];
91
104
  controlChanged: string[];
92
105
  status: {
93
- circadianEnabled: boolean;
94
- sleeping: boolean;
106
+ styled: boolean;
107
+ styleSource: string | null;
95
108
  onCount: number;
109
+ offlineCount: number;
96
110
  manualCount: number;
97
111
  overriddenCount: number;
98
112
  control: {