@avantics/node-red-home-automation 4.0.1 → 4.0.3

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 CHANGED
@@ -200,11 +200,30 @@ also attaches the package tarball and its SHA-256 checksum. Install a downloaded
200
200
  tarball through **Manage palette → Install → Upload module**, or with:
201
201
 
202
202
  ```sh
203
- npm install /path/to/avantics-node-red-home-automation-4.0.1.tgz
203
+ npm install /path/to/avantics-node-red-home-automation-4.0.3.tgz
204
204
  ```
205
205
 
206
206
  Add the installed nodes from the **home automation** section of the Node-RED palette, then configure the room, device hosts, MQTT topics, source mappings, and timing limits for your deployment.
207
207
 
208
+ ### 4.0.3
209
+
210
+ Fixes the theatre state flapping on every scheduled refresh: with an activity
211
+ settled and ready, backlighting and room lighting reported themselves as
212
+ confirming while they re-read their devices, so the theatre published
213
+ `unknown` and back, and counted drift each time. A refresh of a ready target
214
+ now re-reads it without leaving ready, as the display, receiver and source
215
+ already did. A target that really changes on its own still counts as drift.
216
+
217
+ ### 4.0.2
218
+
219
+ Fixes the display controller switching the TV off before the projector was
220
+ ready: with a source playing, there was sound but no picture while the screen
221
+ opened and the projector warmed up. Projector mode now starts the projector and
222
+ waits for its warm-up, opens the screen, then puts the TV in standby, so the
223
+ picture stays up and the TV stays on if the projector fails to start. A request
224
+ made while the projector is warming up or cooling down now waits for that to
225
+ finish, so the lamp is no longer left on or toggled mid-warm-up.
226
+
208
227
  ### 4.0.1
209
228
 
210
229
  Fixes the cover controller ending a move too early when a transport echoes the
