@avantics/node-red-home-automation 3.0.0 → 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 +285 -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/command-echo.d.ts +2 -0
- package/dist/lib/command-echo.js +39 -15
- 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 +10 -0
- package/dist/lib/room-controller.js +68 -59
- 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 +54 -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
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const room_controller_1 = require("../lib/room-controller");
|
|
3
2
|
const circadian_1 = require("../lib/circadian");
|
|
4
3
|
const circadian_schedule_1 = require("../lib/circadian-schedule");
|
|
4
|
+
const publishing_lifecycle_1 = require("./publishing-lifecycle");
|
|
5
|
+
const room_publishing_1 = require("../lib/room-publishing");
|
|
5
6
|
const adapter_1 = require("./adapter");
|
|
7
|
+
const shared_schedule_1 = require("./shared-schedule");
|
|
6
8
|
const settings_1 = require("../lib/settings");
|
|
9
|
+
const ha_discovery_1 = require("../lib/ha-discovery");
|
|
10
|
+
const topic_names_1 = require("../lib/topic-names");
|
|
7
11
|
function parseTargets(value) {
|
|
8
12
|
const targets = (0, settings_1.jsonSetting)(value, "targets", []);
|
|
9
13
|
if (!Array.isArray(targets) || targets.some((target) => {
|
|
@@ -30,14 +34,18 @@ const registerRoomController = (RED) => {
|
|
|
30
34
|
let refreshTimer;
|
|
31
35
|
let controllerConfig;
|
|
32
36
|
let refreshSeconds;
|
|
37
|
+
// A schedule that is set but not running, as when it was deleted: the
|
|
38
|
+
// room keeps to its own times and says so.
|
|
39
|
+
const { schedule: house, missing: houseMissing } = (0, shared_schedule_1.referencedSchedule)(RED, config.houseSchedule);
|
|
33
40
|
try {
|
|
34
41
|
// Not set (null, or absent from a flow saved before these settings)
|
|
35
42
|
// means on, so an older flow keeps publishing as before.
|
|
36
43
|
const publishState = (0, settings_1.optionalBooleanSetting)(config.publishState, "publish state") ?? true;
|
|
37
44
|
const discovery = (0, settings_1.optionalBooleanSetting)(config.discovery, "Home Assistant discovery") ?? true;
|
|
38
|
-
// Both publish under topics and IDs named after the area
|
|
39
|
-
|
|
40
|
-
|
|
45
|
+
// Both publish under topics and IDs named after the area; otherwise the
|
|
46
|
+
// area is only a label.
|
|
47
|
+
if (publishState || discovery)
|
|
48
|
+
(0, topic_names_1.publishingArea)(area, true);
|
|
41
49
|
refreshSeconds = Math.max(10, (0, settings_1.numberSetting)(config.refreshSeconds, "refresh interval", 60));
|
|
42
50
|
// Saved latitude, longitude and minimum settings from earlier versions
|
|
43
51
|
// are ignored.
|
|
@@ -49,8 +57,14 @@ const registerRoomController = (RED) => {
|
|
|
49
57
|
};
|
|
50
58
|
const schedule = (0, circadian_schedule_1.resolveSchedule)((0, settings_1.textSetting)(config.wakeTime, "wake time", "07:00"), (0, settings_1.textSetting)(config.bedTime, "bed time", "23:00"));
|
|
51
59
|
controllerConfig = {
|
|
60
|
+
nodeId: node.id,
|
|
61
|
+
// Not set: a node saved before node IDs, which keeps its area-named
|
|
62
|
+
// entities. The editor gives new nodes "node".
|
|
63
|
+
idScheme: (0, settings_1.optionalChoiceSetting)(config.idScheme, "ID scheme", ha_discovery_1.ID_SCHEMES) ?? "area",
|
|
64
|
+
timesFrom: house ? "house" : "room",
|
|
52
65
|
area,
|
|
53
66
|
displayName: config.displayName || area,
|
|
67
|
+
discoveryPrefix: (0, ha_discovery_1.discoveryPrefixSetting)(config.discoveryPrefix),
|
|
54
68
|
publishState,
|
|
55
69
|
discovery,
|
|
56
70
|
targets: parseTargets(config.targets),
|
|
@@ -59,25 +73,35 @@ const registerRoomController = (RED) => {
|
|
|
59
73
|
initialSleep: (0, settings_1.booleanSetting)(config.initialSleep, "initial sleep", false),
|
|
60
74
|
// The adapter picks the circadian lighting; the controller only asks
|
|
61
75
|
// it how a light should look.
|
|
62
|
-
lighting: (0, circadian_1.scheduledLighting)(schedule, levels)
|
|
76
|
+
lighting: (0, circadian_1.scheduledLighting)(schedule, levels),
|
|
77
|
+
schedule
|
|
63
78
|
};
|
|
64
79
|
}
|
|
65
80
|
catch (error) {
|
|
66
81
|
(0, adapter_1.invalidConfig)(node, error);
|
|
67
82
|
return;
|
|
68
83
|
}
|
|
84
|
+
// Available, and clear of what it no longer publishes, as soon as it
|
|
85
|
+
// runs; offline as it stops; nothing left behind when deleted.
|
|
86
|
+
const lifecycle = (0, publishing_lifecycle_1.publishingLifecycle)(RED, node, {
|
|
87
|
+
retainedTopics: () => (0, room_publishing_1.roomRetainedTopics)(controllerConfig),
|
|
88
|
+
starting: () => (0, room_publishing_1.roomStartingOutputs)(controllerConfig),
|
|
89
|
+
stopping: () => (0, room_publishing_1.roomStoppingOutputs)(controllerConfig),
|
|
90
|
+
output: 0,
|
|
91
|
+
outputs: 1
|
|
92
|
+
});
|
|
69
93
|
function updateStatus(status) {
|
|
70
94
|
node.status({
|
|
71
|
-
fill: status.manualCount ? "yellow" : status.circadianEnabled ? "green" : "grey",
|
|
95
|
+
fill: status.manualCount || houseMissing ? "yellow" : status.circadianEnabled ? "green" : "grey",
|
|
72
96
|
shape: "dot",
|
|
73
|
-
text: (status.circadianEnabled
|
|
97
|
+
text: (houseMissing ? "schedule missing: own times · " : "") + (status.circadianEnabled
|
|
74
98
|
? (status.sleeping ? "sleep" : "circadian")
|
|
75
99
|
: "manual only") + " · " + status.onCount + " on · " + status.manualCount + " manual" +
|
|
76
100
|
(status.overriddenCount ? " · " + status.overriddenCount + " overridden" : "")
|
|
77
101
|
});
|
|
78
102
|
}
|
|
79
103
|
function process(msg, send) {
|
|
80
|
-
const result = (0, adapter_1.runReducer)(node, { area: controllerConfig.area, component: "room-controller" }, (saved, now) => (0,
|
|
104
|
+
const result = (0, adapter_1.runReducer)(node, { area: controllerConfig.area, component: "room-controller" }, (saved, now) => (0, room_publishing_1.publishRoom)(saved, msg, controllerConfig, now));
|
|
81
105
|
if (result.outputs.length) {
|
|
82
106
|
send([result.outputs.map((output) => ({ ...output, payload: output.payload }))]);
|
|
83
107
|
}
|
|
@@ -85,6 +109,9 @@ const registerRoomController = (RED) => {
|
|
|
85
109
|
return result;
|
|
86
110
|
}
|
|
87
111
|
(0, adapter_1.onInput)(node, (msg, send) => {
|
|
112
|
+
// The startup's own announcement comes from publishRoom.
|
|
113
|
+
if ((0, adapter_1.objectField)(msg, "lighting")?.kind === "startup")
|
|
114
|
+
lifecycle.startup(send);
|
|
88
115
|
process({
|
|
89
116
|
lighting: (0, adapter_1.objectField)(msg, "lighting"),
|
|
90
117
|
topic: typeof msg.topic === "string" ? msg.topic : undefined,
|
|
@@ -92,9 +119,41 @@ const registerRoomController = (RED) => {
|
|
|
92
119
|
retain: msg.retain === true
|
|
93
120
|
}, send);
|
|
94
121
|
});
|
|
122
|
+
// Times taken from a house are the house's: a room that no longer follows
|
|
123
|
+
// one, as when its schedule was set to none or deleted, goes back to its
|
|
124
|
+
// own times rather than keeping the house's last ones.
|
|
125
|
+
const roomTrace = { area: controllerConfig.area, component: "room-controller" };
|
|
126
|
+
if (house) {
|
|
127
|
+
node.context().set("followsHouse", true);
|
|
128
|
+
}
|
|
129
|
+
else if (node.context().get("followsHouse") === true) {
|
|
130
|
+
node.context().set("followsHouse", false);
|
|
131
|
+
(0, adapter_1.runReducer)(node, roomTrace, (saved) => ({
|
|
132
|
+
state: { ...saved, schedule: undefined, scheduleSetting: undefined },
|
|
133
|
+
traces: [{ event: "house-schedule", outcome: "changed", reason: "own-times", details: {} }]
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
if (house) {
|
|
137
|
+
// The house's times: once the flows have started, as this room may
|
|
138
|
+
// have restarted alone, and at every change until it stops.
|
|
139
|
+
const follow = (0, adapter_1.guarded)(node, () => {
|
|
140
|
+
process({ lighting: { kind: "schedule", ...house.schedule() } }, node.send.bind(node));
|
|
141
|
+
});
|
|
142
|
+
(0, adapter_1.whenFlowsStarted)(RED, node, follow);
|
|
143
|
+
node.on("close", house.subscribe(follow));
|
|
144
|
+
}
|
|
145
|
+
else if (houseMissing) {
|
|
146
|
+
(0, adapter_1.runReducer)(node, roomTrace, (state) => ({
|
|
147
|
+
state,
|
|
148
|
+
traces: [{ event: "house-schedule", outcome: "ignored", reason: "schedule-missing", details: { schedule: config.houseSchedule } }]
|
|
149
|
+
}));
|
|
150
|
+
node.status({ fill: "yellow", shape: "ring", text: "schedule missing: own times" });
|
|
151
|
+
}
|
|
95
152
|
refreshTimer = setInterval((0, adapter_1.guarded)(node, () => {
|
|
96
153
|
process({ lighting: { kind: "refresh" } }, node.send.bind(node));
|
|
97
154
|
}), refreshSeconds * 1000);
|
|
155
|
+
// Available again as soon as this node runs, as after a redeploy of it
|
|
156
|
+
// alone, rather than waiting for the flow's startup message.
|
|
98
157
|
node.on("close", (_removed, done) => {
|
|
99
158
|
clearInterval(refreshTimer);
|
|
100
159
|
done();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.referencedSchedule = referencedSchedule;
|
|
4
|
+
// The house schedule a node's setting references. Not set (or "", as the
|
|
5
|
+
// editor saves "none") means no schedule; one that is set but isn't running,
|
|
6
|
+
// as when it was deleted or its settings are invalid, is missing.
|
|
7
|
+
function referencedSchedule(RED, id) {
|
|
8
|
+
if (typeof id !== "string" || id === "")
|
|
9
|
+
return { schedule: null, missing: false };
|
|
10
|
+
const node = RED.nodes.getNode(id);
|
|
11
|
+
return typeof node?.subscribe === "function" && typeof node.schedule === "function"
|
|
12
|
+
? { schedule: node, missing: false }
|
|
13
|
+
: { schedule: null, missing: true };
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=shared-schedule.js.map
|
|
@@ -55,9 +55,11 @@ const registerSourceCapabilityController = (RED) => {
|
|
|
55
55
|
schedule(result.state);
|
|
56
56
|
return result;
|
|
57
57
|
}
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
//
|
|
58
|
+
// A pending transition is here only if the node's context survived its
|
|
59
|
+
// stop, which needs a configured context store (see the README); timers
|
|
60
|
+
// never survive. Recover it with the reducer's own startup (re-observe,
|
|
61
|
+
// never replay) rather than ticking old state; a later startup from the
|
|
62
|
+
// flow repeats it.
|
|
61
63
|
if (context.get("state")?.pending) {
|
|
62
64
|
timer = setTimeout((0, adapter_1.guarded)(node, () => {
|
|
63
65
|
process({ sourceCapability: { kind: "startup" } }, node.send.bind(node));
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
name: {value: ""},
|
|
7
7
|
area: {value: ""},
|
|
8
8
|
freshnessMs: {value: 30000, required: true, validate: RED.validators.number()},
|
|
9
|
-
recoveryOffActivity: {value: "off", required: true},
|
|
10
9
|
// User data with no sensible default: empty until the user fills it in,
|
|
11
10
|
// and marked invalid until then, as the runtime rejects it.
|
|
12
11
|
activityProfiles: {value: "{}", required: true, validate: function (v) { try { var parsed = JSON.parse(v); return Boolean(parsed) && typeof parsed === "object" && !Array.isArray(parsed) && Object.keys(parsed).length > 0; } catch (e) { return false; } }}
|
|
@@ -23,12 +22,11 @@
|
|
|
23
22
|
<div class="form-row"><label for="node-input-name">Name</label><input type="text" id="node-input-name"></div>
|
|
24
23
|
<div class="form-row"><label for="node-input-area">Area</label><input type="text" id="node-input-area"></div>
|
|
25
24
|
<div class="form-row"><label for="node-input-freshnessMs">Freshness ms</label><input type="number" id="node-input-freshnessMs"></div>
|
|
26
|
-
<div class="form-row"><label for="node-input-recoveryOffActivity">Recovery Off activity</label><input type="text" id="node-input-recoveryOffActivity"></div>
|
|
27
25
|
<div class="form-row"><label for="node-input-activityProfiles">Profiles JSON</label><input type="text" id="node-input-activityProfiles"></div>
|
|
28
26
|
</script>
|
|
29
27
|
|
|
30
28
|
<script type="text/html" data-help-name="home-theatre-activity-controller">
|
|
31
29
|
<p>Owns latest-request-wins whole-theatre activity state and aggregates generation-scoped target evidence.</p>
|
|
32
30
|
<p>Input <code>msg.theatre</code> accepts activity intent, target-state, startup, refresh, recovery and tick events. Messages without <code>msg.theatre</code>, such as a target controller's own events on the same wire, are ignored. Output 1 emits semantic <code>msg.theatreCommand</code> messages for target owners. Output 2 emits activity events and a complete state snapshot. Device transports remain separate.</p>
|
|
33
|
-
<p>Startup without persisted intent probes physical state. One fresh profile match is adopted without commands
|
|
31
|
+
<p>Startup without persisted intent probes physical state. One fresh profile match is adopted without commands. With no evidence, or more than one match, the activity is unknown and nothing is commanded until the next request, so a redeploy or restart never switches a running activity off. Manual overrides are held without corrective commands and adopted only when the physical state uniquely matches a profile.</p>
|
|
34
32
|
</script>
|
|
@@ -13,8 +13,7 @@ const registerTheatreActivityController = (RED) => {
|
|
|
13
13
|
controllerConfig = {
|
|
14
14
|
area: (0, adapter_1.optionalArea)(config),
|
|
15
15
|
freshnessMs: Math.max(1000, (0, settings_1.numberSetting)(config.freshnessMs, "freshness", 30000)),
|
|
16
|
-
activityProfiles: (0, theatre_activity_controller_1.normaliseActivityProfiles)((0, settings_1.jsonSetting)(config.activityProfiles, "activity profiles", {}))
|
|
17
|
-
recoveryOffActivity: (0, settings_1.textSetting)(config.recoveryOffActivity, "recovery off activity", "off")
|
|
16
|
+
activityProfiles: (0, theatre_activity_controller_1.normaliseActivityProfiles)((0, settings_1.jsonSetting)(config.activityProfiles, "activity profiles", {}))
|
|
18
17
|
};
|
|
19
18
|
}
|
|
20
19
|
catch (error) {
|
|
@@ -7,21 +7,33 @@
|
|
|
7
7
|
category: "home automation",
|
|
8
8
|
color: "#d9c7f1",
|
|
9
9
|
defaults: {
|
|
10
|
-
|
|
11
|
-
//
|
|
10
|
+
// A marker only a node new from the palette has, as core nodes do: import
|
|
11
|
+
// and paste keep the saved name, so onadd leaves a saved node's settings.
|
|
12
|
+
name: {value: "_DEFAULT_"},
|
|
13
|
+
// Required for the default base topic home/<area>/theatre, and for the
|
|
14
|
+
// discovery of a contract saved before node IDs; when set, it needs a
|
|
15
|
+
// letter or digit, from which topics and IDs are made.
|
|
12
16
|
area: {value: "", validate: function (v) {
|
|
13
17
|
var dialog = $("#node-input-discovery").length > 0;
|
|
14
18
|
var discovery = dialog ? $("#node-input-discovery").prop("checked") : on(this.discovery);
|
|
15
19
|
var baseTopic = dialog ? $("#node-input-baseTopic").val() : this.baseTopic;
|
|
16
|
-
|
|
20
|
+
var area = String(v || "").trim();
|
|
21
|
+
// Needed for the default base topic, and for the entities of a
|
|
22
|
+
// contract saved before node IDs.
|
|
23
|
+
var needed = !baseTopic || (discovery && this.idScheme !== "node");
|
|
24
|
+
return area ? /[a-z0-9]/i.test(area) : !needed;
|
|
17
25
|
}},
|
|
18
26
|
// null means "not set": Node-RED fills it into a saved flow from before
|
|
19
27
|
// this setting, which keeps publishing discovery. New nodes start with
|
|
20
28
|
// it off (onadd).
|
|
21
29
|
discovery: {value: null},
|
|
30
|
+
// How Home Assistant IDs are named. null means "not set": a node saved
|
|
31
|
+
// before this setting, which keeps its area-named entities. New nodes
|
|
32
|
+
// name them after the node (onadd), so renaming the area keeps them.
|
|
33
|
+
idScheme: {value: null},
|
|
22
34
|
displayName: {value: ""},
|
|
23
35
|
baseTopic: {value: ""},
|
|
24
|
-
discoveryPrefix: {value: "homeassistant", required: true},
|
|
36
|
+
discoveryPrefix: {value: "homeassistant", required: true, validate: function (v) { var prefix = String(v || "").trim().replace(/^\/+|\/+$/g, ""); return Boolean(prefix) && !/[+#]/.test(prefix); }},
|
|
25
37
|
// User data with no sensible default: empty until the user fills it in,
|
|
26
38
|
// and marked invalid until then, as the runtime rejects it.
|
|
27
39
|
activities: {value: "[]", required: true, validate: function (v) { try { var parsed = JSON.parse(v); return Array.isArray(parsed) && parsed.length > 0; } catch (e) { return false; } }},
|
|
@@ -31,6 +43,9 @@
|
|
|
31
43
|
sloSuccessObjectivePct: {value: 95, required: true, validate: RED.validators.number()}
|
|
32
44
|
},
|
|
33
45
|
onadd: function () {
|
|
46
|
+
if (this.name !== "_DEFAULT_") return;
|
|
47
|
+
this.name = "";
|
|
48
|
+
this.idScheme = "node";
|
|
34
49
|
this.discovery = false;
|
|
35
50
|
},
|
|
36
51
|
oneditprepare: function () {
|
|
@@ -64,7 +79,15 @@
|
|
|
64
79
|
|
|
65
80
|
<script type="text/html" data-help-name="home-theatre-state-contract">
|
|
66
81
|
<p>Bridges non-retained MQTT activity requests to the theatre controller and publishes retained controller truth.</p>
|
|
67
|
-
<p>Requests arrive on <code><base>/request</code> with a request ID and activity. Retained requests are inert. Complete <code>msg.theatre</code> state snapshots publish desired, current, phase,
|
|
82
|
+
<p>Requests arrive on <code><base>/request</code> with a request ID and activity. Retained requests are inert. Complete <code>msg.theatre</code> state snapshots publish desired, current, phase, transition (started and completed times and degraded targets, shown as the
|
|
83
|
+
Phase sensor's attributes in Home Assistant), failure, readiness, operational SLO and per-target health topics. </p>
|
|
84
|
+
<p>With discovery, a contract added since node IDs suggests its <b>Area</b> to Home Assistant for its device, and
|
|
85
|
+
Home Assistant creates an area of that name if none exists. With no area, its entity IDs come from the
|
|
86
|
+
<b>Display name</b> and no area is suggested.</p>
|
|
87
|
+
<p>Once the flows start it publishes a retained <code>online</code> on <code><base>/availability</code>, and
|
|
88
|
+
<code>offline</code> as it stops; its Home Assistant entities follow it. These get through only
|
|
89
|
+
when this node is deployed on its own, so set the MQTT broker node's Birth, Close and Will messages to the same (see the
|
|
90
|
+
README).</p>
|
|
68
91
|
<p>With <b>Home Assistant discovery</b> on, a startup event also publishes discovery for the activity selector and
|
|
69
92
|
status sensors; switched off, it clears them, so Home Assistant removes them. New nodes start with it off; a node
|
|
70
93
|
saved before the setting existed keeps it on.</p>
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const theatre_state_contract_1 = require("../lib/theatre-state-contract");
|
|
3
|
+
const publishing_lifecycle_1 = require("./publishing-lifecycle");
|
|
3
4
|
const adapter_1 = require("./adapter");
|
|
4
5
|
const settings_1 = require("../lib/settings");
|
|
6
|
+
const ha_discovery_1 = require("../lib/ha-discovery");
|
|
5
7
|
const registerTheatreStateContract = (RED) => {
|
|
6
8
|
function HomeTheatreStateContract(config) {
|
|
7
9
|
RED.nodes.createNode(this, config);
|
|
@@ -13,6 +15,10 @@ const registerTheatreStateContract = (RED) => {
|
|
|
13
15
|
try {
|
|
14
16
|
const activities = (0, settings_1.jsonSetting)(config.activities, "activities", []);
|
|
15
17
|
controllerConfig = (0, theatre_state_contract_1.normaliseStateContractConfig)({
|
|
18
|
+
nodeId: node.id,
|
|
19
|
+
// Not set: a node saved before node IDs, which keeps its area-named
|
|
20
|
+
// entities. The editor gives new nodes "node".
|
|
21
|
+
idScheme: (0, settings_1.optionalChoiceSetting)(config.idScheme, "ID scheme", ha_discovery_1.ID_SCHEMES) ?? "area",
|
|
16
22
|
area,
|
|
17
23
|
// Optional, with documented meanings: an empty display name is the
|
|
18
24
|
// area, and an empty base topic is home/<area>/theatre.
|
|
@@ -21,7 +27,7 @@ const registerTheatreStateContract = (RED) => {
|
|
|
21
27
|
// Not set (null, or absent from a flow saved before the setting)
|
|
22
28
|
// means on, so an older flow keeps publishing discovery.
|
|
23
29
|
discovery: (0, settings_1.optionalBooleanSetting)(config.discovery, "Home Assistant discovery") ?? true,
|
|
24
|
-
discoveryPrefix: (0,
|
|
30
|
+
discoveryPrefix: (0, ha_discovery_1.discoveryPrefixSetting)(config.discoveryPrefix),
|
|
25
31
|
activities: (Array.isArray(activities) ? activities.map(String) : activities),
|
|
26
32
|
slo: {
|
|
27
33
|
windowSize: (0, settings_1.numberSetting)(config.sloWindowSize, "SLO window", 20),
|
|
@@ -35,6 +41,15 @@ const registerTheatreStateContract = (RED) => {
|
|
|
35
41
|
(0, adapter_1.invalidConfig)(node, error);
|
|
36
42
|
return;
|
|
37
43
|
}
|
|
44
|
+
// Available, and clear of what it no longer publishes, as soon as it
|
|
45
|
+
// runs; offline as it stops; nothing left behind when deleted.
|
|
46
|
+
const lifecycle = (0, publishing_lifecycle_1.publishingLifecycle)(RED, node, {
|
|
47
|
+
retainedTopics: () => (0, theatre_state_contract_1.theatreRetainedTopics)(controllerConfig),
|
|
48
|
+
starting: () => (0, theatre_state_contract_1.theatreStartingPublications)(controllerConfig),
|
|
49
|
+
stopping: () => (0, theatre_state_contract_1.theatreStoppingPublications)(controllerConfig),
|
|
50
|
+
output: 1,
|
|
51
|
+
outputs: 2
|
|
52
|
+
});
|
|
38
53
|
function process(msg, send) {
|
|
39
54
|
const result = (0, adapter_1.runReducer)(node, { area: controllerConfig.area, component: "theatre-state-contract" }, (saved, now) => (0, theatre_state_contract_1.transitionTheatreStateContract)(saved, msg, controllerConfig, now));
|
|
40
55
|
if (result.requests.length) {
|
|
@@ -54,6 +69,10 @@ const registerTheatreStateContract = (RED) => {
|
|
|
54
69
|
return result;
|
|
55
70
|
}
|
|
56
71
|
(0, adapter_1.onInput)(node, (msg, send) => {
|
|
72
|
+
// The startup's own announcement comes from the contract's transition.
|
|
73
|
+
if ((0, adapter_1.objectField)(msg, "theatreStateContract")?.kind === "startup") {
|
|
74
|
+
lifecycle.startup(send);
|
|
75
|
+
}
|
|
57
76
|
process({
|
|
58
77
|
topic: typeof msg.topic === "string" ? msg.topic : undefined,
|
|
59
78
|
payload: msg.payload,
|
|
@@ -62,9 +81,8 @@ const registerTheatreStateContract = (RED) => {
|
|
|
62
81
|
theatreStateContract: (0, adapter_1.objectField)(msg, "theatreStateContract")
|
|
63
82
|
}, send);
|
|
64
83
|
});
|
|
65
|
-
node
|
|
66
|
-
|
|
67
|
-
});
|
|
84
|
+
// Available again as soon as this node runs, as after a redeploy of it
|
|
85
|
+
// alone, rather than waiting for the flow's startup message.
|
|
68
86
|
}
|
|
69
87
|
RED.nodes.registerType("home-theatre-state-contract", HomeTheatreStateContract);
|
|
70
88
|
};
|