@avantics/node-red-home-automation 0.0.0-stage → 2.3.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/LICENSE +21 -0
- package/README.md +292 -2
- package/contract-examples/README.md +28 -0
- package/contract-examples/_shared.mjs +11 -0
- package/contract-examples/motion-lighting.mjs +42 -0
- package/contract-examples/occupancy-fusion.mjs +35 -0
- package/contract-examples/room-lighting.mjs +58 -0
- package/contract-examples/run.mjs +16 -0
- package/contract-examples/source-readiness.mjs +64 -0
- package/contract-examples/switch-gestures.mjs +34 -0
- package/contract-examples/theatre-activity.mjs +62 -0
- package/contract-examples/volume-ownership.mjs +59 -0
- package/dist/lib/activity-lighting-controller.d.ts +129 -0
- package/dist/lib/activity-lighting-controller.js +372 -0
- package/dist/lib/avr-controller.d.ts +169 -0
- package/dist/lib/avr-controller.js +948 -0
- package/dist/lib/backlighting-controller.d.ts +108 -0
- package/dist/lib/backlighting-controller.js +269 -0
- package/dist/lib/bounded-trace.d.ts +30 -0
- package/dist/lib/bounded-trace.js +36 -0
- package/dist/lib/circadian-refresh.d.ts +7 -0
- package/dist/lib/circadian-refresh.js +11 -0
- package/dist/lib/circadian-schedule.d.ts +11 -0
- package/dist/lib/circadian-schedule.js +63 -0
- package/dist/lib/circadian.d.ts +6 -0
- package/dist/lib/circadian.js +15 -0
- package/dist/lib/cover-controller.d.ts +130 -0
- package/dist/lib/cover-controller.js +336 -0
- package/dist/lib/display-mode-controller.d.ts +148 -0
- package/dist/lib/display-mode-controller.js +587 -0
- package/dist/lib/display-transport.d.ts +41 -0
- package/dist/lib/display-transport.js +177 -0
- package/dist/lib/light-styling.d.ts +11 -0
- package/dist/lib/light-styling.js +15 -0
- package/dist/lib/motion-policy.d.ts +72 -0
- package/dist/lib/motion-policy.js +251 -0
- package/dist/lib/observation-time.d.ts +10 -0
- package/dist/lib/observation-time.js +40 -0
- package/dist/lib/occupancy-fusion.d.ts +53 -0
- package/dist/lib/occupancy-fusion.js +131 -0
- package/dist/lib/room-controller.d.ts +113 -0
- package/dist/lib/room-controller.js +431 -0
- package/dist/lib/source-capability-controller.d.ts +144 -0
- package/dist/lib/source-capability-controller.js +494 -0
- package/dist/lib/switch-policy.d.ts +53 -0
- package/dist/lib/switch-policy.js +110 -0
- package/dist/lib/theatre-activity-controller.d.ts +165 -0
- package/dist/lib/theatre-activity-controller.js +846 -0
- package/dist/lib/theatre-slo.d.ts +49 -0
- package/dist/lib/theatre-slo.js +156 -0
- package/dist/lib/theatre-state-contract.d.ts +77 -0
- package/dist/lib/theatre-state-contract.js +391 -0
- package/dist/lib/wall-input.d.ts +62 -0
- package/dist/lib/wall-input.js +198 -0
- package/dist/nodes/activity-lighting-controller.d.ts +3 -0
- package/dist/nodes/activity-lighting-controller.html +38 -0
- package/dist/nodes/activity-lighting-controller.js +116 -0
- package/dist/nodes/avr-controller.d.ts +3 -0
- package/dist/nodes/avr-controller.html +47 -0
- package/dist/nodes/avr-controller.js +130 -0
- package/dist/nodes/backlighting-controller.d.ts +3 -0
- package/dist/nodes/backlighting-controller.html +31 -0
- package/dist/nodes/backlighting-controller.js +103 -0
- package/dist/nodes/display-mode-controller.d.ts +3 -0
- package/dist/nodes/display-mode-controller.html +66 -0
- package/dist/nodes/display-mode-controller.js +132 -0
- package/dist/nodes/motion-policy.d.ts +3 -0
- package/dist/nodes/motion-policy.html +35 -0
- package/dist/nodes/motion-policy.js +194 -0
- package/dist/nodes/occupancy-fusion.d.ts +3 -0
- package/dist/nodes/occupancy-fusion.html +32 -0
- package/dist/nodes/occupancy-fusion.js +53 -0
- package/dist/nodes/room-controller.d.ts +3 -0
- package/dist/nodes/room-controller.html +82 -0
- package/dist/nodes/room-controller.js +123 -0
- package/dist/nodes/source-capability-controller.d.ts +3 -0
- package/dist/nodes/source-capability-controller.html +46 -0
- package/dist/nodes/source-capability-controller.js +114 -0
- package/dist/nodes/switch-policy.d.ts +3 -0
- package/dist/nodes/switch-policy.html +29 -0
- package/dist/nodes/switch-policy.js +129 -0
- package/dist/nodes/theatre-activity-controller.d.ts +3 -0
- package/dist/nodes/theatre-activity-controller.html +32 -0
- package/dist/nodes/theatre-activity-controller.js +105 -0
- package/dist/nodes/theatre-state-contract.d.ts +3 -0
- package/dist/nodes/theatre-state-contract.html +41 -0
- package/dist/nodes/theatre-state-contract.js +83 -0
- package/examples/Home theatre activity.json +477 -0
- package/examples/Home theatre equipment.json +329 -0
- package/examples/Room lighting.json +212 -0
- package/package.json +62 -4
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSwitchPolicyState = createSwitchPolicyState;
|
|
4
|
+
exports.transitionSwitchPolicy = transitionSwitchPolicy;
|
|
5
|
+
const wall_input_1 = require("./wall-input");
|
|
6
|
+
function createSwitchPolicyState(saved = {}) {
|
|
7
|
+
const legacy = saved;
|
|
8
|
+
return {
|
|
9
|
+
wallInput: (0, wall_input_1.createWallInputState)(saved.wallInput ?? {
|
|
10
|
+
baselineKnown: legacy.switchStateKnown,
|
|
11
|
+
value: legacy.switchState,
|
|
12
|
+
generation: legacy.generation,
|
|
13
|
+
edgeAt: legacy.switchAt,
|
|
14
|
+
timerDueAt: legacy.timerDueAt
|
|
15
|
+
})
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function intent(targets, state, manual = false) {
|
|
19
|
+
return {
|
|
20
|
+
lighting: {
|
|
21
|
+
kind: "intent",
|
|
22
|
+
targets: [...targets],
|
|
23
|
+
state,
|
|
24
|
+
source: "wall",
|
|
25
|
+
person: true,
|
|
26
|
+
...(manual ? { manual: true, values: { brightness: 254 } } : {})
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function transitionSwitchPolicy(saved, input, config, now = Date.now()) {
|
|
31
|
+
const state = createSwitchPolicyState(saved);
|
|
32
|
+
const effects = [];
|
|
33
|
+
const traces = [];
|
|
34
|
+
function trace(event, outcome, reason, details = {}) {
|
|
35
|
+
traces.push({ event, outcome, reason, details });
|
|
36
|
+
}
|
|
37
|
+
function cancelTimer(reason) {
|
|
38
|
+
const wasActive = Number(state.wallInput.timerDueAt) > now;
|
|
39
|
+
state.wallInput.generation += 1;
|
|
40
|
+
state.wallInput.edgeAt = 0;
|
|
41
|
+
state.wallInput.timerDueAt = null;
|
|
42
|
+
effects.push({ kind: "cancel-switch-timer" });
|
|
43
|
+
if (wasActive && reason)
|
|
44
|
+
trace("switch-timer", "cancelled", reason);
|
|
45
|
+
}
|
|
46
|
+
function emit(message, event) {
|
|
47
|
+
effects.push({ kind: "send", message });
|
|
48
|
+
trace(event, "emitted", null, {
|
|
49
|
+
state: message.lighting.state,
|
|
50
|
+
targets: message.lighting.targets,
|
|
51
|
+
manual: message.lighting.manual === true
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
if (input.source === "switch-startup" ||
|
|
55
|
+
input.source === "switch" ||
|
|
56
|
+
input.source === "switch-availability" ||
|
|
57
|
+
input.source === "switch-timer") {
|
|
58
|
+
const wallInput = (0, wall_input_1.transitionWallInput)(state.wallInput, input.source === "switch-startup"
|
|
59
|
+
? { kind: "startup" }
|
|
60
|
+
: input.source === "switch"
|
|
61
|
+
? {
|
|
62
|
+
kind: "observation",
|
|
63
|
+
payload: input.payload,
|
|
64
|
+
retain: input.retain,
|
|
65
|
+
baseline: input.baseline,
|
|
66
|
+
observedAt: input.observedAt
|
|
67
|
+
}
|
|
68
|
+
: input.source === "switch-availability"
|
|
69
|
+
? { kind: "availability", payload: input.payload }
|
|
70
|
+
: {
|
|
71
|
+
kind: "timer",
|
|
72
|
+
generation: input.generation,
|
|
73
|
+
edgeAt: input.switchAt
|
|
74
|
+
}, config, now);
|
|
75
|
+
state.wallInput = wallInput.state;
|
|
76
|
+
effects.push(...wallInput.effects);
|
|
77
|
+
traces.push(...wallInput.traces);
|
|
78
|
+
if (wallInput.gesture === "single") {
|
|
79
|
+
emit(intent(config.targets, "TOGGLE"), "switch");
|
|
80
|
+
}
|
|
81
|
+
else if (wallInput.gesture === "double") {
|
|
82
|
+
emit(intent(config.targets, "ON", true), "switch");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else if (input.source === "switch-action") {
|
|
86
|
+
const action = String(input.payload && typeof input.payload === "object"
|
|
87
|
+
? input.payload.action ?? ""
|
|
88
|
+
: input.payload ?? "").toLowerCase();
|
|
89
|
+
if (input.retain === true) {
|
|
90
|
+
trace("switch-action", "ignored", "retained-message", { action });
|
|
91
|
+
}
|
|
92
|
+
else if (action === "single" || action === "double") {
|
|
93
|
+
cancelTimer("explicit-action");
|
|
94
|
+
emit(intent(config.targets, action === "single" ? "TOGGLE" : "ON", action === "double"), "switch-action");
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
trace("switch-action", "ignored", "unsupported-action", { action });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
trace("message", "ignored", "unsupported-source", { source: input.source });
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
state,
|
|
105
|
+
effects,
|
|
106
|
+
traces,
|
|
107
|
+
status: (0, wall_input_1.wallInputStatus)(state.wallInput, config.switchFreshnessMs, now)
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=switch-policy.js.map
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
export declare const TARGETS: readonly ["display", "avr", "source", "lighting", "backlighting"];
|
|
2
|
+
export type TheatreTarget = typeof TARGETS[number];
|
|
3
|
+
export type TargetStatus = "discovering" | "transitioning" | "confirming" | "ready" | "waiting_for_source" | "failed" | "unavailable";
|
|
4
|
+
export type TargetClassification = "drift" | "manual_override";
|
|
5
|
+
export type TheatreAvailability = "unknown" | "available" | "degraded" | "unavailable";
|
|
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
|
+
}
|
|
101
|
+
export interface TheatreConfig {
|
|
102
|
+
area: string;
|
|
103
|
+
freshnessMs: number;
|
|
104
|
+
activityProfiles: ActivityProfiles;
|
|
105
|
+
recoveryOffActivity?: string;
|
|
106
|
+
}
|
|
107
|
+
export type TheatreInputEvent = {
|
|
108
|
+
kind: "intent";
|
|
109
|
+
requestId: string;
|
|
110
|
+
generation: number;
|
|
111
|
+
activity: string;
|
|
112
|
+
requestedAt?: string;
|
|
113
|
+
} | {
|
|
114
|
+
kind: "target_state";
|
|
115
|
+
target: TheatreTarget;
|
|
116
|
+
generation: number;
|
|
117
|
+
status: TargetStatus;
|
|
118
|
+
observedAt: string;
|
|
119
|
+
classification?: TargetClassification;
|
|
120
|
+
failure?: TargetFailure;
|
|
121
|
+
details?: Record<string, unknown>;
|
|
122
|
+
} | {
|
|
123
|
+
kind: "startup" | "refresh";
|
|
124
|
+
} | {
|
|
125
|
+
kind: "tick";
|
|
126
|
+
generation?: number;
|
|
127
|
+
} | {
|
|
128
|
+
kind: "recover";
|
|
129
|
+
reason: "startup" | "manual_override";
|
|
130
|
+
observations: RecoveryObservations;
|
|
131
|
+
};
|
|
132
|
+
export interface TheatreOutput {
|
|
133
|
+
theatre: Record<string, unknown>;
|
|
134
|
+
}
|
|
135
|
+
export interface TheatreMessage {
|
|
136
|
+
theatre?: TheatreInputEvent;
|
|
137
|
+
}
|
|
138
|
+
export interface TargetCommand extends Record<string, unknown> {
|
|
139
|
+
target: TheatreTarget;
|
|
140
|
+
kind: string;
|
|
141
|
+
requestId: string | null;
|
|
142
|
+
generation: number;
|
|
143
|
+
}
|
|
144
|
+
export declare function normaliseActivityProfiles(value: unknown): ActivityProfiles;
|
|
145
|
+
export declare function createTheatreState(saved?: Partial<TheatreState>, activityProfiles?: ActivityProfiles): TheatreState;
|
|
146
|
+
export declare function normaliseConfig(config?: Partial<TheatreConfig> & {
|
|
147
|
+
activityProfiles?: unknown;
|
|
148
|
+
}): TheatreConfig;
|
|
149
|
+
export declare function transitionTheatre(saved: Partial<TheatreState> | undefined, msg: TheatreMessage, suppliedConfig?: Partial<TheatreConfig> & {
|
|
150
|
+
activityProfiles?: unknown;
|
|
151
|
+
}, nowValue?: Date | string | number): {
|
|
152
|
+
state: TheatreState;
|
|
153
|
+
commands: TargetCommand[];
|
|
154
|
+
events: TheatreOutput[];
|
|
155
|
+
traces: {
|
|
156
|
+
event: string;
|
|
157
|
+
outcome: string;
|
|
158
|
+
reason: string | null;
|
|
159
|
+
details: Record<string, unknown>;
|
|
160
|
+
}[];
|
|
161
|
+
status: {
|
|
162
|
+
phase: string;
|
|
163
|
+
text: string;
|
|
164
|
+
};
|
|
165
|
+
};
|