@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
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.circadianStateTopic = circadianStateTopic;
|
|
4
|
+
exports.circadianCommandTopic = circadianCommandTopic;
|
|
5
|
+
exports.circadianStateMessage = circadianStateMessage;
|
|
6
|
+
exports.roomLightingDiscovery = roomLightingDiscovery;
|
|
7
|
+
function circadianStateTopic(area) {
|
|
8
|
+
return "home/" + area + "/circadian/state";
|
|
9
|
+
}
|
|
10
|
+
function circadianCommandTopic(area) {
|
|
11
|
+
return "home/" + area + "/circadian/set";
|
|
12
|
+
}
|
|
13
|
+
// The retained circadian state, as Home Assistant reads it.
|
|
14
|
+
function circadianStateMessage(area, enabled) {
|
|
15
|
+
return { topic: circadianStateTopic(area), payload: enabled ? "ON" : "OFF", retain: true };
|
|
16
|
+
}
|
|
17
|
+
// The discovery entry for the room's circadian switch, then its state.
|
|
18
|
+
function roomLightingDiscovery(area, displayName, circadianEnabled) {
|
|
19
|
+
const objectId = area + "_circadian_lighting";
|
|
20
|
+
return [
|
|
21
|
+
{
|
|
22
|
+
topic: "homeassistant/switch/" + objectId + "/config",
|
|
23
|
+
payload: {
|
|
24
|
+
name: displayName + " Circadian Lighting",
|
|
25
|
+
unique_id: objectId,
|
|
26
|
+
default_entity_id: "switch." + objectId,
|
|
27
|
+
icon: "mdi:clock-time-seven-outline",
|
|
28
|
+
command_topic: circadianCommandTopic(area),
|
|
29
|
+
state_topic: circadianStateTopic(area),
|
|
30
|
+
payload_on: "ON",
|
|
31
|
+
payload_off: "OFF",
|
|
32
|
+
optimistic: false,
|
|
33
|
+
device: {
|
|
34
|
+
identifiers: ["nodered_" + area + "_lighting"],
|
|
35
|
+
name: displayName + " Lighting Controller",
|
|
36
|
+
manufacturer: "Node-RED",
|
|
37
|
+
model: "Composable circadian lighting"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
retain: true
|
|
41
|
+
},
|
|
42
|
+
circadianStateMessage(area, circadianEnabled)
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=room-lighting-discovery.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function numberSetting(value: unknown, label: string, fallback: number): number;
|
|
2
|
+
export declare function booleanSetting(value: unknown, label: string, fallback: boolean): boolean;
|
|
3
|
+
export declare function optionalBooleanSetting(value: unknown, label: string): boolean | null;
|
|
4
|
+
export declare function textSetting(value: unknown, label: string, fallback?: string): string;
|
|
5
|
+
export declare function jsonSetting(value: unknown, label: string, fallback: unknown): unknown;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.numberSetting = numberSetting;
|
|
4
|
+
exports.booleanSetting = booleanSetting;
|
|
5
|
+
exports.optionalBooleanSetting = optionalBooleanSetting;
|
|
6
|
+
exports.textSetting = textSetting;
|
|
7
|
+
exports.jsonSetting = jsonSetting;
|
|
8
|
+
// A numeric node setting, read from the editor's value. A setting absent from
|
|
9
|
+
// a flow saved before it existed takes its default. Anything else must be a
|
|
10
|
+
// number: an emptied field, null or text is an error naming the setting, so
|
|
11
|
+
// the node reports it instead of running with a value nobody chose.
|
|
12
|
+
function numberSetting(value, label, fallback) {
|
|
13
|
+
if (value === undefined)
|
|
14
|
+
return fallback;
|
|
15
|
+
const parsed = typeof value === "number" ? value
|
|
16
|
+
: typeof value === "string" && value.trim() !== "" ? Number(value)
|
|
17
|
+
: NaN;
|
|
18
|
+
if (!Number.isFinite(parsed))
|
|
19
|
+
throw new Error(`${label} must be a number`);
|
|
20
|
+
return parsed;
|
|
21
|
+
}
|
|
22
|
+
// An on/off setting. A setting absent from an older saved flow takes its
|
|
23
|
+
// default; true/"true" and false/"false" are read as such; anything else is
|
|
24
|
+
// an error naming the setting.
|
|
25
|
+
function booleanSetting(value, label, fallback) {
|
|
26
|
+
if (value === undefined)
|
|
27
|
+
return fallback;
|
|
28
|
+
const read = optionalBooleanSetting(value, label);
|
|
29
|
+
return read ?? fallback;
|
|
30
|
+
}
|
|
31
|
+
// An on/off setting that can be "not set": null (what the editor stores for
|
|
32
|
+
// it) or absent. Returns null for "not set"; the caller applies its documented
|
|
33
|
+
// meaning. An empty string is not "not set" and is an error.
|
|
34
|
+
function optionalBooleanSetting(value, label) {
|
|
35
|
+
if (value === undefined || value === null)
|
|
36
|
+
return null;
|
|
37
|
+
if (value === true || value === "true")
|
|
38
|
+
return true;
|
|
39
|
+
if (value === false || value === "false")
|
|
40
|
+
return false;
|
|
41
|
+
throw new Error(`${label} must be on or off`);
|
|
42
|
+
}
|
|
43
|
+
// A text setting. Absent from an older saved flow: its default (or, with no
|
|
44
|
+
// default, an error). Otherwise it must not be empty.
|
|
45
|
+
function textSetting(value, label, fallback) {
|
|
46
|
+
if (value === undefined && fallback !== undefined)
|
|
47
|
+
return fallback;
|
|
48
|
+
const text = typeof value === "string" ? value.trim() : "";
|
|
49
|
+
if (!text)
|
|
50
|
+
throw new Error(`${label} is required`);
|
|
51
|
+
return text;
|
|
52
|
+
}
|
|
53
|
+
// A JSON setting, parsed. Absent from an older saved flow: its default.
|
|
54
|
+
// Otherwise it must be JSON text that parses; the caller checks its shape.
|
|
55
|
+
function jsonSetting(value, label, fallback) {
|
|
56
|
+
if (value === undefined)
|
|
57
|
+
return fallback;
|
|
58
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
59
|
+
try {
|
|
60
|
+
return JSON.parse(value);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
// Reported below.
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
throw new Error(`${label} must be valid JSON`);
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=settings.js.map
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { TraceEntry } from "./bounded-trace";
|
|
2
|
+
import { type TargetStateEvent } from "./target-state";
|
|
1
3
|
export type SourceAction = "activate" | "deactivate";
|
|
2
4
|
export type SourceControlMode = "command" | "external" | "unavailable";
|
|
3
5
|
export type SourceConfirmation = "active" | "available" | "application" | "playing" | "unavailable";
|
|
@@ -48,7 +50,6 @@ export interface SourceState {
|
|
|
48
50
|
observed: SourceObservation | null;
|
|
49
51
|
pending: SourcePending | null;
|
|
50
52
|
failure: SourceFailure | null;
|
|
51
|
-
blockedGeneration: number | null;
|
|
52
53
|
classification: "manual_override" | null;
|
|
53
54
|
lastAttempt: number;
|
|
54
55
|
fallbackUsed: boolean;
|
|
@@ -84,8 +85,8 @@ export interface SourceMessage {
|
|
|
84
85
|
sourceCapability?: SourceEvent;
|
|
85
86
|
}
|
|
86
87
|
export declare function normaliseCapabilities(value: unknown): SourceCapabilities;
|
|
87
|
-
export declare function normaliseConfig(config?:
|
|
88
|
-
|
|
88
|
+
export declare function normaliseConfig(config?: {
|
|
89
|
+
[K in keyof SourceConfig]?: unknown;
|
|
89
90
|
}): SourceConfig;
|
|
90
91
|
export interface SourceCommand {
|
|
91
92
|
sourceId: string | null;
|
|
@@ -95,48 +96,42 @@ export interface SourceCommand {
|
|
|
95
96
|
attempt: number;
|
|
96
97
|
}
|
|
97
98
|
export interface SourceOutputEvent {
|
|
98
|
-
theatre: {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
theatre: TargetStateEvent<"source", {
|
|
100
|
+
observedStatus: SourceObservationStatus | null;
|
|
101
|
+
readiness: {
|
|
102
|
+
required: SourceConfirmation;
|
|
103
|
+
available: boolean;
|
|
104
|
+
active: boolean;
|
|
105
|
+
application: string | null;
|
|
106
|
+
playback: SourcePlaybackState;
|
|
107
|
+
satisfied: boolean;
|
|
108
|
+
};
|
|
109
|
+
recovery: Record<string, unknown>;
|
|
110
|
+
metrics: {
|
|
111
|
+
attempts: number;
|
|
112
|
+
retries: number;
|
|
113
|
+
fallbackUsed: boolean;
|
|
114
|
+
};
|
|
115
|
+
}, SourceFailure> & {
|
|
105
116
|
sourceId: string | null;
|
|
106
117
|
action: SourceAction;
|
|
107
|
-
classification?: "manual_override";
|
|
108
|
-
details: {
|
|
109
|
-
observedStatus: SourceObservationStatus | null;
|
|
110
|
-
readiness: {
|
|
111
|
-
required: SourceConfirmation;
|
|
112
|
-
available: boolean;
|
|
113
|
-
active: boolean;
|
|
114
|
-
application: string | null;
|
|
115
|
-
playback: SourcePlaybackState;
|
|
116
|
-
satisfied: boolean;
|
|
117
|
-
};
|
|
118
|
-
recovery: Record<string, unknown>;
|
|
119
|
-
metrics: {
|
|
120
|
-
attempts: number;
|
|
121
|
-
retries: number;
|
|
122
|
-
fallbackUsed: boolean;
|
|
123
|
-
};
|
|
124
|
-
};
|
|
125
|
-
failure?: SourceFailure;
|
|
126
118
|
};
|
|
127
119
|
}
|
|
120
|
+
export declare function readinessEvidence(observation: SourceObservation | null, required: SourceConfirmation): {
|
|
121
|
+
available: boolean;
|
|
122
|
+
active: boolean;
|
|
123
|
+
application: string | null;
|
|
124
|
+
playback: SourcePlaybackState;
|
|
125
|
+
required: SourceConfirmation;
|
|
126
|
+
satisfied: boolean;
|
|
127
|
+
};
|
|
128
128
|
export declare function transitionSource(saved: Partial<SourceState> | undefined, msg: SourceMessage, suppliedConfig?: Partial<SourceConfig> & {
|
|
129
129
|
sources?: unknown;
|
|
130
130
|
}, nowValue?: Date | string | number): {
|
|
131
131
|
state: SourceState;
|
|
132
132
|
commands: SourceCommand[];
|
|
133
133
|
events: SourceOutputEvent[];
|
|
134
|
-
traces:
|
|
135
|
-
event: string;
|
|
136
|
-
outcome: string;
|
|
137
|
-
reason: string | null;
|
|
138
|
-
details: Record<string, unknown>;
|
|
139
|
-
}[];
|
|
134
|
+
traces: TraceEntry<Record<string, unknown>>[];
|
|
140
135
|
status: {
|
|
141
136
|
phase: string;
|
|
142
137
|
text: string;
|
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normaliseCapabilities = normaliseCapabilities;
|
|
4
4
|
exports.normaliseConfig = normaliseConfig;
|
|
5
|
+
exports.readinessEvidence = readinessEvidence;
|
|
5
6
|
exports.transitionSource = transitionSource;
|
|
7
|
+
const settings_1 = require("./settings");
|
|
6
8
|
const observation_time_1 = require("./observation-time");
|
|
9
|
+
const target_state_1 = require("./target-state");
|
|
7
10
|
const ACTIONS = { activate: true, deactivate: true };
|
|
8
11
|
const CONTROL_MODES = {
|
|
9
12
|
command: true,
|
|
@@ -70,12 +73,14 @@ function normaliseCapabilities(value) {
|
|
|
70
73
|
throw new Error("sources must not be empty");
|
|
71
74
|
return sources;
|
|
72
75
|
}
|
|
76
|
+
// Settings may be editor strings; missing, zero or unusable numbers take
|
|
77
|
+
// defaults.
|
|
73
78
|
function normaliseConfig(config = {}) {
|
|
74
79
|
return {
|
|
75
80
|
sources: normaliseCapabilities(config.sources),
|
|
76
|
-
pollMs: Math.max(250,
|
|
77
|
-
confirmationTimeoutMs: Math.max(1000,
|
|
78
|
-
maxAttempts: Math.max(1, Math.floor(
|
|
81
|
+
pollMs: Math.max(250, (0, settings_1.numberSetting)(config.pollMs, "poll interval", 2000)),
|
|
82
|
+
confirmationTimeoutMs: Math.max(1000, (0, settings_1.numberSetting)(config.confirmationTimeoutMs, "confirmation timeout", 15000)),
|
|
83
|
+
maxAttempts: Math.max(1, Math.floor((0, settings_1.numberSetting)(config.maxAttempts, "max attempts", 2)))
|
|
79
84
|
};
|
|
80
85
|
}
|
|
81
86
|
function initialState(saved = {}, sources = {}) {
|
|
@@ -100,7 +105,6 @@ function initialState(saved = {}, sources = {}) {
|
|
|
100
105
|
: null,
|
|
101
106
|
pending: saved.pending && typeof saved.pending === "object" ? { ...saved.pending } : null,
|
|
102
107
|
failure: saved.failure && typeof saved.failure === "object" ? { ...saved.failure } : null,
|
|
103
|
-
blockedGeneration: Number.isInteger(saved.blockedGeneration) ? saved.blockedGeneration : null,
|
|
104
108
|
classification: saved.classification === "manual_override" ? "manual_override" : null,
|
|
105
109
|
lastAttempt: Number.isInteger(saved.lastAttempt) && (saved.lastAttempt ?? -1) >= 0
|
|
106
110
|
? saved.lastAttempt
|
|
@@ -138,35 +142,34 @@ function descriptorFor(state, sources) {
|
|
|
138
142
|
return null;
|
|
139
143
|
return sources[state.desired.sourceId] ?? null;
|
|
140
144
|
}
|
|
145
|
+
// What each kind of confirmation needs from an observation before the source
|
|
146
|
+
// counts as ready.
|
|
147
|
+
const READINESS = {
|
|
148
|
+
available: ({ available }) => available,
|
|
149
|
+
active: ({ active }) => active,
|
|
150
|
+
application: ({ active, application }) => active && application !== null,
|
|
151
|
+
playing: ({ active, playback }) => active && playback === "playing",
|
|
152
|
+
unavailable: () => false
|
|
153
|
+
};
|
|
141
154
|
function readinessEvidence(observation, required) {
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
? active
|
|
150
|
-
: required === "application"
|
|
151
|
-
? active && application !== null
|
|
152
|
-
: required === "playing"
|
|
153
|
-
? active && playback === "playing"
|
|
154
|
-
: false;
|
|
155
|
-
return { required, available, active, application, playback, satisfied };
|
|
155
|
+
const facts = {
|
|
156
|
+
available: observation?.status === "active" || observation?.status === "available",
|
|
157
|
+
active: observation?.status === "active",
|
|
158
|
+
application: observation?.application ?? null,
|
|
159
|
+
playback: observation?.playback ?? "unknown"
|
|
160
|
+
};
|
|
161
|
+
return { required, ...facts, satisfied: READINESS[required](facts) };
|
|
156
162
|
}
|
|
157
163
|
function targetEvent(state, now, sources) {
|
|
158
164
|
if (!state.desired)
|
|
159
165
|
return null;
|
|
160
166
|
const readiness = readinessEvidence(state.observed, descriptorFor(state, sources)?.confirmation ?? "unavailable");
|
|
161
|
-
const
|
|
162
|
-
kind: "target_state",
|
|
167
|
+
const envelope = (0, target_state_1.targetStateEvent)({
|
|
163
168
|
target: "source",
|
|
164
169
|
requestId: state.desired.requestId,
|
|
165
170
|
generation: state.generation,
|
|
166
171
|
status: targetStatus(state.phase),
|
|
167
172
|
observedAt: state.observed?.confirmedAt ?? state.observed?.observedAt ?? iso(now),
|
|
168
|
-
sourceId: state.desired.sourceId,
|
|
169
|
-
action: state.desired.action,
|
|
170
173
|
details: {
|
|
171
174
|
observedStatus: state.observed?.status ?? null,
|
|
172
175
|
readiness,
|
|
@@ -180,13 +183,11 @@ function targetEvent(state, now, sources) {
|
|
|
180
183
|
retries: Math.max(0, state.lastAttempt - 1),
|
|
181
184
|
fallbackUsed: state.fallbackUsed
|
|
182
185
|
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
theatre.classification = state.classification;
|
|
189
|
-
return { theatre };
|
|
186
|
+
},
|
|
187
|
+
classification: state.classification,
|
|
188
|
+
failure: state.failure
|
|
189
|
+
});
|
|
190
|
+
return { theatre: { ...envelope, sourceId: state.desired.sourceId, action: state.desired.action } };
|
|
190
191
|
}
|
|
191
192
|
function statusFor(state) {
|
|
192
193
|
const sourceId = state.desired?.sourceId || "none";
|
|
@@ -225,7 +226,6 @@ function transitionSource(saved, msg, suppliedConfig = {}, nowValue = new Date()
|
|
|
225
226
|
function fail(operation, reason) {
|
|
226
227
|
state.pending = null;
|
|
227
228
|
state.phase = "failed";
|
|
228
|
-
state.blockedGeneration = state.generation;
|
|
229
229
|
state.failure = { operation, reason, occurredAt: iso(now) };
|
|
230
230
|
trace("source", "failed", reason, { sourceId: state.desired?.sourceId ?? null, operation });
|
|
231
231
|
}
|
|
@@ -261,7 +261,6 @@ function transitionSource(saved, msg, suppliedConfig = {}, nowValue = new Date()
|
|
|
261
261
|
if (observationSatisfies(state.observed)) {
|
|
262
262
|
state.pending = null;
|
|
263
263
|
state.failure = null;
|
|
264
|
-
state.blockedGeneration = null;
|
|
265
264
|
state.classification = null;
|
|
266
265
|
state.phase = "ready";
|
|
267
266
|
const readiness = readinessEvidence(state.observed, descriptor()?.confirmation ?? "unavailable");
|
|
@@ -323,7 +322,6 @@ function transitionSource(saved, msg, suppliedConfig = {}, nowValue = new Date()
|
|
|
323
322
|
state.refreshAsked = false;
|
|
324
323
|
state.pending = null;
|
|
325
324
|
state.failure = null;
|
|
326
|
-
state.blockedGeneration = null;
|
|
327
325
|
state.classification = null;
|
|
328
326
|
state.lastAttempt = 0;
|
|
329
327
|
state.fallbackUsed = false;
|
|
@@ -385,10 +383,11 @@ function transitionSource(saved, msg, suppliedConfig = {}, nowValue = new Date()
|
|
|
385
383
|
application,
|
|
386
384
|
playback
|
|
387
385
|
};
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
386
|
+
// Theatre gets the time the report arrived, as from every other target:
|
|
387
|
+
// a quiet source repeats an unchanged time, and a device clock running
|
|
388
|
+
// behind would otherwise date it before the request it answers.
|
|
389
|
+
state.observed.confirmedAt = new Date(Math.max(bounded.ms, nowMs)).toISOString();
|
|
390
|
+
state.refreshAsked = false;
|
|
392
391
|
reconcileObservation();
|
|
393
392
|
}
|
|
394
393
|
function acceptCommandResult(event) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { TraceEntry } from "./bounded-trace";
|
|
1
2
|
import { type WallInputConfig, type WallInputState } from "./wall-input";
|
|
2
3
|
export interface SwitchPolicyConfig extends WallInputConfig {
|
|
3
4
|
targets: string[];
|
|
@@ -38,16 +39,10 @@ export type SwitchPolicyEffect = {
|
|
|
38
39
|
kind: "send";
|
|
39
40
|
message: SwitchLightingIntent;
|
|
40
41
|
};
|
|
41
|
-
export interface SwitchPolicyTrace {
|
|
42
|
-
event: string;
|
|
43
|
-
outcome: string;
|
|
44
|
-
reason: string | null;
|
|
45
|
-
details: Record<string, unknown>;
|
|
46
|
-
}
|
|
47
42
|
export declare function createSwitchPolicyState(saved?: Partial<SwitchPolicyState>): SwitchPolicyState;
|
|
48
43
|
export declare function transitionSwitchPolicy(saved: Partial<SwitchPolicyState> | undefined, input: SwitchPolicyInput, config: SwitchPolicyConfig, now?: number): {
|
|
49
44
|
state: SwitchPolicyState;
|
|
50
45
|
effects: SwitchPolicyEffect[];
|
|
51
|
-
traces:
|
|
46
|
+
traces: TraceEntry<Record<string, unknown>>[];
|
|
52
47
|
status: import("./wall-input").WallInputStatus;
|
|
53
48
|
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type TargetStatus = "discovering" | "transitioning" | "confirming" | "ready" | "waiting_for_source" | "failed" | "unavailable";
|
|
2
|
+
export declare function isTargetStatus(value: unknown): value is TargetStatus;
|
|
3
|
+
export declare function asTargetStatus(phase: string, otherwise: TargetStatus): TargetStatus;
|
|
4
|
+
export interface TargetStateEvent<Target extends string = string, Details = Record<string, unknown>, Failure = Record<string, unknown>> {
|
|
5
|
+
kind: "target_state";
|
|
6
|
+
target: Target;
|
|
7
|
+
requestId: string;
|
|
8
|
+
generation: number;
|
|
9
|
+
status: TargetStatus;
|
|
10
|
+
observedAt: string;
|
|
11
|
+
details: Details;
|
|
12
|
+
classification?: "manual_override";
|
|
13
|
+
failure?: Failure;
|
|
14
|
+
}
|
|
15
|
+
export declare function targetStateEvent<Target extends string, Details, Failure>(fields: {
|
|
16
|
+
target: Target;
|
|
17
|
+
requestId: string;
|
|
18
|
+
generation: number;
|
|
19
|
+
status: TargetStatus;
|
|
20
|
+
observedAt: string;
|
|
21
|
+
details: Details;
|
|
22
|
+
classification?: "manual_override" | null;
|
|
23
|
+
failure?: Failure | null;
|
|
24
|
+
}): TargetStateEvent<Target, Details, Failure>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isTargetStatus = isTargetStatus;
|
|
4
|
+
exports.asTargetStatus = asTargetStatus;
|
|
5
|
+
exports.targetStateEvent = targetStateEvent;
|
|
6
|
+
const TARGET_STATUSES = {
|
|
7
|
+
discovering: true,
|
|
8
|
+
transitioning: true,
|
|
9
|
+
confirming: true,
|
|
10
|
+
ready: true,
|
|
11
|
+
waiting_for_source: true,
|
|
12
|
+
failed: true,
|
|
13
|
+
unavailable: true
|
|
14
|
+
};
|
|
15
|
+
function isTargetStatus(value) {
|
|
16
|
+
return typeof value === "string" && Object.hasOwn(TARGET_STATUSES, value);
|
|
17
|
+
}
|
|
18
|
+
// An owner's phase when it is already a target status, or the given status.
|
|
19
|
+
function asTargetStatus(phase, otherwise) {
|
|
20
|
+
return isTargetStatus(phase) ? phase : otherwise;
|
|
21
|
+
}
|
|
22
|
+
function targetStateEvent(fields) {
|
|
23
|
+
const event = {
|
|
24
|
+
kind: "target_state",
|
|
25
|
+
target: fields.target,
|
|
26
|
+
requestId: fields.requestId,
|
|
27
|
+
generation: fields.generation,
|
|
28
|
+
status: fields.status,
|
|
29
|
+
observedAt: fields.observedAt,
|
|
30
|
+
details: fields.details
|
|
31
|
+
};
|
|
32
|
+
if (fields.classification)
|
|
33
|
+
event.classification = fields.classification;
|
|
34
|
+
if (fields.failure)
|
|
35
|
+
event.failure = { ...fields.failure };
|
|
36
|
+
return event;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=target-state.js.map
|
|
@@ -1,103 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export type
|
|
5
|
-
export type TheatreAvailability
|
|
6
|
-
export interface ActivitySourceProfile extends Record<string, unknown> {
|
|
7
|
-
action: "activate" | "deactivate";
|
|
8
|
-
readiness: "required" | "optional";
|
|
9
|
-
sourceId?: string | null;
|
|
10
|
-
}
|
|
11
|
-
export interface ActivityLightingProfile extends Record<string, unknown> {
|
|
12
|
-
profile: string;
|
|
13
|
-
}
|
|
14
|
-
export interface ActivityBacklightingProfile extends Record<string, unknown> {
|
|
15
|
-
power: "on" | "off";
|
|
16
|
-
}
|
|
17
|
-
export type ActivityProfile = Record<TheatreTarget, Record<string, unknown>> & {
|
|
18
|
-
source: ActivitySourceProfile;
|
|
19
|
-
lighting: ActivityLightingProfile;
|
|
20
|
-
backlighting: ActivityBacklightingProfile;
|
|
21
|
-
};
|
|
22
|
-
export type ActivityProfiles = Record<string, ActivityProfile>;
|
|
23
|
-
export interface TheatreDesired {
|
|
24
|
-
requestId: string;
|
|
25
|
-
generation: number;
|
|
26
|
-
activity: string;
|
|
27
|
-
requestedAt: string;
|
|
28
|
-
}
|
|
29
|
-
export interface TargetFailure {
|
|
30
|
-
operation?: string | null;
|
|
31
|
-
reason?: string;
|
|
32
|
-
occurredAt?: string;
|
|
33
|
-
}
|
|
34
|
-
export interface TargetState {
|
|
35
|
-
status: TargetStatus;
|
|
36
|
-
observedAt: string;
|
|
37
|
-
classification: TargetClassification | null;
|
|
38
|
-
failure: TargetFailure | null;
|
|
39
|
-
details: Record<string, unknown> | null;
|
|
40
|
-
}
|
|
41
|
-
export interface TheatreFailure {
|
|
42
|
-
target: TheatreTarget;
|
|
43
|
-
operation: string | null;
|
|
44
|
-
reason: string;
|
|
45
|
-
occurredAt: string;
|
|
46
|
-
}
|
|
47
|
-
export interface TheatreTargetMetrics {
|
|
48
|
-
attempts: number;
|
|
49
|
-
retries: number;
|
|
50
|
-
failures: number;
|
|
51
|
-
manualOverrides: number;
|
|
52
|
-
fallbackUses: number;
|
|
53
|
-
fallbackUsed: boolean;
|
|
54
|
-
lastConfirmationMs: number | null;
|
|
55
|
-
observationAgeMs: number | null;
|
|
56
|
-
availability: TheatreAvailability;
|
|
57
|
-
}
|
|
58
|
-
export interface TheatreMetrics {
|
|
59
|
-
requests: number;
|
|
60
|
-
ready: number;
|
|
61
|
-
failed: number;
|
|
62
|
-
superseded: number;
|
|
63
|
-
manualOverrides: number;
|
|
64
|
-
driftEvents: number;
|
|
65
|
-
recoveriesAdopted: number;
|
|
66
|
-
recoveriesSafeOff: number;
|
|
67
|
-
lastTransitionMs: number | null;
|
|
68
|
-
maxTransitionMs: number | null;
|
|
69
|
-
lastOutcome: string | null;
|
|
70
|
-
targets: Record<TheatreTarget, TheatreTargetMetrics>;
|
|
71
|
-
}
|
|
72
|
-
export interface RecoveryObservation {
|
|
73
|
-
observedAt: string;
|
|
74
|
-
values: Record<string, unknown>;
|
|
75
|
-
}
|
|
76
|
-
export type RecoveryObservations = Partial<Record<TheatreTarget, RecoveryObservation>>;
|
|
77
|
-
export interface RefreshPending {
|
|
78
|
-
sentAt: number;
|
|
79
|
-
attempts: number;
|
|
80
|
-
exhausted: boolean;
|
|
81
|
-
}
|
|
82
|
-
export interface TheatreState {
|
|
83
|
-
desired: TheatreDesired | null;
|
|
84
|
-
currentActivity: string;
|
|
85
|
-
generation: number;
|
|
86
|
-
lastProposedGeneration: number;
|
|
87
|
-
phase: string;
|
|
88
|
-
targets: Record<TheatreTarget, TargetState | null>;
|
|
89
|
-
refreshPending: Record<TheatreTarget, RefreshPending | null>;
|
|
90
|
-
failure: TheatreFailure | null;
|
|
91
|
-
blockedGeneration: number | null;
|
|
92
|
-
degraded: Array<{
|
|
93
|
-
target: TheatreTarget;
|
|
94
|
-
reason: string;
|
|
95
|
-
}>;
|
|
96
|
-
availability: TheatreAvailability;
|
|
97
|
-
transitionStartedAt: string | null;
|
|
98
|
-
transitionCompletedAt: string | null;
|
|
99
|
-
metrics: TheatreMetrics;
|
|
100
|
-
}
|
|
1
|
+
import type { TraceEntry } from "./bounded-trace";
|
|
2
|
+
import { type ActivityProfiles, type TheatreTarget } from "./theatre-profiles";
|
|
3
|
+
import { type RecoveryObservations, type TargetClassification, type TargetFailure, type TargetStatus, type TheatreState } from "./theatre-state";
|
|
4
|
+
export { TARGETS, normaliseActivityProfiles, type ActivityBacklightingProfile, type ActivityLightingProfile, type ActivityProfile, type ActivityProfiles, type ActivitySourceProfile, type TheatreTarget } from "./theatre-profiles";
|
|
5
|
+
export { createTheatreState, type RecoveryObservation, type RecoveryObservations, type RefreshPending, type TargetClassification, type TargetFailure, type TargetState, type TargetStatus, type TheatreAvailability, type TheatreDesired, type TheatreFailure, type TheatreMetrics, type TheatreSnapshot, type TheatreState, type TheatreTargetMetrics } from "./theatre-state";
|
|
101
6
|
export interface TheatreConfig {
|
|
102
7
|
area: string;
|
|
103
8
|
freshnessMs: number;
|
|
@@ -141,8 +46,6 @@ export interface TargetCommand extends Record<string, unknown> {
|
|
|
141
46
|
requestId: string | null;
|
|
142
47
|
generation: number;
|
|
143
48
|
}
|
|
144
|
-
export declare function normaliseActivityProfiles(value: unknown): ActivityProfiles;
|
|
145
|
-
export declare function createTheatreState(saved?: Partial<TheatreState>, activityProfiles?: ActivityProfiles): TheatreState;
|
|
146
49
|
export declare function normaliseConfig(config?: Partial<TheatreConfig> & {
|
|
147
50
|
activityProfiles?: unknown;
|
|
148
51
|
}): TheatreConfig;
|
|
@@ -152,12 +55,7 @@ export declare function transitionTheatre(saved: Partial<TheatreState> | undefin
|
|
|
152
55
|
state: TheatreState;
|
|
153
56
|
commands: TargetCommand[];
|
|
154
57
|
events: TheatreOutput[];
|
|
155
|
-
traces:
|
|
156
|
-
event: string;
|
|
157
|
-
outcome: string;
|
|
158
|
-
reason: string | null;
|
|
159
|
-
details: Record<string, unknown>;
|
|
160
|
-
}[];
|
|
58
|
+
traces: TraceEntry<Record<string, unknown>>[];
|
|
161
59
|
status: {
|
|
162
60
|
phase: string;
|
|
163
61
|
text: string;
|