@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
|
@@ -4,6 +4,7 @@ exports.parseAvrLine = exports.formatVolumeCommand = exports.QUERY_COMMAND = voi
|
|
|
4
4
|
exports.createAvrState = createAvrState;
|
|
5
5
|
exports.normaliseAvrConfig = normaliseAvrConfig;
|
|
6
6
|
exports.transitionAvr = transitionAvr;
|
|
7
|
+
const adopted_request_1 = require("./adopted-request");
|
|
7
8
|
const settings_1 = require("./settings");
|
|
8
9
|
const target_state_1 = require("./target-state");
|
|
9
10
|
const denon_protocol_1 = require("./denon-protocol");
|
|
@@ -73,7 +74,8 @@ function createAvrState(_config, saved = {}) {
|
|
|
73
74
|
},
|
|
74
75
|
lastAttempt: Number.isInteger(saved.lastAttempt) && (saved.lastAttempt ?? -1) >= 0
|
|
75
76
|
? saved.lastAttempt
|
|
76
|
-
: 0
|
|
77
|
+
: 0,
|
|
78
|
+
adoptedGeneration: (0, adopted_request_1.savedAdoptedGeneration)(saved)
|
|
77
79
|
};
|
|
78
80
|
}
|
|
79
81
|
function sameVolume(left, right) {
|
|
@@ -450,7 +452,19 @@ function transitionAvr(saved, msg, rawConfig, nowValue = new Date()) {
|
|
|
450
452
|
return "zero-volume-delta";
|
|
451
453
|
return null;
|
|
452
454
|
}
|
|
453
|
-
|
|
455
|
+
// A refresh with the activity's wanted values, reaching a node with
|
|
456
|
+
// nothing desired (it started with nothing saved): adopt them, and
|
|
457
|
+
// rediscover below as at startup (see adopted-request.ts).
|
|
458
|
+
const adoptable = event.kind === "refresh" ? (0, adopted_request_1.adoptableRefresh)(event, state) : null;
|
|
459
|
+
const adopted = adoptable !== null && event.kind === "refresh" &&
|
|
460
|
+
validateIntent({ kind: "intent", ...adoptable, power: event.power, source: event.source ?? null }) === null;
|
|
461
|
+
if (adopted && event.kind === "refresh") {
|
|
462
|
+
state.desired = { ...adoptable, power: event.power, source: event.source || null };
|
|
463
|
+
state.generation = adoptable.generation;
|
|
464
|
+
state.adoptedGeneration = adoptable.generation;
|
|
465
|
+
trace("refresh", "adopted", "nothing-desired", { power: event.power, source: event.source || null, generation: adoptable.generation });
|
|
466
|
+
}
|
|
467
|
+
if (event.kind === "refresh" && !adopted) {
|
|
454
468
|
// Re-read the receiver without touching work in flight: desired state,
|
|
455
469
|
// pending commands, the volume request and the phase all carry on.
|
|
456
470
|
commands.push({
|
|
@@ -466,7 +480,7 @@ function transitionAvr(saved, msg, rawConfig, nowValue = new Date()) {
|
|
|
466
480
|
trace("refresh", "querying", null, { pending: state.pending?.operation ?? null });
|
|
467
481
|
forceStateEvent = true;
|
|
468
482
|
}
|
|
469
|
-
else if (event.kind === "startup") {
|
|
483
|
+
else if (event.kind === "startup" || adopted) {
|
|
470
484
|
const requestBlocked = state.desired &&
|
|
471
485
|
state.blockedGeneration === state.desired.generation;
|
|
472
486
|
const abandonedVolumeRequest = state.volumeRequest?.requestId || null;
|
|
@@ -785,6 +799,16 @@ function transitionAvr(saved, msg, rawConfig, nowValue = new Date()) {
|
|
|
785
799
|
}
|
|
786
800
|
forceStateEvent = true;
|
|
787
801
|
}
|
|
802
|
+
// An adopted request only reads the receiver (see adopted-request.ts): a
|
|
803
|
+
// power, zone or source command means it isn't as wanted.
|
|
804
|
+
const held = (0, adopted_request_1.readsOnly)(state, commands, (command) => command.avrCommand.operation === "query" || command.avrCommand.operation === "volume-query");
|
|
805
|
+
if (held.mismatch) {
|
|
806
|
+
commands.splice(0, commands.length, ...held.commands);
|
|
807
|
+
state.pending = null;
|
|
808
|
+
state.classification = "manual_override";
|
|
809
|
+
state.phase = "manual_override";
|
|
810
|
+
trace("command", "withheld", adopted_request_1.ADOPTED_MISMATCH);
|
|
811
|
+
}
|
|
788
812
|
const after = JSON.stringify({
|
|
789
813
|
observed: state.observed,
|
|
790
814
|
seen: state.seen,
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AvrObserved } from "./avr-controller";
|
|
2
|
+
import { type OptInPublishingConfig, type RetainedText } from "./publishing-node";
|
|
3
|
+
export interface AvrPublishingConfig extends OptInPublishingConfig {
|
|
4
|
+
minVolume: number;
|
|
5
|
+
maxVolume: number;
|
|
6
|
+
}
|
|
7
|
+
export type AvrPublication = RetainedText;
|
|
8
|
+
export declare function receiverTopic(area: string, name: string): string;
|
|
9
|
+
export declare function avrDiscovery(config: AvrPublishingConfig): AvrPublication[];
|
|
10
|
+
export declare const VOLUME_SET_SETTLE_MS = 300;
|
|
11
|
+
export declare function avrVolumeRequest(msg: {
|
|
12
|
+
topic?: unknown;
|
|
13
|
+
payload?: unknown;
|
|
14
|
+
retain?: unknown;
|
|
15
|
+
}, config: AvrPublishingConfig): {
|
|
16
|
+
value: number;
|
|
17
|
+
} | {
|
|
18
|
+
ignored: string;
|
|
19
|
+
payload: string;
|
|
20
|
+
} | null;
|
|
21
|
+
export declare function avrStateOutputs(config: AvrPublishingConfig, observed: Partial<AvrObserved> | undefined, before?: Partial<AvrObserved>): AvrPublication[];
|
|
22
|
+
export declare const avrStartingOutputs: (config: AvrPublishingConfig, state: Partial<AvrObserved> | undefined) => RetainedText[];
|
|
23
|
+
export declare const avrStoppingOutputs: (config: AvrPublishingConfig) => RetainedText[];
|
|
24
|
+
export declare const avrRetainedTopics: (config: AvrPublishingConfig) => string[];
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.avrRetainedTopics = exports.avrStoppingOutputs = exports.avrStartingOutputs = exports.VOLUME_SET_SETTLE_MS = void 0;
|
|
4
|
+
exports.receiverTopic = receiverTopic;
|
|
5
|
+
exports.avrDiscovery = avrDiscovery;
|
|
6
|
+
exports.avrVolumeRequest = avrVolumeRequest;
|
|
7
|
+
exports.avrStateOutputs = avrStateOutputs;
|
|
8
|
+
const topic_names_1 = require("./topic-names");
|
|
9
|
+
const publishing_node_1 = require("./publishing-node");
|
|
10
|
+
const FIELDS = ["power", "source", "volume"];
|
|
11
|
+
const DEVICE = { kind: "receiver", label: "Receiver", model: "AV receiver controller" };
|
|
12
|
+
function receiverTopic(area, name) {
|
|
13
|
+
return "home/" + (0, topic_names_1.areaId)(area) + "/receiver/" + name;
|
|
14
|
+
}
|
|
15
|
+
// A field's state as published, or null while it isn't known.
|
|
16
|
+
function fieldValue(observed, field) {
|
|
17
|
+
const value = observed?.[field];
|
|
18
|
+
if (value === null || value === undefined)
|
|
19
|
+
return null;
|
|
20
|
+
if (field === "power")
|
|
21
|
+
return value === "on" ? "ON" : "OFF";
|
|
22
|
+
return String(value);
|
|
23
|
+
}
|
|
24
|
+
// Power and source sensors, and a volume number that shows the volume and
|
|
25
|
+
// sets it, within the configured bounds, on one device per node.
|
|
26
|
+
function avrDiscovery(config) {
|
|
27
|
+
const entry = (component, id, name, fields) => (0, publishing_node_1.discoveryEntry)(config, DEVICE, receiverTopic(config.area, "availability"), { component, id, name, fields });
|
|
28
|
+
return [
|
|
29
|
+
entry("binary_sensor", "receiver_power", "Power", { device_class: "power", state_topic: receiverTopic(config.area, "power/state"), payload_on: "ON", payload_off: "OFF" }),
|
|
30
|
+
entry("sensor", "receiver_source", "Source", { icon: "mdi:import", state_topic: receiverTopic(config.area, "source/state") }),
|
|
31
|
+
entry("number", "receiver_volume", "Volume", {
|
|
32
|
+
icon: "mdi:volume-high",
|
|
33
|
+
state_topic: receiverTopic(config.area, "volume/state"),
|
|
34
|
+
command_topic: receiverTopic(config.area, "volume/set"),
|
|
35
|
+
min: config.minVolume,
|
|
36
|
+
max: config.maxVolume,
|
|
37
|
+
step: 0.5,
|
|
38
|
+
mode: "slider"
|
|
39
|
+
})
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
// How long a volume from Home Assistant waits for a newer one. A slider,
|
|
43
|
+
// repeated taps or an automation can send several in a row; only the last
|
|
44
|
+
// becomes a request, so the receiver never chases steps already replaced.
|
|
45
|
+
exports.VOLUME_SET_SETTLE_MS = 300;
|
|
46
|
+
// A volume from the volume number's set topic, as the receiver's own
|
|
47
|
+
// absolute volume request, so it takes the same bounded, confirmed path as
|
|
48
|
+
// any other request. Read only while the node publishes; retained messages
|
|
49
|
+
// and anything but a number are ignored with a trace.
|
|
50
|
+
function avrVolumeRequest(msg, config) {
|
|
51
|
+
if (!(0, publishing_node_1.publishesState)(config) || msg.topic !== receiverTopic(config.area, "volume/set"))
|
|
52
|
+
return null;
|
|
53
|
+
const text = typeof msg.payload === "string" ? msg.payload.trim() : typeof msg.payload === "number" ? String(msg.payload) : "";
|
|
54
|
+
if (msg.retain === true)
|
|
55
|
+
return { ignored: "retained-message", payload: text };
|
|
56
|
+
const value = text === "" ? NaN : Number(text);
|
|
57
|
+
return Number.isFinite(value) ? { value } : { ignored: "not-a-number", payload: text };
|
|
58
|
+
}
|
|
59
|
+
// The observed fields that changed since `before` (all known fields when
|
|
60
|
+
// there's no `before`).
|
|
61
|
+
function avrStateOutputs(config, observed, before) {
|
|
62
|
+
if (!(0, publishing_node_1.publishesState)(config))
|
|
63
|
+
return [];
|
|
64
|
+
return FIELDS.flatMap((field) => {
|
|
65
|
+
const value = fieldValue(observed, field);
|
|
66
|
+
if (value === null || (before && fieldValue(before, field) === value))
|
|
67
|
+
return [];
|
|
68
|
+
return [(0, publishing_node_1.retainedText)(receiverTopic(config.area, field + "/state"), value)];
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
const receiver = (0, publishing_node_1.publishingNode)({
|
|
72
|
+
entries: avrDiscovery,
|
|
73
|
+
availabilityTopic: (area) => receiverTopic(area, "availability"),
|
|
74
|
+
stateTopics: (config) => FIELDS.map((field) => receiverTopic(config.area, field + "/state")),
|
|
75
|
+
stateOutputs: (config, observed) => avrStateOutputs(config, observed)
|
|
76
|
+
});
|
|
77
|
+
exports.avrStartingOutputs = receiver.starting;
|
|
78
|
+
exports.avrStoppingOutputs = receiver.stopping;
|
|
79
|
+
exports.avrRetainedTopics = receiver.retainedTopics;
|
|
80
|
+
//# sourceMappingURL=avr-publishing.js.map
|
|
@@ -37,6 +37,7 @@ export interface BacklightingState {
|
|
|
37
37
|
blockedGeneration: number | null;
|
|
38
38
|
classification: "manual_override" | null;
|
|
39
39
|
lastAttempt: number;
|
|
40
|
+
adoptedGeneration: number | null;
|
|
40
41
|
}
|
|
41
42
|
export type BacklightingEvent = {
|
|
42
43
|
kind: "intent";
|
|
@@ -58,7 +59,12 @@ export type BacklightingEvent = {
|
|
|
58
59
|
kind: "tick";
|
|
59
60
|
generation: number;
|
|
60
61
|
} | {
|
|
61
|
-
kind: "startup"
|
|
62
|
+
kind: "startup";
|
|
63
|
+
} | {
|
|
64
|
+
kind: "refresh";
|
|
65
|
+
requestId?: string | null;
|
|
66
|
+
generation?: number;
|
|
67
|
+
power?: string;
|
|
62
68
|
};
|
|
63
69
|
export interface BacklightingMessage {
|
|
64
70
|
backlighting?: BacklightingEvent;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normaliseBacklightingConfig = normaliseBacklightingConfig;
|
|
4
4
|
exports.transitionBacklighting = transitionBacklighting;
|
|
5
|
+
const adopted_request_1 = require("./adopted-request");
|
|
5
6
|
const settings_1 = require("./settings");
|
|
6
7
|
const observation_time_1 = require("./observation-time");
|
|
7
8
|
const target_state_1 = require("./target-state");
|
|
@@ -25,7 +26,8 @@ function initialState(saved = {}) {
|
|
|
25
26
|
classification: saved.classification === "manual_override" ? "manual_override" : null,
|
|
26
27
|
lastAttempt: Number.isInteger(saved.lastAttempt) && (saved.lastAttempt ?? -1) >= 0
|
|
27
28
|
? saved.lastAttempt
|
|
28
|
-
: 0
|
|
29
|
+
: 0,
|
|
30
|
+
adoptedGeneration: (0, adopted_request_1.savedAdoptedGeneration)(saved)
|
|
29
31
|
};
|
|
30
32
|
}
|
|
31
33
|
function commandFor(state, operation, attempt) {
|
|
@@ -152,11 +154,13 @@ function transitionBacklighting(saved, msg, suppliedConfig = {}, nowValue = new
|
|
|
152
154
|
state.phase = "ready";
|
|
153
155
|
trace("observation", "ready", null, { power: observation.power });
|
|
154
156
|
}
|
|
155
|
-
else if (wasReady) {
|
|
157
|
+
else if (wasReady || (0, adopted_request_1.isAdopted)(state)) {
|
|
158
|
+
// A change seen after ready, or an adopted request the device doesn't
|
|
159
|
+
// match: someone else's, and never corrected.
|
|
156
160
|
state.pending = null;
|
|
157
161
|
state.classification = "manual_override";
|
|
158
162
|
state.phase = "manual_override";
|
|
159
|
-
trace("observation", "manual_override", null, {
|
|
163
|
+
trace("observation", "manual_override", wasReady ? null : adopted_request_1.ADOPTED_MISMATCH, {
|
|
160
164
|
expected: state.desired.power,
|
|
161
165
|
observed: observation.power
|
|
162
166
|
});
|
|
@@ -173,6 +177,16 @@ function transitionBacklighting(saved, msg, suppliedConfig = {}, nowValue = new
|
|
|
173
177
|
});
|
|
174
178
|
}
|
|
175
179
|
}
|
|
180
|
+
// A refresh with the activity's wanted values, reaching a node with
|
|
181
|
+
// nothing desired (it started with nothing saved): adopt them, and observe
|
|
182
|
+
// below as at startup (see adopted-request.ts).
|
|
183
|
+
const adoptable = event.kind === "refresh" ? (0, adopted_request_1.adoptableRefresh)(event, state) : null;
|
|
184
|
+
if (adoptable && event.kind === "refresh" && typeof event.power === "string" && Object.hasOwn(POWERS, event.power)) {
|
|
185
|
+
state.desired = { ...adoptable, power: event.power, requestedAt: now.toISOString() };
|
|
186
|
+
state.generation = adoptable.generation;
|
|
187
|
+
state.adoptedGeneration = adoptable.generation;
|
|
188
|
+
trace("refresh", "adopted", "nothing-desired", { power: event.power, generation: adoptable.generation });
|
|
189
|
+
}
|
|
176
190
|
if (event.kind === "intent") {
|
|
177
191
|
acceptIntent(event);
|
|
178
192
|
}
|
|
@@ -235,6 +249,15 @@ function transitionBacklighting(saved, msg, suppliedConfig = {}, nowValue = new
|
|
|
235
249
|
else {
|
|
236
250
|
throw new Error("unknown backlighting event kind");
|
|
237
251
|
}
|
|
252
|
+
// An adopted request only reads the device (see adopted-request.ts).
|
|
253
|
+
const held = (0, adopted_request_1.readsOnly)(state, commands, (command) => command.operation === "observe");
|
|
254
|
+
if (held.mismatch) {
|
|
255
|
+
commands.splice(0, commands.length, ...held.commands);
|
|
256
|
+
state.pending = null;
|
|
257
|
+
state.classification = "manual_override";
|
|
258
|
+
state.phase = "manual_override";
|
|
259
|
+
trace("command", "withheld", adopted_request_1.ADOPTED_MISMATCH);
|
|
260
|
+
}
|
|
238
261
|
if (state.desired) {
|
|
239
262
|
const theatre = (0, target_state_1.targetStateEvent)({
|
|
240
263
|
target: "backlighting",
|
package/dist/lib/circadian.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ import { type DaySchedule } from "./circadian-schedule";
|
|
|
2
2
|
import { type LightLevels, type LightStyle } from "./light-styling";
|
|
3
3
|
export interface CircadianLighting {
|
|
4
4
|
styleAt(now: Date, sleeping: boolean): LightStyle;
|
|
5
|
+
withSchedule(schedule: DaySchedule): CircadianLighting;
|
|
5
6
|
}
|
|
6
7
|
export declare function scheduledLighting(schedule: DaySchedule, levels: LightLevels): CircadianLighting;
|
package/dist/lib/circadian.js
CHANGED
|
@@ -9,6 +9,9 @@ function scheduledLighting(schedule, levels) {
|
|
|
9
9
|
return {
|
|
10
10
|
styleAt(now, sleeping) {
|
|
11
11
|
return (0, light_styling_1.styleAtLevel)(sleeping ? 0 : (0, circadian_schedule_1.scheduleLevel)(now, schedule.wakeTime, schedule.bedTime), levels);
|
|
12
|
+
},
|
|
13
|
+
withSchedule(next) {
|
|
14
|
+
return scheduledLighting(next, levels);
|
|
12
15
|
}
|
|
13
16
|
};
|
|
14
17
|
}
|
|
@@ -4,6 +4,7 @@ export interface ExpectedCommand {
|
|
|
4
4
|
fingerprint: string;
|
|
5
5
|
expires: number;
|
|
6
6
|
on?: boolean;
|
|
7
|
+
power?: boolean;
|
|
7
8
|
echoed?: boolean;
|
|
8
9
|
}
|
|
9
10
|
export declare function parsePayload(payload: unknown): unknown;
|
|
@@ -17,4 +18,5 @@ export declare function checkStateReport(queue: ExpectedCommand[] | undefined, o
|
|
|
17
18
|
export declare function checkCommandEcho(queue: ExpectedCommand[] | undefined, payload: unknown, nowMs: number): {
|
|
18
19
|
queue: ExpectedCommand[];
|
|
19
20
|
own: boolean;
|
|
21
|
+
changed: boolean;
|
|
20
22
|
};
|
package/dist/lib/command-echo.js
CHANGED
|
@@ -46,8 +46,10 @@ function rememberCommand(queue, payload, nowMs) {
|
|
|
46
46
|
const requested = payload && typeof payload === "object"
|
|
47
47
|
? String(payload.state || "").toUpperCase()
|
|
48
48
|
: "";
|
|
49
|
-
if (requested === "ON" || requested === "OFF")
|
|
49
|
+
if (requested === "ON" || requested === "OFF") {
|
|
50
50
|
entry.on = requested === "ON";
|
|
51
|
+
entry.power = entry.on;
|
|
52
|
+
}
|
|
51
53
|
next.push(entry);
|
|
52
54
|
return next.slice(-exports.ECHO_QUEUE_LIMIT);
|
|
53
55
|
}
|
|
@@ -59,24 +61,46 @@ function checkStateReport(queue, observedOn, nowMs) {
|
|
|
59
61
|
for (const entry of next)
|
|
60
62
|
delete entry.on;
|
|
61
63
|
}
|
|
62
|
-
return {
|
|
63
|
-
queue: next.filter((entry) => entry.on !== undefined || entry.echoed !== true),
|
|
64
|
-
verdict
|
|
65
|
-
};
|
|
64
|
+
return { queue: next, verdict };
|
|
66
65
|
}
|
|
67
|
-
// A command seen on the command topic: one of ours
|
|
68
|
-
//
|
|
66
|
+
// A command seen on the command topic: one of ours, or someone else's.
|
|
67
|
+
// - Exactly a command we sent in the echo window is ours, even when its echo
|
|
68
|
+
// was already seen: a duplicate or late echo.
|
|
69
|
+
// - A bare ON or OFF that arrives while one of our commands with that power
|
|
70
|
+
// isn't echoed yet is taken as that command, changed on the way (a
|
|
71
|
+
// function between the controller and MQTT out that cut the payload to
|
|
72
|
+
// {"state":"ON"}, say): `changed`. That command is then marked echoed but
|
|
73
|
+
// kept, so its own exact echo, if it still comes, is ours too. Without
|
|
74
|
+
// this the controller answered its own command as someone else's, which
|
|
75
|
+
// looped.
|
|
69
76
|
function checkCommandEcho(queue, payload, nowMs) {
|
|
70
77
|
const next = live(queue, nowMs);
|
|
71
|
-
const
|
|
78
|
+
const print = fingerprint(payload);
|
|
79
|
+
let ownIndex = next.findIndex((entry) => entry.echoed !== true && entry.fingerprint === print);
|
|
80
|
+
if (ownIndex < 0) {
|
|
81
|
+
const repeat = next.findIndex((entry) => entry.echoed === true && entry.fingerprint === print);
|
|
82
|
+
if (repeat >= 0)
|
|
83
|
+
return { queue: next, own: true, changed: false };
|
|
84
|
+
}
|
|
85
|
+
let changed = false;
|
|
86
|
+
if (ownIndex < 0) {
|
|
87
|
+
const requested = payload && typeof payload === "object"
|
|
88
|
+
? String(payload.state || "").toUpperCase()
|
|
89
|
+
: "";
|
|
90
|
+
if (requested === "ON" || requested === "OFF") {
|
|
91
|
+
for (let index = next.length - 1; index >= 0 && ownIndex < 0; index -= 1) {
|
|
92
|
+
if (next[index].echoed !== true && next[index].power === (requested === "ON"))
|
|
93
|
+
ownIndex = index;
|
|
94
|
+
}
|
|
95
|
+
changed = ownIndex >= 0;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
72
98
|
const own = next[ownIndex];
|
|
73
99
|
if (!own)
|
|
74
|
-
return { queue: next, own: false };
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
own.echoed = true;
|
|
80
|
-
return { queue: next, own: true };
|
|
100
|
+
return { queue: next, own: false, changed: false };
|
|
101
|
+
// Kept until it expires: for state reports while its power is unconfirmed,
|
|
102
|
+
// and to know a repeat of its echo.
|
|
103
|
+
own.echoed = true;
|
|
104
|
+
return { queue: next, own: true, changed };
|
|
81
105
|
}
|
|
82
106
|
//# sourceMappingURL=command-echo.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyCoverAvailability = applyCoverAvailability;
|
|
4
|
+
// Applies a change of availability; says which way it went, or null when it
|
|
5
|
+
// was no change. The caller clears what it observed and re-reads on "online".
|
|
6
|
+
function applyCoverAvailability(state, online) {
|
|
7
|
+
if (online !== true && online !== false)
|
|
8
|
+
throw new Error("cover availability online must be true or false");
|
|
9
|
+
if (!online && state.available) {
|
|
10
|
+
state.available = false;
|
|
11
|
+
state.phaseBeforeUnavailable = state.phase;
|
|
12
|
+
state.pending = null;
|
|
13
|
+
state.phase = "unavailable";
|
|
14
|
+
return "offline";
|
|
15
|
+
}
|
|
16
|
+
if (online && !state.available) {
|
|
17
|
+
state.available = true;
|
|
18
|
+
state.phase = state.phaseBeforeUnavailable ?? "idle";
|
|
19
|
+
state.phaseBeforeUnavailable = null;
|
|
20
|
+
return "online";
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=cover-availability.js.map
|
|
@@ -22,6 +22,8 @@ export interface CoverObservation {
|
|
|
22
22
|
position: number;
|
|
23
23
|
motion: CoverMotion | null;
|
|
24
24
|
observedAt: string;
|
|
25
|
+
battery?: number | null;
|
|
26
|
+
charging?: string | null;
|
|
25
27
|
}
|
|
26
28
|
export interface CoverPending {
|
|
27
29
|
operation: CoverOperation;
|
|
@@ -50,12 +52,15 @@ export interface CoverState {
|
|
|
50
52
|
blockedGeneration: number | null;
|
|
51
53
|
classification: "manual_override" | null;
|
|
52
54
|
lastAttempt: number;
|
|
55
|
+
available: boolean;
|
|
56
|
+
phaseBeforeUnavailable: string | null;
|
|
53
57
|
}
|
|
54
58
|
interface IntentBase {
|
|
55
59
|
requestId: string;
|
|
56
60
|
generation: number;
|
|
57
61
|
source?: string;
|
|
58
62
|
requestedAt?: string;
|
|
63
|
+
respectManual?: boolean;
|
|
59
64
|
}
|
|
60
65
|
export type CoverEvent = (IntentBase & {
|
|
61
66
|
kind: "set_position";
|
|
@@ -67,11 +72,16 @@ export type CoverEvent = (IntentBase & {
|
|
|
67
72
|
position: number;
|
|
68
73
|
motion?: CoverMotion;
|
|
69
74
|
observedAt: string;
|
|
75
|
+
battery?: number;
|
|
76
|
+
charging?: string;
|
|
70
77
|
} | {
|
|
71
78
|
kind: "command_result";
|
|
72
79
|
generation: number;
|
|
73
80
|
ok: boolean;
|
|
74
81
|
reason?: string;
|
|
82
|
+
} | {
|
|
83
|
+
kind: "availability";
|
|
84
|
+
online: boolean;
|
|
75
85
|
} | {
|
|
76
86
|
kind: "tick";
|
|
77
87
|
generation: number;
|
|
@@ -103,7 +113,8 @@ export interface CoverOutputEvent {
|
|
|
103
113
|
};
|
|
104
114
|
}, CoverFailure>;
|
|
105
115
|
}
|
|
106
|
-
export declare function normaliseCoverConfig(config?: Partial<CoverConfig
|
|
116
|
+
export declare function normaliseCoverConfig(config?: Partial<Record<keyof CoverConfig, unknown>>): CoverConfig;
|
|
117
|
+
export declare function coverMoving(state: Pick<CoverState, "observed" | "phase">): boolean;
|
|
107
118
|
export declare function transitionCover(saved: Partial<CoverState> | undefined, msg: CoverMessage, suppliedConfig?: Partial<CoverConfig>, nowValue?: Date | string | number): {
|
|
108
119
|
state: CoverState;
|
|
109
120
|
commands: CoverCommand[];
|
|
@@ -112,6 +123,7 @@ export declare function transitionCover(saved: Partial<CoverState> | undefined,
|
|
|
112
123
|
status: {
|
|
113
124
|
phase: string;
|
|
114
125
|
text: string;
|
|
126
|
+
moving: boolean;
|
|
115
127
|
};
|
|
116
128
|
};
|
|
117
129
|
export {};
|