homebridge-ratgdo 2.8.1 → 2.9.1

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.
@@ -0,0 +1,313 @@
1
+ import type { HomebridgePluginLogging, Nullable } from "homebridge-plugin-utils";
2
+ import { EventEmitter } from "node:events";
3
+ /**
4
+ * Represents one entity from the ESPHome device.
5
+ *
6
+ * @property key - The numeric key identifier for the entity.
7
+ * @property name - The human-readable name of the entity.
8
+ * @property type - The type of entity (e.g., "switch", "light", "cover").
9
+ */
10
+ interface Entity {
11
+ key: number;
12
+ name: string;
13
+ type: string;
14
+ }
15
+ /**
16
+ * Device information to send when requested by the ESPHome device.
17
+ *
18
+ * @property bluetoothProxyFeatureFlags - Bluetooth proxy feature flags.
19
+ * @property compilationTime - When the client was compiled/started.
20
+ * @property esphomeVersion - Version of ESPHome protocol being used.
21
+ * @property hasDeepSleep - Whether the client supports deep sleep.
22
+ * @property legacyBluetoothProxyVersion - Legacy Bluetooth proxy version.
23
+ * @property macAddress - MAC address of the client (format: "AA:BB:CC:DD:EE:FF").
24
+ * @property model - Model or type of the client.
25
+ * @property name - Friendly name of the client.
26
+ * @property projectName - Name of the project/plugin.
27
+ * @property projectVersion - Version of the project/plugin.
28
+ * @property usesPassword - Whether the client uses password authentication.
29
+ * @property webserverPort - Port number of any web server.
30
+ */
31
+ export interface DeviceInfo {
32
+ bluetoothProxyFeatureFlags?: number;
33
+ compilationTime?: string;
34
+ esphomeVersion?: string;
35
+ hasDeepSleep?: boolean;
36
+ legacyBluetoothProxyVersion?: number;
37
+ macAddress?: string;
38
+ model?: string;
39
+ name?: string;
40
+ projectName?: string;
41
+ projectVersion?: string;
42
+ usesPassword?: boolean;
43
+ webserverPort?: number;
44
+ }
45
+ /**
46
+ * ESPHome API client for communicating with ESPHome devices.
47
+ * Implements the ESPHome native API protocol over TCP.
48
+ *
49
+ * @extends EventEmitter
50
+ * @emits connect - Connected to device.
51
+ * @emits disconnect - Disconnected from device.
52
+ * @emits message - Raw message received with type and payload.
53
+ * @emits entities - List of discovered entities after enumeration.
54
+ * @emits telemetry - Generic telemetry update for any entity.
55
+ * @emits heartbeat - Heartbeat response received.
56
+ * @emits {entityType} - Type-specific telemetry events (e.g., "cover", "light", "switch").
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * const client = new EspHomeClient(ratgdo, "192.168.1.100");
61
+ * client.connect();
62
+ *
63
+ * // Listen for discovered entities
64
+ * client.on("entities", (entities) => {
65
+ *
66
+ * // Log all available entity IDs
67
+ * client.logAllEntityIds();
68
+ * });
69
+ *
70
+ * // Send commands using entity IDs
71
+ * await client.sendSwitchCommand("switch-garagedoor", true);
72
+ * await client.sendLightCommand("light-light", { state: true, brightness: 0.8 });
73
+ * await client.sendCoverCommand("cover-door", "open");
74
+ * ```
75
+ */
76
+ export declare class EspHomeClient extends EventEmitter {
77
+ private clientSocket;
78
+ private dataListener;
79
+ private host;
80
+ private log;
81
+ private port;
82
+ private recvBuffer;
83
+ private remoteDeviceInfo;
84
+ private discoveredEntities;
85
+ private entityKeys;
86
+ private entityNames;
87
+ private entityTypes;
88
+ /**
89
+ * Creates a new ESPHome client instance.
90
+ *
91
+ * @param log - Logging interface.
92
+ * @param host - The hostname or IP address of the ESPHome device.
93
+ * @param port - The port number for the ESPHome API (default: 6053).
94
+ */
95
+ constructor(log: HomebridgePluginLogging, host: string, port?: number);
96
+ /**
97
+ * Connect to the ESPHome device and start communication.
98
+ */
99
+ connect(): void;
100
+ /**
101
+ * Disconnect from the ESPHome device and cleanup resources.
102
+ */
103
+ disconnect(): void;
104
+ /**
105
+ * Handle a newly connected socket.
106
+ */
107
+ private handleConnect;
108
+ /**
109
+ * Handle socket errors.
110
+ */
111
+ private handleSocketError;
112
+ /**
113
+ * Handle socket closure.
114
+ */
115
+ private handleSocketClose;
116
+ /**
117
+ * Clean up the data listener if it exists.
118
+ */
119
+ private cleanupDataListener;
120
+ /**
121
+ * Handle incoming raw data, frame messages, and dispatch.
122
+ */
123
+ private handleData;
124
+ /**
125
+ * Dispatch based on message type.
126
+ */
127
+ private handleMessage;
128
+ /**
129
+ * Handle device info response from the ESPHome device.
130
+ */
131
+ private handleDeviceInfoResponse;
132
+ /**
133
+ * Return the device information of the connected ESPHome device if available.
134
+ *
135
+ * @returns The device information if available, or `null`.
136
+ */
137
+ deviceInfo(): Nullable<DeviceInfo>;
138
+ /**
139
+ * Check if a message type is a list entities response.
140
+ */
141
+ private isListEntitiesResponse;
142
+ /**
143
+ * Check if a message type is a state update.
144
+ */
145
+ private isStateUpdate;
146
+ /**
147
+ * Extract entity type label from message type.
148
+ */
149
+ private getEntityTypeLabel;
150
+ /**
151
+ * Parses a single ListEntities*Response, logs it, and stores it.
152
+ */
153
+ private handleListEntity;
154
+ /**
155
+ * Decodes a state update, looks up entity info, and emits events.
156
+ */
157
+ private handleTelemetry;
158
+ /**
159
+ * Handle cover state telemetry.
160
+ */
161
+ private handleCoverState;
162
+ /**
163
+ * Extract entity key from protobuf fields.
164
+ */
165
+ private extractEntityKey;
166
+ /**
167
+ * Extract fixed32 field from protobuf fields.
168
+ */
169
+ private extractFixed32Field;
170
+ /**
171
+ * Extract string field from protobuf fields.
172
+ */
173
+ private extractStringField;
174
+ /**
175
+ * Extract number field from protobuf fields.
176
+ */
177
+ private extractNumberField;
178
+ /**
179
+ * Extract telemetry value from protobuf fields.
180
+ */
181
+ private extractTelemetryValue;
182
+ /**
183
+ * Frames a raw protobuf payload with the 0x00 sentinel, length, and message type.
184
+ */
185
+ private frameAndSend;
186
+ /**
187
+ * Encode protobuf fields into a buffer.
188
+ */
189
+ private encodeProtoFields;
190
+ /**
191
+ * Build key field as fixed32 for command requests.
192
+ */
193
+ private buildKeyField;
194
+ /**
195
+ * Get entity key by ID.
196
+ *
197
+ * @param id - The entity ID to look up.
198
+ *
199
+ * @returns The entity key or `null` if not found.
200
+ */
201
+ getEntityKey(id: string): Nullable<number>;
202
+ /**
203
+ * Log all registered entity IDs for debugging.
204
+ * Logs entities grouped by type with their names and keys.
205
+ */
206
+ logAllEntityIds(): void;
207
+ /**
208
+ * Get entity information by ID.
209
+ *
210
+ * @param id - The entity ID to look up.
211
+ *
212
+ * @returns The entity information or `null` if not found.
213
+ */
214
+ getEntityById(id: string): Nullable<Entity>;
215
+ /**
216
+ * Check if an entity ID exists.
217
+ *
218
+ * @param id - The entity ID to check.
219
+ *
220
+ * @returns `true` if the entity exists, `false` otherwise.
221
+ */
222
+ hasEntity(id: string): boolean;
223
+ /**
224
+ * Get all available entity IDs grouped by type.
225
+ *
226
+ * @returns Object with entity types as keys and arrays of IDs as values.
227
+ */
228
+ getAvailableEntityIds(): Record<string, string[]>;
229
+ /**
230
+ * Get all entities with their IDs.
231
+ *
232
+ * @returns Array of entities with their corresponding IDs.
233
+ */
234
+ getEntitiesWithIds(): Array<Entity & {
235
+ id: string;
236
+ }>;
237
+ /**
238
+ * Send a ping request to the device to heartbeat the connection.
239
+ */
240
+ sendPing(): void;
241
+ /**
242
+ * Sends a SwitchCommandRequest for the given entity ID and on/off state.
243
+ *
244
+ * @param id - The entity ID (format: "switch-entityname").
245
+ * @param state - `true` for on, `false` for off.
246
+ */
247
+ sendSwitchCommand(id: string, state: boolean): void;
248
+ /**
249
+ * Sends a ButtonCommandRequest to press a button entity.
250
+ *
251
+ * @param id - The entity ID (format: "button-entityname").
252
+ */
253
+ sendButtonCommand(id: string): void;
254
+ /**
255
+ * Sends a CoverCommandRequest for the given entity ID.
256
+ *
257
+ * @param id - The entity ID (format: "cover-entityname").
258
+ * @param options - Command options (at least one option must be provided).
259
+ * @param options.command - The command: "open", "close", or "stop" (optional).
260
+ * @param options.position - Target position 0.0-1.0 where 0 is closed, 1 is open (optional).
261
+ * @param options.tilt - Target tilt 0.0-1.0 where 0 is closed, 1 is open (optional).
262
+ *
263
+ * @example
264
+ * ```typescript
265
+ * // Send a simple command
266
+ * await client.sendCoverCommand("cover-garagedoor", { command: "open" });
267
+ *
268
+ * // Set to specific position
269
+ * await client.sendCoverCommand("cover-garagedoor", { position: 0.5 }); // 50% open
270
+ *
271
+ * // Set position and tilt
272
+ * await client.sendCoverCommand("cover-blinds", { position: 1.0, tilt: 0.25 });
273
+ * ```
274
+ */
275
+ sendCoverCommand(id: string, options: {
276
+ command?: "open" | "close" | "stop";
277
+ position?: number;
278
+ tilt?: number;
279
+ }): void;
280
+ /**
281
+ * Sends a LightCommandRequest to turn on/off and optionally set brightness.
282
+ *
283
+ * @param id - The entity ID (format: "light-entityname").
284
+ * @param options - Command options.
285
+ * @param options.state - `true` for on, `false` for off (optional).
286
+ * @param options.brightness - Brightness level 0.0-1.0 (optional).
287
+ */
288
+ sendLightCommand(id: string, options: {
289
+ state?: boolean;
290
+ brightness?: number;
291
+ }): void;
292
+ /**
293
+ * Sends a LockCommandRequest to lock or unlock the given entity ID.
294
+ *
295
+ * @param id - The entity ID (format: "lock-entityname").
296
+ * @param command - The command to send: "lock" or "unlock".
297
+ * @param code - Optional unlock code.
298
+ */
299
+ sendLockCommand(id: string, command: "lock" | "unlock", code?: string): void;
300
+ /**
301
+ * Encode an integer as a VarInt (protobuf-style).
302
+ */
303
+ private encodeVarint;
304
+ /**
305
+ * Read a VarInt from buffer at offset; returns [value, bytesRead].
306
+ */
307
+ private readVarint;
308
+ /**
309
+ * Decode a simple protobuf message into a map of field numbers to values.
310
+ */
311
+ private decodeProtobuf;
312
+ }
313
+ export {};