@homelib/core 0.0.0-wip.33a9dc48299c
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 +19 -0
- package/README.md +7 -0
- package/bld/exports/mobx.d.ts +1 -0
- package/bld/exports/mobx.js +2 -0
- package/bld/exports/mobx.js.map +1 -0
- package/bld/library/@lifecycle.d.ts +4 -0
- package/bld/library/@lifecycle.js +23 -0
- package/bld/library/@lifecycle.js.map +1 -0
- package/bld/library/atomics/index.d.ts +1 -0
- package/bld/library/atomics/index.js +2 -0
- package/bld/library/atomics/index.js.map +1 -0
- package/bld/library/atomics/temperature.d.ts +13 -0
- package/bld/library/atomics/temperature.js +53 -0
- package/bld/library/atomics/temperature.js.map +1 -0
- package/bld/library/command.d.ts +12 -0
- package/bld/library/command.js +21 -0
- package/bld/library/command.js.map +1 -0
- package/bld/library/device/index.d.ts +1 -0
- package/bld/library/device/index.js +2 -0
- package/bld/library/device/index.js.map +1 -0
- package/bld/library/device/sensor.d.ts +8 -0
- package/bld/library/device/sensor.js +2 -0
- package/bld/library/device/sensor.js.map +1 -0
- package/bld/library/device-namespace.d.ts +11 -0
- package/bld/library/device-namespace.js +9 -0
- package/bld/library/device-namespace.js.map +1 -0
- package/bld/library/device.d.ts +23 -0
- package/bld/library/device.js +92 -0
- package/bld/library/device.js.map +1 -0
- package/bld/library/devices/air-conditioner.d.ts +72 -0
- package/bld/library/devices/air-conditioner.js +246 -0
- package/bld/library/devices/air-conditioner.js.map +1 -0
- package/bld/library/devices/dehumidifier.d.ts +62 -0
- package/bld/library/devices/dehumidifier.js +211 -0
- package/bld/library/devices/dehumidifier.js.map +1 -0
- package/bld/library/devices/fan.d.ts +70 -0
- package/bld/library/devices/fan.js +229 -0
- package/bld/library/devices/fan.js.map +1 -0
- package/bld/library/devices/index.d.ts +4 -0
- package/bld/library/devices/index.js +5 -0
- package/bld/library/devices/index.js.map +1 -0
- package/bld/library/devices/light.d.ts +59 -0
- package/bld/library/devices/light.js +197 -0
- package/bld/library/devices/light.js.map +1 -0
- package/bld/library/endpoint.d.ts +100 -0
- package/bld/library/endpoint.js +431 -0
- package/bld/library/endpoint.js.map +1 -0
- package/bld/library/home.d.ts +4 -0
- package/bld/library/home.js +11 -0
- package/bld/library/home.js.map +1 -0
- package/bld/library/index.d.ts +16 -0
- package/bld/library/index.js +17 -0
- package/bld/library/index.js.map +1 -0
- package/bld/library/log.d.ts +43 -0
- package/bld/library/log.js +78 -0
- package/bld/library/log.js.map +1 -0
- package/bld/library/provider.d.ts +26 -0
- package/bld/library/provider.js +18 -0
- package/bld/library/provider.js.map +1 -0
- package/bld/library/registry.d.ts +19 -0
- package/bld/library/registry.js +65 -0
- package/bld/library/registry.js.map +1 -0
- package/bld/library/runtime/@binding-creation.d.ts +4 -0
- package/bld/library/runtime/@binding-creation.js +19 -0
- package/bld/library/runtime/@binding-creation.js.map +1 -0
- package/bld/library/runtime/binding.d.ts +50 -0
- package/bld/library/runtime/binding.js +108 -0
- package/bld/library/runtime/binding.js.map +1 -0
- package/bld/library/runtime/bootstrap-frontend.d.ts +48 -0
- package/bld/library/runtime/bootstrap-frontend.js +96 -0
- package/bld/library/runtime/bootstrap-frontend.js.map +1 -0
- package/bld/library/runtime/bootstrap.d.ts +9 -0
- package/bld/library/runtime/bootstrap.js +165 -0
- package/bld/library/runtime/bootstrap.js.map +1 -0
- package/bld/library/runtime/environment.d.ts +1 -0
- package/bld/library/runtime/environment.js +7 -0
- package/bld/library/runtime/environment.js.map +1 -0
- package/bld/library/runtime/index.d.ts +4 -0
- package/bld/library/runtime/index.js +5 -0
- package/bld/library/runtime/index.js.map +1 -0
- package/bld/library/scope.d.ts +41 -0
- package/bld/library/scope.js +132 -0
- package/bld/library/scope.js.map +1 -0
- package/bld/library/types.d.ts +17 -0
- package/bld/library/types.js +8 -0
- package/bld/library/types.js.map +1 -0
- package/bld/library/utils/backoff.d.ts +10 -0
- package/bld/library/utils/backoff.js +63 -0
- package/bld/library/utils/backoff.js.map +1 -0
- package/bld/library/utils/constructor.d.ts +21 -0
- package/bld/library/utils/constructor.js +30 -0
- package/bld/library/utils/constructor.js.map +1 -0
- package/bld/library/utils/index.d.ts +2 -0
- package/bld/library/utils/index.js +3 -0
- package/bld/library/utils/index.js.map +1 -0
- package/bld/library/x-data-medium.d.ts +12 -0
- package/bld/library/x-data-medium.js +3 -0
- package/bld/library/x-data-medium.js.map +1 -0
- package/package.json +27 -0
- package/src/exports/mobx.ts +1 -0
- package/src/library/@lifecycle.ts +30 -0
- package/src/library/atomics/index.ts +1 -0
- package/src/library/atomics/temperature.ts +60 -0
- package/src/library/command.ts +25 -0
- package/src/library/device/index.ts +1 -0
- package/src/library/device/sensor.ts +10 -0
- package/src/library/device-namespace.ts +21 -0
- package/src/library/device.ts +91 -0
- package/src/library/devices/air-conditioner.ts +234 -0
- package/src/library/devices/dehumidifier.ts +200 -0
- package/src/library/devices/fan.ts +204 -0
- package/src/library/devices/index.ts +4 -0
- package/src/library/devices/light.ts +177 -0
- package/src/library/endpoint.ts +610 -0
- package/src/library/home.ts +11 -0
- package/src/library/index.ts +16 -0
- package/src/library/log.ts +163 -0
- package/src/library/provider.ts +66 -0
- package/src/library/registry.ts +129 -0
- package/src/library/runtime/@binding-creation.ts +48 -0
- package/src/library/runtime/binding.ts +165 -0
- package/src/library/runtime/bootstrap-frontend.ts +243 -0
- package/src/library/runtime/bootstrap.ts +286 -0
- package/src/library/runtime/environment.ts +6 -0
- package/src/library/runtime/index.ts +4 -0
- package/src/library/scope.ts +193 -0
- package/src/library/types/global.d.ts +8 -0
- package/src/library/types.ts +26 -0
- package/src/library/utils/backoff.ts +65 -0
- package/src/library/utils/constructor.ts +89 -0
- package/src/library/utils/index.ts +2 -0
- package/src/library/x-data-medium.ts +16 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import {computed} from 'mobx';
|
|
2
|
+
|
|
3
|
+
import {StatefulCommand} from '../command.js';
|
|
4
|
+
import {Device, type DeviceEntry} from '../device.js';
|
|
5
|
+
import {
|
|
6
|
+
Endpoint,
|
|
7
|
+
type EndpointConnection,
|
|
8
|
+
type EndpointLogState,
|
|
9
|
+
} from '../endpoint.js';
|
|
10
|
+
|
|
11
|
+
export type FanMode = 'normal' | 'natural';
|
|
12
|
+
|
|
13
|
+
export class Fan extends Device {
|
|
14
|
+
protected readonly endpoint: FanEndpoint;
|
|
15
|
+
|
|
16
|
+
@computed
|
|
17
|
+
get on(): boolean {
|
|
18
|
+
return this.endpoint.on;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@computed
|
|
22
|
+
get mode(): FanMode | undefined {
|
|
23
|
+
return this.endpoint.mode;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Fan speed as a normalized ratio from 0 to 1. */
|
|
27
|
+
@computed
|
|
28
|
+
get speed(): number | undefined {
|
|
29
|
+
return this.endpoint.speed;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@computed
|
|
33
|
+
get horizontalSwing(): boolean | undefined {
|
|
34
|
+
return this.endpoint.horizontalSwing;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
constructor(entry: DeviceEntry) {
|
|
38
|
+
super(entry);
|
|
39
|
+
this.endpoint = this.getOrCreateEndpoint(FanEndpoint);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
turnOn(): this {
|
|
43
|
+
this.endpoint.turnOn();
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
turnOff(): this {
|
|
48
|
+
this.endpoint.turnOff();
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
setMode(value: FanMode): this {
|
|
53
|
+
this.endpoint.setMode(value);
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Sets fan speed using a normalized ratio from 0 to 1.
|
|
59
|
+
* A value of 0 turns the fan off.
|
|
60
|
+
*/
|
|
61
|
+
setSpeed(value: number): this {
|
|
62
|
+
if (value === 0) {
|
|
63
|
+
return this.turnOff();
|
|
64
|
+
} else {
|
|
65
|
+
this.endpoint.setSpeed(value);
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
setHorizontalSwing(value: boolean): this {
|
|
71
|
+
this.endpoint.setHorizontalSwing(value);
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export class FanEndpoint<
|
|
77
|
+
TConnection extends FanEndpointConnection = FanEndpointConnection,
|
|
78
|
+
> extends Endpoint<FanEndpointCommand, TConnection> {
|
|
79
|
+
@computed
|
|
80
|
+
get on(): boolean {
|
|
81
|
+
return this.connection?.on ?? false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@computed
|
|
85
|
+
get mode(): FanMode | undefined {
|
|
86
|
+
return this.connection?.mode;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Fan speed as a normalized ratio from 0 to 1. */
|
|
90
|
+
@computed
|
|
91
|
+
get speed(): number | undefined {
|
|
92
|
+
return this.connection?.speed;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@computed
|
|
96
|
+
get horizontalSwing(): boolean | undefined {
|
|
97
|
+
return this.connection?.horizontalSwing;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
protected override get logState(): EndpointLogState {
|
|
101
|
+
if (!this.ready) {
|
|
102
|
+
return {ready: false};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
ready: true,
|
|
107
|
+
on: this.on,
|
|
108
|
+
mode: this.mode,
|
|
109
|
+
speed: this.speed,
|
|
110
|
+
horizontalSwing: this.horizontalSwing,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
turnOn(): this {
|
|
115
|
+
return this.enqueueCommand(new SetFanOnCommand(true));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
turnOff(): this {
|
|
119
|
+
return this.enqueueCommand(new SetFanOnCommand(false));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
setMode(value: FanMode): this {
|
|
123
|
+
return this.enqueueCommand(new SetFanModeCommand(value));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Sets fan speed using a normalized ratio from 0 to 1.
|
|
128
|
+
* A value of 0 turns the fan off.
|
|
129
|
+
*/
|
|
130
|
+
setSpeed(value: number): this {
|
|
131
|
+
if (value === 0) {
|
|
132
|
+
return this.turnOff();
|
|
133
|
+
} else {
|
|
134
|
+
return this.enqueueCommand(new SetFanSpeedCommand(value));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
setHorizontalSwing(value: boolean): this {
|
|
139
|
+
return this.enqueueCommand(new SetFanHorizontalSwingCommand(value));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export type FanEndpointConnection = EndpointConnection<FanEndpointCommand> & {
|
|
144
|
+
readonly on: boolean;
|
|
145
|
+
readonly mode: FanMode | undefined;
|
|
146
|
+
/** Fan speed as a normalized ratio from 0 to 1. */
|
|
147
|
+
readonly speed: number | undefined;
|
|
148
|
+
readonly horizontalSwing: boolean | undefined;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
export abstract class FanCommand extends StatefulCommand {}
|
|
152
|
+
|
|
153
|
+
export class SetFanOnCommand extends FanCommand {
|
|
154
|
+
constructor(readonly value: boolean) {
|
|
155
|
+
super();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
override toLogString(): string {
|
|
159
|
+
return `set on=${this.value}`;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export class SetFanModeCommand extends FanCommand {
|
|
164
|
+
constructor(readonly value: FanMode) {
|
|
165
|
+
super();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
override toLogString(): string {
|
|
169
|
+
return `set mode=${this.value}`;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export class SetFanSpeedCommand extends FanCommand {
|
|
174
|
+
/** `value` is a normalized fan-speed ratio greater than 0 and at most 1. */
|
|
175
|
+
constructor(readonly value: number) {
|
|
176
|
+
super();
|
|
177
|
+
|
|
178
|
+
if (!Number.isFinite(value) || value <= 0 || value > 1) {
|
|
179
|
+
throw new RangeError(
|
|
180
|
+
'Fan speed must be a finite number greater than 0 and at most 1.',
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
override toLogString(): string {
|
|
186
|
+
return `set speed=${this.value}`;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export class SetFanHorizontalSwingCommand extends FanCommand {
|
|
191
|
+
constructor(readonly value: boolean) {
|
|
192
|
+
super();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
override toLogString(): string {
|
|
196
|
+
return `set horizontalSwing=${this.value}`;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export type FanEndpointCommand =
|
|
201
|
+
| SetFanOnCommand
|
|
202
|
+
| SetFanModeCommand
|
|
203
|
+
| SetFanSpeedCommand
|
|
204
|
+
| SetFanHorizontalSwingCommand;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import {computed} from 'mobx';
|
|
2
|
+
|
|
3
|
+
import {StatefulCommand} from '../command.js';
|
|
4
|
+
import {Device, type DeviceEntry} from '../device.js';
|
|
5
|
+
import {
|
|
6
|
+
Endpoint,
|
|
7
|
+
type EndpointConnection,
|
|
8
|
+
type EndpointLogState,
|
|
9
|
+
} from '../endpoint.js';
|
|
10
|
+
|
|
11
|
+
export class Light extends Device {
|
|
12
|
+
protected readonly endpoint: LightEndpoint;
|
|
13
|
+
|
|
14
|
+
@computed
|
|
15
|
+
get on(): boolean {
|
|
16
|
+
return this.endpoint.on;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Brightness as a normalized ratio from 0 to 1. */
|
|
20
|
+
@computed
|
|
21
|
+
get brightness(): number | undefined {
|
|
22
|
+
return this.endpoint.brightness;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@computed
|
|
26
|
+
get colorTemperature(): number | undefined {
|
|
27
|
+
return this.endpoint.colorTemperature;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
constructor(entry: DeviceEntry) {
|
|
31
|
+
super(entry);
|
|
32
|
+
this.endpoint = this.getOrCreateEndpoint(LightEndpoint);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
turnOn(): this {
|
|
36
|
+
this.endpoint.turnOn();
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
turnOff(): this {
|
|
41
|
+
this.endpoint.turnOff();
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Sets brightness using a normalized ratio from 0 to 1.
|
|
47
|
+
* A value of 0 turns the light off.
|
|
48
|
+
*/
|
|
49
|
+
setBrightness(value: number): this {
|
|
50
|
+
if (value === 0) {
|
|
51
|
+
return this.turnOff();
|
|
52
|
+
} else {
|
|
53
|
+
this.endpoint.setBrightness(value);
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
setColorTemperature(value: number): this {
|
|
59
|
+
this.endpoint.setColorTemperature(value);
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export class LightEndpoint<
|
|
65
|
+
TConnection extends LightEndpointConnection = LightEndpointConnection,
|
|
66
|
+
> extends Endpoint<LightEndpointCommand, TConnection> {
|
|
67
|
+
@computed
|
|
68
|
+
get on(): boolean {
|
|
69
|
+
return this.connection?.on ?? false;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Brightness as a normalized ratio from 0 to 1. */
|
|
73
|
+
@computed
|
|
74
|
+
get brightness(): number | undefined {
|
|
75
|
+
return this.connection?.brightness;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@computed
|
|
79
|
+
get colorTemperature(): number | undefined {
|
|
80
|
+
return this.connection?.colorTemperature;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
protected override get logState(): EndpointLogState {
|
|
84
|
+
if (!this.ready) {
|
|
85
|
+
return {ready: false};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
ready: true,
|
|
90
|
+
on: this.on,
|
|
91
|
+
brightness: this.brightness,
|
|
92
|
+
colorTemperature: this.colorTemperature,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
turnOn(): this {
|
|
97
|
+
return this.enqueueCommand(new SetLightOnCommand(true));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
turnOff(): this {
|
|
101
|
+
return this.enqueueCommand(new SetLightOnCommand(false));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Sets brightness using a normalized ratio from 0 to 1.
|
|
106
|
+
* A value of 0 turns the light off.
|
|
107
|
+
*/
|
|
108
|
+
setBrightness(value: number): this {
|
|
109
|
+
if (value === 0) {
|
|
110
|
+
return this.turnOff();
|
|
111
|
+
} else {
|
|
112
|
+
return this.enqueueCommand(new SetLightBrightnessCommand(value));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
setColorTemperature(value: number): this {
|
|
117
|
+
return this.enqueueCommand(new SetLightColorTemperatureCommand(value));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export type LightEndpointConnection =
|
|
122
|
+
EndpointConnection<LightEndpointCommand> & {
|
|
123
|
+
readonly on: boolean;
|
|
124
|
+
/** Brightness as a normalized ratio from 0 to 1. */
|
|
125
|
+
readonly brightness: number | undefined;
|
|
126
|
+
readonly colorTemperature: number | undefined;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
export abstract class LightCommand extends StatefulCommand {}
|
|
130
|
+
|
|
131
|
+
export class SetLightOnCommand extends LightCommand {
|
|
132
|
+
constructor(readonly value: boolean) {
|
|
133
|
+
super();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
override toLogString(): string {
|
|
137
|
+
return `set on=${this.value}`;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export class SetLightBrightnessCommand extends LightCommand {
|
|
142
|
+
/** `value` is a normalized brightness ratio greater than 0 and at most 1. */
|
|
143
|
+
constructor(readonly value: number) {
|
|
144
|
+
super();
|
|
145
|
+
|
|
146
|
+
if (!Number.isFinite(value) || value <= 0 || value > 1) {
|
|
147
|
+
throw new RangeError(
|
|
148
|
+
'Brightness must be a finite number greater than 0 and at most 1.',
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
override toLogString(): string {
|
|
154
|
+
return `set brightness=${this.value}`;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export class SetLightColorTemperatureCommand extends LightCommand {
|
|
159
|
+
constructor(readonly value: number) {
|
|
160
|
+
super();
|
|
161
|
+
|
|
162
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
163
|
+
throw new RangeError(
|
|
164
|
+
'Color temperature must be a finite number greater than 0.',
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
override toLogString(): string {
|
|
170
|
+
return `set colorTemperature=${this.value}`;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export type LightEndpointCommand =
|
|
175
|
+
| SetLightOnCommand
|
|
176
|
+
| SetLightBrightnessCommand
|
|
177
|
+
| SetLightColorTemperatureCommand;
|