@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,28 +1,14 @@
|
|
|
1
1
|
import { type DiscoveryOwner } from "./ha-discovery";
|
|
2
|
-
import type { DaySchedule } from "./circadian-schedule";
|
|
3
2
|
export interface DiscoveryMessage {
|
|
4
3
|
topic: string;
|
|
5
4
|
payload: unknown;
|
|
6
5
|
retain: boolean;
|
|
7
6
|
}
|
|
8
7
|
export declare function roomTopic(area: string, name: string): string;
|
|
9
|
-
export declare function circadianStateTopic(area: string): string;
|
|
10
|
-
export declare function circadianCommandTopic(area: string): string;
|
|
11
8
|
export declare function roomAvailabilityTopic(area: string): string;
|
|
12
9
|
export declare function roomAvailabilityMessage(area: string, online: boolean): DiscoveryMessage;
|
|
13
10
|
export declare function roomControlTopic(area: string, targetId: string): string;
|
|
14
|
-
export declare function sleepStateTopic(area: string): string;
|
|
15
|
-
export declare function sleepCommandTopic(area: string): string;
|
|
16
|
-
export type ScheduleTime = "wake-time" | "bed-time";
|
|
17
|
-
export declare function scheduleStateTopic(area: string, time: ScheduleTime): string;
|
|
18
|
-
export declare function scheduleCommandTopic(area: string, time: ScheduleTime): string;
|
|
19
|
-
export declare function sleepStateMessage(area: string, sleeping: boolean): DiscoveryMessage;
|
|
20
|
-
export declare function scheduleStateMessages(area: string, schedule: DaySchedule): DiscoveryMessage[];
|
|
21
|
-
export declare function circadianStateMessage(area: string, enabled: boolean): DiscoveryMessage;
|
|
22
11
|
export interface RoomDiscoveryConfig extends DiscoveryOwner {
|
|
23
12
|
displayName: string;
|
|
24
|
-
timesFrom?: "room" | "house";
|
|
25
13
|
}
|
|
26
|
-
export declare function roomTimeDiscoveryTopics(config: RoomDiscoveryConfig): string[];
|
|
27
14
|
export declare function roomDiscovery(config: RoomDiscoveryConfig, targetIds: string[]): DiscoveryMessage[];
|
|
28
|
-
export declare function roomLightingDiscovery(config: RoomDiscoveryConfig, circadianEnabled: boolean): DiscoveryMessage[];
|
|
@@ -1,35 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.roomTopic = roomTopic;
|
|
4
|
-
exports.circadianStateTopic = circadianStateTopic;
|
|
5
|
-
exports.circadianCommandTopic = circadianCommandTopic;
|
|
6
4
|
exports.roomAvailabilityTopic = roomAvailabilityTopic;
|
|
7
5
|
exports.roomAvailabilityMessage = roomAvailabilityMessage;
|
|
8
6
|
exports.roomControlTopic = roomControlTopic;
|
|
9
|
-
exports.sleepStateTopic = sleepStateTopic;
|
|
10
|
-
exports.sleepCommandTopic = sleepCommandTopic;
|
|
11
|
-
exports.scheduleStateTopic = scheduleStateTopic;
|
|
12
|
-
exports.scheduleCommandTopic = scheduleCommandTopic;
|
|
13
|
-
exports.sleepStateMessage = sleepStateMessage;
|
|
14
|
-
exports.scheduleStateMessages = scheduleStateMessages;
|
|
15
|
-
exports.circadianStateMessage = circadianStateMessage;
|
|
16
|
-
exports.roomTimeDiscoveryTopics = roomTimeDiscoveryTopics;
|
|
17
7
|
exports.roomDiscovery = roomDiscovery;
|
|
18
|
-
|
|
19
|
-
//
|
|
20
|
-
// circadian
|
|
21
|
-
//
|
|
8
|
+
// The room controller's Home Assistant view: its availability, and a sensor
|
|
9
|
+
// for each light's control state (in-control, overridden or manual). Its
|
|
10
|
+
// circadian, sleep, wake and bed entities moved to the circadian lighting
|
|
11
|
+
// policy in 6.0 (circadian-publishing.ts).
|
|
22
12
|
const ha_discovery_1 = require("./ha-discovery");
|
|
23
13
|
const topic_names_1 = require("./topic-names");
|
|
24
14
|
// The one place a room topic is named: home/<area ID>/<name>.
|
|
25
15
|
function roomTopic(area, name) {
|
|
26
|
-
return
|
|
27
|
-
}
|
|
28
|
-
function circadianStateTopic(area) {
|
|
29
|
-
return roomTopic(area, "circadian/state");
|
|
30
|
-
}
|
|
31
|
-
function circadianCommandTopic(area) {
|
|
32
|
-
return roomTopic(area, "circadian/set");
|
|
16
|
+
return (0, topic_names_1.homeTopic)(area, name);
|
|
33
17
|
}
|
|
34
18
|
// The room's own availability, online or offline, for Home Assistant.
|
|
35
19
|
function roomAvailabilityTopic(area) {
|
|
@@ -42,126 +26,36 @@ function roomAvailabilityMessage(area, online) {
|
|
|
42
26
|
function roomControlTopic(area, targetId) {
|
|
43
27
|
return roomTopic(area, "lighting/" + targetId + "/control");
|
|
44
28
|
}
|
|
45
|
-
// Sleep, and the wake and bed times, each with a state topic and a set
|
|
46
|
-
// topic Home Assistant commands.
|
|
47
|
-
function sleepStateTopic(area) {
|
|
48
|
-
return roomTopic(area, "sleep/state");
|
|
49
|
-
}
|
|
50
|
-
function sleepCommandTopic(area) {
|
|
51
|
-
return roomTopic(area, "sleep/set");
|
|
52
|
-
}
|
|
53
|
-
function scheduleStateTopic(area, time) {
|
|
54
|
-
return roomTopic(area, time + "/state");
|
|
55
|
-
}
|
|
56
|
-
function scheduleCommandTopic(area, time) {
|
|
57
|
-
return roomTopic(area, time + "/set");
|
|
58
|
-
}
|
|
59
|
-
function sleepStateMessage(area, sleeping) {
|
|
60
|
-
return { topic: sleepStateTopic(area), payload: sleeping ? "ON" : "OFF", retain: true };
|
|
61
|
-
}
|
|
62
|
-
// The times in use, "HH:MM:SS" as Home Assistant's time entity reads them.
|
|
63
|
-
function scheduleStateMessages(area, schedule) {
|
|
64
|
-
return [
|
|
65
|
-
{ topic: scheduleStateTopic(area, "wake-time"), payload: schedule.wakeTime + ":00", retain: true },
|
|
66
|
-
{ topic: scheduleStateTopic(area, "bed-time"), payload: schedule.bedTime + ":00", retain: true }
|
|
67
|
-
];
|
|
68
|
-
}
|
|
69
|
-
// The retained circadian state, as Home Assistant reads it.
|
|
70
|
-
function circadianStateMessage(area, enabled) {
|
|
71
|
-
return { topic: circadianStateTopic(area), payload: enabled ? "ON" : "OFF", retain: true };
|
|
72
|
-
}
|
|
73
|
-
const CIRCADIAN_ENTITY = "circadian_lighting";
|
|
74
29
|
function roomDevice(config) {
|
|
75
30
|
return {
|
|
76
31
|
...(0, ha_discovery_1.discoveryDevice)(config, "lighting"),
|
|
77
32
|
name: config.displayName + " Lighting Controller",
|
|
78
33
|
manufacturer: "Node-RED",
|
|
79
|
-
model: "
|
|
34
|
+
model: "Room lighting controller"
|
|
80
35
|
};
|
|
81
36
|
}
|
|
82
|
-
//
|
|
83
|
-
// origin every room entity carries.
|
|
84
|
-
function roomEntity(config, component, entity, name, fields) {
|
|
85
|
-
const ids = (0, ha_discovery_1.discoveryEntity)(config, component, entity);
|
|
86
|
-
return {
|
|
87
|
-
topic: ids.topic,
|
|
88
|
-
payload: {
|
|
89
|
-
name: config.displayName + " " + name,
|
|
90
|
-
unique_id: ids.uniqueId,
|
|
91
|
-
default_entity_id: ids.defaultEntityId,
|
|
92
|
-
...fields,
|
|
93
|
-
availability_topic: roomAvailabilityTopic(config.area),
|
|
94
|
-
device: roomDevice(config),
|
|
95
|
-
origin: ha_discovery_1.DISCOVERY_ORIGIN
|
|
96
|
-
},
|
|
97
|
-
retain: true
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
// Every discovery entry the room publishes: its circadian switch, a sleep
|
|
101
|
-
// switch, its wake and bed times, and each light's control state.
|
|
102
|
-
function roomTimeEntities(config) {
|
|
103
|
-
const time = (which, entity, name, icon) => roomEntity(config, "time", entity, name, {
|
|
104
|
-
icon,
|
|
105
|
-
command_topic: scheduleCommandTopic(config.area, which),
|
|
106
|
-
state_topic: scheduleStateTopic(config.area, which),
|
|
107
|
-
entity_category: "config"
|
|
108
|
-
});
|
|
109
|
-
return [
|
|
110
|
-
time("wake-time", "wake_time", "Wake time", "mdi:weather-sunset-up"),
|
|
111
|
-
time("bed-time", "bed_time", "Bed time", "mdi:weather-night")
|
|
112
|
-
];
|
|
113
|
-
}
|
|
114
|
-
// The discovery topics of the room's own wake and bed time entities.
|
|
115
|
-
function roomTimeDiscoveryTopics(config) {
|
|
116
|
-
return roomTimeEntities(config).map(({ topic }) => topic);
|
|
117
|
-
}
|
|
37
|
+
// Each light's control state, as a sensor on the room's device.
|
|
118
38
|
function roomDiscovery(config, targetIds) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
roomEntity(config, "switch", "sleep", "Sleep", {
|
|
123
|
-
icon: "mdi:sleep",
|
|
124
|
-
command_topic: sleepCommandTopic(area),
|
|
125
|
-
state_topic: sleepStateTopic(area),
|
|
126
|
-
payload_on: "ON",
|
|
127
|
-
payload_off: "OFF",
|
|
128
|
-
optimistic: false
|
|
129
|
-
}),
|
|
130
|
-
...(config.timesFrom === "house" ? [] : roomTimeEntities(config)),
|
|
131
|
-
...targetIds.map((id) => roomEntity(config, "sensor", id + "_control", id + " control", {
|
|
132
|
-
icon: "mdi:account-lock-outline",
|
|
133
|
-
state_topic: roomControlTopic(area, id),
|
|
134
|
-
value_template: "{{ value_json.state }}",
|
|
135
|
-
json_attributes_topic: roomControlTopic(area, id),
|
|
136
|
-
json_attributes_template: "{{ {'owner': value_json.owner} | tojson }}",
|
|
137
|
-
entity_category: "diagnostic"
|
|
138
|
-
}))
|
|
139
|
-
];
|
|
140
|
-
}
|
|
141
|
-
// The discovery entry for the room's circadian switch, then its state.
|
|
142
|
-
function roomLightingDiscovery(config, circadianEnabled) {
|
|
143
|
-
const { area, displayName } = config;
|
|
144
|
-
const ids = (0, ha_discovery_1.discoveryEntity)(config, "switch", CIRCADIAN_ENTITY);
|
|
145
|
-
return [
|
|
146
|
-
{
|
|
39
|
+
return targetIds.map((id) => {
|
|
40
|
+
const ids = (0, ha_discovery_1.discoveryEntity)(config, "sensor", id + "_control");
|
|
41
|
+
return {
|
|
147
42
|
topic: ids.topic,
|
|
148
43
|
payload: {
|
|
149
|
-
name: displayName + "
|
|
44
|
+
name: config.displayName + " " + id + " control",
|
|
150
45
|
unique_id: ids.uniqueId,
|
|
151
46
|
default_entity_id: ids.defaultEntityId,
|
|
152
|
-
icon: "mdi:
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
47
|
+
icon: "mdi:account-lock-outline",
|
|
48
|
+
state_topic: roomControlTopic(config.area, id),
|
|
49
|
+
value_template: "{{ value_json.state }}",
|
|
50
|
+
json_attributes_topic: roomControlTopic(config.area, id),
|
|
51
|
+
json_attributes_template: "{{ {'owner': value_json.owner, 'available': value_json.available} | tojson }}",
|
|
52
|
+
entity_category: "diagnostic",
|
|
53
|
+
availability_topic: roomAvailabilityTopic(config.area),
|
|
159
54
|
device: roomDevice(config),
|
|
160
55
|
origin: ha_discovery_1.DISCOVERY_ORIGIN
|
|
161
56
|
},
|
|
162
57
|
retain: true
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
];
|
|
58
|
+
};
|
|
59
|
+
});
|
|
166
60
|
}
|
|
167
61
|
//# sourceMappingURL=room-lighting-discovery.js.map
|
|
@@ -1,35 +1,34 @@
|
|
|
1
|
-
import type { TraceEntry } from "./bounded-trace";
|
|
2
1
|
import { type IdScheme } from "./ha-discovery";
|
|
3
2
|
import { type RoomConfig, type RoomMessage, type RoomOutput, type RoomState } from "./room-controller";
|
|
4
3
|
type PublishSettings = {
|
|
5
4
|
area: string;
|
|
6
5
|
publishState?: boolean;
|
|
7
6
|
discovery?: boolean;
|
|
8
|
-
timesFrom?: TimesFrom;
|
|
9
7
|
};
|
|
10
|
-
export type TimesFrom = "room" | "house";
|
|
11
8
|
export interface RoomPublishingConfig {
|
|
12
9
|
nodeId?: string;
|
|
13
10
|
idScheme?: IdScheme;
|
|
14
|
-
|
|
11
|
+
discoveryPrefix?: string;
|
|
12
|
+
publishState?: boolean;
|
|
13
|
+
discovery?: boolean;
|
|
15
14
|
}
|
|
16
15
|
type PublishingRoomConfig = RoomConfig & RoomPublishingConfig;
|
|
17
16
|
export declare function roomRetainedTopics(config: PublishingRoomConfig): string[];
|
|
17
|
+
export declare function withoutCircadianState(recorded: readonly string[]): string[];
|
|
18
18
|
export declare function roomPublishesState(config: PublishSettings): boolean;
|
|
19
19
|
export declare function roomPublishesDiscovery(config: PublishSettings): boolean;
|
|
20
|
-
export declare function roomStartingOutputs(config:
|
|
20
|
+
export declare function roomStartingOutputs(config: PublishingRoomConfig): RoomOutput[];
|
|
21
21
|
export declare function roomStoppingOutputs(config: PublishSettings): RoomOutput[];
|
|
22
|
-
export declare function roomInbound(msg: RoomMessage, config: PublishSettings): {
|
|
23
|
-
msg: RoomMessage;
|
|
24
|
-
traces: TraceEntry[];
|
|
25
|
-
};
|
|
26
22
|
export declare function publishRoom(saved: Partial<RoomState> | undefined, msg: RoomMessage, config: PublishingRoomConfig, now?: Date | string | number): {
|
|
27
23
|
state: RoomState;
|
|
24
|
+
commands: import("./light-contract").LightRoomMessage[];
|
|
25
|
+
traces: import("./bounded-trace").TraceEntry<Record<string, unknown>>[];
|
|
28
26
|
controlChanged: string[];
|
|
29
27
|
status: {
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
styled: boolean;
|
|
29
|
+
styleSource: string | null;
|
|
32
30
|
onCount: number;
|
|
31
|
+
offlineCount: number;
|
|
33
32
|
manualCount: number;
|
|
34
33
|
overriddenCount: number;
|
|
35
34
|
control: {
|
|
@@ -37,6 +36,5 @@ export declare function publishRoom(saved: Partial<RoomState> | undefined, msg:
|
|
|
37
36
|
};
|
|
38
37
|
};
|
|
39
38
|
outputs: RoomOutput[];
|
|
40
|
-
traces: TraceEntry<Record<string, unknown>>[];
|
|
41
39
|
};
|
|
42
40
|
export {};
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.roomRetainedTopics = roomRetainedTopics;
|
|
4
|
+
exports.withoutCircadianState = withoutCircadianState;
|
|
4
5
|
exports.roomPublishesState = roomPublishesState;
|
|
5
6
|
exports.roomPublishesDiscovery = roomPublishesDiscovery;
|
|
6
7
|
exports.roomStartingOutputs = roomStartingOutputs;
|
|
7
8
|
exports.roomStoppingOutputs = roomStoppingOutputs;
|
|
8
|
-
exports.roomInbound = roomInbound;
|
|
9
9
|
exports.publishRoom = publishRoom;
|
|
10
|
+
// The room's MQTT and Home Assistant side, as the theatre state contract is
|
|
11
|
+
// for the theatre: it turns the room controller's decisions into the
|
|
12
|
+
// retained topics other systems read. The room controller itself only
|
|
13
|
+
// decides about lights. Its circadian, sleep, wake and bed entities and set
|
|
14
|
+
// topics moved to the circadian lighting policy in 6.0.
|
|
15
|
+
const circadian_publishing_1 = require("./circadian-publishing");
|
|
10
16
|
const ha_discovery_1 = require("./ha-discovery");
|
|
11
17
|
const room_controller_1 = require("./room-controller");
|
|
12
18
|
const room_lighting_discovery_1 = require("./room-lighting-discovery");
|
|
13
19
|
const topic_names_1 = require("./topic-names");
|
|
14
|
-
function ownTimes(config) {
|
|
15
|
-
return config.timesFrom !== "house";
|
|
16
|
-
}
|
|
17
20
|
function targetIds(config) {
|
|
18
21
|
return config.targets.map((target) => target.id);
|
|
19
22
|
}
|
|
@@ -21,153 +24,91 @@ function discoveryConfig(config) {
|
|
|
21
24
|
return { ...config, discoveryPrefix: config.discoveryPrefix ?? ha_discovery_1.DEFAULT_DISCOVERY_PREFIX };
|
|
22
25
|
}
|
|
23
26
|
// Every retained topic the room publishes, for clearing those it no longer
|
|
24
|
-
// does after a change. The discovery
|
|
25
|
-
// area, as
|
|
27
|
+
// does after a change. The discovery entries count whenever the room has an
|
|
28
|
+
// area, as they are published or cleared at each start.
|
|
26
29
|
function roomRetainedTopics(config) {
|
|
27
30
|
const topics = (0, topic_names_1.areaId)(config.area) ? (0, room_lighting_discovery_1.roomDiscovery)(discoveryConfig(config), targetIds(config)).map(({ topic }) => topic) : [];
|
|
28
31
|
if (roomPublishesState(config)) {
|
|
29
|
-
topics.push((0, room_lighting_discovery_1.roomAvailabilityTopic)(config.area)
|
|
30
|
-
if (ownTimes(config))
|
|
31
|
-
topics.push((0, room_lighting_discovery_1.scheduleStateTopic)(config.area, "wake-time"), (0, room_lighting_discovery_1.scheduleStateTopic)(config.area, "bed-time"));
|
|
32
|
+
topics.push((0, room_lighting_discovery_1.roomAvailabilityTopic)(config.area));
|
|
32
33
|
topics.push(...config.targets.map((target) => (0, room_lighting_discovery_1.roomControlTopic)(config.area, target.id)));
|
|
33
34
|
}
|
|
34
35
|
return topics;
|
|
35
36
|
}
|
|
36
|
-
//
|
|
37
|
-
//
|
|
37
|
+
// The state topics of the circadian lighting policy, which a room published
|
|
38
|
+
// before 6.0 and may still have in its record of what it published. They are
|
|
39
|
+
// never the room's to clear now: a circadian node with the same area
|
|
40
|
+
// publishes them.
|
|
41
|
+
const CIRCADIAN_STATE = /^home\/[^/]+\/(?:circadian|sleep|wake-time|bed-time)\/state$/;
|
|
42
|
+
function withoutCircadianState(recorded) {
|
|
43
|
+
return recorded.filter((topic) => !CIRCADIAN_STATE.test(topic));
|
|
44
|
+
}
|
|
45
|
+
// Whether the room publishes its control states and availability under its
|
|
46
|
+
// area, and their discovery.
|
|
38
47
|
function roomPublishesState(config) {
|
|
39
48
|
return config.area !== "" && config.publishState !== false;
|
|
40
49
|
}
|
|
41
50
|
function roomPublishesDiscovery(config) {
|
|
42
51
|
return roomPublishesState(config) && config.discovery !== false;
|
|
43
52
|
}
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
|
|
53
|
+
// The circadian, sleep, wake and bed entities the room published before
|
|
54
|
+
// 6.0, cleared at every start: the circadian lighting policy publishes its
|
|
55
|
+
// own, and no 6.0 node publishes these, so clearing them is always safe.
|
|
56
|
+
function oldCircadianClears(config) {
|
|
57
|
+
// A room that publishes nothing cleared them itself before 6.0, when its
|
|
58
|
+
// publishing was switched off.
|
|
59
|
+
if ((0, topic_names_1.areaId)(config.area) === "" || !roomPublishesState(config))
|
|
60
|
+
return [];
|
|
61
|
+
const prefix = discoveryConfig(config).discoveryPrefix;
|
|
62
|
+
return (0, circadian_publishing_1.roomCircadianDiscoveryTopics)({ area: config.area, discoveryPrefix: prefix }, config.idScheme === "node" ? "node" : "area", config.nodeId)
|
|
63
|
+
.map((topic) => ({ topic, payload: "", retain: true }));
|
|
48
64
|
}
|
|
49
|
-
|
|
50
|
-
|
|
65
|
+
// Each light's control sensor, or with discovery switched off, empty
|
|
66
|
+
// retained entries that remove them.
|
|
67
|
+
function roomDiscoveryOutputs(config) {
|
|
68
|
+
if ((0, topic_names_1.areaId)(config.area) === "")
|
|
69
|
+
return [];
|
|
70
|
+
return (0, room_lighting_discovery_1.roomDiscovery)(discoveryConfig(config), targetIds(config))
|
|
71
|
+
.map((entry) => (roomPublishesDiscovery(config) ? entry : { topic: entry.topic, payload: "", retain: true }));
|
|
51
72
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
73
|
+
// What the room publishes as the flows start and as it stops: its old
|
|
74
|
+
// circadian entries cleared, then with discovery on, its entries, and when it
|
|
75
|
+
// publishes at all, its availability, so Home Assistant shows its entities as
|
|
76
|
+
// available only while it runs. Removing its entries when discovery is off
|
|
77
|
+
// waits for the startup message: under the area scheme, another room could
|
|
78
|
+
// publish them.
|
|
79
|
+
function roomStartingOutputs(config) {
|
|
80
|
+
const entries = roomPublishesDiscovery(config) ? roomDiscoveryOutputs(config) : [];
|
|
81
|
+
return [...oldCircadianClears(config), ...entries, ...(roomPublishesState(config) ? [(0, room_lighting_discovery_1.roomAvailabilityMessage)(config.area, true)] : [])];
|
|
55
82
|
}
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
function
|
|
59
|
-
|
|
60
|
-
{ name: "circadian-set", topic: (0, room_lighting_discovery_1.circadianCommandTopic)(area), invalid: "not-on-or-off",
|
|
61
|
-
event: (payload) => {
|
|
62
|
-
const enabled = onOff(payload);
|
|
63
|
-
return enabled === null ? null : { kind: "circadian", enabled };
|
|
64
|
-
} },
|
|
65
|
-
{ name: "sleep-set", topic: (0, room_lighting_discovery_1.sleepCommandTopic)(area), invalid: "not-on-or-off",
|
|
66
|
-
event: (payload) => {
|
|
67
|
-
const enabled = onOff(payload);
|
|
68
|
-
return enabled === null ? null : { kind: "sleep", enabled };
|
|
69
|
-
} },
|
|
70
|
-
{ name: "wake-time-set", topic: (0, room_lighting_discovery_1.scheduleCommandTopic)(area, "wake-time"), invalid: "not-a-time",
|
|
71
|
-
event: (payload) => {
|
|
72
|
-
const wakeTime = (0, ha_discovery_1.timeEntityValue)(payload);
|
|
73
|
-
return wakeTime === null ? null : { kind: "schedule", wakeTime };
|
|
74
|
-
} },
|
|
75
|
-
{ name: "bed-time-set", topic: (0, room_lighting_discovery_1.scheduleCommandTopic)(area, "bed-time"), invalid: "not-a-time",
|
|
76
|
-
event: (payload) => {
|
|
77
|
-
const bedTime = (0, ha_discovery_1.timeEntityValue)(payload);
|
|
78
|
-
return bedTime === null ? null : { kind: "schedule", bedTime };
|
|
79
|
-
} }
|
|
80
|
-
];
|
|
81
|
-
// Following the house, the room's own wake and bed set topics are not read.
|
|
82
|
-
return ownTimesToo ? topics : topics.filter(({ name }) => name !== "wake-time-set" && name !== "bed-time-set");
|
|
83
|
+
// At the startup message: as at the flows start, and with discovery off,
|
|
84
|
+
// its entries removed.
|
|
85
|
+
function roomStartupOutputs(config) {
|
|
86
|
+
return [...oldCircadianClears(config), ...roomDiscoveryOutputs(config), ...(roomPublishesState(config) ? [(0, room_lighting_discovery_1.roomAvailabilityMessage)(config.area, true)] : [])];
|
|
83
87
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
// Read only while the room publishes, as the entities are only discovered
|
|
87
|
-
// then; a bare MQTT message, or one a flow tagged as observed, is accepted.
|
|
88
|
-
// Anything else passes through unchanged.
|
|
89
|
-
function roomInbound(msg, config) {
|
|
90
|
-
const event = msg.lighting || {};
|
|
91
|
-
const set = roomPublishesState(config) && (!event.kind || event.kind === "observed" || event.kind === "command-observed")
|
|
92
|
-
? setTopics(config.area, ownTimes(config)).find(({ topic }) => topic === msg.topic)
|
|
93
|
-
: undefined;
|
|
94
|
-
if (!set)
|
|
95
|
-
return { msg, traces: [] };
|
|
96
|
-
if (msg.retain === true || event.retained === true) {
|
|
97
|
-
return {
|
|
98
|
-
msg: { ...msg, lighting: { kind: "ignored" } },
|
|
99
|
-
traces: [{ event: set.name, outcome: "ignored", reason: "retained-message", details: {} }]
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
const mapped = set.event(msg.payload);
|
|
103
|
-
if (mapped)
|
|
104
|
-
return { msg: { ...msg, lighting: mapped }, traces: [] };
|
|
105
|
-
return {
|
|
106
|
-
msg: { ...msg, lighting: { kind: "ignored" } },
|
|
107
|
-
traces: [{
|
|
108
|
-
event: set.name,
|
|
109
|
-
outcome: "ignored",
|
|
110
|
-
reason: set.invalid,
|
|
111
|
-
details: { payload: typeof msg.payload === "string" ? msg.payload : null }
|
|
112
|
-
}]
|
|
113
|
-
};
|
|
88
|
+
function roomStoppingOutputs(config) {
|
|
89
|
+
return roomPublishesState(config) ? [(0, room_lighting_discovery_1.roomAvailabilityMessage)(config.area, false)] : [];
|
|
114
90
|
}
|
|
115
91
|
// A light's retained control state: in-control, overridden or manual.
|
|
116
92
|
function controlMessage(config, state, targetId) {
|
|
117
93
|
const entry = state.control[targetId];
|
|
94
|
+
const available = state.available[targetId];
|
|
118
95
|
return {
|
|
119
96
|
topic: (0, room_lighting_discovery_1.roomControlTopic)(config.area, targetId),
|
|
120
|
-
|
|
97
|
+
// Its availability once its adapter has reported it: shown, never acted on.
|
|
98
|
+
payload: { state: entry?.state ?? "in-control", owner: entry?.state === "overridden" ? entry.owner : null,
|
|
99
|
+
...(available !== undefined ? { available } : {}) },
|
|
121
100
|
retain: true
|
|
122
101
|
};
|
|
123
102
|
}
|
|
124
|
-
// The room's transition with its MQTT side
|
|
125
|
-
//
|
|
126
|
-
//
|
|
127
|
-
//
|
|
128
|
-
// the circadian state before the lights are restyled; any light whose control
|
|
129
|
-
// state changed has it published after the commands.
|
|
103
|
+
// The room's transition with its MQTT side. At startup, the discovery
|
|
104
|
+
// entries (or their removal) and availability come first and every light's
|
|
105
|
+
// control state last; any light whose control state changed has it
|
|
106
|
+
// published after the commands.
|
|
130
107
|
function publishRoom(saved, msg, config, now) {
|
|
131
|
-
const
|
|
132
|
-
const
|
|
133
|
-
const kind = inbound.msg.lighting?.kind;
|
|
108
|
+
const result = (0, room_controller_1.transitionRoom)(saved, msg, config, now);
|
|
109
|
+
const kind = msg.lighting?.kind;
|
|
134
110
|
const publishes = roomPublishesState(config);
|
|
135
|
-
const before = [];
|
|
136
|
-
if (kind === "startup") {
|
|
137
|
-
if ((0, topic_names_1.areaId)(config.area) !== "") {
|
|
138
|
-
// Discovery switched off: empty retained entries remove the entities
|
|
139
|
-
// from Home Assistant.
|
|
140
|
-
for (const entry of (0, room_lighting_discovery_1.roomDiscovery)(discoveryConfig(config), targetIds(config))) {
|
|
141
|
-
before.push(roomPublishesDiscovery(config) ? entry : { topic: entry.topic, payload: "", retain: true });
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
if (publishes) {
|
|
145
|
-
before.push((0, room_lighting_discovery_1.roomAvailabilityMessage)(config.area, true));
|
|
146
|
-
before.push((0, room_lighting_discovery_1.circadianStateMessage)(config.area, result.state.circadianEnabled));
|
|
147
|
-
before.push((0, room_lighting_discovery_1.sleepStateMessage)(config.area, result.state.sleeping));
|
|
148
|
-
if (ownTimes(config))
|
|
149
|
-
before.push(...(0, room_lighting_discovery_1.scheduleStateMessages)(config.area, result.state.schedule));
|
|
150
|
-
}
|
|
151
|
-
// Following the house, the room's own time entities and their state are
|
|
152
|
-
// cleared, every start, whatever was published before.
|
|
153
|
-
if (!ownTimes(config) && (0, topic_names_1.areaId)(config.area) !== "") {
|
|
154
|
-
const ownTimeTopics = [
|
|
155
|
-
...(0, room_lighting_discovery_1.roomTimeDiscoveryTopics)(discoveryConfig(config)),
|
|
156
|
-
(0, room_lighting_discovery_1.scheduleStateTopic)(config.area, "wake-time"),
|
|
157
|
-
(0, room_lighting_discovery_1.scheduleStateTopic)(config.area, "bed-time")
|
|
158
|
-
];
|
|
159
|
-
before.push(...ownTimeTopics.map((topic) => ({ topic, payload: "", retain: true })));
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
else if (kind === "circadian" && publishes) {
|
|
163
|
-
before.push((0, room_lighting_discovery_1.circadianStateMessage)(config.area, result.state.circadianEnabled));
|
|
164
|
-
}
|
|
165
|
-
else if (kind === "sleep" && publishes) {
|
|
166
|
-
before.push((0, room_lighting_discovery_1.sleepStateMessage)(config.area, result.state.sleeping));
|
|
167
|
-
}
|
|
168
|
-
else if (kind === "schedule" && publishes && ownTimes(config)) {
|
|
169
|
-
before.push(...(0, room_lighting_discovery_1.scheduleStateMessages)(config.area, result.state.schedule));
|
|
170
|
-
}
|
|
111
|
+
const before = kind === "startup" ? roomStartupOutputs(config) : [];
|
|
171
112
|
const controls = publishes
|
|
172
113
|
? config.targets
|
|
173
114
|
.filter((target) => kind === "startup" || result.controlChanged.includes(target.id))
|
|
@@ -175,8 +116,7 @@ function publishRoom(saved, msg, config, now) {
|
|
|
175
116
|
: [];
|
|
176
117
|
return {
|
|
177
118
|
...result,
|
|
178
|
-
outputs: [...before, ...result.outputs, ...controls]
|
|
179
|
-
traces: [...inbound.traces, ...result.traces]
|
|
119
|
+
outputs: [...before, ...result.outputs, ...controls]
|
|
180
120
|
};
|
|
181
121
|
}
|
|
182
122
|
//# sourceMappingURL=room-publishing.js.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { TraceEntry } from "./bounded-trace";
|
|
2
|
+
import type { CoverCommand, CoverEvent } from "./cover-controller";
|
|
3
|
+
import { type MqttPublication } from "./mqtt-message";
|
|
4
|
+
export type { MqttPublication } from "./mqtt-message";
|
|
5
|
+
export interface ShellyCoverConfig {
|
|
6
|
+
topicPrefix: string;
|
|
7
|
+
channel: number;
|
|
8
|
+
}
|
|
9
|
+
export interface ShellyCoverState {
|
|
10
|
+
status: Record<string, unknown> | null;
|
|
11
|
+
complete: boolean;
|
|
12
|
+
command: {
|
|
13
|
+
operation: string;
|
|
14
|
+
generation: number;
|
|
15
|
+
} | null;
|
|
16
|
+
}
|
|
17
|
+
export interface ShellyCoverMessage {
|
|
18
|
+
topic?: unknown;
|
|
19
|
+
payload?: unknown;
|
|
20
|
+
cover_command?: CoverCommand;
|
|
21
|
+
}
|
|
22
|
+
export declare function normaliseShellyCoverConfig(config: {
|
|
23
|
+
topicPrefix?: unknown;
|
|
24
|
+
channel?: unknown;
|
|
25
|
+
}): ShellyCoverConfig;
|
|
26
|
+
export declare function shellyCoverTopics(config: ShellyCoverConfig): {
|
|
27
|
+
command: string;
|
|
28
|
+
status: string;
|
|
29
|
+
events: string;
|
|
30
|
+
online: string;
|
|
31
|
+
component: string;
|
|
32
|
+
};
|
|
33
|
+
export declare function transitionShellyCover(saved: Partial<ShellyCoverState> | undefined, msg: ShellyCoverMessage, config: ShellyCoverConfig, now: Date): {
|
|
34
|
+
state: ShellyCoverState;
|
|
35
|
+
publications: MqttPublication[];
|
|
36
|
+
readings: {
|
|
37
|
+
cover: CoverEvent;
|
|
38
|
+
}[];
|
|
39
|
+
traces: TraceEntry<Record<string, unknown>>[];
|
|
40
|
+
status: {
|
|
41
|
+
text: string;
|
|
42
|
+
calibrated: boolean;
|
|
43
|
+
};
|
|
44
|
+
};
|