@avantics/node-red-home-automation 4.0.2 → 5.0.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.
- package/README.md +126 -4
- package/contract-examples/switch-gestures.mjs +1 -1
- package/contract-examples/volume-ownership.mjs +6 -5
- package/dist/lib/activity-lighting-controller.d.ts +2 -0
- package/dist/lib/activity-lighting-controller.js +46 -7
- package/dist/lib/adopted-request.d.ts +17 -0
- package/dist/lib/adopted-request.js +61 -7
- package/dist/lib/avr-controller.d.ts +9 -3
- package/dist/lib/avr-controller.js +76 -24
- package/dist/lib/avr-publishing.d.ts +3 -3
- package/dist/lib/avr-publishing.js +11 -5
- package/dist/lib/backlighting-controller.d.ts +2 -0
- package/dist/lib/backlighting-controller.js +37 -8
- package/dist/lib/cover-publishing.js +1 -1
- package/dist/lib/denon-protocol.d.ts +5 -1
- package/dist/lib/denon-protocol.js +26 -11
- package/dist/lib/display-mode-controller.d.ts +12 -5
- package/dist/lib/display-mode-controller.js +181 -87
- package/dist/lib/house-schedule-publishing.js +1 -1
- package/dist/lib/light-styling.d.ts +2 -2
- package/dist/lib/light-styling.js +5 -4
- package/dist/lib/motion-publishing.js +1 -1
- package/dist/lib/occupancy-publishing.js +1 -1
- package/dist/lib/power-reading.d.ts +5 -0
- package/dist/lib/power-reading.js +13 -0
- package/dist/lib/room-controller.d.ts +2 -3
- package/dist/lib/room-controller.js +18 -2
- package/dist/lib/room-lighting-discovery.js +1 -1
- package/dist/lib/room-publishing.d.ts +3 -0
- package/dist/lib/shelly-cover.d.ts +46 -0
- package/dist/lib/shelly-cover.js +193 -0
- package/dist/lib/source-capability-controller.d.ts +2 -0
- package/dist/lib/source-capability-controller.js +27 -6
- package/dist/lib/switch-policy.d.ts +1 -1
- package/dist/lib/switch-policy.js +1 -1
- package/dist/lib/theatre-requests.d.ts +29 -0
- package/dist/lib/theatre-requests.js +89 -0
- package/dist/lib/theatre-state-contract.d.ts +5 -22
- package/dist/lib/theatre-state-contract.js +18 -73
- package/dist/lib/toggle-power.d.ts +41 -0
- package/dist/lib/toggle-power.js +74 -0
- package/dist/lib/topic-names.d.ts +1 -0
- package/dist/lib/topic-names.js +7 -0
- package/dist/lib/{display-transport.d.ts → transports/display-transport.d.ts} +1 -1
- package/dist/lib/{display-transport.js → transports/display-transport.js} +32 -7
- package/dist/lib/z2m-light.d.ts +8 -0
- package/dist/lib/z2m-light.js +64 -3
- package/dist/nodes/activity-lighting-controller.html +8 -0
- package/dist/nodes/avr-controller.html +28 -6
- package/dist/nodes/avr-controller.js +16 -6
- package/dist/nodes/display-mode-controller.html +61 -11
- package/dist/nodes/display-mode-controller.js +16 -6
- package/dist/nodes/room-controller.js +14 -0
- package/dist/nodes/shelly-cover.d.ts +3 -0
- package/dist/nodes/shelly-cover.html +65 -0
- package/dist/nodes/shelly-cover.js +34 -0
- package/examples/Home theatre activity.json +5 -5
- package/examples/Home theatre equipment.json +4 -4
- package/examples/Shelly cover.json +252 -0
- package/package.json +3 -2
|
@@ -6,6 +6,8 @@ exports.transitionDisplay = transitionDisplay;
|
|
|
6
6
|
const adopted_request_1 = require("./adopted-request");
|
|
7
7
|
const settings_1 = require("./settings");
|
|
8
8
|
const observation_time_1 = require("./observation-time");
|
|
9
|
+
const power_reading_1 = require("./power-reading");
|
|
10
|
+
const toggle_power_1 = require("./toggle-power");
|
|
9
11
|
const target_state_1 = require("./target-state");
|
|
10
12
|
const MODES = { off: true, tv: true, projector: true };
|
|
11
13
|
const DEVICES = ["tv", "screen", "projector"];
|
|
@@ -28,19 +30,42 @@ function initialState(saved = {}) {
|
|
|
28
30
|
? saved.lastAttempt
|
|
29
31
|
: 0,
|
|
30
32
|
fallbackUsed: saved.fallbackUsed === true,
|
|
31
|
-
adoptedGeneration: (0, adopted_request_1.savedAdoptedGeneration)(saved)
|
|
33
|
+
adoptedGeneration: (0, adopted_request_1.savedAdoptedGeneration)(saved),
|
|
34
|
+
carried: (0, adopted_request_1.savedCarried)(saved),
|
|
35
|
+
...(saved.discovery && Number.isFinite(saved.discovery.nextAt) ? { discovery: { ...saved.discovery } } : {})
|
|
32
36
|
};
|
|
33
37
|
}
|
|
38
|
+
// The projector's power from its meter, with the display's own bands.
|
|
34
39
|
function classifyProjectorPower(watts, previous = "unknown", config = {}) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
return (0, power_reading_1.classifyPower)(watts, previous, {
|
|
41
|
+
onWatts: Number(config.projectorOnWatts ?? 20),
|
|
42
|
+
offWatts: Number(config.projectorOffWatts ?? 10)
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
// What a projector power reading says: a meter's watts, classified against
|
|
46
|
+
// the on and standby watts, or the state itself from any adapter. A
|
|
47
|
+
// "transitioning" lamp is read as a reading between the two would be: it
|
|
48
|
+
// keeps its last settled state, or is transitioning if it has none. Given
|
|
49
|
+
// both, the state wins and the watts are kept for reporting.
|
|
50
|
+
const PROJECTOR_POWER_STATES = ["on", "standby", "transitioning"];
|
|
51
|
+
function projectorReading(event, previous, config) {
|
|
52
|
+
const watts = event.watts === undefined ? null : Number(event.watts);
|
|
53
|
+
if (watts !== null && (!Number.isFinite(watts) || watts < 0))
|
|
54
|
+
throw new Error("invalid projector power observation");
|
|
55
|
+
if (event.power === undefined) {
|
|
56
|
+
if (watts === null)
|
|
57
|
+
throw new Error("invalid projector power observation");
|
|
58
|
+
return { watts, power: classifyProjectorPower(watts, previous, config) };
|
|
59
|
+
}
|
|
60
|
+
// Lower case only. A smart plug's own ON and OFF are its relay, not the
|
|
61
|
+
// lamp: a projector in standby on a switched-on plug would read as on, and
|
|
62
|
+
// a request for TV mode would then toggle it on. So they fail as invalid.
|
|
63
|
+
const power = typeof event.power === "string" ? event.power.trim() : "";
|
|
64
|
+
if (!PROJECTOR_POWER_STATES.includes(power)) {
|
|
65
|
+
throw new Error("projector power must be on, standby or transitioning");
|
|
66
|
+
}
|
|
67
|
+
const settled = previous === "on" || previous === "standby" ? previous : "transitioning";
|
|
68
|
+
return { watts, power: power === "transitioning" ? settled : power };
|
|
44
69
|
}
|
|
45
70
|
function statusFor(state) {
|
|
46
71
|
const mode = state.desired?.mode || "none";
|
|
@@ -78,31 +103,48 @@ function allSeen(state) {
|
|
|
78
103
|
return DEVICES.every((device) => state.seen[device]);
|
|
79
104
|
}
|
|
80
105
|
function screenAtPosition(observed, target, tolerance) {
|
|
81
|
-
if (!observed || !Number.isFinite(observed.position))
|
|
106
|
+
if (!observed || observed.position === null || !Number.isFinite(observed.position))
|
|
82
107
|
return false;
|
|
83
108
|
if (observed.state === "opening" || observed.state === "closing")
|
|
84
109
|
return false;
|
|
85
110
|
return Math.abs(observed.position - target) <= tolerance;
|
|
86
111
|
}
|
|
112
|
+
// Closed: at 0, or reported closed.
|
|
113
|
+
function screenClosed(observed, config) {
|
|
114
|
+
return observed?.state === "closed" || screenAtPosition(observed, 0, config.screenTolerance);
|
|
115
|
+
}
|
|
116
|
+
// Open for projector mode: at the configured position, or with none
|
|
117
|
+
// configured, reported fully open (or stopped at the top).
|
|
118
|
+
function screenOpen(observed, config) {
|
|
119
|
+
if (config.screenOpenPosition !== null)
|
|
120
|
+
return screenAtPosition(observed, config.screenOpenPosition, config.screenTolerance);
|
|
121
|
+
return observed?.state === "open" || screenAtPosition(observed, 100, config.screenTolerance);
|
|
122
|
+
}
|
|
87
123
|
function operationSatisfied(operation, observed, config) {
|
|
88
124
|
switch (operation) {
|
|
89
125
|
case "tv_on": return observed.tv?.power === "on";
|
|
90
126
|
case "tv_standby": return observed.tv?.power === "standby";
|
|
91
|
-
case "screen_open": return
|
|
92
|
-
case "screen_close": return
|
|
93
|
-
|
|
94
|
-
case "projector_settle": return observed.projector?.power === "on" || observed.projector?.power === "standby";
|
|
95
|
-
case "projector_shutdown_observe":
|
|
96
|
-
case "projector_shutdown_confirm":
|
|
97
|
-
case "projector_cooldown": return observed.projector?.power === "standby";
|
|
98
|
-
default: return false;
|
|
127
|
+
case "screen_open": return screenOpen(observed.screen, config);
|
|
128
|
+
case "screen_close": return screenClosed(observed.screen, config);
|
|
129
|
+
default: return (0, toggle_power_1.togglePowerSatisfied)(operation, observed.projector?.power) ?? false;
|
|
99
130
|
}
|
|
100
131
|
}
|
|
132
|
+
// Where projector mode opens the screen: a percentage above 0, or nothing
|
|
133
|
+
// (empty, missing) for the screen's own open command. There is no default
|
|
134
|
+
// position: each screen has its own.
|
|
135
|
+
function screenOpenPositionSetting(value) {
|
|
136
|
+
if (value === undefined || value === null || (typeof value === "string" && value.trim() === ""))
|
|
137
|
+
return null;
|
|
138
|
+
const position = (0, settings_1.numberSetting)(value, "screen open position", NaN);
|
|
139
|
+
if (!(position > 0 && position <= 100))
|
|
140
|
+
throw new Error("screen open position must be above 0 and at most 100, or empty");
|
|
141
|
+
return position;
|
|
142
|
+
}
|
|
101
143
|
// Settings may be editor strings; missing or unusable numbers take defaults.
|
|
102
144
|
function normaliseConfig(config = {}) {
|
|
103
145
|
const projectorWarmupMs = Math.max(1000, (0, settings_1.numberSetting)(config.projectorWarmupMs, "projector warm-up", 60000));
|
|
104
146
|
return {
|
|
105
|
-
screenOpenPosition: (
|
|
147
|
+
screenOpenPosition: screenOpenPositionSetting(config.screenOpenPosition),
|
|
106
148
|
screenTolerance: Math.max(0, (0, settings_1.numberSetting)(config.screenTolerance, "screen tolerance", 2)),
|
|
107
149
|
pollMs: Math.max(250, (0, settings_1.numberSetting)(config.pollMs, "poll interval", 2000)),
|
|
108
150
|
queryTimeoutMs: Math.max(1000, (0, settings_1.numberSetting)(config.queryTimeoutMs, "query timeout", 5000)),
|
|
@@ -124,19 +166,28 @@ function modeSatisfied(state, config) {
|
|
|
124
166
|
if (state.desired.mode === "tv") {
|
|
125
167
|
return state.observed.tv?.power === "on" &&
|
|
126
168
|
state.observed.projector?.power === "standby" &&
|
|
127
|
-
|
|
169
|
+
screenClosed(state.observed.screen, config);
|
|
128
170
|
}
|
|
129
171
|
if (state.desired.mode === "projector") {
|
|
130
172
|
return state.observed.tv?.power === "standby" &&
|
|
131
173
|
state.observed.projector?.power === "on" &&
|
|
132
|
-
|
|
174
|
+
screenOpen(state.observed.screen, config);
|
|
133
175
|
}
|
|
134
176
|
return state.observed.tv?.power === "standby" &&
|
|
135
177
|
state.observed.projector?.power === "standby" &&
|
|
136
|
-
|
|
178
|
+
screenClosed(state.observed.screen, config);
|
|
137
179
|
}
|
|
138
180
|
function transitionDisplay(saved, msg, suppliedConfig = {}, now = new Date()) {
|
|
139
181
|
const config = normaliseConfig(suppliedConfig);
|
|
182
|
+
// The projector's toggle-only power, with the display's own timings.
|
|
183
|
+
const toggleTiming = {
|
|
184
|
+
pollMs: config.pollMs,
|
|
185
|
+
queryTimeoutMs: config.queryTimeoutMs,
|
|
186
|
+
warmupMs: config.projectorWarmupMs,
|
|
187
|
+
minimumWarmupMs: config.projectorMinimumWarmupMs,
|
|
188
|
+
shutdownConfirmMs: config.projectorShutdownConfirmMs,
|
|
189
|
+
cooldownMs: config.projectorCooldownMs
|
|
190
|
+
};
|
|
140
191
|
const state = initialState(saved);
|
|
141
192
|
const previousPhase = state.phase;
|
|
142
193
|
// Set when a device reading is stored: only then may a settled display
|
|
@@ -152,6 +203,7 @@ function transitionDisplay(saved, msg, suppliedConfig = {}, now = new Date()) {
|
|
|
152
203
|
}
|
|
153
204
|
function fail(device, operation, reason) {
|
|
154
205
|
state.pending = null;
|
|
206
|
+
delete state.discovery;
|
|
155
207
|
state.phase = "failed";
|
|
156
208
|
state.blockedGeneration = state.desired?.generation || state.generation;
|
|
157
209
|
state.failure = { device, operation, reason, occurredAt: iso(now) };
|
|
@@ -196,27 +248,23 @@ function transitionDisplay(saved, msg, suppliedConfig = {}, now = new Date()) {
|
|
|
196
248
|
const operation = power === "on" ? "tv_on" : "tv_standby";
|
|
197
249
|
issue("tv", operation, commandFor(state, "tv", "set_power", { power }), config.tvTimeoutMs);
|
|
198
250
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
251
|
+
// The screen open or closed. Opening with an open position configured, the
|
|
252
|
+
// command carries the position; otherwise the transport uses the screen's
|
|
253
|
+
// own open or close. Closing always runs to the end, which also restores a
|
|
254
|
+
// position the screen has lost.
|
|
255
|
+
function issueScreen(open) {
|
|
256
|
+
const position = open && config.screenOpenPosition !== null ? { position: config.screenOpenPosition } : {};
|
|
257
|
+
issue("screen", open ? "screen_open" : "screen_close", commandFor(state, "screen", open ? "open" : "close", position), config.screenTimeoutMs);
|
|
202
258
|
}
|
|
203
259
|
function issueProjectorStart() {
|
|
204
|
-
issue("projector",
|
|
260
|
+
issue("projector", toggle_power_1.TOGGLE_START, commandFor(state, "projector", "power_toggle", { reason: "start" }), toggleTiming.warmupMs, false);
|
|
205
261
|
if (!state.pending)
|
|
206
262
|
throw new Error("projector start did not create pending state");
|
|
207
|
-
state.pending.readyAt = now.getTime()
|
|
263
|
+
state.pending.readyAt = (0, toggle_power_1.startReadyAt)(now.getTime(), toggleTiming);
|
|
208
264
|
}
|
|
209
265
|
function issueProjectorShutdown() {
|
|
210
266
|
const command = commandFor(state, "projector", "power_toggle", { reason: "shutdown-request" });
|
|
211
|
-
state.pending =
|
|
212
|
-
device: "projector",
|
|
213
|
-
operation: "projector_shutdown_observe",
|
|
214
|
-
command,
|
|
215
|
-
attempt: 1,
|
|
216
|
-
retryable: false,
|
|
217
|
-
deadlineAt: now.getTime() + config.projectorShutdownConfirmMs + config.queryTimeoutMs,
|
|
218
|
-
nextAt: now.getTime() + config.projectorShutdownConfirmMs
|
|
219
|
-
};
|
|
267
|
+
state.pending = (0, toggle_power_1.shutdownRequestPending)("projector", command, now.getTime(), toggleTiming);
|
|
220
268
|
state.phase = "transitioning";
|
|
221
269
|
commands.push(command);
|
|
222
270
|
trace("command", "emitted", null, { device: "projector", operation: "shutdown-request", attempt: 1 });
|
|
@@ -226,6 +274,8 @@ function transitionDisplay(saved, msg, suppliedConfig = {}, now = new Date()) {
|
|
|
226
274
|
}
|
|
227
275
|
function beginDiscovery() {
|
|
228
276
|
state.phase = "discovering";
|
|
277
|
+
if (!state.discovery)
|
|
278
|
+
state.discovery = { attempt: 1, nextAt: now.getTime() + config.queryTimeoutMs };
|
|
229
279
|
for (const device of DEVICES) {
|
|
230
280
|
if (!state.seen[device] && !state.querying[device]) {
|
|
231
281
|
state.querying[device] = true;
|
|
@@ -239,7 +289,7 @@ function transitionDisplay(saved, msg, suppliedConfig = {}, now = new Date()) {
|
|
|
239
289
|
function awaitProjectorPower() {
|
|
240
290
|
state.pending = {
|
|
241
291
|
device: "projector",
|
|
242
|
-
operation:
|
|
292
|
+
operation: toggle_power_1.TOGGLE_SETTLE,
|
|
243
293
|
command: queryFor(state, "projector"),
|
|
244
294
|
attempt: 1,
|
|
245
295
|
retryable: false,
|
|
@@ -286,8 +336,8 @@ function transitionDisplay(saved, msg, suppliedConfig = {}, now = new Date()) {
|
|
|
286
336
|
return issueProjectorShutdown();
|
|
287
337
|
return awaitProjectorPower();
|
|
288
338
|
}
|
|
289
|
-
if (!
|
|
290
|
-
return issueScreen(
|
|
339
|
+
if (!screenClosed(state.observed.screen, config))
|
|
340
|
+
return issueScreen(false);
|
|
291
341
|
return markReady();
|
|
292
342
|
}
|
|
293
343
|
// Make before break, as TV mode does: the projector warms up and the
|
|
@@ -299,8 +349,16 @@ function transitionDisplay(saved, msg, suppliedConfig = {}, now = new Date()) {
|
|
|
299
349
|
return issueProjectorStart();
|
|
300
350
|
return awaitProjectorPower();
|
|
301
351
|
}
|
|
302
|
-
if (!
|
|
303
|
-
|
|
352
|
+
if (!screenOpen(state.observed.screen, config)) {
|
|
353
|
+
// A position to go to needs a screen that knows where it is: close it
|
|
354
|
+
// first, which restores a lost position; one still without a
|
|
355
|
+
// position once closed isn't calibrated for positions.
|
|
356
|
+
if (config.screenOpenPosition !== null && state.observed.screen?.position === null) {
|
|
357
|
+
if (!screenClosed(state.observed.screen, config))
|
|
358
|
+
return issueScreen(false);
|
|
359
|
+
return fail("screen", "screen_open", "screen-not-calibrated");
|
|
360
|
+
}
|
|
361
|
+
return issueScreen(true);
|
|
304
362
|
}
|
|
305
363
|
if (state.observed.tv?.power !== "standby")
|
|
306
364
|
return issueTv("standby");
|
|
@@ -313,15 +371,15 @@ function transitionDisplay(saved, msg, suppliedConfig = {}, now = new Date()) {
|
|
|
313
371
|
return issueProjectorShutdown();
|
|
314
372
|
return awaitProjectorPower();
|
|
315
373
|
}
|
|
316
|
-
if (!
|
|
317
|
-
return issueScreen(
|
|
374
|
+
if (!screenClosed(state.observed.screen, config))
|
|
375
|
+
return issueScreen(false);
|
|
318
376
|
return markReady();
|
|
319
377
|
}
|
|
320
378
|
function acceptObservation(event) {
|
|
321
379
|
const device = event.device;
|
|
322
380
|
if (!DEVICES.includes(device))
|
|
323
381
|
throw new Error("unknown display observation device");
|
|
324
|
-
if (Number.isInteger(event.generation) && state.desired &&
|
|
382
|
+
if (Number.isInteger(event.generation) && state.desired && !(0, adopted_request_1.answersRequest)(state.carried, state.desired.generation, event.generation)) {
|
|
325
383
|
trace("observation", "ignored", "stale-generation", { device, generation: event.generation });
|
|
326
384
|
return;
|
|
327
385
|
}
|
|
@@ -344,22 +402,16 @@ function transitionDisplay(saved, msg, suppliedConfig = {}, now = new Date()) {
|
|
|
344
402
|
state.observed.tv = { power: event.power, observedAt, source };
|
|
345
403
|
}
|
|
346
404
|
else if (device === "screen") {
|
|
347
|
-
|
|
348
|
-
|
|
405
|
+
// A position, or none (a screen that doesn't know it): then only its
|
|
406
|
+
// state says whether it is open or closed.
|
|
407
|
+
const position = event.position === undefined || event.position === null ? null : Number(event.position);
|
|
408
|
+
if (position !== null && (!Number.isFinite(position) || position < 0 || position > 100))
|
|
349
409
|
throw new Error("invalid screen position");
|
|
350
410
|
state.observed.screen = { position, state: event.state || "unknown", observedAt, source };
|
|
351
411
|
}
|
|
352
412
|
else {
|
|
353
|
-
const watts = Number(event.watts);
|
|
354
|
-
if (!Number.isFinite(watts) || watts < 0)
|
|
355
|
-
throw new Error("invalid projector power observation");
|
|
356
413
|
const previous = state.observed.projector?.power || "unknown";
|
|
357
|
-
state.observed.projector = {
|
|
358
|
-
watts,
|
|
359
|
-
power: classifyProjectorPower(watts, previous, config),
|
|
360
|
-
observedAt,
|
|
361
|
-
source
|
|
362
|
-
};
|
|
414
|
+
state.observed.projector = { ...projectorReading(event, previous, config), observedAt, source };
|
|
363
415
|
}
|
|
364
416
|
state.seen[device] = true;
|
|
365
417
|
observationAccepted = true;
|
|
@@ -375,37 +427,59 @@ function transitionDisplay(saved, msg, suppliedConfig = {}, now = new Date()) {
|
|
|
375
427
|
}
|
|
376
428
|
if (!state.pending || state.pending.device !== device)
|
|
377
429
|
return reconcile();
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
state.
|
|
381
|
-
state.pending.nextAt = Math.min(state.pending.deadlineAt, state.pending.readyAt);
|
|
430
|
+
const warming = (0, toggle_power_1.holdForWarmup)(state.pending, state.observed.projector?.power, now.getTime());
|
|
431
|
+
if (warming !== null) {
|
|
432
|
+
state.pending.nextAt = warming;
|
|
382
433
|
return;
|
|
383
434
|
}
|
|
384
435
|
if (operationSatisfied(state.pending.operation, state.observed, config)) {
|
|
385
436
|
state.pending = null;
|
|
386
437
|
return reconcile();
|
|
387
438
|
}
|
|
388
|
-
if (
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
attempt: 1,
|
|
397
|
-
retryable: false,
|
|
398
|
-
deadlineAt: now.getTime() + config.projectorCooldownMs,
|
|
399
|
-
nextAt: now.getTime() + config.pollMs
|
|
400
|
-
};
|
|
401
|
-
trace("command", "emitted", null, { device: "projector", operation: "shutdown-confirm", attempt: 1 });
|
|
402
|
-
state.lastAttempt = Math.max(state.lastAttempt, 1);
|
|
403
|
-
if (config.projectorPowerFallback)
|
|
404
|
-
state.fallbackUsed = true;
|
|
405
|
-
}
|
|
439
|
+
if (device === "projector" && (0, toggle_power_1.needsShutdownConfirm)(state.pending, state.observed.projector?.power)) {
|
|
440
|
+
const command = commandFor(state, "projector", "power_toggle", { reason: "shutdown-confirm" });
|
|
441
|
+
commands.push(command);
|
|
442
|
+
state.pending = (0, toggle_power_1.cooldownPending)("projector", command, now.getTime(), toggleTiming);
|
|
443
|
+
trace("command", "emitted", null, { device: "projector", operation: "shutdown-confirm", attempt: 1 });
|
|
444
|
+
state.lastAttempt = Math.max(state.lastAttempt, 1);
|
|
445
|
+
if (config.projectorPowerFallback)
|
|
446
|
+
state.fallbackUsed = true;
|
|
406
447
|
}
|
|
407
448
|
}
|
|
449
|
+
// A device that hasn't reported by the query timeout is asked again, up to
|
|
450
|
+
// maxAttempts in all; then the request fails naming it, rather than
|
|
451
|
+
// waiting in discovering for a reading that may never come.
|
|
452
|
+
function discoveryDue(event) {
|
|
453
|
+
const discovery = state.discovery;
|
|
454
|
+
if (!discovery || now.getTime() < discovery.nextAt)
|
|
455
|
+
return false;
|
|
456
|
+
if (Number.isInteger(event.generation) && state.desired && event.generation !== state.desired.generation)
|
|
457
|
+
return false;
|
|
458
|
+
const unseen = DEVICES.filter((device) => !state.seen[device]);
|
|
459
|
+
if (unseen.length === 0) {
|
|
460
|
+
delete state.discovery;
|
|
461
|
+
return false;
|
|
462
|
+
}
|
|
463
|
+
if (discovery.attempt < config.maxAttempts) {
|
|
464
|
+
discovery.attempt += 1;
|
|
465
|
+
discovery.nextAt = now.getTime() + config.queryTimeoutMs;
|
|
466
|
+
for (const device of unseen)
|
|
467
|
+
commands.push({ ...queryFor(state, device), attempt: discovery.attempt });
|
|
468
|
+
trace("discovery", "retried", "no-reading", { devices: unseen, attempt: discovery.attempt });
|
|
469
|
+
return false;
|
|
470
|
+
}
|
|
471
|
+
if (state.desired) {
|
|
472
|
+
fail(unseen[0], "discovery", "no-reading");
|
|
473
|
+
}
|
|
474
|
+
else {
|
|
475
|
+
delete state.discovery;
|
|
476
|
+
trace("discovery", "unanswered", "no-reading", { devices: unseen });
|
|
477
|
+
}
|
|
478
|
+
return true;
|
|
479
|
+
}
|
|
408
480
|
function handleTick(event) {
|
|
481
|
+
if (discoveryDue(event))
|
|
482
|
+
return;
|
|
409
483
|
const pending = state.pending;
|
|
410
484
|
if (!pending)
|
|
411
485
|
return reconcile();
|
|
@@ -415,11 +489,9 @@ function transitionDisplay(saved, msg, suppliedConfig = {}, now = new Date()) {
|
|
|
415
489
|
}
|
|
416
490
|
if (now.getTime() < pending.nextAt)
|
|
417
491
|
return;
|
|
418
|
-
if (pending.operation ===
|
|
492
|
+
if (pending.operation === toggle_power_1.TOGGLE_SHUTDOWN_OBSERVE) {
|
|
419
493
|
commands.push(queryFor(state, "projector"));
|
|
420
|
-
pending.
|
|
421
|
-
pending.nextAt = now.getTime() + config.queryTimeoutMs;
|
|
422
|
-
pending.deadlineAt = pending.nextAt;
|
|
494
|
+
(0, toggle_power_1.beginShutdownConfirm)(pending, now.getTime(), toggleTiming);
|
|
423
495
|
trace("command", "emitted", null, { device: "projector", operation: "query-before-confirm", attempt: 1 });
|
|
424
496
|
return;
|
|
425
497
|
}
|
|
@@ -445,7 +517,7 @@ function transitionDisplay(saved, msg, suppliedConfig = {}, now = new Date()) {
|
|
|
445
517
|
retry(pending, null);
|
|
446
518
|
return;
|
|
447
519
|
}
|
|
448
|
-
return fail(pending.device, pending.operation, pending.operation ===
|
|
520
|
+
return fail(pending.device, pending.operation, pending.operation === toggle_power_1.TOGGLE_SETTLE ? "projector-power-unsettled" : "confirmation-timeout");
|
|
449
521
|
}
|
|
450
522
|
commands.push(queryFor(state, pending.device));
|
|
451
523
|
pending.nextAt = Math.min(pending.deadlineAt, now.getTime() + config.pollMs);
|
|
@@ -456,13 +528,30 @@ function transitionDisplay(saved, msg, suppliedConfig = {}, now = new Date()) {
|
|
|
456
528
|
// A refresh with the activity's wanted values, reaching a node with
|
|
457
529
|
// nothing desired (it started with nothing saved): adopt them, and
|
|
458
530
|
// rediscover below as at startup (see adopted-request.ts).
|
|
531
|
+
let replacedRequest = false;
|
|
459
532
|
const adoptable = event.kind === "refresh" ? (0, adopted_request_1.adoptableRefresh)(event, state) : null;
|
|
460
|
-
|
|
533
|
+
// The same wanted values as the work in hand: carry on under the new
|
|
534
|
+
// request rather than adopting it read-only (see carryOn).
|
|
535
|
+
const carried = event.kind === "refresh" && (0, adopted_request_1.carryOn)(state, adoptable, event.mode === state.desired?.mode, state.classification === "manual_override" || state.phase === "failed" || state.blockedGeneration === state.desired?.generation);
|
|
536
|
+
if (carried)
|
|
537
|
+
trace("refresh", "continued", "same-request", { generation: state.generation });
|
|
538
|
+
const adopted = !carried && adoptable !== null && event.kind === "refresh" && typeof event.mode === "string" && Object.hasOwn(MODES, event.mode);
|
|
461
539
|
if (adopted) {
|
|
540
|
+
const reason = (0, adopted_request_1.adoptionReason)(state.desired);
|
|
541
|
+
// Replacing a request the theatre already counts as ready, it answers
|
|
542
|
+
// from its reading, not with an interim state the theatre would take as
|
|
543
|
+
// drift.
|
|
544
|
+
replacedRequest = reason === "newer-generation";
|
|
545
|
+
// A request it replaces takes its classification and failure with it.
|
|
546
|
+
state.failure = null;
|
|
547
|
+
state.blockedGeneration = null;
|
|
548
|
+
state.classification = null;
|
|
549
|
+
state.lastAttempt = 0;
|
|
550
|
+
state.fallbackUsed = false;
|
|
462
551
|
state.desired = { ...adoptable, mode: event.mode };
|
|
463
552
|
state.generation = adoptable.generation;
|
|
464
553
|
state.adoptedGeneration = adoptable.generation;
|
|
465
|
-
trace("refresh", "adopted",
|
|
554
|
+
trace("refresh", "adopted", reason, { mode: event.mode, generation: adoptable.generation });
|
|
466
555
|
}
|
|
467
556
|
if (event.kind === "startup" || adopted) {
|
|
468
557
|
// A projector power operation in flight cannot be repeated safely (a
|
|
@@ -472,6 +561,7 @@ function transitionDisplay(saved, msg, suppliedConfig = {}, now = new Date()) {
|
|
|
472
561
|
state.pending = null;
|
|
473
562
|
state.seen = { tv: false, screen: false, projector: false };
|
|
474
563
|
state.querying = { tv: false, screen: false, projector: false };
|
|
564
|
+
delete state.discovery;
|
|
475
565
|
beginDiscovery();
|
|
476
566
|
if (inFlight) {
|
|
477
567
|
const deadlineAt = Math.max(inFlight.deadlineAt, now.getTime() + config.queryTimeoutMs);
|
|
@@ -516,6 +606,7 @@ function transitionDisplay(saved, msg, suppliedConfig = {}, now = new Date()) {
|
|
|
516
606
|
state.pending = state.pending && !state.pending.retryable ? state.pending : null;
|
|
517
607
|
state.seen = { tv: false, screen: false, projector: false };
|
|
518
608
|
state.querying = { tv: false, screen: false, projector: false };
|
|
609
|
+
delete state.discovery;
|
|
519
610
|
beginDiscovery();
|
|
520
611
|
trace("intent", "accepted", null, { mode: event.mode });
|
|
521
612
|
}
|
|
@@ -524,7 +615,7 @@ function transitionDisplay(saved, msg, suppliedConfig = {}, now = new Date()) {
|
|
|
524
615
|
acceptObservation(event);
|
|
525
616
|
}
|
|
526
617
|
else if (event.kind === "transport_failed") {
|
|
527
|
-
if (Number.isInteger(event.generation) && state.desired &&
|
|
618
|
+
if (Number.isInteger(event.generation) && state.desired && !(0, adopted_request_1.answersRequest)(state.carried, state.desired.generation, event.generation)) {
|
|
528
619
|
trace("transport", "ignored", "stale-generation", { device: event.device });
|
|
529
620
|
}
|
|
530
621
|
else if (state.querying[event.device]) {
|
|
@@ -569,6 +660,9 @@ function transitionDisplay(saved, msg, suppliedConfig = {}, now = new Date()) {
|
|
|
569
660
|
// fresh as its least recent confirmation.
|
|
570
661
|
// An adopted request only reads the device (see adopted-request.ts): a
|
|
571
662
|
// power, toggle or screen command means the display isn't as wanted.
|
|
663
|
+
// Discovery is over once every device has reported.
|
|
664
|
+
if (allSeen(state))
|
|
665
|
+
delete state.discovery;
|
|
572
666
|
const held = (0, adopted_request_1.readsOnly)(state, commands, (command) => command.operation.startsWith("query"));
|
|
573
667
|
if (held.mismatch) {
|
|
574
668
|
commands.splice(0, commands.length, ...held.commands);
|
|
@@ -578,7 +672,7 @@ function transitionDisplay(saved, msg, suppliedConfig = {}, now = new Date()) {
|
|
|
578
672
|
events.push(displayEvent("manual_override", state, { reason: adopted_request_1.ADOPTED_MISMATCH }));
|
|
579
673
|
trace("command", "withheld", adopted_request_1.ADOPTED_MISMATCH);
|
|
580
674
|
}
|
|
581
|
-
if (state.desired) {
|
|
675
|
+
if (state.desired && !replacedRequest) {
|
|
582
676
|
const readings = DEVICES.map((device) => (0, observation_time_1.parseObservedAt)(state.observed[device]?.observedAt));
|
|
583
677
|
const confirmedMs = readings.every((ms) => ms !== null) ? Math.min(...readings) : null;
|
|
584
678
|
const status = state.phase === "manual_override"
|
|
@@ -9,7 +9,7 @@ const publishing_node_1 = require("./publishing-node");
|
|
|
9
9
|
const topic_names_1 = require("./topic-names");
|
|
10
10
|
// The one place a house schedule topic is named.
|
|
11
11
|
function houseTopic(name, path) {
|
|
12
|
-
return
|
|
12
|
+
return (0, topic_names_1.homeTopic)(name, "schedule", path);
|
|
13
13
|
}
|
|
14
14
|
const houseStateTopic = (name, which) => houseTopic(name, which + "/state");
|
|
15
15
|
exports.houseStateTopic = houseStateTopic;
|
|
@@ -5,7 +5,7 @@ export interface LightLevels {
|
|
|
5
5
|
maxColorTempKelvin: number;
|
|
6
6
|
}
|
|
7
7
|
export interface LightStyle {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
brightnessPct: number;
|
|
9
|
+
colorTempKelvin: number;
|
|
10
10
|
}
|
|
11
11
|
export declare function styleAtLevel(level: number, levels: LightLevels): LightStyle;
|
|
@@ -3,13 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.styleAtLevel = styleAtLevel;
|
|
4
4
|
function styleAtLevel(level, levels) {
|
|
5
5
|
const percent = levels.sleepBrightnessPct + (levels.maxBrightnessPct - levels.sleepBrightnessPct) * level;
|
|
6
|
-
// Colour moves evenly in mireds
|
|
7
|
-
// evenly spaced, where equal kelvin steps would bunch up at the cool
|
|
6
|
+
// Colour moves evenly in mireds (reciprocal megakelvin): equal mired steps
|
|
7
|
+
// look evenly spaced, where equal kelvin steps would bunch up at the cool
|
|
8
|
+
// end.
|
|
8
9
|
const sleepMired = 1_000_000 / levels.sleepColorTempKelvin;
|
|
9
10
|
const dayMired = 1_000_000 / levels.maxColorTempKelvin;
|
|
10
11
|
return {
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
brightnessPct: percent,
|
|
13
|
+
colorTempKelvin: 1_000_000 / (sleepMired + (dayMired - sleepMired) * level)
|
|
13
14
|
};
|
|
14
15
|
}
|
|
15
16
|
//# sourceMappingURL=light-styling.js.map
|
|
@@ -9,7 +9,7 @@ const publishing_node_1 = require("./publishing-node");
|
|
|
9
9
|
// The vacancy delays Home Assistant offers, in seconds: up to a day.
|
|
10
10
|
exports.MAX_DELAY_SECONDS = 86400;
|
|
11
11
|
function motionTopic(area, name) {
|
|
12
|
-
return
|
|
12
|
+
return (0, topic_names_1.homeTopic)(area, "motion", name);
|
|
13
13
|
}
|
|
14
14
|
const motionEnabledTopic = (area, end) => motionTopic(area, "enabled/" + end);
|
|
15
15
|
exports.motionEnabledTopic = motionEnabledTopic;
|
|
@@ -12,7 +12,7 @@ exports.occupancyStateOutputs = occupancyStateOutputs;
|
|
|
12
12
|
const topic_names_1 = require("./topic-names");
|
|
13
13
|
const publishing_node_1 = require("./publishing-node");
|
|
14
14
|
function occupancyTopic(area, name) {
|
|
15
|
-
return
|
|
15
|
+
return (0, topic_names_1.homeTopic)(area, "occupancy", name);
|
|
16
16
|
}
|
|
17
17
|
function occupancyStateTopic(area) {
|
|
18
18
|
return occupancyTopic(area, "state");
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.classifyPower = classifyPower;
|
|
4
|
+
function classifyPower(watts, previous = "unknown", bands) {
|
|
5
|
+
if (!Number.isFinite(watts) || watts < 0)
|
|
6
|
+
return "unknown";
|
|
7
|
+
if (watts >= bands.onWatts)
|
|
8
|
+
return "on";
|
|
9
|
+
if (watts <= bands.offWatts)
|
|
10
|
+
return "standby";
|
|
11
|
+
return previous === "on" || previous === "standby" ? previous : "transitioning";
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=power-reading.js.map
|
|
@@ -12,11 +12,8 @@ export interface RoomTarget {
|
|
|
12
12
|
export interface RoomConfig {
|
|
13
13
|
area: string;
|
|
14
14
|
displayName: string;
|
|
15
|
-
discoveryPrefix?: string;
|
|
16
15
|
targets: RoomTarget[];
|
|
17
16
|
initialSleep: boolean;
|
|
18
|
-
publishState?: boolean;
|
|
19
|
-
discovery?: boolean;
|
|
20
17
|
refreshTransitionSeconds: number;
|
|
21
18
|
initialTransitionSeconds: number;
|
|
22
19
|
lighting: CircadianLighting;
|
|
@@ -32,6 +29,8 @@ export type TargetControl = {
|
|
|
32
29
|
state: "overridden";
|
|
33
30
|
owner: string;
|
|
34
31
|
};
|
|
32
|
+
export declare const LEGACY_LIGHT_UNITS = "legacy-light-units";
|
|
33
|
+
export declare const INVALID_LIGHT_VALUES = "invalid-light-values";
|
|
35
34
|
export interface RoomState {
|
|
36
35
|
observed: Record<string, RoomObservation>;
|
|
37
36
|
desired: Record<string, boolean>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parsePayload = exports.fingerprint = void 0;
|
|
3
|
+
exports.INVALID_LIGHT_VALUES = exports.LEGACY_LIGHT_UNITS = exports.parsePayload = exports.fingerprint = void 0;
|
|
4
4
|
exports.createRoomState = createRoomState;
|
|
5
5
|
exports.adaptivePayload = adaptivePayload;
|
|
6
6
|
exports.transitionRoom = transitionRoom;
|
|
@@ -10,6 +10,14 @@ const command_echo_1 = require("./command-echo");
|
|
|
10
10
|
var command_echo_2 = require("./command-echo");
|
|
11
11
|
Object.defineProperty(exports, "fingerprint", { enumerable: true, get: function () { return command_echo_2.fingerprint; } });
|
|
12
12
|
Object.defineProperty(exports, "parsePayload", { enumerable: true, get: function () { return command_echo_2.parsePayload; } });
|
|
13
|
+
// Traced when an intent gives brightness or color_temp in Zigbee2MQTT's own
|
|
14
|
+
// units rather than brightnessPct or colorTempKelvin: still accepted during
|
|
15
|
+
// 5.x, and the node warns.
|
|
16
|
+
exports.LEGACY_LIGHT_UNITS = "legacy-light-units";
|
|
17
|
+
// Traced when an intent's brightnessPct or colorTempKelvin is unusable (not
|
|
18
|
+
// a number, or a kelvin of 0 or less): it is left out of the command, and
|
|
19
|
+
// the node warns.
|
|
20
|
+
exports.INVALID_LIGHT_VALUES = "invalid-light-values";
|
|
13
21
|
function savedControl(saved) {
|
|
14
22
|
if (saved.control) {
|
|
15
23
|
return Object.fromEntries(Object.entries(saved.control).map(([target, entry]) => [target, { ...entry }]));
|
|
@@ -176,7 +184,15 @@ function transitionRoom(saved, msg, config, nowValue = new Date()) {
|
|
|
176
184
|
payload = { state: "OFF" };
|
|
177
185
|
}
|
|
178
186
|
else if (manualValues) {
|
|
179
|
-
|
|
187
|
+
// The intent's values in the light's own units (z2m-light).
|
|
188
|
+
const device = (0, z2m_light_1.lightValues)(manualValues);
|
|
189
|
+
if (device.legacy)
|
|
190
|
+
trace("intent", "accepted", exports.LEGACY_LIGHT_UNITS, { target: targetId, values: manualValues });
|
|
191
|
+
if (device.superseded.length)
|
|
192
|
+
trace("intent", "accepted", "legacy-light-units-ignored", { target: targetId, ignored: device.superseded });
|
|
193
|
+
if (device.invalid.length)
|
|
194
|
+
trace("intent", "accepted", exports.INVALID_LIGHT_VALUES, { target: targetId, dropped: device.invalid, values: manualValues });
|
|
195
|
+
payload = { state: "ON", ...device.values };
|
|
180
196
|
if (!Object.hasOwn(payload, "transition")) {
|
|
181
197
|
payload.transition = config.initialTransitionSeconds;
|
|
182
198
|
}
|
|
@@ -23,7 +23,7 @@ const ha_discovery_1 = require("./ha-discovery");
|
|
|
23
23
|
const topic_names_1 = require("./topic-names");
|
|
24
24
|
// The one place a room topic is named: home/<area ID>/<name>.
|
|
25
25
|
function roomTopic(area, name) {
|
|
26
|
-
return
|
|
26
|
+
return (0, topic_names_1.homeTopic)(area, name);
|
|
27
27
|
}
|
|
28
28
|
function circadianStateTopic(area) {
|
|
29
29
|
return roomTopic(area, "circadian/state");
|
|
@@ -12,6 +12,9 @@ export interface RoomPublishingConfig {
|
|
|
12
12
|
nodeId?: string;
|
|
13
13
|
idScheme?: IdScheme;
|
|
14
14
|
timesFrom?: TimesFrom;
|
|
15
|
+
discoveryPrefix?: string;
|
|
16
|
+
publishState?: boolean;
|
|
17
|
+
discovery?: boolean;
|
|
15
18
|
}
|
|
16
19
|
type PublishingRoomConfig = RoomConfig & RoomPublishingConfig;
|
|
17
20
|
export declare function roomRetainedTopics(config: PublishingRoomConfig): string[];
|