@avantics/node-red-home-automation 2.3.0 → 3.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 +32 -8
- package/contract-examples/room-lighting.mjs +12 -7
- package/dist/lib/activity-lighting-controller.d.ts +13 -25
- package/dist/lib/activity-lighting-controller.js +15 -11
- package/dist/lib/avr-controller.d.ts +13 -47
- package/dist/lib/avr-controller.js +39 -90
- package/dist/lib/backlighting-controller.d.ts +12 -25
- package/dist/lib/backlighting-controller.js +11 -18
- package/dist/lib/bounded-trace.d.ts +6 -0
- package/dist/lib/command-echo.d.ts +20 -0
- package/dist/lib/command-echo.js +82 -0
- package/dist/lib/cover-controller.d.ts +15 -28
- package/dist/lib/cover-controller.js +6 -8
- package/dist/lib/denon-protocol.d.ts +29 -0
- package/dist/lib/denon-protocol.js +76 -0
- package/dist/lib/display-mode-controller.d.ts +7 -18
- package/dist/lib/display-mode-controller.js +39 -47
- package/dist/lib/motion-policy.d.ts +12 -22
- package/dist/lib/motion-policy.js +53 -56
- package/dist/lib/occupancy-fusion.d.ts +8 -12
- package/dist/lib/room-controller.d.ts +14 -34
- package/dist/lib/room-controller.js +80 -132
- package/dist/lib/room-lighting-discovery.d.ts +9 -0
- package/dist/lib/room-lighting-discovery.js +45 -0
- package/dist/lib/settings.d.ts +5 -0
- package/dist/lib/settings.js +68 -0
- package/dist/lib/source-capability-controller.d.ts +30 -35
- package/dist/lib/source-capability-controller.js +35 -36
- package/dist/lib/switch-policy.d.ts +2 -7
- package/dist/lib/target-state.d.ts +24 -0
- package/dist/lib/target-state.js +38 -0
- package/dist/lib/theatre-activity-controller.d.ts +6 -108
- package/dist/lib/theatre-activity-controller.js +67 -318
- package/dist/lib/theatre-ha-discovery.d.ts +14 -0
- package/dist/lib/theatre-ha-discovery.js +163 -0
- package/dist/lib/theatre-metrics.d.ts +4 -0
- package/dist/lib/theatre-metrics.js +66 -0
- package/dist/lib/theatre-profiles.d.ts +23 -0
- package/dist/lib/theatre-profiles.js +73 -0
- package/dist/lib/theatre-refresh.d.ts +20 -0
- package/dist/lib/theatre-refresh.js +46 -0
- package/dist/lib/theatre-slo.js +7 -9
- package/dist/lib/theatre-state-contract.d.ts +7 -19
- package/dist/lib/theatre-state-contract.js +33 -169
- package/dist/lib/theatre-state.d.ts +110 -0
- package/dist/lib/theatre-state.js +139 -0
- package/dist/lib/wall-input.d.ts +2 -7
- package/dist/lib/z2m-light.d.ts +16 -0
- package/dist/lib/z2m-light.js +36 -0
- package/dist/nodes/activity-lighting-controller.html +5 -3
- package/dist/nodes/activity-lighting-controller.js +21 -52
- package/dist/nodes/adapter.d.ts +15 -0
- package/dist/nodes/adapter.js +60 -0
- package/dist/nodes/avr-controller.html +3 -3
- package/dist/nodes/avr-controller.js +17 -56
- package/dist/nodes/backlighting-controller.html +1 -1
- package/dist/nodes/backlighting-controller.js +25 -47
- package/dist/nodes/display-mode-controller.html +2 -2
- package/dist/nodes/display-mode-controller.js +19 -57
- package/dist/nodes/motion-policy.html +23 -10
- package/dist/nodes/motion-policy.js +14 -135
- package/dist/nodes/occupancy-fusion.html +2 -2
- package/dist/nodes/occupancy-fusion.js +23 -29
- package/dist/nodes/room-controller.html +80 -26
- package/dist/nodes/room-controller.js +37 -54
- package/dist/nodes/source-capability-controller.html +4 -13
- package/dist/nodes/source-capability-controller.js +17 -52
- package/dist/nodes/switch-policy.html +3 -3
- package/dist/nodes/switch-policy.js +23 -42
- package/dist/nodes/theatre-activity-controller.html +4 -2
- package/dist/nodes/theatre-activity-controller.js +18 -45
- package/dist/nodes/theatre-state-contract.html +55 -22
- package/dist/nodes/theatre-state-contract.js +30 -41
- package/examples/Home theatre activity.json +13 -12
- package/examples/Home theatre equipment.json +4 -4
- package/examples/Room lighting.json +9 -9
- package/package.json +1 -1
- package/dist/lib/circadian-refresh.d.ts +0 -7
- package/dist/lib/circadian-refresh.js +0 -11
|
@@ -1,31 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const bounded_trace_1 = require("../lib/bounded-trace");
|
|
3
2
|
const activity_lighting_controller_1 = require("../lib/activity-lighting-controller");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return Number.isFinite(parsed) ? parsed : fallback;
|
|
7
|
-
}
|
|
3
|
+
const adapter_1 = require("./adapter");
|
|
4
|
+
const settings_1 = require("../lib/settings");
|
|
8
5
|
const registerActivityLightingController = (RED) => {
|
|
9
6
|
function HomeActivityLightingController(config) {
|
|
10
7
|
RED.nodes.createNode(this, config);
|
|
11
8
|
const node = this;
|
|
12
9
|
const context = node.context();
|
|
13
10
|
let timer;
|
|
14
|
-
let
|
|
11
|
+
let controllerConfig;
|
|
15
12
|
try {
|
|
16
|
-
|
|
13
|
+
controllerConfig = {
|
|
14
|
+
profiles: (0, activity_lighting_controller_1.normaliseLightingProfiles)((0, settings_1.jsonSetting)(config.profiles, "profiles", {})),
|
|
15
|
+
owner: (0, settings_1.textSetting)(config.owner, "owner", "activity"),
|
|
16
|
+
confirmationTimeoutMs: (0, settings_1.numberSetting)(config.confirmationTimeoutMs, "confirmation timeout", 15000),
|
|
17
|
+
maxAttempts: (0, settings_1.numberSetting)(config.maxAttempts, "max attempts", 2)
|
|
18
|
+
};
|
|
17
19
|
}
|
|
18
20
|
catch (error) {
|
|
19
|
-
|
|
20
|
-
node.error(error);
|
|
21
|
+
(0, adapter_1.invalidConfig)(node, error);
|
|
21
22
|
return;
|
|
22
23
|
}
|
|
23
|
-
const controllerConfig = {
|
|
24
|
-
profiles,
|
|
25
|
-
owner: config.owner || "activity",
|
|
26
|
-
confirmationTimeoutMs: number(config.confirmationTimeoutMs, 15000),
|
|
27
|
-
maxAttempts: number(config.maxAttempts, 2)
|
|
28
|
-
};
|
|
29
24
|
function updateStatus(status) {
|
|
30
25
|
const appearances = {
|
|
31
26
|
idle: { fill: "grey", shape: "dot" },
|
|
@@ -43,24 +38,12 @@ const registerActivityLightingController = (RED) => {
|
|
|
43
38
|
if (!state.pending?.deadlineAt)
|
|
44
39
|
return;
|
|
45
40
|
const delay = Math.max(0, state.pending.deadlineAt - Date.now());
|
|
46
|
-
timer = setTimeout(() => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
node.error(error);
|
|
52
|
-
}
|
|
53
|
-
}, delay);
|
|
41
|
+
timer = setTimeout((0, adapter_1.guarded)(node, () => {
|
|
42
|
+
process({ activityLighting: { kind: "tick", generation: state.generation } }, node.send.bind(node));
|
|
43
|
+
}), delay);
|
|
54
44
|
}
|
|
55
45
|
function process(msg, send) {
|
|
56
|
-
const
|
|
57
|
-
const saved = context.get("state");
|
|
58
|
-
const result = (0, activity_lighting_controller_1.transitionActivityLighting)(saved, msg, controllerConfig, now);
|
|
59
|
-
context.set("state", result.state);
|
|
60
|
-
(0, bounded_trace_1.appendTrace)(context, {
|
|
61
|
-
area: config.area || "lounge",
|
|
62
|
-
component: "activity-lighting-controller"
|
|
63
|
-
}, result.traces, now);
|
|
46
|
+
const result = (0, adapter_1.runReducer)(node, { area: (0, adapter_1.optionalArea)(config), component: "activity-lighting-controller" }, (saved, now) => (0, activity_lighting_controller_1.transitionActivityLighting)(saved, msg, controllerConfig, now));
|
|
64
47
|
if (result.commands.length) {
|
|
65
48
|
send([
|
|
66
49
|
result.commands.map((activityLightingCommand) => ({
|
|
@@ -82,28 +65,14 @@ const registerActivityLightingController = (RED) => {
|
|
|
82
65
|
// transition with the reducer's own startup (re-observe, never replay)
|
|
83
66
|
// rather than ticking old state; a later startup from the flow repeats it.
|
|
84
67
|
if (context.get("state")?.pending) {
|
|
85
|
-
timer = setTimeout(() => {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
node.error(error);
|
|
91
|
-
}
|
|
92
|
-
}, 0);
|
|
68
|
+
timer = setTimeout((0, adapter_1.guarded)(node, () => {
|
|
69
|
+
process({ activityLighting: { kind: "startup" } }, node.send.bind(node));
|
|
70
|
+
}), 0);
|
|
93
71
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
? msg.activityLighting
|
|
99
|
-
: undefined
|
|
100
|
-
}, send);
|
|
101
|
-
done();
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
node.error(error, msg);
|
|
105
|
-
done(error instanceof Error ? error : new Error(String(error)));
|
|
106
|
-
}
|
|
72
|
+
(0, adapter_1.onInput)(node, (msg, send) => {
|
|
73
|
+
process({
|
|
74
|
+
activityLighting: (0, adapter_1.objectField)(msg, "activityLighting")
|
|
75
|
+
}, send);
|
|
107
76
|
});
|
|
108
77
|
node.on("close", (_removed, done) => {
|
|
109
78
|
clearTimeout(timer);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Node, NodeMessage } from "node-red";
|
|
2
|
+
import { type TraceInput, type TraceMetadata } from "../lib/bounded-trace";
|
|
3
|
+
export type Send = (msg: NodeMessage | Array<NodeMessage | NodeMessage[] | null>) => void;
|
|
4
|
+
export type InputMessage = NodeMessage & Record<string, unknown>;
|
|
5
|
+
export declare function objectField<T>(msg: InputMessage, key: string): T | undefined;
|
|
6
|
+
export declare function onInput(node: Node, handle: (msg: InputMessage, send: Send) => void): void;
|
|
7
|
+
export declare function guarded(node: Node, work: () => void): () => void;
|
|
8
|
+
export declare function runReducer<Saved, Result extends {
|
|
9
|
+
state: unknown;
|
|
10
|
+
traces: TraceInput[];
|
|
11
|
+
}>(node: Node, trace: TraceMetadata, reduce: (saved: Saved | undefined, now: Date) => Result): Result;
|
|
12
|
+
export declare function optionalArea(config: {
|
|
13
|
+
area?: unknown;
|
|
14
|
+
}): string;
|
|
15
|
+
export declare function invalidConfig(node: Node, reason: unknown): void;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.objectField = objectField;
|
|
4
|
+
exports.onInput = onInput;
|
|
5
|
+
exports.guarded = guarded;
|
|
6
|
+
exports.runReducer = runReducer;
|
|
7
|
+
exports.optionalArea = optionalArea;
|
|
8
|
+
exports.invalidConfig = invalidConfig;
|
|
9
|
+
const bounded_trace_1 = require("../lib/bounded-trace");
|
|
10
|
+
// The object a message carries under a key, or undefined.
|
|
11
|
+
function objectField(msg, key) {
|
|
12
|
+
const value = msg[key];
|
|
13
|
+
return value && typeof value === "object" ? value : undefined;
|
|
14
|
+
}
|
|
15
|
+
// Handle each input; an error is reported against the message and ends it.
|
|
16
|
+
function onInput(node, handle) {
|
|
17
|
+
node.on("input", (msg, send, done) => {
|
|
18
|
+
try {
|
|
19
|
+
handle(msg, send);
|
|
20
|
+
done();
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
node.error(error, msg);
|
|
24
|
+
done(error instanceof Error ? error : new Error(String(error)));
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
// Work run from a timer, with any error reported on the node.
|
|
29
|
+
function guarded(node, work) {
|
|
30
|
+
return () => {
|
|
31
|
+
try {
|
|
32
|
+
work();
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
node.error(error);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
// Run a reducer on the node's saved state, save the new state and append its
|
|
40
|
+
// traces.
|
|
41
|
+
function runReducer(node, trace, reduce) {
|
|
42
|
+
const context = node.context();
|
|
43
|
+
const now = new Date();
|
|
44
|
+
const result = reduce(context.get("state"), now);
|
|
45
|
+
context.set("state", result.state);
|
|
46
|
+
(0, bounded_trace_1.appendTrace)(context, trace, result.traces, now);
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
// A node's area. Most nodes only use it as a label, so it is optional and an
|
|
50
|
+
// empty one means no area; there is never a default.
|
|
51
|
+
function optionalArea(config) {
|
|
52
|
+
return typeof config.area === "string" ? config.area.trim() : "";
|
|
53
|
+
}
|
|
54
|
+
// The one badge for a configuration the node cannot use, with the reason in
|
|
55
|
+
// the log.
|
|
56
|
+
function invalidConfig(node, reason) {
|
|
57
|
+
node.status({ fill: "red", shape: "ring", text: "invalid configuration" });
|
|
58
|
+
node.error("invalid configuration: " + (reason instanceof Error ? reason.message : String(reason)));
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
color: "#c7d9f1",
|
|
5
5
|
defaults: {
|
|
6
6
|
name: {value: ""},
|
|
7
|
-
area: {value: "
|
|
8
|
-
sources: {value: "{\"shield\":\"SAT/CBL\",\"playstation\":\"GAME\"}", required: true},
|
|
7
|
+
area: {value: ""},
|
|
8
|
+
sources: {value: "{\"shield\":\"SAT/CBL\",\"playstation\":\"GAME\"}", required: true, validate: function (v) { try { JSON.parse(v); return true; } catch (e) { return false; } }},
|
|
9
9
|
retryMs: {value: 2000, required: true, validate: RED.validators.number()},
|
|
10
10
|
maxAttempts: {value: 3, required: true, validate: RED.validators.number()},
|
|
11
11
|
minVolume: {value: 0, required: true, validate: RED.validators.number()},
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
outputs: 2,
|
|
16
16
|
outputLabels: ["Denon commands", "state and results"],
|
|
17
17
|
icon: "font-awesome/fa-volume-up",
|
|
18
|
-
label: function () { return this.name || this.area + " AVR controller"; }
|
|
18
|
+
label: function () { return this.name || (this.area ? this.area + " " : "") + "AVR controller"; }
|
|
19
19
|
});
|
|
20
20
|
</script>
|
|
21
21
|
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const bounded_trace_1 = require("../lib/bounded-trace");
|
|
3
2
|
const avr_controller_1 = require("../lib/avr-controller");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return Number.isFinite(parsed) ? parsed : fallback;
|
|
7
|
-
}
|
|
3
|
+
const adapter_1 = require("./adapter");
|
|
4
|
+
const settings_1 = require("../lib/settings");
|
|
8
5
|
function parseSources(value) {
|
|
9
|
-
const sources =
|
|
6
|
+
const sources = (0, settings_1.jsonSetting)(value, "sources", {});
|
|
10
7
|
if (!sources || Array.isArray(sources) || typeof sources !== "object") {
|
|
11
8
|
throw new Error("sources must be a JSON object");
|
|
12
9
|
}
|
|
@@ -22,20 +19,10 @@ const registerAvrController = (RED) => {
|
|
|
22
19
|
try {
|
|
23
20
|
// The same validation the reducer applies, so a bad configuration
|
|
24
21
|
// fails here at deploy rather than on every message.
|
|
25
|
-
controllerConfig = (0, avr_controller_1.normaliseAvrConfig)({
|
|
26
|
-
area: config.area || "room",
|
|
27
|
-
sources: parseSources(config.sources),
|
|
28
|
-
retryMs: Math.max(250, number(config.retryMs, 2000)),
|
|
29
|
-
maxAttempts: Math.max(1, Math.floor(number(config.maxAttempts, 3))),
|
|
30
|
-
minVolume: number(config.minVolume, 0),
|
|
31
|
-
maxVolume: number(config.maxVolume, 60)
|
|
32
|
-
});
|
|
22
|
+
controllerConfig = (0, avr_controller_1.normaliseAvrConfig)({ ...config, area: (0, adapter_1.optionalArea)(config), sources: parseSources(config.sources) });
|
|
33
23
|
}
|
|
34
24
|
catch (error) {
|
|
35
|
-
|
|
36
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
37
|
-
node.status({ fill: "red", shape: "ring", text: "invalid configuration" });
|
|
38
|
-
node.error("invalid configuration: " + reason);
|
|
25
|
+
(0, adapter_1.invalidConfig)(node, error);
|
|
39
26
|
return;
|
|
40
27
|
}
|
|
41
28
|
function updateStatus(status) {
|
|
@@ -56,24 +43,12 @@ const registerAvrController = (RED) => {
|
|
|
56
43
|
if (!state.pending?.deadlineAt)
|
|
57
44
|
return;
|
|
58
45
|
const delay = Math.max(0, state.pending.deadlineAt - Date.now());
|
|
59
|
-
retryTimer = setTimeout(() => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
node.error(error);
|
|
65
|
-
}
|
|
66
|
-
}, delay);
|
|
46
|
+
retryTimer = setTimeout((0, adapter_1.guarded)(node, () => {
|
|
47
|
+
process({ avr: { kind: "tick" } }, node.send.bind(node));
|
|
48
|
+
}), delay);
|
|
67
49
|
}
|
|
68
50
|
function process(msg, send) {
|
|
69
|
-
const
|
|
70
|
-
const saved = context.get("state");
|
|
71
|
-
const result = (0, avr_controller_1.transitionAvr)(saved, msg, controllerConfig, now);
|
|
72
|
-
context.set("state", result.state);
|
|
73
|
-
(0, bounded_trace_1.appendTrace)(context, {
|
|
74
|
-
area: controllerConfig.area,
|
|
75
|
-
component: "avr-controller"
|
|
76
|
-
}, result.traces, now);
|
|
51
|
+
const result = (0, adapter_1.runReducer)(node, { area: controllerConfig.area, component: "avr-controller" }, (saved, now) => (0, avr_controller_1.transitionAvr)(saved, msg, controllerConfig, now));
|
|
77
52
|
const commands = result.commands.map((command) => ({
|
|
78
53
|
payload: Buffer.from(command.payload, "utf8"),
|
|
79
54
|
avr_command: command.avrCommand
|
|
@@ -95,29 +70,15 @@ const registerAvrController = (RED) => {
|
|
|
95
70
|
// transition with the reducer's own startup (re-observe, never replay)
|
|
96
71
|
// rather than ticking old state; a later startup from the flow repeats it.
|
|
97
72
|
if (context.get("state")?.pending) {
|
|
98
|
-
retryTimer = setTimeout(() => {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
catch (error) {
|
|
103
|
-
node.error(error);
|
|
104
|
-
}
|
|
105
|
-
}, 0);
|
|
73
|
+
retryTimer = setTimeout((0, adapter_1.guarded)(node, () => {
|
|
74
|
+
process({ avr: { kind: "startup" } }, node.send.bind(node));
|
|
75
|
+
}), 0);
|
|
106
76
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
: undefined,
|
|
113
|
-
payload: msg.payload
|
|
114
|
-
}, send);
|
|
115
|
-
done();
|
|
116
|
-
}
|
|
117
|
-
catch (error) {
|
|
118
|
-
node.error(error, msg);
|
|
119
|
-
done(error instanceof Error ? error : new Error(String(error)));
|
|
120
|
-
}
|
|
77
|
+
(0, adapter_1.onInput)(node, (msg, send) => {
|
|
78
|
+
process({
|
|
79
|
+
avr: (0, adapter_1.objectField)(msg, "avr"),
|
|
80
|
+
payload: msg.payload
|
|
81
|
+
}, send);
|
|
121
82
|
});
|
|
122
83
|
node.on("close", (_removed, done) => {
|
|
123
84
|
clearTimeout(retryTimer);
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
color: "#c7d9f1",
|
|
5
5
|
defaults: {
|
|
6
6
|
name: {value: ""},
|
|
7
|
-
area: {value: "
|
|
7
|
+
area: {value: ""},
|
|
8
8
|
pollMs: {value: 2000, required: true, validate: RED.validators.number()},
|
|
9
9
|
confirmationTimeoutMs: {value: 15000, required: true, validate: RED.validators.number()},
|
|
10
10
|
maxAttempts: {value: 2, required: true, validate: RED.validators.number()}
|
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const bounded_trace_1 = require("../lib/bounded-trace");
|
|
3
2
|
const backlighting_controller_1 = require("../lib/backlighting-controller");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return Number.isFinite(parsed) ? parsed : fallback;
|
|
7
|
-
}
|
|
3
|
+
const adapter_1 = require("./adapter");
|
|
4
|
+
const settings_1 = require("../lib/settings");
|
|
8
5
|
const registerBacklightingController = (RED) => {
|
|
9
6
|
function HomeBacklightingController(config) {
|
|
10
7
|
RED.nodes.createNode(this, config);
|
|
11
8
|
const node = this;
|
|
12
9
|
const context = node.context();
|
|
13
10
|
let timer;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
let controllerConfig;
|
|
12
|
+
try {
|
|
13
|
+
controllerConfig = {
|
|
14
|
+
pollMs: (0, settings_1.numberSetting)(config.pollMs, "poll interval", 2000),
|
|
15
|
+
confirmationTimeoutMs: (0, settings_1.numberSetting)(config.confirmationTimeoutMs, "confirmation timeout", 15000),
|
|
16
|
+
maxAttempts: (0, settings_1.numberSetting)(config.maxAttempts, "max attempts", 2)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
(0, adapter_1.invalidConfig)(node, error);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
19
23
|
function updateStatus(status) {
|
|
20
24
|
const appearances = {
|
|
21
25
|
idle: { fill: "grey", shape: "dot" },
|
|
@@ -34,24 +38,12 @@ const registerBacklightingController = (RED) => {
|
|
|
34
38
|
return;
|
|
35
39
|
const dueAt = Math.min(state.pending.nextAt, state.pending.deadlineAt);
|
|
36
40
|
const delay = Math.max(0, dueAt - Date.now());
|
|
37
|
-
timer = setTimeout(() => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
node.error(error);
|
|
43
|
-
}
|
|
44
|
-
}, delay);
|
|
41
|
+
timer = setTimeout((0, adapter_1.guarded)(node, () => {
|
|
42
|
+
process({ backlighting: { kind: "tick", generation: state.generation } }, node.send.bind(node));
|
|
43
|
+
}), delay);
|
|
45
44
|
}
|
|
46
45
|
function process(msg, send) {
|
|
47
|
-
const
|
|
48
|
-
const saved = context.get("state");
|
|
49
|
-
const result = (0, backlighting_controller_1.transitionBacklighting)(saved, msg, controllerConfig, now);
|
|
50
|
-
context.set("state", result.state);
|
|
51
|
-
(0, bounded_trace_1.appendTrace)(context, {
|
|
52
|
-
area: config.area || "lounge",
|
|
53
|
-
component: "backlighting-controller"
|
|
54
|
-
}, result.traces, now);
|
|
46
|
+
const result = (0, adapter_1.runReducer)(node, { area: (0, adapter_1.optionalArea)(config), component: "backlighting-controller" }, (saved, now) => (0, backlighting_controller_1.transitionBacklighting)(saved, msg, controllerConfig, now));
|
|
55
47
|
if (result.commands.length) {
|
|
56
48
|
send([
|
|
57
49
|
result.commands.map((backlightingCommand) => ({ payload: undefined, backlightingCommand })),
|
|
@@ -69,28 +61,14 @@ const registerBacklightingController = (RED) => {
|
|
|
69
61
|
// transition with the reducer's own startup (re-observe, never replay)
|
|
70
62
|
// rather than ticking old state; a later startup from the flow repeats it.
|
|
71
63
|
if (context.get("state")?.pending) {
|
|
72
|
-
timer = setTimeout(() => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
node.error(error);
|
|
78
|
-
}
|
|
79
|
-
}, 0);
|
|
64
|
+
timer = setTimeout((0, adapter_1.guarded)(node, () => {
|
|
65
|
+
process({ backlighting: { kind: "startup" } }, node.send.bind(node));
|
|
66
|
+
}), 0);
|
|
80
67
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
? msg.backlighting
|
|
86
|
-
: undefined
|
|
87
|
-
}, send);
|
|
88
|
-
done();
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
node.error(error, msg);
|
|
92
|
-
done(error instanceof Error ? error : new Error(String(error)));
|
|
93
|
-
}
|
|
68
|
+
(0, adapter_1.onInput)(node, (msg, send) => {
|
|
69
|
+
process({
|
|
70
|
+
backlighting: (0, adapter_1.objectField)(msg, "backlighting")
|
|
71
|
+
}, send);
|
|
94
72
|
});
|
|
95
73
|
node.on("close", (_removed, done) => {
|
|
96
74
|
clearTimeout(timer);
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
color: "#c7d9f1",
|
|
5
5
|
defaults: {
|
|
6
6
|
name: {value: ""},
|
|
7
|
-
area: {value: "
|
|
7
|
+
area: {value: ""},
|
|
8
8
|
tvHost: {value: "", required: true},
|
|
9
9
|
screenHost: {value: "", required: true},
|
|
10
10
|
projectorMeterHost: {value: "", required: true},
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
outputs: 2,
|
|
30
30
|
outputLabels: ["projector IR fallback", "state and results"],
|
|
31
31
|
icon: "font-awesome/fa-television",
|
|
32
|
-
label: function () { return this.name || this.area + " display mode"; }
|
|
32
|
+
label: function () { return this.name || (this.area ? this.area + " " : "") + "display mode"; }
|
|
33
33
|
});
|
|
34
34
|
</script>
|
|
35
35
|
|
|
@@ -1,47 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const bounded_trace_1 = require("../lib/bounded-trace");
|
|
3
2
|
const display_mode_controller_1 = require("../lib/display-mode-controller");
|
|
4
3
|
const display_transport_1 = require("../lib/display-transport");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return Number.isFinite(parsed) ? parsed : fallback;
|
|
8
|
-
}
|
|
4
|
+
const adapter_1 = require("./adapter");
|
|
5
|
+
const settings_1 = require("../lib/settings");
|
|
9
6
|
const registerDisplayModeController = (RED) => {
|
|
10
7
|
function HomeDisplayModeController(config) {
|
|
11
8
|
RED.nodes.createNode(this, config);
|
|
12
9
|
const node = this;
|
|
13
|
-
const context = node.context();
|
|
14
10
|
let timer;
|
|
15
11
|
let closed = false;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
screenTolerance: number(config.screenTolerance, 2),
|
|
19
|
-
pollMs: number(config.pollMs, 2000),
|
|
20
|
-
queryTimeoutMs: number(config.queryTimeoutMs, 5000),
|
|
21
|
-
tvTimeoutMs: number(config.tvTimeoutMs, 30000),
|
|
22
|
-
screenTimeoutMs: number(config.screenTimeoutMs, 65000),
|
|
23
|
-
projectorWarmupMs: number(config.projectorWarmupMs, 60000),
|
|
24
|
-
projectorMinimumWarmupMs: number(config.projectorMinimumWarmupMs, 15000),
|
|
25
|
-
projectorShutdownConfirmMs: number(config.projectorShutdownConfirmMs, 5000),
|
|
26
|
-
projectorCooldownMs: number(config.projectorCooldownMs, 120000),
|
|
27
|
-
maxAttempts: number(config.maxAttempts, 2),
|
|
28
|
-
projectorOnWatts: number(config.projectorOnWatts, 20),
|
|
29
|
-
projectorOffWatts: number(config.projectorOffWatts, 10),
|
|
30
|
-
projectorPowerFallback: config.projectorPowerFallback === true
|
|
31
|
-
};
|
|
12
|
+
// Defaults and limits come from the reducer's own normalisation.
|
|
13
|
+
let controllerConfig;
|
|
32
14
|
let transport;
|
|
33
15
|
try {
|
|
16
|
+
controllerConfig = (0, display_mode_controller_1.normaliseConfig)(config);
|
|
34
17
|
transport = new display_transport_1.DisplayTransport({
|
|
35
|
-
|
|
18
|
+
// No defaults: these name the user's own devices.
|
|
19
|
+
tvHost: (0, settings_1.textSetting)(config.tvHost, "TV host"),
|
|
36
20
|
tvPsk: String(node.credentials?.tvPsk ?? ""),
|
|
37
|
-
screenHost:
|
|
38
|
-
projectorMeterHost:
|
|
39
|
-
timeoutMs:
|
|
21
|
+
screenHost: (0, settings_1.textSetting)(config.screenHost, "screen host"),
|
|
22
|
+
projectorMeterHost: (0, settings_1.textSetting)(config.projectorMeterHost, "projector meter host"),
|
|
23
|
+
timeoutMs: (0, settings_1.numberSetting)(config.transportTimeoutMs, "transport timeout", 5000)
|
|
40
24
|
});
|
|
41
25
|
}
|
|
42
26
|
catch (error) {
|
|
43
|
-
|
|
44
|
-
node.error(error);
|
|
27
|
+
(0, adapter_1.invalidConfig)(node, error);
|
|
45
28
|
return;
|
|
46
29
|
}
|
|
47
30
|
function updateStatus(status) {
|
|
@@ -63,14 +46,9 @@ const registerDisplayModeController = (RED) => {
|
|
|
63
46
|
return;
|
|
64
47
|
const delay = Math.max(0, state.pending.nextAt - Date.now());
|
|
65
48
|
const generation = state.desired?.generation || state.generation;
|
|
66
|
-
timer = setTimeout(() => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
node.error(error);
|
|
72
|
-
}
|
|
73
|
-
}, delay);
|
|
49
|
+
timer = setTimeout((0, adapter_1.guarded)(node, () => {
|
|
50
|
+
process({ display: { kind: "tick", generation } }, node.send.bind(node));
|
|
51
|
+
}), delay);
|
|
74
52
|
}
|
|
75
53
|
async function dispatch(command) {
|
|
76
54
|
if (command.device === "projector" && command.operation === "power_toggle") {
|
|
@@ -85,14 +63,7 @@ const registerDisplayModeController = (RED) => {
|
|
|
85
63
|
process(result, node.send.bind(node));
|
|
86
64
|
}
|
|
87
65
|
function process(msg, send) {
|
|
88
|
-
const
|
|
89
|
-
const saved = context.get("state");
|
|
90
|
-
const result = (0, display_mode_controller_1.transitionDisplay)(saved, msg, controllerConfig, now);
|
|
91
|
-
context.set("state", result.state);
|
|
92
|
-
(0, bounded_trace_1.appendTrace)(context, {
|
|
93
|
-
area: config.area || "lounge",
|
|
94
|
-
component: "display-mode-controller"
|
|
95
|
-
}, result.traces, now);
|
|
66
|
+
const result = (0, adapter_1.runReducer)(node, { area: (0, adapter_1.optionalArea)(config), component: "display-mode-controller" }, (saved, now) => (0, display_mode_controller_1.transitionDisplay)(saved, msg, controllerConfig, now));
|
|
96
67
|
const outputs = [...result.events, ...result.targetStates];
|
|
97
68
|
if (outputs.length) {
|
|
98
69
|
send([null, outputs.map((event) => ({ payload: undefined, ...event }))]);
|
|
@@ -104,19 +75,10 @@ const registerDisplayModeController = (RED) => {
|
|
|
104
75
|
}
|
|
105
76
|
return result;
|
|
106
77
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
? msg.display
|
|
112
|
-
: undefined
|
|
113
|
-
}, send);
|
|
114
|
-
done();
|
|
115
|
-
}
|
|
116
|
-
catch (error) {
|
|
117
|
-
node.error(error, msg);
|
|
118
|
-
done(error instanceof Error ? error : new Error(String(error)));
|
|
119
|
-
}
|
|
78
|
+
(0, adapter_1.onInput)(node, (msg, send) => {
|
|
79
|
+
process({
|
|
80
|
+
display: (0, adapter_1.objectField)(msg, "display")
|
|
81
|
+
}, send);
|
|
120
82
|
});
|
|
121
83
|
node.on("close", (_removed, done) => {
|
|
122
84
|
closed = true;
|
|
@@ -4,18 +4,16 @@
|
|
|
4
4
|
color: "#d8bfd8",
|
|
5
5
|
defaults: {
|
|
6
6
|
name: {value: ""},
|
|
7
|
-
area: {value: "
|
|
8
|
-
onTargets: {value: "[\"main\"]", required: true},
|
|
9
|
-
offTargets: {value: "[\"main\"]", required: true},
|
|
7
|
+
area: {value: ""},
|
|
8
|
+
onTargets: {value: "[\"main\"]", required: true, validate: function (v) { try { JSON.parse(v); return true; } catch (e) { return false; } }},
|
|
9
|
+
offTargets: {value: "[\"main\"]", required: true, validate: function (v) { try { JSON.parse(v); return true; } catch (e) { return false; } }},
|
|
10
10
|
defaultDelaySeconds: {value: 120, required: true, validate: RED.validators.number()},
|
|
11
|
-
defaultIlluminanceCutoff: {value: 10, required: true, validate: RED.validators.number()}
|
|
12
|
-
switchWindowMs: {value: 500, required: true, validate: RED.validators.number()},
|
|
13
|
-
switchFreshnessSeconds: {value: 3600, required: true, validate: RED.validators.number()}
|
|
11
|
+
defaultIlluminanceCutoff: {value: 10, required: true, validate: RED.validators.number()}
|
|
14
12
|
},
|
|
15
13
|
inputs: 1,
|
|
16
14
|
outputs: 1,
|
|
17
15
|
icon: "font-awesome/fa-lightbulb-o",
|
|
18
|
-
label: function () { return this.name || this.area + " motion policy"; }
|
|
16
|
+
label: function () { return this.name || (this.area ? this.area + " " : "") + "motion policy"; }
|
|
19
17
|
});
|
|
20
18
|
</script>
|
|
21
19
|
|
|
@@ -26,10 +24,25 @@
|
|
|
26
24
|
<div class="form-row"><label for="node-input-offTargets">OFF targets</label><input type="text" id="node-input-offTargets"></div>
|
|
27
25
|
<div class="form-row"><label for="node-input-defaultDelaySeconds">Vacancy seconds</label><input type="number" id="node-input-defaultDelaySeconds"></div>
|
|
28
26
|
<div class="form-row"><label for="node-input-defaultIlluminanceCutoff">Lux cutoff</label><input type="number" id="node-input-defaultIlluminanceCutoff"></div>
|
|
29
|
-
<div class="form-row"><label for="node-input-switchWindowMs">Switch window ms</label><input type="number" id="node-input-switchWindowMs"></div>
|
|
30
|
-
<div class="form-row"><label for="node-input-switchFreshnessSeconds">Switch freshness seconds</label><input type="number" id="node-input-switchFreshnessSeconds"></div>
|
|
31
27
|
</script>
|
|
32
28
|
|
|
33
29
|
<script type="text/html" data-help-name="home-motion-lighting-policy">
|
|
34
|
-
<p>Turns normalised occupancy, illuminance
|
|
30
|
+
<p>Turns normalised occupancy, illuminance and enable-state events into <code>msg.lighting</code> intents: ON when
|
|
31
|
+
the room is occupied and dark enough, and OFF once it has been vacant for the vacancy time. The OFF intent carries
|
|
32
|
+
<code>vacantSince</code>, so the room lighting controller keeps any light a person set after the room went
|
|
33
|
+
vacant.</p>
|
|
34
|
+
<p>Wall switches go to the <b>switch lighting policy</b> node, not here; switch messages sent to this node are
|
|
35
|
+
ignored.</p>
|
|
36
|
+
<h3>Inputs</h3>
|
|
37
|
+
<p>Each message names its kind in <code>msg.source</code>:</p>
|
|
38
|
+
<dl class="message-properties">
|
|
39
|
+
<dt>occupancy</dt><dd><code>msg.payload.occupied</code>, from the occupancy fusion node.</dd>
|
|
40
|
+
<dt>illuminance</dt><dd>the light level in lux.</dd>
|
|
41
|
+
<dt>area-enabled</dt><dd>ON or OFF for this node; <code>global-enabled</code> for every motion node.</dd>
|
|
42
|
+
<dt>delay</dt><dd>a new vacancy time, in <b>seconds</b>, the same unit as <b>Vacancy seconds</b>.</dd>
|
|
43
|
+
<dt>illuminance-cut-off</dt><dd>a new lux cutoff.</dd>
|
|
44
|
+
</dl>
|
|
45
|
+
<p>A <code>delay</code> or <code>illuminance-cut-off</code> message overrides the setting, and lasts across
|
|
46
|
+
restarts until the node is deployed with a different <b>Vacancy seconds</b> or <b>Lux cutoff</b>, which then
|
|
47
|
+
applies.</p>
|
|
35
48
|
</script>
|