@avantics/node-red-home-automation 3.0.1 → 4.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 +262 -13
- package/dist/lib/activity-lighting-controller.d.ts +7 -1
- package/dist/lib/activity-lighting-controller.js +37 -3
- package/dist/lib/adopted-request.d.ts +26 -0
- package/dist/lib/adopted-request.js +44 -0
- package/dist/lib/avr-controller.d.ts +8 -1
- package/dist/lib/avr-controller.js +27 -3
- package/dist/lib/avr-publishing.d.ts +24 -0
- package/dist/lib/avr-publishing.js +80 -0
- package/dist/lib/backlighting-controller.d.ts +7 -1
- package/dist/lib/backlighting-controller.js +26 -3
- package/dist/lib/circadian.d.ts +1 -0
- package/dist/lib/circadian.js +3 -0
- package/dist/lib/cover-availability.d.ts +7 -0
- package/dist/lib/cover-availability.js +24 -0
- package/dist/lib/cover-controller.d.ts +13 -1
- package/dist/lib/cover-controller.js +113 -30
- package/dist/lib/cover-group.d.ts +62 -0
- package/dist/lib/cover-group.js +125 -0
- package/dist/lib/cover-models.d.ts +37 -0
- package/dist/lib/cover-models.js +83 -0
- package/dist/lib/cover-publishing.d.ts +40 -0
- package/dist/lib/cover-publishing.js +102 -0
- package/dist/lib/cover-requests.d.ts +21 -0
- package/dist/lib/cover-requests.js +49 -0
- package/dist/lib/display-mode-controller.d.ts +4 -0
- package/dist/lib/display-mode-controller.js +26 -2
- package/dist/lib/ha-discovery.d.ts +27 -0
- package/dist/lib/ha-discovery.js +91 -0
- package/dist/lib/house-schedule-publishing.d.ts +23 -0
- package/dist/lib/house-schedule-publishing.js +71 -0
- package/dist/lib/house-schedule.d.ts +23 -0
- package/dist/lib/house-schedule.js +29 -0
- package/dist/lib/motion-policy.d.ts +9 -0
- package/dist/lib/motion-policy.js +45 -11
- package/dist/lib/motion-publishing.d.ts +28 -0
- package/dist/lib/motion-publishing.js +92 -0
- package/dist/lib/occupancy-publishing.d.ts +10 -0
- package/dist/lib/occupancy-publishing.js +45 -0
- package/dist/lib/open-close-cover.d.ts +92 -0
- package/dist/lib/open-close-cover.js +287 -0
- package/dist/lib/publishing-node.d.ts +39 -0
- package/dist/lib/publishing-node.js +72 -0
- package/dist/lib/retained-topics.d.ts +10 -0
- package/dist/lib/retained-topics.js +19 -0
- package/dist/lib/room-controller.d.ts +9 -0
- package/dist/lib/room-controller.js +47 -56
- package/dist/lib/room-lighting-discovery.d.ts +20 -1
- package/dist/lib/room-lighting-discovery.js +135 -13
- package/dist/lib/room-publishing.d.ts +42 -0
- package/dist/lib/room-publishing.js +182 -0
- package/dist/lib/room-schedule.d.ts +8 -0
- package/dist/lib/room-schedule.js +41 -0
- package/dist/lib/settings.d.ts +2 -0
- package/dist/lib/settings.js +20 -0
- package/dist/lib/source-capability-controller.d.ts +8 -1
- package/dist/lib/source-capability-controller.js +29 -3
- package/dist/lib/theatre-activity-controller.d.ts +0 -1
- package/dist/lib/theatre-activity-controller.js +27 -24
- package/dist/lib/theatre-ha-discovery.d.ts +3 -4
- package/dist/lib/theatre-ha-discovery.js +46 -36
- package/dist/lib/theatre-state-contract.d.ts +6 -0
- package/dist/lib/theatre-state-contract.js +83 -47
- package/dist/lib/theatre-state.d.ts +1 -1
- package/dist/lib/theatre-state.js +1 -1
- package/dist/lib/topic-names.d.ts +4 -0
- package/dist/lib/topic-names.js +31 -0
- package/dist/nodes/activity-lighting-controller.js +5 -3
- package/dist/nodes/adapter.d.ts +6 -1
- package/dist/nodes/adapter.js +65 -1
- package/dist/nodes/avr-controller.html +59 -5
- package/dist/nodes/avr-controller.js +74 -4
- package/dist/nodes/backlighting-controller.js +5 -3
- package/dist/nodes/cover-controller.d.ts +3 -0
- package/dist/nodes/cover-controller.html +177 -0
- package/dist/nodes/cover-controller.js +178 -0
- package/dist/nodes/cover-group.d.ts +3 -0
- package/dist/nodes/cover-group.html +89 -0
- package/dist/nodes/cover-group.js +84 -0
- package/dist/nodes/flows-started.d.ts +4 -0
- package/dist/nodes/flows-started.js +39 -0
- package/dist/nodes/house-schedule-mqtt.d.ts +3 -0
- package/dist/nodes/house-schedule-mqtt.html +61 -0
- package/dist/nodes/house-schedule-mqtt.js +80 -0
- package/dist/nodes/house-schedule.d.ts +3 -0
- package/dist/nodes/house-schedule.html +31 -0
- package/dist/nodes/house-schedule.js +51 -0
- package/dist/nodes/motion-policy.html +81 -5
- package/dist/nodes/motion-policy.js +69 -8
- package/dist/nodes/occupancy-fusion.html +69 -14
- package/dist/nodes/occupancy-fusion.js +46 -4
- package/dist/nodes/publishing-lifecycle.d.ts +25 -0
- package/dist/nodes/publishing-lifecycle.js +38 -0
- package/dist/nodes/room-controller.html +49 -5
- package/dist/nodes/room-controller.js +67 -8
- package/dist/nodes/shared-schedule.d.ts +6 -0
- package/dist/nodes/shared-schedule.js +15 -0
- package/dist/nodes/source-capability-controller.js +5 -3
- package/dist/nodes/theatre-activity-controller.html +1 -3
- package/dist/nodes/theatre-activity-controller.js +1 -2
- package/dist/nodes/theatre-state-contract.html +28 -5
- package/dist/nodes/theatre-state-contract.js +22 -4
- package/examples/Cover control.json +380 -0
- package/examples/Cover pair.json +230 -0
- package/examples/Home theatre activity.json +4 -4
- package/examples/House schedule.json +164 -0
- package/examples/Room lighting.json +4 -3
- package/package.json +6 -2
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.savedSchedule = savedSchedule;
|
|
4
|
+
exports.withActiveSchedule = withActiveSchedule;
|
|
5
|
+
exports.requestedSchedule = requestedSchedule;
|
|
6
|
+
// The room's wake and bed times while it runs: the configured times, or times
|
|
7
|
+
// set at runtime (from Home Assistant, say), which last until the node is
|
|
8
|
+
// deployed with a different setting for them. And the room's lighting on
|
|
9
|
+
// whichever times are in use.
|
|
10
|
+
const circadian_schedule_1 = require("./circadian-schedule");
|
|
11
|
+
const settings_1 = require("./settings");
|
|
12
|
+
function configuredSchedule(config) {
|
|
13
|
+
return config.schedule ?? { wakeTime: circadian_schedule_1.DEFAULT_WAKE_TIME, bedTime: circadian_schedule_1.DEFAULT_BED_TIME };
|
|
14
|
+
}
|
|
15
|
+
// Each saved time stands only while the setting it was based on is
|
|
16
|
+
// unchanged; state saved before times could change takes the settings.
|
|
17
|
+
function savedSchedule(config, saved) {
|
|
18
|
+
const setting = configuredSchedule(config);
|
|
19
|
+
const kept = (key) => (0, settings_1.keptOverride)(saved.schedule?.[key], saved.scheduleSetting?.[key], setting[key]);
|
|
20
|
+
return { schedule: { wakeTime: kept("wakeTime"), bedTime: kept("bedTime") }, scheduleSetting: { ...setting } };
|
|
21
|
+
}
|
|
22
|
+
// The room's settings with lighting that follows the times in use.
|
|
23
|
+
function withActiveSchedule(config, state) {
|
|
24
|
+
const setting = configuredSchedule(config);
|
|
25
|
+
const same = state.schedule.wakeTime === setting.wakeTime && state.schedule.bedTime === setting.bedTime;
|
|
26
|
+
if (same)
|
|
27
|
+
return config;
|
|
28
|
+
return { ...config, lighting: config.lighting.withSchedule(state.schedule) };
|
|
29
|
+
}
|
|
30
|
+
// New times from a "schedule" message, each "HH:MM", with a time left out
|
|
31
|
+
// staying as it is; null if they aren't valid, different times.
|
|
32
|
+
function requestedSchedule(current, event) {
|
|
33
|
+
const next = {
|
|
34
|
+
wakeTime: typeof event.wakeTime === "string" ? event.wakeTime.trim() : current.wakeTime,
|
|
35
|
+
bedTime: typeof event.bedTime === "string" ? event.bedTime.trim() : current.bedTime
|
|
36
|
+
};
|
|
37
|
+
const wake = (0, circadian_schedule_1.clockMinutes)(next.wakeTime);
|
|
38
|
+
const bed = (0, circadian_schedule_1.clockMinutes)(next.bedTime);
|
|
39
|
+
return wake === null || bed === null || wake === bed ? null : next;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=room-schedule.js.map
|
package/dist/lib/settings.d.ts
CHANGED
|
@@ -3,3 +3,5 @@ export declare function booleanSetting(value: unknown, label: string, fallback:
|
|
|
3
3
|
export declare function optionalBooleanSetting(value: unknown, label: string): boolean | null;
|
|
4
4
|
export declare function textSetting(value: unknown, label: string, fallback?: string): string;
|
|
5
5
|
export declare function jsonSetting(value: unknown, label: string, fallback: unknown): unknown;
|
|
6
|
+
export declare function optionalChoiceSetting<Choice extends string>(value: unknown, label: string, choices: readonly Choice[]): Choice | null;
|
|
7
|
+
export declare function keptOverride<Value extends string | number>(savedValue: unknown, savedSetting: unknown, setting: Value): Value;
|
package/dist/lib/settings.js
CHANGED
|
@@ -5,6 +5,8 @@ exports.booleanSetting = booleanSetting;
|
|
|
5
5
|
exports.optionalBooleanSetting = optionalBooleanSetting;
|
|
6
6
|
exports.textSetting = textSetting;
|
|
7
7
|
exports.jsonSetting = jsonSetting;
|
|
8
|
+
exports.optionalChoiceSetting = optionalChoiceSetting;
|
|
9
|
+
exports.keptOverride = keptOverride;
|
|
8
10
|
// A numeric node setting, read from the editor's value. A setting absent from
|
|
9
11
|
// a flow saved before it existed takes its default. Anything else must be a
|
|
10
12
|
// number: an emptied field, null or text is an error naming the setting, so
|
|
@@ -65,4 +67,22 @@ function jsonSetting(value, label, fallback) {
|
|
|
65
67
|
}
|
|
66
68
|
throw new Error(`${label} must be valid JSON`);
|
|
67
69
|
}
|
|
70
|
+
// One of a fixed set of words, such as a scheme name. Absent or null is "not
|
|
71
|
+
// set" (null), for the caller to give its documented meaning; anything else
|
|
72
|
+
// that isn't one of the choices is an error naming them.
|
|
73
|
+
function optionalChoiceSetting(value, label, choices) {
|
|
74
|
+
if (value === undefined || value === null)
|
|
75
|
+
return null;
|
|
76
|
+
if (typeof value === "string" && choices.includes(value))
|
|
77
|
+
return value;
|
|
78
|
+
throw new Error(`${label} must be ${choices.slice(0, -1).join(", ")}${choices.length > 1 ? " or " : ""}${choices.at(-1)}`);
|
|
79
|
+
}
|
|
80
|
+
// The rule for a value set at runtime (from Home Assistant, say) over a
|
|
81
|
+
// setting: it lasts until the node is deployed with a different setting,
|
|
82
|
+
// which then applies. `savedSetting` is the setting the saved value was
|
|
83
|
+
// based on; state saved before such values were recorded has none, so the
|
|
84
|
+
// setting applies.
|
|
85
|
+
function keptOverride(savedValue, savedSetting, setting) {
|
|
86
|
+
return savedSetting === setting && typeof savedValue === typeof setting ? savedValue : setting;
|
|
87
|
+
}
|
|
68
88
|
//# sourceMappingURL=settings.js.map
|
|
@@ -54,6 +54,7 @@ export interface SourceState {
|
|
|
54
54
|
lastAttempt: number;
|
|
55
55
|
fallbackUsed: boolean;
|
|
56
56
|
refreshAsked: boolean;
|
|
57
|
+
adoptedGeneration: number | null;
|
|
57
58
|
}
|
|
58
59
|
export type SourceEvent = {
|
|
59
60
|
kind: "intent";
|
|
@@ -79,7 +80,13 @@ export type SourceEvent = {
|
|
|
79
80
|
kind: "tick";
|
|
80
81
|
generation: number;
|
|
81
82
|
} | {
|
|
82
|
-
kind: "startup"
|
|
83
|
+
kind: "startup";
|
|
84
|
+
} | {
|
|
85
|
+
kind: "refresh";
|
|
86
|
+
requestId?: string | null;
|
|
87
|
+
generation?: number;
|
|
88
|
+
sourceId?: string | null;
|
|
89
|
+
action?: string;
|
|
83
90
|
};
|
|
84
91
|
export interface SourceMessage {
|
|
85
92
|
sourceCapability?: SourceEvent;
|
|
@@ -4,6 +4,7 @@ exports.normaliseCapabilities = normaliseCapabilities;
|
|
|
4
4
|
exports.normaliseConfig = normaliseConfig;
|
|
5
5
|
exports.readinessEvidence = readinessEvidence;
|
|
6
6
|
exports.transitionSource = transitionSource;
|
|
7
|
+
const adopted_request_1 = require("./adopted-request");
|
|
7
8
|
const settings_1 = require("./settings");
|
|
8
9
|
const observation_time_1 = require("./observation-time");
|
|
9
10
|
const target_state_1 = require("./target-state");
|
|
@@ -110,7 +111,8 @@ function initialState(saved = {}, sources = {}) {
|
|
|
110
111
|
? saved.lastAttempt
|
|
111
112
|
: 0,
|
|
112
113
|
fallbackUsed: saved.fallbackUsed === true,
|
|
113
|
-
refreshAsked: saved.refreshAsked === true
|
|
114
|
+
refreshAsked: saved.refreshAsked === true,
|
|
115
|
+
adoptedGeneration: (0, adopted_request_1.savedAdoptedGeneration)(saved)
|
|
114
116
|
};
|
|
115
117
|
}
|
|
116
118
|
function commandFor(state, operation, attempt = 1) {
|
|
@@ -272,10 +274,13 @@ function transitionSource(saved, msg, suppliedConfig = {}, nowValue = new Date()
|
|
|
272
274
|
required: readiness.required
|
|
273
275
|
});
|
|
274
276
|
}
|
|
275
|
-
else if (state.phase === "ready" && !state.pending) {
|
|
277
|
+
else if ((state.phase === "ready" && !state.pending) || (0, adopted_request_1.isAdopted)(state)) {
|
|
278
|
+
// A change seen after ready, or an adopted request the source doesn't
|
|
279
|
+
// match: someone else's, and never corrected.
|
|
280
|
+
state.pending = null;
|
|
276
281
|
state.classification = "manual_override";
|
|
277
282
|
state.phase = "manual_override";
|
|
278
|
-
trace("observation", "manual_override", null, {
|
|
283
|
+
trace("observation", "manual_override", (0, adopted_request_1.isAdopted)(state) ? adopted_request_1.ADOPTED_MISMATCH : null, {
|
|
279
284
|
sourceId: state.desired.sourceId,
|
|
280
285
|
status: state.observed.status
|
|
281
286
|
});
|
|
@@ -435,6 +440,18 @@ function transitionSource(saved, msg, suppliedConfig = {}, nowValue = new Date()
|
|
|
435
440
|
trace("command", "emitted", null, { sourceId: state.desired.sourceId, operation: "observe" });
|
|
436
441
|
}
|
|
437
442
|
}
|
|
443
|
+
// A refresh with the activity's wanted values, reaching a node with
|
|
444
|
+
// nothing desired (it started with nothing saved): adopt them, and observe
|
|
445
|
+
// below as at startup (see adopted-request.ts).
|
|
446
|
+
const adoptable = event.kind === "refresh" ? (0, adopted_request_1.adoptableRefresh)(event, state) : null;
|
|
447
|
+
if (adoptable && event.kind === "refresh" && typeof event.action === "string" && Object.hasOwn(ACTIONS, event.action) &&
|
|
448
|
+
((typeof event.sourceId === "string" && Object.hasOwn(config.sources, event.sourceId)) ||
|
|
449
|
+
(!event.sourceId && event.action === "deactivate"))) {
|
|
450
|
+
state.desired = { ...adoptable, sourceId: event.sourceId || null, action: event.action };
|
|
451
|
+
state.generation = adoptable.generation;
|
|
452
|
+
state.adoptedGeneration = adoptable.generation;
|
|
453
|
+
trace("refresh", "adopted", "nothing-desired", { sourceId: event.sourceId || null, action: event.action, generation: adoptable.generation });
|
|
454
|
+
}
|
|
438
455
|
if (event.kind === "intent") {
|
|
439
456
|
acceptIntent(event);
|
|
440
457
|
}
|
|
@@ -485,6 +502,15 @@ function transitionSource(saved, msg, suppliedConfig = {}, nowValue = new Date()
|
|
|
485
502
|
throw new Error("unknown source capability event kind");
|
|
486
503
|
}
|
|
487
504
|
// A refresh of a settled source reports nothing until its reading arrives.
|
|
505
|
+
// An adopted request only reads the source (see adopted-request.ts).
|
|
506
|
+
const held = (0, adopted_request_1.readsOnly)(state, commands, (command) => command.operation === "observe");
|
|
507
|
+
if (held.mismatch) {
|
|
508
|
+
commands.splice(0, commands.length, ...held.commands);
|
|
509
|
+
state.pending = null;
|
|
510
|
+
state.classification = "manual_override";
|
|
511
|
+
state.phase = "manual_override";
|
|
512
|
+
trace("command", "withheld", adopted_request_1.ADOPTED_MISMATCH);
|
|
513
|
+
}
|
|
488
514
|
const outputEvent = event.kind === "refresh" && state.refreshAsked ? null : targetEvent(state, now, config.sources);
|
|
489
515
|
if (outputEvent)
|
|
490
516
|
events.push(outputEvent);
|
|
@@ -18,13 +18,11 @@ var theatre_state_2 = require("./theatre-state");
|
|
|
18
18
|
Object.defineProperty(exports, "createTheatreState", { enumerable: true, get: function () { return theatre_state_2.createTheatreState; } });
|
|
19
19
|
function normaliseConfig(config = {}) {
|
|
20
20
|
const activityProfiles = (0, theatre_profiles_1.normaliseActivityProfiles)(config.activityProfiles);
|
|
21
|
-
const recoveryOffActivity = (0, settings_1.textSetting)(config.recoveryOffActivity, "recovery off activity", "off");
|
|
22
21
|
return {
|
|
23
22
|
// Optional: an empty area means none.
|
|
24
23
|
area: typeof config.area === "string" ? config.area.trim() : "",
|
|
25
24
|
freshnessMs: Math.max(1000, (0, settings_1.numberSetting)(config.freshnessMs, "freshness", 30000)),
|
|
26
|
-
activityProfiles
|
|
27
|
-
recoveryOffActivity
|
|
25
|
+
activityProfiles
|
|
28
26
|
};
|
|
29
27
|
}
|
|
30
28
|
function targetCommand(target, kind, desired, values = {}) {
|
|
@@ -51,8 +49,15 @@ function targetIntentCommands(desired, config, previousDesired) {
|
|
|
51
49
|
return targetCommand(target, "intent", desired, values);
|
|
52
50
|
});
|
|
53
51
|
}
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
// A refresh carries the activity's wanted values for the target, as its
|
|
53
|
+
// intent did, so a target node that has nothing desired (it started with
|
|
54
|
+
// nothing saved) can adopt them and observe, instead of staying idle.
|
|
55
|
+
function targetRefreshCommand(target, desired, config) {
|
|
56
|
+
const values = desired ? config.activityProfiles[desired.activity]?.[target] ?? {} : {};
|
|
57
|
+
return targetCommand(target, "refresh", desired, values);
|
|
58
|
+
}
|
|
59
|
+
function targetRefreshCommands(desired, config) {
|
|
60
|
+
return theatre_profiles_1.TARGETS.map((target) => targetRefreshCommand(target, desired, config));
|
|
56
61
|
}
|
|
57
62
|
function targetProbeCommands() {
|
|
58
63
|
return theatre_profiles_1.TARGETS.map((target) => targetCommand(target, "refresh", null));
|
|
@@ -287,7 +292,7 @@ function transitionTheatre(saved, msg, suppliedConfig = {}, nowValue = new Date(
|
|
|
287
292
|
noResponse(action.target);
|
|
288
293
|
continue;
|
|
289
294
|
}
|
|
290
|
-
commands.push(
|
|
295
|
+
commands.push(targetRefreshCommand(action.target, state.desired, config));
|
|
291
296
|
if (action.kind === "retry")
|
|
292
297
|
trace("refresh", "retried", null, { target: action.target, attempt: action.attempt });
|
|
293
298
|
if (action.kind === "re-ask")
|
|
@@ -309,7 +314,7 @@ function transitionTheatre(saved, msg, suppliedConfig = {}, nowValue = new Date(
|
|
|
309
314
|
};
|
|
310
315
|
}
|
|
311
316
|
}
|
|
312
|
-
function acceptIntent(event
|
|
317
|
+
function acceptIntent(event) {
|
|
313
318
|
if (typeof event.requestId !== "string" || !event.requestId) {
|
|
314
319
|
throw new Error("theatre requestId is required");
|
|
315
320
|
}
|
|
@@ -326,7 +331,7 @@ function transitionTheatre(saved, msg, suppliedConfig = {}, nowValue = new Date(
|
|
|
326
331
|
// already taken (for example by a recovery) gets the next free one.
|
|
327
332
|
let generation = event.generation;
|
|
328
333
|
const taken = generation < state.generation || (generation === state.generation && state.desired !== null);
|
|
329
|
-
if (taken &&
|
|
334
|
+
if (taken && state.desired?.requestId !== event.requestId &&
|
|
330
335
|
event.generation > state.lastProposedGeneration) {
|
|
331
336
|
generation = state.generation + 1;
|
|
332
337
|
trace("intent", "reassigned", "generation-taken", { requestId: event.requestId, proposed: event.generation, assigned: generation });
|
|
@@ -368,8 +373,7 @@ function transitionTheatre(saved, msg, suppliedConfig = {}, nowValue = new Date(
|
|
|
368
373
|
requestedAt
|
|
369
374
|
};
|
|
370
375
|
state.generation = generation;
|
|
371
|
-
|
|
372
|
-
state.lastProposedGeneration = Math.max(state.lastProposedGeneration, event.generation);
|
|
376
|
+
state.lastProposedGeneration = Math.max(state.lastProposedGeneration, event.generation);
|
|
373
377
|
state.phase = "preparing";
|
|
374
378
|
state.currentActivity = "unknown";
|
|
375
379
|
state.targets = (0, theatre_state_1.emptyTargets)();
|
|
@@ -501,22 +505,21 @@ function transitionTheatre(saved, msg, suppliedConfig = {}, nowValue = new Date(
|
|
|
501
505
|
return;
|
|
502
506
|
}
|
|
503
507
|
if (event.reason === "startup") {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
emit("recovery_safe_off", {
|
|
508
|
+
// No evidence, or more than one match: the activity is unknown, and
|
|
509
|
+
// nothing is commanded until the next request. Starting with nothing
|
|
510
|
+
// saved happens on a redeploy without a context store, so it must never
|
|
511
|
+
// switch a running activity off.
|
|
512
|
+
state.refreshPending = (0, theatre_state_1.emptyRefreshPending)();
|
|
513
|
+
state.phase = "idle";
|
|
514
|
+
state.currentActivity = "unknown";
|
|
515
|
+
state.availability = "unknown";
|
|
516
|
+
state.metrics.recoveriesUnknown += 1;
|
|
517
|
+
state.metrics.lastOutcome = "recovery_unknown";
|
|
518
|
+
emit("recovery_unknown", {
|
|
516
519
|
matchCount: matches.length,
|
|
517
520
|
matchedActivities: matches
|
|
518
521
|
});
|
|
519
|
-
trace("recovery", "
|
|
522
|
+
trace("recovery", "unknown", matches.length ? "ambiguous" : "no-clean-match", {
|
|
520
523
|
matchedActivities: matches
|
|
521
524
|
});
|
|
522
525
|
return;
|
|
@@ -546,7 +549,7 @@ function transitionTheatre(saved, msg, suppliedConfig = {}, nowValue = new Date(
|
|
|
546
549
|
state.targets = (0, theatre_state_1.emptyTargets)();
|
|
547
550
|
state.refreshPending = (0, theatre_state_1.emptyRefreshPending)();
|
|
548
551
|
if (state.desired) {
|
|
549
|
-
commands.push(...targetRefreshCommands(state.desired));
|
|
552
|
+
commands.push(...targetRefreshCommands(state.desired, config));
|
|
550
553
|
for (const target of theatre_profiles_1.TARGETS)
|
|
551
554
|
state.refreshPending[target] = { sentAt: nowMs, attempts: 1, exhausted: false };
|
|
552
555
|
state.phase = state.blockedGeneration === state.generation ? "failed" : "confirming";
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
+
import { type DiscoveryOwner } from "./ha-discovery";
|
|
1
2
|
import { type TheatreTarget } from "./theatre-profiles";
|
|
2
|
-
export type TheatreTopicName = "request" | "desired" | "current" | "phase" | "availability" | "failure" | "metrics" | "slo" | "slo/breach" | `health/${TheatreTarget}`;
|
|
3
|
+
export type TheatreTopicName = "request" | "desired" | "current" | "phase" | "transition" | "availability" | "readiness" | "failure" | "metrics" | "slo" | "slo/breach" | `health/${TheatreTarget}`;
|
|
3
4
|
export declare function theatreTopic(baseTopic: string, name: TheatreTopicName): string;
|
|
4
|
-
export interface TheatreDiscoveryConfig {
|
|
5
|
-
area: string;
|
|
5
|
+
export interface TheatreDiscoveryConfig extends DiscoveryOwner {
|
|
6
6
|
displayName: string;
|
|
7
7
|
baseTopic: string;
|
|
8
|
-
discoveryPrefix: string;
|
|
9
8
|
activities: string[];
|
|
10
9
|
}
|
|
11
10
|
export declare function theatreDiscovery(config: TheatreDiscoveryConfig): Array<{
|
|
@@ -5,30 +5,37 @@ exports.theatreDiscovery = theatreDiscovery;
|
|
|
5
5
|
// The theatre's Home Assistant view: the topic names its state is published
|
|
6
6
|
// on, and the discovery entries that describe them. Home Assistant may send
|
|
7
7
|
// a request on the request topic, which the state contract acts on.
|
|
8
|
+
const ha_discovery_1 = require("./ha-discovery");
|
|
8
9
|
const theatre_profiles_1 = require("./theatre-profiles");
|
|
9
10
|
// The one place a theatre topic is named, for discovery and state alike.
|
|
10
11
|
function theatreTopic(baseTopic, name) {
|
|
11
12
|
return `${baseTopic}/${name}`;
|
|
12
13
|
}
|
|
14
|
+
// Under the node scheme the area is optional: entity IDs then come from the
|
|
15
|
+
// display name.
|
|
16
|
+
function namedArea(config) {
|
|
17
|
+
return config.area || config.displayName;
|
|
18
|
+
}
|
|
13
19
|
function device(config) {
|
|
14
20
|
return {
|
|
15
|
-
|
|
21
|
+
...(0, ha_discovery_1.discoveryDevice)(config, "theatre"),
|
|
22
|
+
// Only an area the user typed: Home Assistant creates an area of that name
|
|
23
|
+
// if none exists, so a display name such as "Home Cinema" would make one.
|
|
24
|
+
...(config.idScheme === "node" && config.area ? { suggested_area: config.area } : {}),
|
|
16
25
|
name: `${config.displayName} Theatre Controller`,
|
|
17
26
|
manufacturer: "Node-RED",
|
|
18
27
|
model: "Deterministic theatre activity controller"
|
|
19
28
|
};
|
|
20
29
|
}
|
|
21
|
-
function
|
|
22
|
-
const {
|
|
30
|
+
function theatreEntries(config) {
|
|
31
|
+
const { baseTopic } = config;
|
|
23
32
|
const controllerDevice = device(config);
|
|
24
33
|
const entries = [
|
|
25
34
|
{
|
|
26
35
|
component: "select",
|
|
27
|
-
|
|
36
|
+
entity: `theatre_activity`,
|
|
28
37
|
payload: {
|
|
29
38
|
name: "Requested activity",
|
|
30
|
-
unique_id: `${area}_theatre_activity`,
|
|
31
|
-
default_entity_id: `select.${area}_theatre_activity`,
|
|
32
39
|
icon: "mdi:theater",
|
|
33
40
|
command_topic: theatreTopic(baseTopic, "request"),
|
|
34
41
|
state_topic: theatreTopic(baseTopic, "desired"),
|
|
@@ -41,11 +48,9 @@ function theatreDiscovery(config) {
|
|
|
41
48
|
},
|
|
42
49
|
{
|
|
43
50
|
component: "sensor",
|
|
44
|
-
|
|
51
|
+
entity: `theatre_current`,
|
|
45
52
|
payload: {
|
|
46
53
|
name: "Current activity",
|
|
47
|
-
unique_id: `${area}_theatre_current`,
|
|
48
|
-
default_entity_id: `sensor.${area}_theatre_current`,
|
|
49
54
|
icon: "mdi:play-circle-outline",
|
|
50
55
|
state_topic: theatreTopic(baseTopic, "current"),
|
|
51
56
|
device: controllerDevice
|
|
@@ -53,36 +58,33 @@ function theatreDiscovery(config) {
|
|
|
53
58
|
},
|
|
54
59
|
{
|
|
55
60
|
component: "sensor",
|
|
56
|
-
|
|
61
|
+
entity: `theatre_phase`,
|
|
57
62
|
payload: {
|
|
58
63
|
name: "Phase",
|
|
59
|
-
unique_id: `${area}_theatre_phase`,
|
|
60
|
-
default_entity_id: `sensor.${area}_theatre_phase`,
|
|
61
64
|
icon: "mdi:state-machine",
|
|
62
65
|
state_topic: theatreTopic(baseTopic, "phase"),
|
|
66
|
+
json_attributes_topic: theatreTopic(baseTopic, "transition"),
|
|
63
67
|
device: controllerDevice
|
|
64
68
|
}
|
|
65
69
|
},
|
|
66
70
|
{
|
|
67
71
|
component: "sensor",
|
|
68
|
-
|
|
72
|
+
entity: `theatre_availability`,
|
|
69
73
|
payload: {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
74
|
+
// Named "Readiness" so it isn't mistaken for Home Assistant's own
|
|
75
|
+
// availability; it keeps its entity name, so its entity ID carries over.
|
|
76
|
+
name: "Readiness",
|
|
73
77
|
icon: "mdi:check-network-outline",
|
|
74
|
-
state_topic: theatreTopic(baseTopic, "
|
|
78
|
+
state_topic: theatreTopic(baseTopic, "readiness"),
|
|
75
79
|
entity_category: "diagnostic",
|
|
76
80
|
device: controllerDevice
|
|
77
81
|
}
|
|
78
82
|
},
|
|
79
83
|
{
|
|
80
84
|
component: "sensor",
|
|
81
|
-
|
|
85
|
+
entity: `theatre_failure`,
|
|
82
86
|
payload: {
|
|
83
87
|
name: "Failure",
|
|
84
|
-
unique_id: `${area}_theatre_failure`,
|
|
85
|
-
default_entity_id: `sensor.${area}_theatre_failure`,
|
|
86
88
|
icon: "mdi:alert-circle-outline",
|
|
87
89
|
state_topic: theatreTopic(baseTopic, "failure"),
|
|
88
90
|
value_template: "{{ value_json.reason if value_json else '' }}",
|
|
@@ -92,11 +94,9 @@ function theatreDiscovery(config) {
|
|
|
92
94
|
},
|
|
93
95
|
{
|
|
94
96
|
component: "sensor",
|
|
95
|
-
|
|
97
|
+
entity: `theatre_transition_metrics`,
|
|
96
98
|
payload: {
|
|
97
99
|
name: "Transition latency",
|
|
98
|
-
unique_id: `${area}_theatre_transition_metrics`,
|
|
99
|
-
default_entity_id: `sensor.${area}_theatre_transition_metrics`,
|
|
100
100
|
icon: "mdi:timer-check-outline",
|
|
101
101
|
state_topic: theatreTopic(baseTopic, "metrics"),
|
|
102
102
|
value_template: "{{ value_json.lastTransitionMs if value_json.lastTransitionMs is not none else 'unknown' }}",
|
|
@@ -108,11 +108,9 @@ function theatreDiscovery(config) {
|
|
|
108
108
|
},
|
|
109
109
|
{
|
|
110
110
|
component: "sensor",
|
|
111
|
-
|
|
111
|
+
entity: `theatre_slo_status`,
|
|
112
112
|
payload: {
|
|
113
113
|
name: "Operational SLO",
|
|
114
|
-
unique_id: `${area}_theatre_slo_status`,
|
|
115
|
-
default_entity_id: `sensor.${area}_theatre_slo_status`,
|
|
116
114
|
icon: "mdi:target-account",
|
|
117
115
|
state_topic: theatreTopic(baseTopic, "slo"),
|
|
118
116
|
value_template: "{{ value_json.status }}",
|
|
@@ -123,11 +121,9 @@ function theatreDiscovery(config) {
|
|
|
123
121
|
},
|
|
124
122
|
{
|
|
125
123
|
component: "binary_sensor",
|
|
126
|
-
|
|
124
|
+
entity: `theatre_slo_breach`,
|
|
127
125
|
payload: {
|
|
128
126
|
name: "Operational SLO breach",
|
|
129
|
-
unique_id: `${area}_theatre_slo_breach`,
|
|
130
|
-
default_entity_id: `binary_sensor.${area}_theatre_slo_breach`,
|
|
131
127
|
icon: "mdi:alert-decagram-outline",
|
|
132
128
|
state_topic: theatreTopic(baseTopic, "slo/breach"),
|
|
133
129
|
payload_on: "ON",
|
|
@@ -141,11 +137,9 @@ function theatreDiscovery(config) {
|
|
|
141
137
|
for (const target of theatre_profiles_1.TARGETS) {
|
|
142
138
|
entries.push({
|
|
143
139
|
component: "sensor",
|
|
144
|
-
|
|
140
|
+
entity: `theatre_${target}_health`,
|
|
145
141
|
payload: {
|
|
146
142
|
name: `${target[0]?.toUpperCase()}${target.slice(1)} health`,
|
|
147
|
-
unique_id: `${area}_theatre_${target}_health`,
|
|
148
|
-
default_entity_id: `sensor.${area}_theatre_${target}_health`,
|
|
149
143
|
icon: "mdi:heart-pulse",
|
|
150
144
|
state_topic: theatreTopic(baseTopic, `health/${target}`),
|
|
151
145
|
value_template: "{{ value_json.status }}",
|
|
@@ -155,9 +149,25 @@ function theatreDiscovery(config) {
|
|
|
155
149
|
}
|
|
156
150
|
});
|
|
157
151
|
}
|
|
158
|
-
return entries
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
})
|
|
152
|
+
return entries;
|
|
153
|
+
}
|
|
154
|
+
function theatreDiscovery(config) {
|
|
155
|
+
return theatreEntries(config).map(({ component, entity, payload }) => {
|
|
156
|
+
const ids = (0, ha_discovery_1.discoveryEntity)(config.idScheme === "node" ? { ...config, area: namedArea(config) } : config, component, entity);
|
|
157
|
+
// The IDs follow the name, as they always have, so an area-scheme entry
|
|
158
|
+
// is the same, byte for byte, as before the schemes existed.
|
|
159
|
+
const { name, ...rest } = payload;
|
|
160
|
+
return {
|
|
161
|
+
topic: ids.topic,
|
|
162
|
+
payload: {
|
|
163
|
+
name,
|
|
164
|
+
unique_id: ids.uniqueId,
|
|
165
|
+
default_entity_id: ids.defaultEntityId,
|
|
166
|
+
...rest,
|
|
167
|
+
availability_topic: theatreTopic(config.baseTopic, "availability"),
|
|
168
|
+
origin: ha_discovery_1.DISCOVERY_ORIGIN
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
});
|
|
162
172
|
}
|
|
163
173
|
//# sourceMappingURL=theatre-ha-discovery.js.map
|
|
@@ -2,7 +2,10 @@ import { type TheatreTarget } from "./theatre-profiles";
|
|
|
2
2
|
import type { TheatreMetrics, TheatreSnapshot } from "./theatre-state";
|
|
3
3
|
import { type TheatreSloConfig, type TheatreSloState } from "./theatre-slo";
|
|
4
4
|
import type { TraceEntry } from "./bounded-trace";
|
|
5
|
+
import { type IdScheme } from "./ha-discovery";
|
|
5
6
|
export interface TheatreStateContractConfig {
|
|
7
|
+
nodeId?: string;
|
|
8
|
+
idScheme?: IdScheme;
|
|
6
9
|
area: string;
|
|
7
10
|
displayName: string;
|
|
8
11
|
baseTopic: string;
|
|
@@ -53,6 +56,9 @@ export interface ContractRequestOutput {
|
|
|
53
56
|
};
|
|
54
57
|
}
|
|
55
58
|
export declare function normaliseStateContractConfig(config?: Partial<TheatreStateContractConfig>): TheatreStateContractConfig;
|
|
59
|
+
export declare function theatreRetainedTopics(config: TheatreStateContractConfig): string[];
|
|
60
|
+
export declare function theatreStartingPublications(config: TheatreStateContractConfig): ContractPublication[];
|
|
61
|
+
export declare function theatreStoppingPublications(config: TheatreStateContractConfig): ContractPublication[];
|
|
56
62
|
export declare function transitionTheatreStateContract(saved: Partial<TheatreStateContractState> | undefined, msg: TheatreStateContractMessage, suppliedConfig: Partial<TheatreStateContractConfig>, nowValue?: Date | string | number): {
|
|
57
63
|
state: TheatreStateContractState;
|
|
58
64
|
requests: ContractRequestOutput[];
|