@avantics/node-red-home-automation 4.0.3 → 6.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 +447 -64
- package/contract-examples/room-lighting.mjs +39 -27
- package/contract-examples/switch-gestures.mjs +1 -1
- package/contract-examples/volume-ownership.mjs +6 -5
- package/dist/lib/activity-lighting-controller.d.ts +9 -2
- package/dist/lib/activity-lighting-controller.js +107 -19
- package/dist/lib/adopted-request.d.ts +17 -0
- package/dist/lib/adopted-request.js +61 -7
- package/dist/lib/avr-controller.d.ts +9 -3
- package/dist/lib/avr-controller.js +71 -24
- package/dist/lib/avr-publishing.d.ts +3 -3
- package/dist/lib/avr-publishing.js +11 -5
- package/dist/lib/backlighting-controller.d.ts +2 -0
- package/dist/lib/backlighting-controller.js +27 -7
- package/dist/lib/circadian-policy.d.ts +47 -0
- package/dist/lib/circadian-policy.js +111 -0
- package/dist/lib/circadian-publishing.d.ts +33 -0
- package/dist/lib/circadian-publishing.js +154 -0
- package/dist/lib/circadian-schedule.d.ts +4 -0
- package/dist/lib/circadian-schedule.js +12 -0
- package/dist/lib/command-echo.d.ts +8 -1
- package/dist/lib/command-echo.js +37 -6
- package/dist/lib/cover-controller.js +4 -0
- package/dist/lib/cover-publishing.js +1 -1
- package/dist/lib/denon-protocol.d.ts +5 -1
- package/dist/lib/denon-protocol.js +27 -11
- package/dist/lib/display-mode-controller.d.ts +12 -5
- package/dist/lib/display-mode-controller.js +181 -87
- package/dist/lib/enable-input.d.ts +3 -0
- package/dist/lib/enable-input.js +18 -0
- package/dist/lib/house-schedule-publishing.js +1 -1
- package/dist/lib/house-schedule.js +2 -2
- package/dist/lib/light-contract.d.ts +53 -0
- package/dist/lib/light-contract.js +11 -0
- package/dist/lib/light-styling.d.ts +2 -2
- package/dist/lib/light-styling.js +5 -4
- package/dist/lib/motion-policy.d.ts +0 -1
- package/dist/lib/motion-policy.js +9 -8
- package/dist/lib/motion-publishing.js +3 -2
- package/dist/lib/mqtt-message.d.ts +6 -0
- package/dist/lib/mqtt-message.js +21 -0
- package/dist/lib/occupancy-publishing.js +1 -1
- package/dist/lib/power-reading.d.ts +5 -0
- package/dist/lib/power-reading.js +13 -0
- package/dist/lib/room-controller.d.ts +39 -29
- package/dist/lib/room-controller.js +314 -192
- package/dist/lib/room-lighting-discovery.d.ts +0 -14
- package/dist/lib/room-lighting-discovery.js +20 -126
- package/dist/lib/room-publishing.d.ts +10 -12
- package/dist/lib/room-publishing.js +65 -125
- package/dist/lib/shelly-cover.d.ts +44 -0
- package/dist/lib/shelly-cover.js +153 -0
- package/dist/lib/shelly-gen2.d.ts +25 -0
- package/dist/lib/shelly-gen2.js +58 -0
- package/dist/lib/shelly-switch.d.ts +95 -0
- package/dist/lib/shelly-switch.js +237 -0
- package/dist/lib/source-capability-controller.d.ts +2 -0
- package/dist/lib/source-capability-controller.js +27 -6
- package/dist/lib/switch-policy.d.ts +1 -1
- package/dist/lib/switch-policy.js +1 -1
- package/dist/lib/theatre-requests.d.ts +29 -0
- package/dist/lib/theatre-requests.js +89 -0
- package/dist/lib/theatre-state-contract.d.ts +5 -22
- package/dist/lib/theatre-state-contract.js +30 -77
- package/dist/lib/toggle-power.d.ts +41 -0
- package/dist/lib/toggle-power.js +74 -0
- package/dist/lib/topic-names.d.ts +1 -0
- package/dist/lib/topic-names.js +7 -0
- package/dist/lib/{display-transport.d.ts → transports/display-transport.d.ts} +1 -1
- package/dist/lib/{display-transport.js → transports/display-transport.js} +32 -7
- package/dist/lib/z2m-cover.d.ts +49 -0
- package/dist/lib/z2m-cover.js +120 -0
- package/dist/lib/z2m-light-adapter.d.ts +62 -0
- package/dist/lib/z2m-light-adapter.js +195 -0
- package/dist/lib/z2m-light.d.ts +8 -0
- package/dist/lib/z2m-light.js +61 -3
- package/dist/nodes/activity-lighting-controller.html +20 -3
- package/dist/nodes/activity-lighting-controller.js +21 -0
- package/dist/nodes/avr-controller.html +25 -6
- package/dist/nodes/avr-controller.js +16 -6
- package/dist/nodes/circadian-policy.d.ts +3 -0
- package/dist/nodes/circadian-policy.html +140 -0
- package/dist/nodes/circadian-policy.js +162 -0
- package/dist/nodes/cover-controller.html +4 -3
- package/dist/nodes/display-mode-controller.html +58 -11
- package/dist/nodes/display-mode-controller.js +19 -6
- package/dist/nodes/house-schedule.html +3 -3
- package/dist/nodes/motion-policy.html +5 -2
- package/dist/nodes/motion-policy.js +3 -0
- package/dist/nodes/refused-enable.d.ts +7 -0
- package/dist/nodes/refused-enable.js +24 -0
- package/dist/nodes/room-controller.html +215 -82
- package/dist/nodes/room-controller.js +71 -83
- package/dist/nodes/shelly-cover.d.ts +3 -0
- package/dist/nodes/shelly-cover.html +65 -0
- package/dist/nodes/shelly-cover.js +34 -0
- package/dist/nodes/shelly-switch.d.ts +3 -0
- package/dist/nodes/shelly-switch.html +82 -0
- package/dist/nodes/shelly-switch.js +48 -0
- package/dist/nodes/theatre-state-contract.html +4 -3
- package/dist/nodes/z2m-cover.d.ts +3 -0
- package/dist/nodes/z2m-cover.html +68 -0
- package/dist/nodes/z2m-cover.js +41 -0
- package/dist/nodes/z2m-light.d.ts +3 -0
- package/dist/nodes/z2m-light.html +72 -0
- package/dist/nodes/z2m-light.js +50 -0
- package/examples/Cover control.json +24 -56
- package/examples/Home theatre activity.json +54 -9
- package/examples/Home theatre equipment.json +4 -4
- package/examples/House schedule.json +106 -24
- package/examples/Room lighting.json +54 -11
- package/examples/Shelly cover.json +252 -0
- package/examples/Shelly switch.json +197 -0
- package/package.json +13 -4
- package/dist/lib/room-schedule.d.ts +0 -8
- package/dist/lib/room-schedule.js +0 -41
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DEFAULT_MAX_PAUSE_SECONDS = void 0;
|
|
4
|
-
exports.booleanOn = booleanOn;
|
|
5
4
|
exports.normaliseMotionConfig = normaliseMotionConfig;
|
|
6
5
|
exports.createMotionState = createMotionState;
|
|
7
6
|
exports.lightingIntent = lightingIntent;
|
|
8
7
|
exports.transitionMotion = transitionMotion;
|
|
8
|
+
const enable_input_1 = require("./enable-input");
|
|
9
9
|
const settings_1 = require("./settings");
|
|
10
10
|
exports.DEFAULT_MAX_PAUSE_SECONDS = 600;
|
|
11
|
-
function booleanOn(value) {
|
|
12
|
-
return value === true || (typeof value === "string" && value.toLowerCase() === "on");
|
|
13
|
-
}
|
|
14
11
|
function finiteNumber(value) {
|
|
15
12
|
const number = Number(value);
|
|
16
13
|
return Number.isFinite(number) ? number : null;
|
|
@@ -118,9 +115,13 @@ function transitionMotion(saved, input, config, globalEnabled, now = Date.now())
|
|
|
118
115
|
}
|
|
119
116
|
const source = input.source;
|
|
120
117
|
const payload = input.payload;
|
|
121
|
-
if (source === "global-enabled") {
|
|
118
|
+
if ((source === "global-enabled" || source === "area-enabled" || source === "pause") && (0, enable_input_1.enableValue)(payload) === null) {
|
|
119
|
+
// Refused, never read as off: the node warns and says so on its status.
|
|
120
|
+
trace(source === "pause" ? "pause" : "enabled", "ignored", enable_input_1.NOT_TRUE_OR_FALSE, { source, payload: (0, enable_input_1.describeValue)(payload) });
|
|
121
|
+
}
|
|
122
|
+
else if (source === "global-enabled") {
|
|
122
123
|
const previous = nextGlobalEnabled;
|
|
123
|
-
nextGlobalEnabled =
|
|
124
|
+
nextGlobalEnabled = payload === true;
|
|
124
125
|
if (previous !== nextGlobalEnabled) {
|
|
125
126
|
trace("enabled", "changed", null, { scope: "global", enabled: nextGlobalEnabled });
|
|
126
127
|
}
|
|
@@ -136,7 +137,7 @@ function transitionMotion(saved, input, config, globalEnabled, now = Date.now())
|
|
|
136
137
|
trace("pause", "ignored", "owner-required");
|
|
137
138
|
}
|
|
138
139
|
else {
|
|
139
|
-
const pause = payload === true
|
|
140
|
+
const pause = payload === true;
|
|
140
141
|
const held = state.pausedBy.some((entry) => entry.owner === owner);
|
|
141
142
|
const others = state.pausedBy.filter((entry) => entry.owner !== owner);
|
|
142
143
|
const until = now + (config.maxPauseSeconds ?? exports.DEFAULT_MAX_PAUSE_SECONDS) * 1000;
|
|
@@ -148,7 +149,7 @@ function transitionMotion(saved, input, config, globalEnabled, now = Date.now())
|
|
|
148
149
|
}
|
|
149
150
|
else if (source === "area-enabled") {
|
|
150
151
|
const previous = state.areaEnabled;
|
|
151
|
-
state.areaEnabled =
|
|
152
|
+
state.areaEnabled = payload === true;
|
|
152
153
|
if (previous !== state.areaEnabled) {
|
|
153
154
|
trace("enabled", "changed", null, { scope: "area", enabled: state.areaEnabled });
|
|
154
155
|
}
|
|
@@ -9,7 +9,7 @@ const publishing_node_1 = require("./publishing-node");
|
|
|
9
9
|
// The vacancy delays Home Assistant offers, in seconds: up to a day.
|
|
10
10
|
exports.MAX_DELAY_SECONDS = 86400;
|
|
11
11
|
function motionTopic(area, name) {
|
|
12
|
-
return
|
|
12
|
+
return (0, topic_names_1.homeTopic)(area, "motion", name);
|
|
13
13
|
}
|
|
14
14
|
const motionEnabledTopic = (area, end) => motionTopic(area, "enabled/" + end);
|
|
15
15
|
exports.motionEnabledTopic = motionEnabledTopic;
|
|
@@ -82,7 +82,8 @@ function motionInbound(msg, config) {
|
|
|
82
82
|
const requested = text.toUpperCase();
|
|
83
83
|
if (requested !== "ON" && requested !== "OFF")
|
|
84
84
|
return ignored("not-on-or-off", { payload: text });
|
|
85
|
-
|
|
85
|
+
// Home Assistant's ON and OFF, as the node's own true and false.
|
|
86
|
+
return { input: { source: "area-enabled", payload: requested === "ON" }, traces: [] };
|
|
86
87
|
}
|
|
87
88
|
const seconds = text === "" ? NaN : Number(text);
|
|
88
89
|
if (!Number.isFinite(seconds) || seconds < 0 || seconds > exports.MAX_DELAY_SECONDS)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parsedPayload = parsedPayload;
|
|
4
|
+
exports.isObject = isObject;
|
|
5
|
+
// An MQTT in node may hand over a parsed object, a string or a Buffer;
|
|
6
|
+
// JSON text is parsed, anything else is returned as it is.
|
|
7
|
+
function parsedPayload(payload) {
|
|
8
|
+
const text = Buffer.isBuffer(payload) ? payload.toString("utf8") : payload;
|
|
9
|
+
if (typeof text !== "string")
|
|
10
|
+
return text;
|
|
11
|
+
try {
|
|
12
|
+
return JSON.parse(text);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return text;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function isObject(value) {
|
|
19
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=mqtt-message.js.map
|
|
@@ -12,7 +12,7 @@ exports.occupancyStateOutputs = occupancyStateOutputs;
|
|
|
12
12
|
const topic_names_1 = require("./topic-names");
|
|
13
13
|
const publishing_node_1 = require("./publishing-node");
|
|
14
14
|
function occupancyTopic(area, name) {
|
|
15
|
-
return
|
|
15
|
+
return (0, topic_names_1.homeTopic)(area, "occupancy", name);
|
|
16
16
|
}
|
|
17
17
|
function occupancyStateTopic(area) {
|
|
18
18
|
return occupancyTopic(area, "state");
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.classifyPower = classifyPower;
|
|
4
|
+
function classifyPower(watts, previous = "unknown", bands) {
|
|
5
|
+
if (!Number.isFinite(watts) || watts < 0)
|
|
6
|
+
return "unknown";
|
|
7
|
+
if (watts >= bands.onWatts)
|
|
8
|
+
return "on";
|
|
9
|
+
if (watts <= bands.offWatts)
|
|
10
|
+
return "standby";
|
|
11
|
+
return previous === "on" || previous === "standby" ? previous : "transitioning";
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=power-reading.js.map
|
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
import type { TraceEntry } from "./bounded-trace";
|
|
2
|
-
import type {
|
|
3
|
-
import type
|
|
4
|
-
import { type LightCommand, type LightReport } from "./z2m-light";
|
|
2
|
+
import type { LightStyle } from "./light-styling";
|
|
3
|
+
import { type LightField, type LightRoomMessage } from "./light-contract";
|
|
5
4
|
import { type ExpectedCommand } from "./command-echo";
|
|
6
5
|
export { fingerprint, parsePayload, type ExpectedCommand } from "./command-echo";
|
|
7
6
|
export interface RoomTarget {
|
|
8
7
|
id: string;
|
|
9
|
-
|
|
10
|
-
commandTopic: string;
|
|
8
|
+
onOffOnly?: boolean;
|
|
11
9
|
}
|
|
12
10
|
export interface RoomConfig {
|
|
13
11
|
area: string;
|
|
14
12
|
displayName: string;
|
|
15
|
-
discoveryPrefix?: string;
|
|
16
13
|
targets: RoomTarget[];
|
|
17
|
-
initialSleep: boolean;
|
|
18
|
-
publishState?: boolean;
|
|
19
|
-
discovery?: boolean;
|
|
20
|
-
refreshTransitionSeconds: number;
|
|
21
14
|
initialTransitionSeconds: number;
|
|
22
|
-
lighting: CircadianLighting;
|
|
23
|
-
schedule?: DaySchedule;
|
|
24
15
|
}
|
|
25
|
-
export interface
|
|
16
|
+
export interface RoomStyle {
|
|
17
|
+
values: LightStyle | null;
|
|
18
|
+
transitionSeconds: number;
|
|
19
|
+
until: string;
|
|
20
|
+
source: string;
|
|
21
|
+
}
|
|
22
|
+
export interface RoomObservation {
|
|
23
|
+
on: boolean;
|
|
24
|
+
brightnessPct?: number;
|
|
25
|
+
colorTempKelvin?: number;
|
|
26
|
+
fields?: LightField[];
|
|
26
27
|
observedAt: string;
|
|
27
28
|
}
|
|
28
29
|
export type TargetControlState = "in-control" | "overridden" | "manual";
|
|
@@ -32,18 +33,24 @@ export type TargetControl = {
|
|
|
32
33
|
state: "overridden";
|
|
33
34
|
owner: string;
|
|
34
35
|
};
|
|
36
|
+
export declare const REMOVED_LIGHT_UNITS = "removed-light-units";
|
|
37
|
+
export declare const INVALID_LIGHT_VALUES = "invalid-light-values";
|
|
38
|
+
export declare const ON_OFF_ONLY = "on-off-only";
|
|
39
|
+
export declare const MOVED_CIRCADIAN_SETTINGS: readonly ["houseSchedule", "wakeTime", "bedTime", "maxBrightnessPct", "maxColorTempKelvin", "sleepBrightnessPct", "sleepColorTempKelvin", "refreshTransitionSeconds", "refreshSeconds", "initialSleep", "latitude", "longitude", "minBrightnessPct", "minColorTempKelvin"];
|
|
40
|
+
export declare function movedCircadianSettings(config: Record<string, unknown>): string[];
|
|
41
|
+
export declare function targetsWithTopics(targets: unknown): string[];
|
|
42
|
+
export declare const MOVED_TO_CIRCADIAN = "moved-to-circadian";
|
|
35
43
|
export interface RoomState {
|
|
36
44
|
observed: Record<string, RoomObservation>;
|
|
37
45
|
desired: Record<string, boolean>;
|
|
38
46
|
control: Record<string, TargetControl>;
|
|
39
47
|
expected: Record<string, ExpectedCommand[]>;
|
|
40
|
-
|
|
41
|
-
sleeping: boolean;
|
|
42
|
-
schedule: DaySchedule;
|
|
43
|
-
scheduleSetting: DaySchedule;
|
|
48
|
+
style: RoomStyle | null;
|
|
44
49
|
personAt: Record<string, number>;
|
|
45
50
|
untold: string[];
|
|
46
51
|
restyledAt: Record<string, number>;
|
|
52
|
+
available: Record<string, boolean>;
|
|
53
|
+
commandSeq: number;
|
|
47
54
|
}
|
|
48
55
|
export interface LightingEvent {
|
|
49
56
|
kind?: string;
|
|
@@ -58,15 +65,15 @@ export interface LightingEvent {
|
|
|
58
65
|
person?: boolean;
|
|
59
66
|
owner?: string;
|
|
60
67
|
source?: string;
|
|
61
|
-
refresh?: boolean;
|
|
62
68
|
retained?: boolean;
|
|
63
|
-
enabled?: boolean;
|
|
64
69
|
vacantSince?: string;
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
transitionSeconds?: number;
|
|
71
|
+
until?: string;
|
|
72
|
+
takeBack?: boolean;
|
|
67
73
|
}
|
|
68
74
|
export interface RoomMessage {
|
|
69
75
|
lighting?: LightingEvent;
|
|
76
|
+
light?: unknown;
|
|
70
77
|
topic?: string;
|
|
71
78
|
payload?: unknown;
|
|
72
79
|
retain?: boolean;
|
|
@@ -75,25 +82,28 @@ export interface RoomOutput {
|
|
|
75
82
|
topic: string;
|
|
76
83
|
payload: unknown;
|
|
77
84
|
retain: boolean;
|
|
78
|
-
lighting_command?: {
|
|
79
|
-
area: string;
|
|
80
|
-
target: string;
|
|
81
|
-
source: string;
|
|
82
|
-
};
|
|
83
85
|
}
|
|
84
86
|
export declare function createRoomState(config: RoomConfig, saved?: Partial<RoomState> & {
|
|
85
87
|
manual?: Record<string, boolean>;
|
|
86
88
|
}): RoomState;
|
|
87
|
-
export declare function
|
|
89
|
+
export declare function intentValues(values: Record<string, unknown>): {
|
|
90
|
+
brightnessPct: number | undefined;
|
|
91
|
+
colorTempKelvin: number | undefined;
|
|
92
|
+
extra: Record<string, unknown>;
|
|
93
|
+
removed: string[];
|
|
94
|
+
invalid: string[];
|
|
95
|
+
};
|
|
88
96
|
export declare function transitionRoom(saved: Partial<RoomState> | undefined, msg: RoomMessage, config: RoomConfig, nowValue?: Date | string | number): {
|
|
89
97
|
state: RoomState;
|
|
90
98
|
outputs: RoomOutput[];
|
|
99
|
+
commands: LightRoomMessage[];
|
|
91
100
|
traces: TraceEntry<Record<string, unknown>>[];
|
|
92
101
|
controlChanged: string[];
|
|
93
102
|
status: {
|
|
94
|
-
|
|
95
|
-
|
|
103
|
+
styled: boolean;
|
|
104
|
+
styleSource: string | null;
|
|
96
105
|
onCount: number;
|
|
106
|
+
offlineCount: number;
|
|
97
107
|
manualCount: number;
|
|
98
108
|
overriddenCount: number;
|
|
99
109
|
control: {
|