esphome-ts 3.4.0-beta.0 → 5.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 +54 -3
- package/dist/index.d.ts +406 -2
- package/dist/index.js +3445 -14
- package/package.json +61 -39
- package/dist/api/bytePositions.d.ts +0 -8
- package/dist/api/bytePositions.js +0 -12
- package/dist/api/client.d.ts +0 -21
- package/dist/api/client.js +0 -60
- package/dist/api/espDevice.d.ts +0 -23
- package/dist/api/espDevice.js +0 -76
- package/dist/api/espSocket.d.ts +0 -13
- package/dist/api/espSocket.js +0 -39
- package/dist/api/helpers.d.ts +0 -19
- package/dist/api/helpers.js +0 -116
- package/dist/api/index.d.ts +0 -9
- package/dist/api/index.js +0 -21
- package/dist/api/interfaces.d.ts +0 -4
- package/dist/api/interfaces.js +0 -2
- package/dist/api/protobuf/api.d.ts +0 -922
- package/dist/api/protobuf/api.js +0 -6679
- package/dist/api/protobuf/api_options.d.ts +0 -24
- package/dist/api/protobuf/api_options.js +0 -76
- package/dist/api/protobuf/google_descriptor.d.ts +0 -1022
- package/dist/api/protobuf/google_descriptor.js +0 -3997
- package/dist/api/requestResponseMatching.d.ts +0 -50
- package/dist/api/requestResponseMatching.js +0 -54
- package/dist/api/responses.d.ts +0 -3
- package/dist/api/responses.js +0 -23
- package/dist/api/socket.d.ts +0 -29
- package/dist/api/socket.js +0 -109
- package/dist/api/typeGuards.d.ts +0 -5
- package/dist/api/typeGuards.js +0 -7
- package/dist/components/base.d.ts +0 -23
- package/dist/components/base.js +0 -51
- package/dist/components/binarySensor.d.ts +0 -9
- package/dist/components/binarySensor.js +0 -19
- package/dist/components/binarySensorTypes.d.ts +0 -26
- package/dist/components/binarySensorTypes.js +0 -30
- package/dist/components/commandInterface.d.ts +0 -4
- package/dist/components/commandInterface.js +0 -2
- package/dist/components/entities.d.ts +0 -26
- package/dist/components/entities.js +0 -2
- package/dist/components/fan.d.ts +0 -14
- package/dist/components/fan.js +0 -51
- package/dist/components/helpers.d.ts +0 -1
- package/dist/components/helpers.js +0 -12
- package/dist/components/index.d.ts +0 -12
- package/dist/components/index.js +0 -24
- package/dist/components/interfaces.d.ts +0 -10
- package/dist/components/interfaces.js +0 -2
- package/dist/components/light.d.ts +0 -22
- package/dist/components/light.js +0 -159
- package/dist/components/sensor.d.ts +0 -10
- package/dist/components/sensor.js +0 -23
- package/dist/components/states.d.ts +0 -25
- package/dist/components/states.js +0 -2
- package/dist/components/switch.d.ts +0 -9
- package/dist/components/switch.js +0 -28
- package/dist/run.d.ts +0 -1
- package/dist/run.js +0 -16
package/README.md
CHANGED
|
@@ -5,11 +5,11 @@ This is a client library for use with [esphome](https://esphome.io).
|
|
|
5
5
|
## Example use
|
|
6
6
|
|
|
7
7
|
```typescript
|
|
8
|
-
import { EspDevice, SwitchComponent } from 'esphome-ts
|
|
9
|
-
import { filter, tap } from 'rxjs
|
|
8
|
+
import { EspDevice, SwitchComponent } from 'esphome-ts';
|
|
9
|
+
import { filter, tap } from 'rxjs';
|
|
10
10
|
|
|
11
11
|
const device = new EspDevice('my_esp.local');
|
|
12
|
-
device.discovery$
|
|
12
|
+
const subscription = device.discovery$
|
|
13
13
|
.pipe(
|
|
14
14
|
filter((value) => value),
|
|
15
15
|
tap(() => {
|
|
@@ -20,10 +20,61 @@ device.discovery$
|
|
|
20
20
|
}),
|
|
21
21
|
)
|
|
22
22
|
.subscribe();
|
|
23
|
+
|
|
24
|
+
// Call `subscription.unsubscribe()` to stop watching, and `device.terminate()`
|
|
25
|
+
// to tear the device down for good.
|
|
23
26
|
```
|
|
24
27
|
|
|
28
|
+
`rxjs` (>= 7.8) is a peer dependency: install it next to the library (`npm install esphome-ts rxjs`).
|
|
29
|
+
|
|
25
30
|
Please see more [here](docs/index.md)
|
|
26
31
|
|
|
32
|
+
## Examples
|
|
33
|
+
|
|
34
|
+
See [examples/kitchenLights.ts](examples/kitchenLights.ts) for a runnable demo script (`npx tsx examples/kitchenLights.ts <device-host>`).
|
|
35
|
+
|
|
36
|
+
## Upgrading to v4
|
|
37
|
+
|
|
38
|
+
v4 is a breaking modernisation release. The package is now ESM-only (`"type": "module"`) and
|
|
39
|
+
requires Node.js >= 22.12.0; CommonJS consumers should stay on v3 (or use `require(esm)` on
|
|
40
|
+
Node >= 22.12). Import from the package root (e.g. `import { EspDevice } from 'esphome-ts'`) —
|
|
41
|
+
deep imports such as the previously documented `esphome-ts/dist` no longer resolve under the
|
|
42
|
+
exports map. The legacy `Connection` class, the `isLightComponent` type guard and internal helpers
|
|
43
|
+
(`decode`, `stateParser`, `convertNumbers`, `BytePositions`, …) are no longer exported; the public
|
|
44
|
+
surface is `EspDevice` (with `InvalidPasswordError`), `Client`, `EspSocket`, `RxjsSocket`,
|
|
45
|
+
`MessageTypes`, `ReadData` (type), the `isSwitchComponent` type guard, the `isTrue`/`isFalse` filters and
|
|
46
|
+
the component classes with their entity and state types. `EspDevice` now reconnects when a
|
|
47
|
+
connection attempt fails, reports invalid passwords and undecodable discovery frames on its
|
|
48
|
+
new `error$` observable instead of stalling or crashing, and `Client.listEntities()` /
|
|
49
|
+
`Client.subscribeStateChange()` emit `void` instead of a placeholder message. The
|
|
50
|
+
generated protobuf layer now depends on `@bufbuild/protobuf` instead of `protobufjs`.
|
|
51
|
+
|
|
52
|
+
## Upgrading to v5
|
|
53
|
+
|
|
54
|
+
v5 replaces the exported inheritance-based socket stack with the `Connection` seam:
|
|
55
|
+
|
|
56
|
+
- `RxjsSocket` is internal now — it became `TcpConnection` and is no longer exported.
|
|
57
|
+
- `EspSocket` no longer exposes `data$`, `send()`, `timeout$`, `close(force)` — use
|
|
58
|
+
`sendEspMessage` and `terminate()`.
|
|
59
|
+
- `reconnectOnTimeout`/`disconnectOnTimeout` are gone — an idle timeout always tears the
|
|
60
|
+
connection down, and reconnection stays driven by `EspDevice`.
|
|
61
|
+
- If you need a custom transport, inject your own `Connection` via `EspDevice`'s new options
|
|
62
|
+
parameter or via `EspSocket`'s config. The new `Connection` is an exported interface TYPE for
|
|
63
|
+
custom transports — unrelated to the legacy `Connection` class that v4 removed.
|
|
64
|
+
- ESPHome re-sends identical states; `state$` now de-duplicates them (shallow compare,
|
|
65
|
+
`Object.is` per field) and emits only on actual changes — subscribers no longer see phantom
|
|
66
|
+
re-emissions.
|
|
67
|
+
|
|
68
|
+
## Development
|
|
69
|
+
|
|
70
|
+
The protobuf layer in `src/api/protobuf/` is generated from the `.proto` files alongside it. After changing a `.proto` file, regenerate with:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
npm run proto
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
This requires `protoc` on your `PATH` (e.g. `brew install protobuf`). Do not edit the generated files by hand.
|
|
77
|
+
|
|
27
78
|
## Contribution
|
|
28
79
|
|
|
29
80
|
Please, feel free to make a PR and contribute to this project. Esphome is a good project, and this expands their
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,406 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire';
|
|
2
|
+
import { Observable, BehaviorSubject, Subject } from 'rxjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Message sent at the beginning of each connection
|
|
6
|
+
* Can only be sent by the client and only at the beginning of the connection
|
|
7
|
+
*/
|
|
8
|
+
interface HelloRequest {
|
|
9
|
+
/**
|
|
10
|
+
* Description of client (like User Agent)
|
|
11
|
+
* For example "Home Assistant"
|
|
12
|
+
* Not strictly necessary to send but nice for debugging
|
|
13
|
+
* purposes.
|
|
14
|
+
*/
|
|
15
|
+
clientInfo: string;
|
|
16
|
+
}
|
|
17
|
+
declare const HelloRequest: MessageFns<HelloRequest>;
|
|
18
|
+
/**
|
|
19
|
+
* Confirmation of successful connection request.
|
|
20
|
+
* Can only be sent by the server and only at the beginning of the connection
|
|
21
|
+
*/
|
|
22
|
+
interface HelloResponse {
|
|
23
|
+
/**
|
|
24
|
+
* The version of the API to use. The _client_ (for example Home Assistant) needs to check
|
|
25
|
+
* for compatibility and if necessary adopt to an older API.
|
|
26
|
+
* Major is for breaking changes in the base protocol - a mismatch will lead to immediate disconnect_client_
|
|
27
|
+
* Minor is for breaking changes in individual messages - a mismatch will lead to a warning message
|
|
28
|
+
*/
|
|
29
|
+
apiVersionMajor: number;
|
|
30
|
+
apiVersionMinor: number;
|
|
31
|
+
/**
|
|
32
|
+
* A string identifying the server (ESP); like client info this may be empty
|
|
33
|
+
* and only exists for debugging/logging purposes.
|
|
34
|
+
* For example "ESPHome v1.10.0 on ESP8266"
|
|
35
|
+
*/
|
|
36
|
+
serverInfo: string;
|
|
37
|
+
}
|
|
38
|
+
declare const HelloResponse: MessageFns<HelloResponse>;
|
|
39
|
+
/**
|
|
40
|
+
* Message sent at the beginning of each connection to authenticate the client
|
|
41
|
+
* Can only be sent by the client and only at the beginning of the connection
|
|
42
|
+
*/
|
|
43
|
+
interface ConnectRequest {
|
|
44
|
+
/** The password to log in with */
|
|
45
|
+
password: string;
|
|
46
|
+
}
|
|
47
|
+
declare const ConnectRequest: MessageFns<ConnectRequest>;
|
|
48
|
+
/**
|
|
49
|
+
* Confirmation of successful connection. After this the connection is available for all traffic.
|
|
50
|
+
* Can only be sent by the server and only at the beginning of the connection
|
|
51
|
+
*/
|
|
52
|
+
interface ConnectResponse {
|
|
53
|
+
invalidPassword: boolean;
|
|
54
|
+
}
|
|
55
|
+
declare const ConnectResponse: MessageFns<ConnectResponse>;
|
|
56
|
+
interface PingResponse {
|
|
57
|
+
}
|
|
58
|
+
declare const PingResponse: MessageFns<PingResponse>;
|
|
59
|
+
interface DeviceInfoResponse {
|
|
60
|
+
usesPassword: boolean;
|
|
61
|
+
/** The name of the node, given by "App.set_name()" */
|
|
62
|
+
name: string;
|
|
63
|
+
/** The mac address of the device. For example "AC:BC:32:89:0E:A9" */
|
|
64
|
+
macAddress: string;
|
|
65
|
+
/** A string describing the ESPHome version. For example "1.10.0" */
|
|
66
|
+
esphomeVersion: string;
|
|
67
|
+
/**
|
|
68
|
+
* A string describing the date of compilation, this is generated by the compiler
|
|
69
|
+
* and therefore may not be in the same format all the time.
|
|
70
|
+
* If the user isn't using ESPHome, this will also not be set.
|
|
71
|
+
*/
|
|
72
|
+
compilationTime: string;
|
|
73
|
+
/** The model of the board. For example NodeMCU */
|
|
74
|
+
model: string;
|
|
75
|
+
hasDeepSleep: boolean;
|
|
76
|
+
}
|
|
77
|
+
declare const DeviceInfoResponse: MessageFns<DeviceInfoResponse>;
|
|
78
|
+
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
79
|
+
type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
|
|
80
|
+
[K in keyof T]?: DeepPartial<T[K]>;
|
|
81
|
+
} : Partial<T>;
|
|
82
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
83
|
+
type Exact<P, I extends P> = P extends Builtin ? P : P & {
|
|
84
|
+
[K in keyof P]: Exact<P[K], I[K]>;
|
|
85
|
+
} & {
|
|
86
|
+
[K in Exclude<keyof I, KeysOfUnion<P>>]: never;
|
|
87
|
+
};
|
|
88
|
+
interface MessageFns<T> {
|
|
89
|
+
encode(message: T, writer?: BinaryWriter): BinaryWriter;
|
|
90
|
+
decode(input: BinaryReader | Uint8Array, length?: number): T;
|
|
91
|
+
fromJSON(object: any): T;
|
|
92
|
+
toJSON(message: T): unknown;
|
|
93
|
+
create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
|
|
94
|
+
fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
declare enum MessageTypes {
|
|
98
|
+
HelloRequest = 1,
|
|
99
|
+
HelloResponse = 2,
|
|
100
|
+
ConnectRequest = 3,
|
|
101
|
+
ConnectResponse = 4,
|
|
102
|
+
DisconnectRequest = 5,
|
|
103
|
+
DisconnectResponse = 6,
|
|
104
|
+
PingRequest = 7,
|
|
105
|
+
PingResponse = 8,
|
|
106
|
+
DeviceInfoRequest = 9,
|
|
107
|
+
DeviceInfoResponse = 10,
|
|
108
|
+
ListEntitiesRequest = 11,
|
|
109
|
+
ListEntitiesBinarySensorResponse = 12,
|
|
110
|
+
ListEntitiesCoverResponse = 13,
|
|
111
|
+
ListEntitiesFanResponse = 14,
|
|
112
|
+
ListEntitiesLightResponse = 15,
|
|
113
|
+
ListEntitiesSensorResponse = 16,
|
|
114
|
+
ListEntitiesSwitchResponse = 17,
|
|
115
|
+
ListEntitiesTextSensorResponse = 18,
|
|
116
|
+
ListEntitiesDoneResponse = 19,
|
|
117
|
+
SubscribeStatesRequest = 20,
|
|
118
|
+
BinarySensorStateResponse = 21,
|
|
119
|
+
CoverStateResponse = 22,
|
|
120
|
+
FanStateResponse = 23,
|
|
121
|
+
LightStateResponse = 24,
|
|
122
|
+
SensorStateResponse = 25,
|
|
123
|
+
SwitchStateResponse = 26,
|
|
124
|
+
TextSensorStateResponse = 27,
|
|
125
|
+
SubscribeLogsRequest = 28,
|
|
126
|
+
SubscribeLogsResponse = 29,
|
|
127
|
+
CoverCommandRequest = 30,
|
|
128
|
+
FanCommandRequest = 31,
|
|
129
|
+
LightCommandRequest = 32,
|
|
130
|
+
SwitchCommandRequest = 33,
|
|
131
|
+
SubscribeHomeassistantServicesRequest = 34,
|
|
132
|
+
HomeassistantServiceResponse = 35,
|
|
133
|
+
GetTimeRequest = 36,
|
|
134
|
+
GetTimeResponse = 37,
|
|
135
|
+
SubscribeHomeAssistantStatesRequest = 38,
|
|
136
|
+
SubscribeHomeAssistantStateResponse = 39,
|
|
137
|
+
HomeAssistantStateResponse = 40,
|
|
138
|
+
ListEntitiesServicesResponse = 41,
|
|
139
|
+
ExecuteServiceRequest = 42,
|
|
140
|
+
ListEntitiesCameraResponse = 43,
|
|
141
|
+
CameraImageResponse = 44,
|
|
142
|
+
CameraImageRequest = 45,
|
|
143
|
+
ListEntitiesClimateResponse = 46,
|
|
144
|
+
ClimateStateResponse = 47,
|
|
145
|
+
ClimateCommandRequest = 48
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
interface CommandInterface {
|
|
149
|
+
sendEspMessage(type: MessageTypes, data: Uint8Array): void;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Connection seam: the live path between the library and a device, along which
|
|
154
|
+
* frames travel as byte chunks. The TCP path is the production Connection; any
|
|
155
|
+
* implementation satisfying the same interface may substitute for it.
|
|
156
|
+
*
|
|
157
|
+
* Contract per member:
|
|
158
|
+
* - `open()`: repeatable — a no-op while a connect attempt is already in flight;
|
|
159
|
+
* otherwise a call with a live path tears it down and opens a fresh one.
|
|
160
|
+
* - `terminate()`: with a path or failed attempt open, tears it down and emits `false` on
|
|
161
|
+
* `connected$`; with nothing open it is a no-op — first or repeat call alike.
|
|
162
|
+
* - `connected$`: hot state stream that MUST emit its current value synchronously to every new
|
|
163
|
+
* subscriber (e.g. a BehaviorSubject seeded false pre-connect) — `EspDevice` drives its initial
|
|
164
|
+
* `open()` from the synchronous seed; a plain hot Subject or cold observable silently never
|
|
165
|
+
* connects. Never completes.
|
|
166
|
+
* - `chunks$`: hot, no emission while disconnected, never completes.
|
|
167
|
+
* - `error$`: hot, never completes — late errors after `terminate()` keep arriving.
|
|
168
|
+
*/
|
|
169
|
+
interface Connection {
|
|
170
|
+
open(): void;
|
|
171
|
+
terminate(): void;
|
|
172
|
+
isConnected(): boolean;
|
|
173
|
+
readonly connected$: Observable<boolean>;
|
|
174
|
+
readonly chunks$: Observable<Buffer>;
|
|
175
|
+
readonly error$: Observable<unknown>;
|
|
176
|
+
/** Fire-and-forget. Silently drops when not connected. Write errors surface on error$. */
|
|
177
|
+
write(data: Uint8Array): void;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
interface ReadData {
|
|
181
|
+
type: MessageTypes;
|
|
182
|
+
payload: Uint8Array;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
interface EspSocketConfiguration {
|
|
186
|
+
/** Ignored when `connection` is set: idle-timeout teardown is owned by the injected adapter. */
|
|
187
|
+
timeout?: number;
|
|
188
|
+
connection?: Connection;
|
|
189
|
+
}
|
|
190
|
+
declare class EspSocket implements CommandInterface {
|
|
191
|
+
private readonly connection;
|
|
192
|
+
private readonly teardown;
|
|
193
|
+
private readonly errors;
|
|
194
|
+
readonly connected$: Observable<boolean>;
|
|
195
|
+
readonly espData$: Observable<ReadData>;
|
|
196
|
+
readonly error$: Observable<unknown>;
|
|
197
|
+
constructor(host: string, port: number, config?: EspSocketConfiguration);
|
|
198
|
+
open(): void;
|
|
199
|
+
isConnected(): boolean;
|
|
200
|
+
terminate(): void;
|
|
201
|
+
sendEspMessage(type: MessageTypes, payload: Uint8Array): void;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
declare class Client {
|
|
205
|
+
private readonly socket;
|
|
206
|
+
private readonly subscription;
|
|
207
|
+
constructor(socket: EspSocket);
|
|
208
|
+
terminate(): void;
|
|
209
|
+
hello(request: HelloRequest): Observable<HelloResponse>;
|
|
210
|
+
connect(request: ConnectRequest): Observable<ConnectResponse>;
|
|
211
|
+
ping(): Observable<PingResponse>;
|
|
212
|
+
deviceInfo(): Observable<DeviceInfoResponse>;
|
|
213
|
+
listEntities(): Observable<void>;
|
|
214
|
+
subscribeStateChange(): Observable<void>;
|
|
215
|
+
private request;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
interface ListEntity {
|
|
219
|
+
key: number;
|
|
220
|
+
name: string;
|
|
221
|
+
uniqueId: string;
|
|
222
|
+
objectId: string;
|
|
223
|
+
}
|
|
224
|
+
interface SensorEntity extends ListEntity {
|
|
225
|
+
accuracyDecimals: number;
|
|
226
|
+
deviceClass?: string;
|
|
227
|
+
icon: string;
|
|
228
|
+
unitOfMeasurement: string;
|
|
229
|
+
}
|
|
230
|
+
interface BinarySensorEntity extends ListEntity {
|
|
231
|
+
deviceClass: string;
|
|
232
|
+
}
|
|
233
|
+
interface LightEntity extends ListEntity {
|
|
234
|
+
effects: string[];
|
|
235
|
+
supportsBrightness: boolean;
|
|
236
|
+
supportsRgb: boolean;
|
|
237
|
+
}
|
|
238
|
+
type ComponentType = 'light' | 'binarySensor' | 'sensor' | 'switch';
|
|
239
|
+
|
|
240
|
+
interface StateEvent {
|
|
241
|
+
key: number;
|
|
242
|
+
}
|
|
243
|
+
interface SensorStateEvent extends StateEvent {
|
|
244
|
+
state?: number;
|
|
245
|
+
}
|
|
246
|
+
interface BinarySensorStateEvent extends StateEvent {
|
|
247
|
+
state?: boolean;
|
|
248
|
+
}
|
|
249
|
+
type SwitchStateEvent = BinarySensorStateEvent;
|
|
250
|
+
interface LightStateEvent extends StateEvent {
|
|
251
|
+
state?: boolean;
|
|
252
|
+
brightness?: number;
|
|
253
|
+
red?: number;
|
|
254
|
+
green?: number;
|
|
255
|
+
blue?: number;
|
|
256
|
+
effect?: string;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
declare abstract class BaseComponent<L extends ListEntity = ListEntity, S extends StateEvent = StateEvent> {
|
|
260
|
+
protected readonly listEntity: L;
|
|
261
|
+
private readonly commandInterface;
|
|
262
|
+
protected readonly state: BehaviorSubject<S | undefined>;
|
|
263
|
+
readonly state$: Observable<S>;
|
|
264
|
+
private readonly terminatePreviousStateSubscription;
|
|
265
|
+
private readonly commandInPipeline;
|
|
266
|
+
protected readonly teardown: Subject<void>;
|
|
267
|
+
constructor(listEntity: L, state: Observable<S>, commandInterface: CommandInterface);
|
|
268
|
+
provideStateObservable(state$: Observable<S>): void;
|
|
269
|
+
get ready(): boolean;
|
|
270
|
+
get name(): string;
|
|
271
|
+
get key(): number;
|
|
272
|
+
toString(): string;
|
|
273
|
+
terminate(): void;
|
|
274
|
+
protected queueCommand(type: MessageTypes, dataFn: () => Uint8Array, disableSerialise?: boolean): void;
|
|
275
|
+
abstract get type(): ComponentType;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
declare class InvalidPasswordError extends Error {
|
|
279
|
+
constructor(host: string);
|
|
280
|
+
}
|
|
281
|
+
declare class EspDevice {
|
|
282
|
+
private readonly host;
|
|
283
|
+
private readonly password;
|
|
284
|
+
private readonly port;
|
|
285
|
+
private readonly socket;
|
|
286
|
+
private readonly client;
|
|
287
|
+
private readonly stateEvents$;
|
|
288
|
+
deviceInfo?: DeviceInfoResponse;
|
|
289
|
+
readonly components: {
|
|
290
|
+
[key: string]: BaseComponent;
|
|
291
|
+
};
|
|
292
|
+
private readonly discovery;
|
|
293
|
+
readonly discovery$: Observable<boolean>;
|
|
294
|
+
private readonly errors;
|
|
295
|
+
/**
|
|
296
|
+
* Device level failures: frames that could not be decoded and handshake
|
|
297
|
+
* problems such as an `InvalidPasswordError`. Socket level errors are
|
|
298
|
+
* available on the socket itself.
|
|
299
|
+
*/
|
|
300
|
+
readonly error$: Observable<unknown>;
|
|
301
|
+
private readonly subscription;
|
|
302
|
+
private retrySubscription?;
|
|
303
|
+
private passwordRejected;
|
|
304
|
+
readonly alive$: Observable<boolean>;
|
|
305
|
+
constructor(host: string, password?: string, port?: number,
|
|
306
|
+
/**
|
|
307
|
+
* An injected Connection owns its own liveness/idle teardown — the
|
|
308
|
+
* socket-level `PING_TIMEOUT` does not apply to it.
|
|
309
|
+
*/
|
|
310
|
+
options?: {
|
|
311
|
+
connection?: Connection;
|
|
312
|
+
});
|
|
313
|
+
/**
|
|
314
|
+
* Provides the reconnect cadence used while the device is unreachable.
|
|
315
|
+
* Calling this again replaces the previously provided retry signal, so
|
|
316
|
+
* repeated calls cannot stack parallel reconnect loops. Providing a cadence
|
|
317
|
+
* is also the explicit opt-in re-arm after a password rejection.
|
|
318
|
+
*/
|
|
319
|
+
provideRetryObservable(retryWhen$: Observable<unknown>): void;
|
|
320
|
+
terminate(): void;
|
|
321
|
+
private parseListResponse;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
declare const isTrue: (val: unknown) => val is true;
|
|
325
|
+
declare const isFalse: (val: unknown) => val is false;
|
|
326
|
+
|
|
327
|
+
declare class SwitchComponent extends BaseComponent<ListEntity, SwitchStateEvent> {
|
|
328
|
+
get status(): boolean;
|
|
329
|
+
turnOn(): void;
|
|
330
|
+
turnOff(): void;
|
|
331
|
+
get type(): ComponentType;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
declare const isSwitchComponent: (component: BaseComponent) => component is SwitchComponent;
|
|
335
|
+
|
|
336
|
+
declare enum BinarySensorTypes {
|
|
337
|
+
NONE = "None",
|
|
338
|
+
BATTERY = "battery",
|
|
339
|
+
COLD = "cold",
|
|
340
|
+
CONNECTIVITY = "connectivity",
|
|
341
|
+
DOOR = "door",
|
|
342
|
+
GARAGE_DOOR = "garage_door",
|
|
343
|
+
GAS = "gas",
|
|
344
|
+
HEAT = "heat",
|
|
345
|
+
LIGHT = "light",
|
|
346
|
+
LOCK = "lock",
|
|
347
|
+
MOISTURE = "moisture",
|
|
348
|
+
MOTION = "motion",
|
|
349
|
+
MOVING = "moving",
|
|
350
|
+
OCCUPANCY = "occupancy",
|
|
351
|
+
OPENING = "opening",
|
|
352
|
+
PLUG = "plug",
|
|
353
|
+
POWER = "power",
|
|
354
|
+
PRESENCE = "presence",
|
|
355
|
+
PROBLEM = "problem",
|
|
356
|
+
SAFETY = "safety",
|
|
357
|
+
SMOKE = "smoke",
|
|
358
|
+
SOUND = "sound",
|
|
359
|
+
VIBRATION = "vibration",
|
|
360
|
+
WINDOW = "window"
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
declare class BinarySensorComponent extends BaseComponent<BinarySensorEntity, BinarySensorStateEvent> {
|
|
364
|
+
get deviceClass(): BinarySensorTypes;
|
|
365
|
+
get status(): boolean;
|
|
366
|
+
get type(): ComponentType;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
interface Rgb {
|
|
370
|
+
red: number;
|
|
371
|
+
green: number;
|
|
372
|
+
blue: number;
|
|
373
|
+
}
|
|
374
|
+
interface Hsv {
|
|
375
|
+
hue: number;
|
|
376
|
+
saturation: number;
|
|
377
|
+
value: number;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
declare class LightComponent extends BaseComponent<LightEntity, LightStateEvent> {
|
|
381
|
+
turnOn(): void;
|
|
382
|
+
turnOff(): void;
|
|
383
|
+
getBrightness(): number | undefined;
|
|
384
|
+
setBrightness(brightness: number): void;
|
|
385
|
+
get hsv(): Hsv;
|
|
386
|
+
set hsv(hsv: Hsv);
|
|
387
|
+
get rgb(): Rgb;
|
|
388
|
+
set rgb({ red, green, blue }: Rgb);
|
|
389
|
+
get type(): ComponentType;
|
|
390
|
+
get supportsRgb(): boolean;
|
|
391
|
+
get supportsBrightness(): boolean;
|
|
392
|
+
availableEffects(): string[];
|
|
393
|
+
get effect(): string;
|
|
394
|
+
set effect(effect: string);
|
|
395
|
+
private generateState;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
declare class SensorComponent extends BaseComponent<SensorEntity, SensorStateEvent> {
|
|
399
|
+
get value(): number | undefined;
|
|
400
|
+
get type(): ComponentType;
|
|
401
|
+
get deviceClass(): string | undefined;
|
|
402
|
+
get unitOfMeasurement(): string;
|
|
403
|
+
get icon(): string;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export { BaseComponent, BinarySensorComponent, type BinarySensorEntity, type BinarySensorStateEvent, BinarySensorTypes, Client, type CommandInterface, type ComponentType, type Connection, EspDevice, EspSocket, type Hsv, InvalidPasswordError, LightComponent, type LightEntity, type LightStateEvent, type ListEntity, MessageTypes, type ReadData, type Rgb, SensorComponent, type SensorEntity, type SensorStateEvent, type StateEvent, SwitchComponent, type SwitchStateEvent, isFalse, isSwitchComponent, isTrue };
|