@homelib/core 0.0.0-wip.01265bf1cc90
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 +11 -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 +13 -0
- package/bld/library/device-namespace.js +11 -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 +6 -0
- package/bld/library/devices/index.js +7 -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/devices/pet-feeder.d.ts +36 -0
- package/bld/library/devices/pet-feeder.js +115 -0
- package/bld/library/devices/pet-feeder.js.map +1 -0
- package/bld/library/devices/temperature-humidity-sensor.d.ts +18 -0
- package/bld/library/devices/temperature-humidity-sensor.js +86 -0
- package/bld/library/devices/temperature-humidity-sensor.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 +32 -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 +6 -0
- package/src/library/devices/light.ts +177 -0
- package/src/library/devices/pet-feeder.ts +98 -0
- package/src/library/devices/temperature-humidity-sensor.ts +67 -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;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import {computed} from 'mobx';
|
|
2
|
+
|
|
3
|
+
import {Command} 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 PetFoodLevel = 'normal' | 'low';
|
|
12
|
+
|
|
13
|
+
export class PetFeeder extends Device {
|
|
14
|
+
protected readonly endpoint: PetFeederEndpoint;
|
|
15
|
+
|
|
16
|
+
/** Whether the food remaining in the hopper is normal or low. */
|
|
17
|
+
@computed
|
|
18
|
+
get foodLevel(): PetFoodLevel | undefined {
|
|
19
|
+
return this.endpoint.foodLevel;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Current weight of the food remaining in the bowl, in grams. */
|
|
23
|
+
@computed
|
|
24
|
+
get bowlFoodWeight(): number | undefined {
|
|
25
|
+
return this.endpoint.bowlFoodWeight;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
constructor(entry: DeviceEntry) {
|
|
29
|
+
super(entry);
|
|
30
|
+
this.endpoint = this.getOrCreateEndpoint(PetFeederEndpoint);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Dispenses the requested number of portions of pet food. */
|
|
34
|
+
dispense(portions: number): this {
|
|
35
|
+
this.endpoint.dispense(portions);
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export class PetFeederEndpoint<
|
|
41
|
+
TConnection extends PetFeederEndpointConnection = PetFeederEndpointConnection,
|
|
42
|
+
> extends Endpoint<PetFeederEndpointCommand, TConnection> {
|
|
43
|
+
/** Whether the food remaining in the hopper is normal or low. */
|
|
44
|
+
@computed
|
|
45
|
+
get foodLevel(): PetFoodLevel | undefined {
|
|
46
|
+
return this.connection?.foodLevel;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Current weight of the food remaining in the bowl, in grams. */
|
|
50
|
+
@computed
|
|
51
|
+
get bowlFoodWeight(): number | undefined {
|
|
52
|
+
return this.connection?.bowlFoodWeight;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
protected override get logState(): EndpointLogState {
|
|
56
|
+
if (!this.ready) {
|
|
57
|
+
return {ready: false};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
ready: true,
|
|
62
|
+
foodLevel: this.foodLevel,
|
|
63
|
+
bowlFoodWeightGrams: this.bowlFoodWeight,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Dispenses the requested number of portions of pet food. */
|
|
68
|
+
dispense(portions: number): this {
|
|
69
|
+
return this.enqueueCommand(new DispensePetFoodCommand(portions));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export type PetFeederEndpointConnection =
|
|
74
|
+
EndpointConnection<PetFeederEndpointCommand> & {
|
|
75
|
+
/** Whether the food remaining in the hopper is normal or low. */
|
|
76
|
+
readonly foodLevel: PetFoodLevel | undefined;
|
|
77
|
+
/** Current weight of the food remaining in the bowl, in grams. */
|
|
78
|
+
readonly bowlFoodWeight: number | undefined;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/** A one-shot command; equal values must still dispense food again. */
|
|
82
|
+
export class DispensePetFoodCommand extends Command {
|
|
83
|
+
constructor(readonly portions: number) {
|
|
84
|
+
super();
|
|
85
|
+
|
|
86
|
+
if (!Number.isInteger(portions) || portions <= 0) {
|
|
87
|
+
throw new RangeError(
|
|
88
|
+
'Pet food portion count must be a positive whole number.',
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
override toLogString(): string {
|
|
94
|
+
return `dispense portions=${this.portions}`;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export type PetFeederEndpointCommand = DispensePetFoodCommand;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {computed} from 'mobx';
|
|
2
|
+
|
|
3
|
+
import type {Temperature} from '../atomics/index.js';
|
|
4
|
+
import type {HumiditySensor, TemperatureSensor} from '../device/index.js';
|
|
5
|
+
import {Device, type DeviceEntry} from '../device.js';
|
|
6
|
+
import {
|
|
7
|
+
Endpoint,
|
|
8
|
+
type EndpointConnection,
|
|
9
|
+
type EndpointLogState,
|
|
10
|
+
} from '../endpoint.js';
|
|
11
|
+
|
|
12
|
+
export class TemperatureHumiditySensor
|
|
13
|
+
extends Device
|
|
14
|
+
implements TemperatureSensor, HumiditySensor
|
|
15
|
+
{
|
|
16
|
+
protected readonly endpoint: TemperatureHumiditySensorEndpoint;
|
|
17
|
+
|
|
18
|
+
@computed
|
|
19
|
+
get temperature(): Temperature | undefined {
|
|
20
|
+
return this.endpoint.temperature;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Relative humidity as a normalized ratio from 0 to 1. */
|
|
24
|
+
@computed
|
|
25
|
+
get relativeHumidity(): number | undefined {
|
|
26
|
+
return this.endpoint.relativeHumidity;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
constructor(entry: DeviceEntry) {
|
|
30
|
+
super(entry);
|
|
31
|
+
this.endpoint = this.getOrCreateEndpoint(TemperatureHumiditySensorEndpoint);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class TemperatureHumiditySensorEndpoint<
|
|
36
|
+
TConnection extends TemperatureHumiditySensorEndpointConnection =
|
|
37
|
+
TemperatureHumiditySensorEndpointConnection,
|
|
38
|
+
>
|
|
39
|
+
extends Endpoint<never, TConnection>
|
|
40
|
+
implements TemperatureSensor, HumiditySensor
|
|
41
|
+
{
|
|
42
|
+
@computed
|
|
43
|
+
get temperature(): Temperature | undefined {
|
|
44
|
+
return this.connection?.temperature;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Relative humidity as a normalized ratio from 0 to 1. */
|
|
48
|
+
@computed
|
|
49
|
+
get relativeHumidity(): number | undefined {
|
|
50
|
+
return this.connection?.relativeHumidity;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
protected override get logState(): EndpointLogState {
|
|
54
|
+
if (!this.ready) {
|
|
55
|
+
return {ready: false};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
ready: true,
|
|
60
|
+
temperatureCelsius: this.temperature?.celsius,
|
|
61
|
+
relativeHumidity: this.relativeHumidity,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export type TemperatureHumiditySensorEndpointConnection =
|
|
67
|
+
EndpointConnection<never> & TemperatureSensor & HumiditySensor;
|