@@ -307,6 +307,7 @@ function transitionActivityLighting(saved, msg, suppliedConfig = {}, nowValue =
307
307
  // nothing desired (it started with nothing saved): adopt them, and observe
308
308
  // below as at startup (see adopted-request.ts). Which lights it held is
309
309
  // unknown, so the next activity releases every light it holds.
310
+ let answerWithReading = false;
310
311
  const adoptable = event.kind === "refresh" ? (0, adopted_request_1.adoptableRefresh)(event, state) : null;
311
312
  const adopted = adoptable !== null && event.kind === "refresh" && typeof event.profile === "string" && Object.hasOwn(config.profiles, event.profile);
312
313
  if (adopted && event.kind === "refresh") {
@@ -348,6 +349,15 @@ function transitionActivityLighting(saved, msg, suppliedConfig = {}, nowValue =
348
349
  fail("confirmation-timeout");
349
350
  }
350
351
  }
352
+ else if (event.kind === "refresh" && state.desired && state.phase === "ready" && !state.pending &&
353
+ profileFor(state, config).targets.length > 0) {
354
+ // A settled, ready profile is re-read without leaving ready, as the
355
+ // display, source and receiver are: its target state follows the
356
+ // readings, which reconcile as any reading after ready does.
357
+ commands.push(commandFor(state, config, "observe", 0));
358
+ answerWithReading = true;
359
+ trace("refresh", "observing", "ready", { profile: state.desired.profile });
360
+ }
351
361
  else if (event.kind === "startup" || event.kind === "refresh") {
352
362
  state.observed = {};
353
363
  state.pending = null;
@@ -381,7 +391,7 @@ function transitionActivityLighting(saved, msg, suppliedConfig = {}, nowValue =
381
391
  state.phase = "manual_override";
382
392
  trace("command", "withheld", adopted_request_1.ADOPTED_MISMATCH);
383
393
  }
384
- if (state.desired) {
394
+ if (state.desired && !answerWithReading) {
385
395
  const manual = state.phase === "manual_override";
386
396
  const theatre = (0, target_state_1.targetStateEvent)({
387
397
  target: "lighting",
@@ -180,6 +180,7 @@ function transitionBacklighting(saved, msg, suppliedConfig = {}, nowValue = new
180
180
  // A refresh with the activity's wanted values, reaching a node with
181
181
  // nothing desired (it started with nothing saved): adopt them, and observe
182
182
  // below as at startup (see adopted-request.ts).
183
+ let answerWithReading = false;
183
184
  const adoptable = event.kind === "refresh" ? (0, adopted_request_1.adoptableRefresh)(event, state) : null;
184
185
  if (adoptable && event.kind === "refresh" && typeof event.power === "string" && Object.hasOwn(POWERS, event.power)) {
185
186
  state.desired = { ...adoptable, power: event.power, requestedAt: now.toISOString() };
@@ -228,6 +229,14 @@ function transitionBacklighting(saved, msg, suppliedConfig = {}, nowValue = new
228
229
  trace("command", "emitted", null, { operation: "observe", power: state.desired.power });
229
230
  }
230
231
  }
232
+ else if (event.kind === "refresh" && state.desired && state.phase === "ready" && !state.pending) {
233
+ // A settled, ready target is re-read without leaving ready, as the
234
+ // display, source and receiver are: its target state follows the
235
+ // reading, which classifies as any reading after ready does.
236
+ commands.push(commandFor(state, "observe", 0));
237
+ answerWithReading = true;
238
+ trace("refresh", "observing", "ready", { power: state.desired.power });
239
+ }
231
240
  else if (event.kind === "startup" || event.kind === "refresh") {
232
241
  state.observed = null;
233
242
  state.pending = null;
@@ -258,7 +267,7 @@ function transitionBacklighting(saved, msg, suppliedConfig = {}, nowValue = new
258
267
  state.phase = "manual_override";
259
268
  trace("command", "withheld", adopted_request_1.ADOPTED_MISMATCH);
260
269
  }
261
- if (state.desired) {
270
+ if (state.desired && !answerWithReading) {
262
271
  const theatre = (0, target_state_1.targetStateEvent)({
263
272
  target: "backlighting",
264
273
  requestId: state.desired.requestId,
@@ -290,17 +290,20 @@ function transitionDisplay(saved, msg, suppliedConfig = {}, now = new Date()) {
290
290
  return issueScreen(0);
291
291
  return markReady();
292
292
  }
293
+ // Make before break, as TV mode does: the projector warms up and the
294
+ // screen opens while the TV still shows the picture, which goes to
295
+ // standby last. A projector that fails to start leaves the TV on.
293
296
  if (mode === "projector") {
294
- if (state.observed.tv?.power !== "standby")
295
- return issueTv("standby");
296
- if (!screenAtPosition(state.observed.screen, config.screenOpenPosition, config.screenTolerance)) {
297
- return issueScreen(config.screenOpenPosition);
298
- }
299
297
  if (state.observed.projector?.power !== "on") {
300
298
  if (state.observed.projector?.power === "standby")
301
299
  return issueProjectorStart();
302
300
  return awaitProjectorPower();
303
301
  }
302
+ if (!screenAtPosition(state.observed.screen, config.screenOpenPosition, config.screenTolerance)) {
303
+ return issueScreen(config.screenOpenPosition);
304
+ }
305
+ if (state.observed.tv?.power !== "standby")
306
+ return issueTv("standby");
304
307
  return markReady();
305
308
  }
306
309
  if (state.observed.tv?.power !== "standby")
@@ -421,6 +424,23 @@ function transitionDisplay(saved, msg, suppliedConfig = {}, now = new Date()) {
421
424
  return;
422
425
  }
423
426
  if (now.getTime() >= pending.deadlineAt) {
427
+ // A projector step kept from an older request (see the intent) that
428
+ // never confirmed isn't the newer request's failure: its goal may
429
+ // already be met. Drop it, read the projector afresh, and let the
430
+ // newer request act on what it reports; its own steps fail it, under
431
+ // its own generation, if the projector really is stuck.
432
+ if (state.desired && pending.command.generation !== state.desired.generation) {
433
+ state.pending = null;
434
+ state.seen.projector = false;
435
+ state.querying.projector = true;
436
+ commands.push(queryFor(state, "projector"));
437
+ trace("transition", "dropped", "superseded-operation-unconfirmed", {
438
+ device: pending.device,
439
+ operation: pending.operation,
440
+ generation: pending.command.generation
441
+ });
442
+ return;
443
+ }
424
444
  if (pending.retryable && pending.attempt < config.maxAttempts) {
425
445
  retry(pending, null);
426
446
  return;
@@ -489,7 +509,11 @@ function transitionDisplay(saved, msg, suppliedConfig = {}, now = new Date()) {
489
509
  state.lastAttempt = 0;
490
510
  state.fallbackUsed = false;
491
511
  state.blockedGeneration = null;
492
- state.pending = null;
512
+ // As at startup, a projector power operation in flight (a warm-up, a
513
+ // shutdown or a cool-down) carries on under the new request: a toggle
514
+ // now could switch a warming lamp off or a cooling one back on. The
515
+ // new request's steps follow once it settles.
516
+ state.pending = state.pending && !state.pending.retryable ? state.pending : null;
493
517
  state.seen = { tv: false, screen: false, projector: false };
494
518
  state.querying = { tv: false, screen: false, projector: false };
495
519
  beginDiscovery();
@@ -59,6 +59,11 @@
59
59
 
60
60
  <script type="text/html" data-help-name="home-display-mode-controller">
61
61
  <p>Owns Bravia power, projector lamp power and projector-screen position for <code>off</code>, <code>tv</code> and <code>projector</code> modes.</p>
62
+ <p>Switching between the TV and the projector is make before break, so a source that is already playing keeps a
63
+ picture: for the projector, the lamp starts and warms up, then the screen opens, and the TV goes to standby last;
64
+ for the TV, it comes on before the projector shuts down and the screen closes. If the projector fails to start, the
65
+ TV is left on. A projector warming up or cooling down finishes before a newer request changes it; if it doesn't finish in time, the
66
+ newer request carries on from what the projector then reports.</p>
62
67
  <p>Send <code>msg.display = {kind: "intent", requestId, generation, mode}</code>. Send <code>kind: "startup"</code> after deployment to query every owned device and reconcile persisted intent. Send <code>kind: "refresh"</code> to re-confirm a settled display from fresh readings.</p>
63
68
  <p>The Bravia and both Shelly devices use direct LAN APIs. Output 1 carries the projector power toggle (<code>msg.payload = "power"</code> with <code>msg.display_command</code>) for your infrared transport, commanded directly rather than through Home Assistant. Enable “Projector power is fallback” to include its use in activity metrics. Output 2 emits observed state plus ready, manual-override, failed, rejected and superseded results, and <code>msg.theatre</code> target state for the theatre activity controller: wire it straight back to that controller.</p>
64
69
  <p>An unsolicited physical-state change after readiness latches manual ownership. The controller observes and reports it without issuing corrective commands; a newer activity intent resumes automation.</p>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avantics/node-red-home-automation",
3
- "version": "4.0.1",
3
+ "version": "4.0.3",
4
4
  "description": "Deterministic home automation components for Node-RED",
5
5
  "keywords": [
6
6
  "node-red",