esphome-ts 3.4.0-beta.0 → 4.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.
Files changed (60) hide show
  1. package/README.md +33 -1
  2. package/dist/index.d.ts +379 -2
  3. package/dist/index.js +3355 -14
  4. package/package.json +60 -39
  5. package/dist/api/bytePositions.d.ts +0 -8
  6. package/dist/api/bytePositions.js +0 -12
  7. package/dist/api/client.d.ts +0 -21
  8. package/dist/api/client.js +0 -60
  9. package/dist/api/espDevice.d.ts +0 -23
  10. package/dist/api/espDevice.js +0 -76
  11. package/dist/api/espSocket.d.ts +0 -13
  12. package/dist/api/espSocket.js +0 -39
  13. package/dist/api/helpers.d.ts +0 -19
  14. package/dist/api/helpers.js +0 -116
  15. package/dist/api/index.d.ts +0 -9
  16. package/dist/api/index.js +0 -21
  17. package/dist/api/interfaces.d.ts +0 -4
  18. package/dist/api/interfaces.js +0 -2
  19. package/dist/api/protobuf/api.d.ts +0 -922
  20. package/dist/api/protobuf/api.js +0 -6679
  21. package/dist/api/protobuf/api_options.d.ts +0 -24
  22. package/dist/api/protobuf/api_options.js +0 -76
  23. package/dist/api/protobuf/google_descriptor.d.ts +0 -1022
  24. package/dist/api/protobuf/google_descriptor.js +0 -3997
  25. package/dist/api/requestResponseMatching.d.ts +0 -50
  26. package/dist/api/requestResponseMatching.js +0 -54
  27. package/dist/api/responses.d.ts +0 -3
  28. package/dist/api/responses.js +0 -23
  29. package/dist/api/socket.d.ts +0 -29
  30. package/dist/api/socket.js +0 -109
  31. package/dist/api/typeGuards.d.ts +0 -5
  32. package/dist/api/typeGuards.js +0 -7
  33. package/dist/components/base.d.ts +0 -23
  34. package/dist/components/base.js +0 -51
  35. package/dist/components/binarySensor.d.ts +0 -9
  36. package/dist/components/binarySensor.js +0 -19
  37. package/dist/components/binarySensorTypes.d.ts +0 -26
  38. package/dist/components/binarySensorTypes.js +0 -30
  39. package/dist/components/commandInterface.d.ts +0 -4
  40. package/dist/components/commandInterface.js +0 -2
  41. package/dist/components/entities.d.ts +0 -26
  42. package/dist/components/entities.js +0 -2
  43. package/dist/components/fan.d.ts +0 -14
  44. package/dist/components/fan.js +0 -51
  45. package/dist/components/helpers.d.ts +0 -1
  46. package/dist/components/helpers.js +0 -12
  47. package/dist/components/index.d.ts +0 -12
  48. package/dist/components/index.js +0 -24
  49. package/dist/components/interfaces.d.ts +0 -10
  50. package/dist/components/interfaces.js +0 -2
  51. package/dist/components/light.d.ts +0 -22
  52. package/dist/components/light.js +0 -159
  53. package/dist/components/sensor.d.ts +0 -10
  54. package/dist/components/sensor.js +0 -23
  55. package/dist/components/states.d.ts +0 -25
  56. package/dist/components/states.js +0 -2
  57. package/dist/components/switch.d.ts +0 -9
  58. package/dist/components/switch.js +0 -28
  59. package/dist/run.d.ts +0 -1
  60. package/dist/run.js +0 -16
package/dist/index.js CHANGED
@@ -1,14 +1,3355 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./api"), exports);
14
- __exportStar(require("./components"), exports);
1
+ // src/api/protobuf/api.ts
2
+ import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
3
+ function legacyCoverStateFromJSON(object) {
4
+ switch (object) {
5
+ case 0:
6
+ case "LEGACY_COVER_STATE_OPEN":
7
+ return 0 /* LEGACY_COVER_STATE_OPEN */;
8
+ case 1:
9
+ case "LEGACY_COVER_STATE_CLOSED":
10
+ return 1 /* LEGACY_COVER_STATE_CLOSED */;
11
+ case -1:
12
+ case "UNRECOGNIZED":
13
+ default:
14
+ return -1 /* UNRECOGNIZED */;
15
+ }
16
+ }
17
+ function legacyCoverStateToJSON(object) {
18
+ switch (object) {
19
+ case 0 /* LEGACY_COVER_STATE_OPEN */:
20
+ return "LEGACY_COVER_STATE_OPEN";
21
+ case 1 /* LEGACY_COVER_STATE_CLOSED */:
22
+ return "LEGACY_COVER_STATE_CLOSED";
23
+ case -1 /* UNRECOGNIZED */:
24
+ default:
25
+ return "UNRECOGNIZED";
26
+ }
27
+ }
28
+ function coverOperationFromJSON(object) {
29
+ switch (object) {
30
+ case 0:
31
+ case "COVER_OPERATION_IDLE":
32
+ return 0 /* COVER_OPERATION_IDLE */;
33
+ case 1:
34
+ case "COVER_OPERATION_IS_OPENING":
35
+ return 1 /* COVER_OPERATION_IS_OPENING */;
36
+ case 2:
37
+ case "COVER_OPERATION_IS_CLOSING":
38
+ return 2 /* COVER_OPERATION_IS_CLOSING */;
39
+ case -1:
40
+ case "UNRECOGNIZED":
41
+ default:
42
+ return -1 /* UNRECOGNIZED */;
43
+ }
44
+ }
45
+ function coverOperationToJSON(object) {
46
+ switch (object) {
47
+ case 0 /* COVER_OPERATION_IDLE */:
48
+ return "COVER_OPERATION_IDLE";
49
+ case 1 /* COVER_OPERATION_IS_OPENING */:
50
+ return "COVER_OPERATION_IS_OPENING";
51
+ case 2 /* COVER_OPERATION_IS_CLOSING */:
52
+ return "COVER_OPERATION_IS_CLOSING";
53
+ case -1 /* UNRECOGNIZED */:
54
+ default:
55
+ return "UNRECOGNIZED";
56
+ }
57
+ }
58
+ function createBaseHelloRequest() {
59
+ return { clientInfo: "" };
60
+ }
61
+ var HelloRequest = {
62
+ encode(message, writer = new BinaryWriter()) {
63
+ if (message.clientInfo !== "") {
64
+ writer.uint32(10).string(message.clientInfo);
65
+ }
66
+ return writer;
67
+ },
68
+ decode(input, length) {
69
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
70
+ const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
71
+ if (previousRecursionDepth >= 100) {
72
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
73
+ }
74
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
75
+ try {
76
+ const end = length === void 0 ? reader.len : reader.pos + length;
77
+ const message = createBaseHelloRequest();
78
+ while (reader.pos < end) {
79
+ const tag = reader.uint32();
80
+ switch (tag >>> 3) {
81
+ case 1: {
82
+ if (tag !== 10) {
83
+ break;
84
+ }
85
+ message.clientInfo = reader.string();
86
+ continue;
87
+ }
88
+ }
89
+ if ((tag & 7) === 4 || tag === 0) {
90
+ break;
91
+ }
92
+ reader.skip(tag & 7);
93
+ }
94
+ return message;
95
+ } finally {
96
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
97
+ }
98
+ },
99
+ fromJSON(object) {
100
+ return {
101
+ clientInfo: isSet(object.clientInfo) ? globalThis.String(object.clientInfo) : isSet(object.client_info) ? globalThis.String(object.client_info) : ""
102
+ };
103
+ },
104
+ toJSON(message) {
105
+ const obj = {};
106
+ if (message.clientInfo !== "") {
107
+ obj.clientInfo = message.clientInfo;
108
+ }
109
+ return obj;
110
+ },
111
+ create(base) {
112
+ return HelloRequest.fromPartial(base ?? {});
113
+ },
114
+ fromPartial(object) {
115
+ const message = createBaseHelloRequest();
116
+ message.clientInfo = object.clientInfo ?? "";
117
+ return message;
118
+ }
119
+ };
120
+ function createBaseHelloResponse() {
121
+ return { apiVersionMajor: 0, apiVersionMinor: 0, serverInfo: "" };
122
+ }
123
+ var HelloResponse = {
124
+ encode(message, writer = new BinaryWriter()) {
125
+ if (message.apiVersionMajor !== 0) {
126
+ writer.uint32(8).uint32(message.apiVersionMajor);
127
+ }
128
+ if (message.apiVersionMinor !== 0) {
129
+ writer.uint32(16).uint32(message.apiVersionMinor);
130
+ }
131
+ if (message.serverInfo !== "") {
132
+ writer.uint32(26).string(message.serverInfo);
133
+ }
134
+ return writer;
135
+ },
136
+ decode(input, length) {
137
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
138
+ const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
139
+ if (previousRecursionDepth >= 100) {
140
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
141
+ }
142
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
143
+ try {
144
+ const end = length === void 0 ? reader.len : reader.pos + length;
145
+ const message = createBaseHelloResponse();
146
+ while (reader.pos < end) {
147
+ const tag = reader.uint32();
148
+ switch (tag >>> 3) {
149
+ case 1: {
150
+ if (tag !== 8) {
151
+ break;
152
+ }
153
+ message.apiVersionMajor = reader.uint32();
154
+ continue;
155
+ }
156
+ case 2: {
157
+ if (tag !== 16) {
158
+ break;
159
+ }
160
+ message.apiVersionMinor = reader.uint32();
161
+ continue;
162
+ }
163
+ case 3: {
164
+ if (tag !== 26) {
165
+ break;
166
+ }
167
+ message.serverInfo = reader.string();
168
+ continue;
169
+ }
170
+ }
171
+ if ((tag & 7) === 4 || tag === 0) {
172
+ break;
173
+ }
174
+ reader.skip(tag & 7);
175
+ }
176
+ return message;
177
+ } finally {
178
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
179
+ }
180
+ },
181
+ fromJSON(object) {
182
+ return {
183
+ apiVersionMajor: isSet(object.apiVersionMajor) ? globalThis.Number(object.apiVersionMajor) : isSet(object.api_version_major) ? globalThis.Number(object.api_version_major) : 0,
184
+ apiVersionMinor: isSet(object.apiVersionMinor) ? globalThis.Number(object.apiVersionMinor) : isSet(object.api_version_minor) ? globalThis.Number(object.api_version_minor) : 0,
185
+ serverInfo: isSet(object.serverInfo) ? globalThis.String(object.serverInfo) : isSet(object.server_info) ? globalThis.String(object.server_info) : ""
186
+ };
187
+ },
188
+ toJSON(message) {
189
+ const obj = {};
190
+ if (message.apiVersionMajor !== 0) {
191
+ obj.apiVersionMajor = Math.round(message.apiVersionMajor);
192
+ }
193
+ if (message.apiVersionMinor !== 0) {
194
+ obj.apiVersionMinor = Math.round(message.apiVersionMinor);
195
+ }
196
+ if (message.serverInfo !== "") {
197
+ obj.serverInfo = message.serverInfo;
198
+ }
199
+ return obj;
200
+ },
201
+ create(base) {
202
+ return HelloResponse.fromPartial(base ?? {});
203
+ },
204
+ fromPartial(object) {
205
+ const message = createBaseHelloResponse();
206
+ message.apiVersionMajor = object.apiVersionMajor ?? 0;
207
+ message.apiVersionMinor = object.apiVersionMinor ?? 0;
208
+ message.serverInfo = object.serverInfo ?? "";
209
+ return message;
210
+ }
211
+ };
212
+ function createBaseConnectRequest() {
213
+ return { password: "" };
214
+ }
215
+ var ConnectRequest = {
216
+ encode(message, writer = new BinaryWriter()) {
217
+ if (message.password !== "") {
218
+ writer.uint32(10).string(message.password);
219
+ }
220
+ return writer;
221
+ },
222
+ decode(input, length) {
223
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
224
+ const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
225
+ if (previousRecursionDepth >= 100) {
226
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
227
+ }
228
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
229
+ try {
230
+ const end = length === void 0 ? reader.len : reader.pos + length;
231
+ const message = createBaseConnectRequest();
232
+ while (reader.pos < end) {
233
+ const tag = reader.uint32();
234
+ switch (tag >>> 3) {
235
+ case 1: {
236
+ if (tag !== 10) {
237
+ break;
238
+ }
239
+ message.password = reader.string();
240
+ continue;
241
+ }
242
+ }
243
+ if ((tag & 7) === 4 || tag === 0) {
244
+ break;
245
+ }
246
+ reader.skip(tag & 7);
247
+ }
248
+ return message;
249
+ } finally {
250
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
251
+ }
252
+ },
253
+ fromJSON(object) {
254
+ return { password: isSet(object.password) ? globalThis.String(object.password) : "" };
255
+ },
256
+ toJSON(message) {
257
+ const obj = {};
258
+ if (message.password !== "") {
259
+ obj.password = message.password;
260
+ }
261
+ return obj;
262
+ },
263
+ create(base) {
264
+ return ConnectRequest.fromPartial(base ?? {});
265
+ },
266
+ fromPartial(object) {
267
+ const message = createBaseConnectRequest();
268
+ message.password = object.password ?? "";
269
+ return message;
270
+ }
271
+ };
272
+ function createBaseConnectResponse() {
273
+ return { invalidPassword: false };
274
+ }
275
+ var ConnectResponse = {
276
+ encode(message, writer = new BinaryWriter()) {
277
+ if (message.invalidPassword !== false) {
278
+ writer.uint32(8).bool(message.invalidPassword);
279
+ }
280
+ return writer;
281
+ },
282
+ decode(input, length) {
283
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
284
+ const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
285
+ if (previousRecursionDepth >= 100) {
286
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
287
+ }
288
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
289
+ try {
290
+ const end = length === void 0 ? reader.len : reader.pos + length;
291
+ const message = createBaseConnectResponse();
292
+ while (reader.pos < end) {
293
+ const tag = reader.uint32();
294
+ switch (tag >>> 3) {
295
+ case 1: {
296
+ if (tag !== 8) {
297
+ break;
298
+ }
299
+ message.invalidPassword = reader.bool();
300
+ continue;
301
+ }
302
+ }
303
+ if ((tag & 7) === 4 || tag === 0) {
304
+ break;
305
+ }
306
+ reader.skip(tag & 7);
307
+ }
308
+ return message;
309
+ } finally {
310
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
311
+ }
312
+ },
313
+ fromJSON(object) {
314
+ return {
315
+ invalidPassword: isSet(object.invalidPassword) ? globalThis.Boolean(object.invalidPassword) : isSet(object.invalid_password) ? globalThis.Boolean(object.invalid_password) : false
316
+ };
317
+ },
318
+ toJSON(message) {
319
+ const obj = {};
320
+ if (message.invalidPassword !== false) {
321
+ obj.invalidPassword = message.invalidPassword;
322
+ }
323
+ return obj;
324
+ },
325
+ create(base) {
326
+ return ConnectResponse.fromPartial(base ?? {});
327
+ },
328
+ fromPartial(object) {
329
+ const message = createBaseConnectResponse();
330
+ message.invalidPassword = object.invalidPassword ?? false;
331
+ return message;
332
+ }
333
+ };
334
+ function createBasePingRequest() {
335
+ return {};
336
+ }
337
+ var PingRequest = {
338
+ encode(_, writer = new BinaryWriter()) {
339
+ return writer;
340
+ },
341
+ decode(input, length) {
342
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
343
+ const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
344
+ if (previousRecursionDepth >= 100) {
345
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
346
+ }
347
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
348
+ try {
349
+ const end = length === void 0 ? reader.len : reader.pos + length;
350
+ const message = createBasePingRequest();
351
+ while (reader.pos < end) {
352
+ const tag = reader.uint32();
353
+ switch (tag >>> 3) {
354
+ }
355
+ if ((tag & 7) === 4 || tag === 0) {
356
+ break;
357
+ }
358
+ reader.skip(tag & 7);
359
+ }
360
+ return message;
361
+ } finally {
362
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
363
+ }
364
+ },
365
+ fromJSON(_) {
366
+ return {};
367
+ },
368
+ toJSON(_) {
369
+ const obj = {};
370
+ return obj;
371
+ },
372
+ create(base) {
373
+ return PingRequest.fromPartial(base ?? {});
374
+ },
375
+ fromPartial(_) {
376
+ const message = createBasePingRequest();
377
+ return message;
378
+ }
379
+ };
380
+ function createBasePingResponse() {
381
+ return {};
382
+ }
383
+ var PingResponse = {
384
+ encode(_, writer = new BinaryWriter()) {
385
+ return writer;
386
+ },
387
+ decode(input, length) {
388
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
389
+ const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
390
+ if (previousRecursionDepth >= 100) {
391
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
392
+ }
393
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
394
+ try {
395
+ const end = length === void 0 ? reader.len : reader.pos + length;
396
+ const message = createBasePingResponse();
397
+ while (reader.pos < end) {
398
+ const tag = reader.uint32();
399
+ switch (tag >>> 3) {
400
+ }
401
+ if ((tag & 7) === 4 || tag === 0) {
402
+ break;
403
+ }
404
+ reader.skip(tag & 7);
405
+ }
406
+ return message;
407
+ } finally {
408
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
409
+ }
410
+ },
411
+ fromJSON(_) {
412
+ return {};
413
+ },
414
+ toJSON(_) {
415
+ const obj = {};
416
+ return obj;
417
+ },
418
+ create(base) {
419
+ return PingResponse.fromPartial(base ?? {});
420
+ },
421
+ fromPartial(_) {
422
+ const message = createBasePingResponse();
423
+ return message;
424
+ }
425
+ };
426
+ function createBaseDeviceInfoRequest() {
427
+ return {};
428
+ }
429
+ var DeviceInfoRequest = {
430
+ encode(_, writer = new BinaryWriter()) {
431
+ return writer;
432
+ },
433
+ decode(input, length) {
434
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
435
+ const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
436
+ if (previousRecursionDepth >= 100) {
437
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
438
+ }
439
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
440
+ try {
441
+ const end = length === void 0 ? reader.len : reader.pos + length;
442
+ const message = createBaseDeviceInfoRequest();
443
+ while (reader.pos < end) {
444
+ const tag = reader.uint32();
445
+ switch (tag >>> 3) {
446
+ }
447
+ if ((tag & 7) === 4 || tag === 0) {
448
+ break;
449
+ }
450
+ reader.skip(tag & 7);
451
+ }
452
+ return message;
453
+ } finally {
454
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
455
+ }
456
+ },
457
+ fromJSON(_) {
458
+ return {};
459
+ },
460
+ toJSON(_) {
461
+ const obj = {};
462
+ return obj;
463
+ },
464
+ create(base) {
465
+ return DeviceInfoRequest.fromPartial(base ?? {});
466
+ },
467
+ fromPartial(_) {
468
+ const message = createBaseDeviceInfoRequest();
469
+ return message;
470
+ }
471
+ };
472
+ function createBaseDeviceInfoResponse() {
473
+ return {
474
+ usesPassword: false,
475
+ name: "",
476
+ macAddress: "",
477
+ esphomeVersion: "",
478
+ compilationTime: "",
479
+ model: "",
480
+ hasDeepSleep: false
481
+ };
482
+ }
483
+ var DeviceInfoResponse = {
484
+ encode(message, writer = new BinaryWriter()) {
485
+ if (message.usesPassword !== false) {
486
+ writer.uint32(8).bool(message.usesPassword);
487
+ }
488
+ if (message.name !== "") {
489
+ writer.uint32(18).string(message.name);
490
+ }
491
+ if (message.macAddress !== "") {
492
+ writer.uint32(26).string(message.macAddress);
493
+ }
494
+ if (message.esphomeVersion !== "") {
495
+ writer.uint32(34).string(message.esphomeVersion);
496
+ }
497
+ if (message.compilationTime !== "") {
498
+ writer.uint32(42).string(message.compilationTime);
499
+ }
500
+ if (message.model !== "") {
501
+ writer.uint32(50).string(message.model);
502
+ }
503
+ if (message.hasDeepSleep !== false) {
504
+ writer.uint32(56).bool(message.hasDeepSleep);
505
+ }
506
+ return writer;
507
+ },
508
+ decode(input, length) {
509
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
510
+ const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
511
+ if (previousRecursionDepth >= 100) {
512
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
513
+ }
514
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
515
+ try {
516
+ const end = length === void 0 ? reader.len : reader.pos + length;
517
+ const message = createBaseDeviceInfoResponse();
518
+ while (reader.pos < end) {
519
+ const tag = reader.uint32();
520
+ switch (tag >>> 3) {
521
+ case 1: {
522
+ if (tag !== 8) {
523
+ break;
524
+ }
525
+ message.usesPassword = reader.bool();
526
+ continue;
527
+ }
528
+ case 2: {
529
+ if (tag !== 18) {
530
+ break;
531
+ }
532
+ message.name = reader.string();
533
+ continue;
534
+ }
535
+ case 3: {
536
+ if (tag !== 26) {
537
+ break;
538
+ }
539
+ message.macAddress = reader.string();
540
+ continue;
541
+ }
542
+ case 4: {
543
+ if (tag !== 34) {
544
+ break;
545
+ }
546
+ message.esphomeVersion = reader.string();
547
+ continue;
548
+ }
549
+ case 5: {
550
+ if (tag !== 42) {
551
+ break;
552
+ }
553
+ message.compilationTime = reader.string();
554
+ continue;
555
+ }
556
+ case 6: {
557
+ if (tag !== 50) {
558
+ break;
559
+ }
560
+ message.model = reader.string();
561
+ continue;
562
+ }
563
+ case 7: {
564
+ if (tag !== 56) {
565
+ break;
566
+ }
567
+ message.hasDeepSleep = reader.bool();
568
+ continue;
569
+ }
570
+ }
571
+ if ((tag & 7) === 4 || tag === 0) {
572
+ break;
573
+ }
574
+ reader.skip(tag & 7);
575
+ }
576
+ return message;
577
+ } finally {
578
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
579
+ }
580
+ },
581
+ fromJSON(object) {
582
+ return {
583
+ usesPassword: isSet(object.usesPassword) ? globalThis.Boolean(object.usesPassword) : isSet(object.uses_password) ? globalThis.Boolean(object.uses_password) : false,
584
+ name: isSet(object.name) ? globalThis.String(object.name) : "",
585
+ macAddress: isSet(object.macAddress) ? globalThis.String(object.macAddress) : isSet(object.mac_address) ? globalThis.String(object.mac_address) : "",
586
+ esphomeVersion: isSet(object.esphomeVersion) ? globalThis.String(object.esphomeVersion) : isSet(object.esphome_version) ? globalThis.String(object.esphome_version) : "",
587
+ compilationTime: isSet(object.compilationTime) ? globalThis.String(object.compilationTime) : isSet(object.compilation_time) ? globalThis.String(object.compilation_time) : "",
588
+ model: isSet(object.model) ? globalThis.String(object.model) : "",
589
+ hasDeepSleep: isSet(object.hasDeepSleep) ? globalThis.Boolean(object.hasDeepSleep) : isSet(object.has_deep_sleep) ? globalThis.Boolean(object.has_deep_sleep) : false
590
+ };
591
+ },
592
+ toJSON(message) {
593
+ const obj = {};
594
+ if (message.usesPassword !== false) {
595
+ obj.usesPassword = message.usesPassword;
596
+ }
597
+ if (message.name !== "") {
598
+ obj.name = message.name;
599
+ }
600
+ if (message.macAddress !== "") {
601
+ obj.macAddress = message.macAddress;
602
+ }
603
+ if (message.esphomeVersion !== "") {
604
+ obj.esphomeVersion = message.esphomeVersion;
605
+ }
606
+ if (message.compilationTime !== "") {
607
+ obj.compilationTime = message.compilationTime;
608
+ }
609
+ if (message.model !== "") {
610
+ obj.model = message.model;
611
+ }
612
+ if (message.hasDeepSleep !== false) {
613
+ obj.hasDeepSleep = message.hasDeepSleep;
614
+ }
615
+ return obj;
616
+ },
617
+ create(base) {
618
+ return DeviceInfoResponse.fromPartial(base ?? {});
619
+ },
620
+ fromPartial(object) {
621
+ const message = createBaseDeviceInfoResponse();
622
+ message.usesPassword = object.usesPassword ?? false;
623
+ message.name = object.name ?? "";
624
+ message.macAddress = object.macAddress ?? "";
625
+ message.esphomeVersion = object.esphomeVersion ?? "";
626
+ message.compilationTime = object.compilationTime ?? "";
627
+ message.model = object.model ?? "";
628
+ message.hasDeepSleep = object.hasDeepSleep ?? false;
629
+ return message;
630
+ }
631
+ };
632
+ function createBaseListEntitiesRequest() {
633
+ return {};
634
+ }
635
+ var ListEntitiesRequest = {
636
+ encode(_, writer = new BinaryWriter()) {
637
+ return writer;
638
+ },
639
+ decode(input, length) {
640
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
641
+ const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
642
+ if (previousRecursionDepth >= 100) {
643
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
644
+ }
645
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
646
+ try {
647
+ const end = length === void 0 ? reader.len : reader.pos + length;
648
+ const message = createBaseListEntitiesRequest();
649
+ while (reader.pos < end) {
650
+ const tag = reader.uint32();
651
+ switch (tag >>> 3) {
652
+ }
653
+ if ((tag & 7) === 4 || tag === 0) {
654
+ break;
655
+ }
656
+ reader.skip(tag & 7);
657
+ }
658
+ return message;
659
+ } finally {
660
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
661
+ }
662
+ },
663
+ fromJSON(_) {
664
+ return {};
665
+ },
666
+ toJSON(_) {
667
+ const obj = {};
668
+ return obj;
669
+ },
670
+ create(base) {
671
+ return ListEntitiesRequest.fromPartial(base ?? {});
672
+ },
673
+ fromPartial(_) {
674
+ const message = createBaseListEntitiesRequest();
675
+ return message;
676
+ }
677
+ };
678
+ function createBaseSubscribeStatesRequest() {
679
+ return {};
680
+ }
681
+ var SubscribeStatesRequest = {
682
+ encode(_, writer = new BinaryWriter()) {
683
+ return writer;
684
+ },
685
+ decode(input, length) {
686
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
687
+ const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
688
+ if (previousRecursionDepth >= 100) {
689
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
690
+ }
691
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
692
+ try {
693
+ const end = length === void 0 ? reader.len : reader.pos + length;
694
+ const message = createBaseSubscribeStatesRequest();
695
+ while (reader.pos < end) {
696
+ const tag = reader.uint32();
697
+ switch (tag >>> 3) {
698
+ }
699
+ if ((tag & 7) === 4 || tag === 0) {
700
+ break;
701
+ }
702
+ reader.skip(tag & 7);
703
+ }
704
+ return message;
705
+ } finally {
706
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
707
+ }
708
+ },
709
+ fromJSON(_) {
710
+ return {};
711
+ },
712
+ toJSON(_) {
713
+ const obj = {};
714
+ return obj;
715
+ },
716
+ create(base) {
717
+ return SubscribeStatesRequest.fromPartial(base ?? {});
718
+ },
719
+ fromPartial(_) {
720
+ const message = createBaseSubscribeStatesRequest();
721
+ return message;
722
+ }
723
+ };
724
+ function createBaseListEntitiesBinarySensorResponse() {
725
+ return { objectId: "", key: 0, name: "", uniqueId: "", deviceClass: "", isStatusBinarySensor: false };
726
+ }
727
+ var ListEntitiesBinarySensorResponse = {
728
+ encode(message, writer = new BinaryWriter()) {
729
+ if (message.objectId !== "") {
730
+ writer.uint32(10).string(message.objectId);
731
+ }
732
+ if (message.key !== 0) {
733
+ writer.uint32(21).fixed32(message.key);
734
+ }
735
+ if (message.name !== "") {
736
+ writer.uint32(26).string(message.name);
737
+ }
738
+ if (message.uniqueId !== "") {
739
+ writer.uint32(34).string(message.uniqueId);
740
+ }
741
+ if (message.deviceClass !== "") {
742
+ writer.uint32(42).string(message.deviceClass);
743
+ }
744
+ if (message.isStatusBinarySensor !== false) {
745
+ writer.uint32(48).bool(message.isStatusBinarySensor);
746
+ }
747
+ return writer;
748
+ },
749
+ decode(input, length) {
750
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
751
+ const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
752
+ if (previousRecursionDepth >= 100) {
753
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
754
+ }
755
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
756
+ try {
757
+ const end = length === void 0 ? reader.len : reader.pos + length;
758
+ const message = createBaseListEntitiesBinarySensorResponse();
759
+ while (reader.pos < end) {
760
+ const tag = reader.uint32();
761
+ switch (tag >>> 3) {
762
+ case 1: {
763
+ if (tag !== 10) {
764
+ break;
765
+ }
766
+ message.objectId = reader.string();
767
+ continue;
768
+ }
769
+ case 2: {
770
+ if (tag !== 21) {
771
+ break;
772
+ }
773
+ message.key = reader.fixed32();
774
+ continue;
775
+ }
776
+ case 3: {
777
+ if (tag !== 26) {
778
+ break;
779
+ }
780
+ message.name = reader.string();
781
+ continue;
782
+ }
783
+ case 4: {
784
+ if (tag !== 34) {
785
+ break;
786
+ }
787
+ message.uniqueId = reader.string();
788
+ continue;
789
+ }
790
+ case 5: {
791
+ if (tag !== 42) {
792
+ break;
793
+ }
794
+ message.deviceClass = reader.string();
795
+ continue;
796
+ }
797
+ case 6: {
798
+ if (tag !== 48) {
799
+ break;
800
+ }
801
+ message.isStatusBinarySensor = reader.bool();
802
+ continue;
803
+ }
804
+ }
805
+ if ((tag & 7) === 4 || tag === 0) {
806
+ break;
807
+ }
808
+ reader.skip(tag & 7);
809
+ }
810
+ return message;
811
+ } finally {
812
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
813
+ }
814
+ },
815
+ fromJSON(object) {
816
+ return {
817
+ objectId: isSet(object.objectId) ? globalThis.String(object.objectId) : isSet(object.object_id) ? globalThis.String(object.object_id) : "",
818
+ key: isSet(object.key) ? globalThis.Number(object.key) : 0,
819
+ name: isSet(object.name) ? globalThis.String(object.name) : "",
820
+ uniqueId: isSet(object.uniqueId) ? globalThis.String(object.uniqueId) : isSet(object.unique_id) ? globalThis.String(object.unique_id) : "",
821
+ deviceClass: isSet(object.deviceClass) ? globalThis.String(object.deviceClass) : isSet(object.device_class) ? globalThis.String(object.device_class) : "",
822
+ isStatusBinarySensor: isSet(object.isStatusBinarySensor) ? globalThis.Boolean(object.isStatusBinarySensor) : isSet(object.is_status_binary_sensor) ? globalThis.Boolean(object.is_status_binary_sensor) : false
823
+ };
824
+ },
825
+ toJSON(message) {
826
+ const obj = {};
827
+ if (message.objectId !== "") {
828
+ obj.objectId = message.objectId;
829
+ }
830
+ if (message.key !== 0) {
831
+ obj.key = Math.round(message.key);
832
+ }
833
+ if (message.name !== "") {
834
+ obj.name = message.name;
835
+ }
836
+ if (message.uniqueId !== "") {
837
+ obj.uniqueId = message.uniqueId;
838
+ }
839
+ if (message.deviceClass !== "") {
840
+ obj.deviceClass = message.deviceClass;
841
+ }
842
+ if (message.isStatusBinarySensor !== false) {
843
+ obj.isStatusBinarySensor = message.isStatusBinarySensor;
844
+ }
845
+ return obj;
846
+ },
847
+ create(base) {
848
+ return ListEntitiesBinarySensorResponse.fromPartial(base ?? {});
849
+ },
850
+ fromPartial(object) {
851
+ const message = createBaseListEntitiesBinarySensorResponse();
852
+ message.objectId = object.objectId ?? "";
853
+ message.key = object.key ?? 0;
854
+ message.name = object.name ?? "";
855
+ message.uniqueId = object.uniqueId ?? "";
856
+ message.deviceClass = object.deviceClass ?? "";
857
+ message.isStatusBinarySensor = object.isStatusBinarySensor ?? false;
858
+ return message;
859
+ }
860
+ };
861
+ function createBaseBinarySensorStateResponse() {
862
+ return { key: 0, state: false, missingState: false };
863
+ }
864
+ var BinarySensorStateResponse = {
865
+ encode(message, writer = new BinaryWriter()) {
866
+ if (message.key !== 0) {
867
+ writer.uint32(13).fixed32(message.key);
868
+ }
869
+ if (message.state !== false) {
870
+ writer.uint32(16).bool(message.state);
871
+ }
872
+ if (message.missingState !== false) {
873
+ writer.uint32(24).bool(message.missingState);
874
+ }
875
+ return writer;
876
+ },
877
+ decode(input, length) {
878
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
879
+ const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
880
+ if (previousRecursionDepth >= 100) {
881
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
882
+ }
883
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
884
+ try {
885
+ const end = length === void 0 ? reader.len : reader.pos + length;
886
+ const message = createBaseBinarySensorStateResponse();
887
+ while (reader.pos < end) {
888
+ const tag = reader.uint32();
889
+ switch (tag >>> 3) {
890
+ case 1: {
891
+ if (tag !== 13) {
892
+ break;
893
+ }
894
+ message.key = reader.fixed32();
895
+ continue;
896
+ }
897
+ case 2: {
898
+ if (tag !== 16) {
899
+ break;
900
+ }
901
+ message.state = reader.bool();
902
+ continue;
903
+ }
904
+ case 3: {
905
+ if (tag !== 24) {
906
+ break;
907
+ }
908
+ message.missingState = reader.bool();
909
+ continue;
910
+ }
911
+ }
912
+ if ((tag & 7) === 4 || tag === 0) {
913
+ break;
914
+ }
915
+ reader.skip(tag & 7);
916
+ }
917
+ return message;
918
+ } finally {
919
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
920
+ }
921
+ },
922
+ fromJSON(object) {
923
+ return {
924
+ key: isSet(object.key) ? globalThis.Number(object.key) : 0,
925
+ state: isSet(object.state) ? globalThis.Boolean(object.state) : false,
926
+ missingState: isSet(object.missingState) ? globalThis.Boolean(object.missingState) : isSet(object.missing_state) ? globalThis.Boolean(object.missing_state) : false
927
+ };
928
+ },
929
+ toJSON(message) {
930
+ const obj = {};
931
+ if (message.key !== 0) {
932
+ obj.key = Math.round(message.key);
933
+ }
934
+ if (message.state !== false) {
935
+ obj.state = message.state;
936
+ }
937
+ if (message.missingState !== false) {
938
+ obj.missingState = message.missingState;
939
+ }
940
+ return obj;
941
+ },
942
+ create(base) {
943
+ return BinarySensorStateResponse.fromPartial(base ?? {});
944
+ },
945
+ fromPartial(object) {
946
+ const message = createBaseBinarySensorStateResponse();
947
+ message.key = object.key ?? 0;
948
+ message.state = object.state ?? false;
949
+ message.missingState = object.missingState ?? false;
950
+ return message;
951
+ }
952
+ };
953
+ function createBaseCoverStateResponse() {
954
+ return { key: 0, legacyState: 0, position: 0, tilt: 0, currentOperation: 0 };
955
+ }
956
+ var CoverStateResponse = {
957
+ encode(message, writer = new BinaryWriter()) {
958
+ if (message.key !== 0) {
959
+ writer.uint32(13).fixed32(message.key);
960
+ }
961
+ if (message.legacyState !== 0) {
962
+ writer.uint32(16).int32(message.legacyState);
963
+ }
964
+ if (message.position !== 0) {
965
+ writer.uint32(29).float(message.position);
966
+ }
967
+ if (message.tilt !== 0) {
968
+ writer.uint32(37).float(message.tilt);
969
+ }
970
+ if (message.currentOperation !== 0) {
971
+ writer.uint32(40).int32(message.currentOperation);
972
+ }
973
+ return writer;
974
+ },
975
+ decode(input, length) {
976
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
977
+ const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
978
+ if (previousRecursionDepth >= 100) {
979
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
980
+ }
981
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
982
+ try {
983
+ const end = length === void 0 ? reader.len : reader.pos + length;
984
+ const message = createBaseCoverStateResponse();
985
+ while (reader.pos < end) {
986
+ const tag = reader.uint32();
987
+ switch (tag >>> 3) {
988
+ case 1: {
989
+ if (tag !== 13) {
990
+ break;
991
+ }
992
+ message.key = reader.fixed32();
993
+ continue;
994
+ }
995
+ case 2: {
996
+ if (tag !== 16) {
997
+ break;
998
+ }
999
+ message.legacyState = reader.int32();
1000
+ continue;
1001
+ }
1002
+ case 3: {
1003
+ if (tag !== 29) {
1004
+ break;
1005
+ }
1006
+ message.position = reader.float();
1007
+ continue;
1008
+ }
1009
+ case 4: {
1010
+ if (tag !== 37) {
1011
+ break;
1012
+ }
1013
+ message.tilt = reader.float();
1014
+ continue;
1015
+ }
1016
+ case 5: {
1017
+ if (tag !== 40) {
1018
+ break;
1019
+ }
1020
+ message.currentOperation = reader.int32();
1021
+ continue;
1022
+ }
1023
+ }
1024
+ if ((tag & 7) === 4 || tag === 0) {
1025
+ break;
1026
+ }
1027
+ reader.skip(tag & 7);
1028
+ }
1029
+ return message;
1030
+ } finally {
1031
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
1032
+ }
1033
+ },
1034
+ fromJSON(object) {
1035
+ return {
1036
+ key: isSet(object.key) ? globalThis.Number(object.key) : 0,
1037
+ legacyState: isSet(object.legacyState) ? legacyCoverStateFromJSON(object.legacyState) : isSet(object.legacy_state) ? legacyCoverStateFromJSON(object.legacy_state) : 0,
1038
+ position: isSet(object.position) ? globalThis.Number(object.position) : 0,
1039
+ tilt: isSet(object.tilt) ? globalThis.Number(object.tilt) : 0,
1040
+ currentOperation: isSet(object.currentOperation) ? coverOperationFromJSON(object.currentOperation) : isSet(object.current_operation) ? coverOperationFromJSON(object.current_operation) : 0
1041
+ };
1042
+ },
1043
+ toJSON(message) {
1044
+ const obj = {};
1045
+ if (message.key !== 0) {
1046
+ obj.key = Math.round(message.key);
1047
+ }
1048
+ if (message.legacyState !== 0) {
1049
+ obj.legacyState = legacyCoverStateToJSON(message.legacyState);
1050
+ }
1051
+ if (message.position !== 0) {
1052
+ obj.position = message.position;
1053
+ }
1054
+ if (message.tilt !== 0) {
1055
+ obj.tilt = message.tilt;
1056
+ }
1057
+ if (message.currentOperation !== 0) {
1058
+ obj.currentOperation = coverOperationToJSON(message.currentOperation);
1059
+ }
1060
+ return obj;
1061
+ },
1062
+ create(base) {
1063
+ return CoverStateResponse.fromPartial(base ?? {});
1064
+ },
1065
+ fromPartial(object) {
1066
+ const message = createBaseCoverStateResponse();
1067
+ message.key = object.key ?? 0;
1068
+ message.legacyState = object.legacyState ?? 0;
1069
+ message.position = object.position ?? 0;
1070
+ message.tilt = object.tilt ?? 0;
1071
+ message.currentOperation = object.currentOperation ?? 0;
1072
+ return message;
1073
+ }
1074
+ };
1075
+ function createBaseListEntitiesLightResponse() {
1076
+ return {
1077
+ objectId: "",
1078
+ key: 0,
1079
+ name: "",
1080
+ uniqueId: "",
1081
+ supportsBrightness: false,
1082
+ supportsRgb: false,
1083
+ supportsWhiteValue: false,
1084
+ supportsColorTemperature: false,
1085
+ minMireds: 0,
1086
+ maxMireds: 0,
1087
+ effects: []
1088
+ };
1089
+ }
1090
+ var ListEntitiesLightResponse = {
1091
+ encode(message, writer = new BinaryWriter()) {
1092
+ if (message.objectId !== "") {
1093
+ writer.uint32(10).string(message.objectId);
1094
+ }
1095
+ if (message.key !== 0) {
1096
+ writer.uint32(21).fixed32(message.key);
1097
+ }
1098
+ if (message.name !== "") {
1099
+ writer.uint32(26).string(message.name);
1100
+ }
1101
+ if (message.uniqueId !== "") {
1102
+ writer.uint32(34).string(message.uniqueId);
1103
+ }
1104
+ if (message.supportsBrightness !== false) {
1105
+ writer.uint32(40).bool(message.supportsBrightness);
1106
+ }
1107
+ if (message.supportsRgb !== false) {
1108
+ writer.uint32(48).bool(message.supportsRgb);
1109
+ }
1110
+ if (message.supportsWhiteValue !== false) {
1111
+ writer.uint32(56).bool(message.supportsWhiteValue);
1112
+ }
1113
+ if (message.supportsColorTemperature !== false) {
1114
+ writer.uint32(64).bool(message.supportsColorTemperature);
1115
+ }
1116
+ if (message.minMireds !== 0) {
1117
+ writer.uint32(77).float(message.minMireds);
1118
+ }
1119
+ if (message.maxMireds !== 0) {
1120
+ writer.uint32(85).float(message.maxMireds);
1121
+ }
1122
+ for (const v of message.effects) {
1123
+ writer.uint32(90).string(v);
1124
+ }
1125
+ return writer;
1126
+ },
1127
+ decode(input, length) {
1128
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
1129
+ const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
1130
+ if (previousRecursionDepth >= 100) {
1131
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
1132
+ }
1133
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
1134
+ try {
1135
+ const end = length === void 0 ? reader.len : reader.pos + length;
1136
+ const message = createBaseListEntitiesLightResponse();
1137
+ while (reader.pos < end) {
1138
+ const tag = reader.uint32();
1139
+ switch (tag >>> 3) {
1140
+ case 1: {
1141
+ if (tag !== 10) {
1142
+ break;
1143
+ }
1144
+ message.objectId = reader.string();
1145
+ continue;
1146
+ }
1147
+ case 2: {
1148
+ if (tag !== 21) {
1149
+ break;
1150
+ }
1151
+ message.key = reader.fixed32();
1152
+ continue;
1153
+ }
1154
+ case 3: {
1155
+ if (tag !== 26) {
1156
+ break;
1157
+ }
1158
+ message.name = reader.string();
1159
+ continue;
1160
+ }
1161
+ case 4: {
1162
+ if (tag !== 34) {
1163
+ break;
1164
+ }
1165
+ message.uniqueId = reader.string();
1166
+ continue;
1167
+ }
1168
+ case 5: {
1169
+ if (tag !== 40) {
1170
+ break;
1171
+ }
1172
+ message.supportsBrightness = reader.bool();
1173
+ continue;
1174
+ }
1175
+ case 6: {
1176
+ if (tag !== 48) {
1177
+ break;
1178
+ }
1179
+ message.supportsRgb = reader.bool();
1180
+ continue;
1181
+ }
1182
+ case 7: {
1183
+ if (tag !== 56) {
1184
+ break;
1185
+ }
1186
+ message.supportsWhiteValue = reader.bool();
1187
+ continue;
1188
+ }
1189
+ case 8: {
1190
+ if (tag !== 64) {
1191
+ break;
1192
+ }
1193
+ message.supportsColorTemperature = reader.bool();
1194
+ continue;
1195
+ }
1196
+ case 9: {
1197
+ if (tag !== 77) {
1198
+ break;
1199
+ }
1200
+ message.minMireds = reader.float();
1201
+ continue;
1202
+ }
1203
+ case 10: {
1204
+ if (tag !== 85) {
1205
+ break;
1206
+ }
1207
+ message.maxMireds = reader.float();
1208
+ continue;
1209
+ }
1210
+ case 11: {
1211
+ if (tag !== 90) {
1212
+ break;
1213
+ }
1214
+ message.effects.push(reader.string());
1215
+ continue;
1216
+ }
1217
+ }
1218
+ if ((tag & 7) === 4 || tag === 0) {
1219
+ break;
1220
+ }
1221
+ reader.skip(tag & 7);
1222
+ }
1223
+ return message;
1224
+ } finally {
1225
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
1226
+ }
1227
+ },
1228
+ fromJSON(object) {
1229
+ return {
1230
+ objectId: isSet(object.objectId) ? globalThis.String(object.objectId) : isSet(object.object_id) ? globalThis.String(object.object_id) : "",
1231
+ key: isSet(object.key) ? globalThis.Number(object.key) : 0,
1232
+ name: isSet(object.name) ? globalThis.String(object.name) : "",
1233
+ uniqueId: isSet(object.uniqueId) ? globalThis.String(object.uniqueId) : isSet(object.unique_id) ? globalThis.String(object.unique_id) : "",
1234
+ supportsBrightness: isSet(object.supportsBrightness) ? globalThis.Boolean(object.supportsBrightness) : isSet(object.supports_brightness) ? globalThis.Boolean(object.supports_brightness) : false,
1235
+ supportsRgb: isSet(object.supportsRgb) ? globalThis.Boolean(object.supportsRgb) : isSet(object.supports_rgb) ? globalThis.Boolean(object.supports_rgb) : false,
1236
+ supportsWhiteValue: isSet(object.supportsWhiteValue) ? globalThis.Boolean(object.supportsWhiteValue) : isSet(object.supports_white_value) ? globalThis.Boolean(object.supports_white_value) : false,
1237
+ supportsColorTemperature: isSet(object.supportsColorTemperature) ? globalThis.Boolean(object.supportsColorTemperature) : isSet(object.supports_color_temperature) ? globalThis.Boolean(object.supports_color_temperature) : false,
1238
+ minMireds: isSet(object.minMireds) ? globalThis.Number(object.minMireds) : isSet(object.min_mireds) ? globalThis.Number(object.min_mireds) : 0,
1239
+ maxMireds: isSet(object.maxMireds) ? globalThis.Number(object.maxMireds) : isSet(object.max_mireds) ? globalThis.Number(object.max_mireds) : 0,
1240
+ effects: globalThis.Array.isArray(object?.effects) ? object.effects.map((e) => globalThis.String(e)) : []
1241
+ };
1242
+ },
1243
+ toJSON(message) {
1244
+ const obj = {};
1245
+ if (message.objectId !== "") {
1246
+ obj.objectId = message.objectId;
1247
+ }
1248
+ if (message.key !== 0) {
1249
+ obj.key = Math.round(message.key);
1250
+ }
1251
+ if (message.name !== "") {
1252
+ obj.name = message.name;
1253
+ }
1254
+ if (message.uniqueId !== "") {
1255
+ obj.uniqueId = message.uniqueId;
1256
+ }
1257
+ if (message.supportsBrightness !== false) {
1258
+ obj.supportsBrightness = message.supportsBrightness;
1259
+ }
1260
+ if (message.supportsRgb !== false) {
1261
+ obj.supportsRgb = message.supportsRgb;
1262
+ }
1263
+ if (message.supportsWhiteValue !== false) {
1264
+ obj.supportsWhiteValue = message.supportsWhiteValue;
1265
+ }
1266
+ if (message.supportsColorTemperature !== false) {
1267
+ obj.supportsColorTemperature = message.supportsColorTemperature;
1268
+ }
1269
+ if (message.minMireds !== 0) {
1270
+ obj.minMireds = message.minMireds;
1271
+ }
1272
+ if (message.maxMireds !== 0) {
1273
+ obj.maxMireds = message.maxMireds;
1274
+ }
1275
+ if (message.effects?.length) {
1276
+ obj.effects = message.effects;
1277
+ }
1278
+ return obj;
1279
+ },
1280
+ create(base) {
1281
+ return ListEntitiesLightResponse.fromPartial(base ?? {});
1282
+ },
1283
+ fromPartial(object) {
1284
+ const message = createBaseListEntitiesLightResponse();
1285
+ message.objectId = object.objectId ?? "";
1286
+ message.key = object.key ?? 0;
1287
+ message.name = object.name ?? "";
1288
+ message.uniqueId = object.uniqueId ?? "";
1289
+ message.supportsBrightness = object.supportsBrightness ?? false;
1290
+ message.supportsRgb = object.supportsRgb ?? false;
1291
+ message.supportsWhiteValue = object.supportsWhiteValue ?? false;
1292
+ message.supportsColorTemperature = object.supportsColorTemperature ?? false;
1293
+ message.minMireds = object.minMireds ?? 0;
1294
+ message.maxMireds = object.maxMireds ?? 0;
1295
+ message.effects = object.effects?.map((e) => e) || [];
1296
+ return message;
1297
+ }
1298
+ };
1299
+ function createBaseLightStateResponse() {
1300
+ return { key: 0, state: false, brightness: 0, red: 0, green: 0, blue: 0, white: 0, colorTemperature: 0, effect: "" };
1301
+ }
1302
+ var LightStateResponse = {
1303
+ encode(message, writer = new BinaryWriter()) {
1304
+ if (message.key !== 0) {
1305
+ writer.uint32(13).fixed32(message.key);
1306
+ }
1307
+ if (message.state !== false) {
1308
+ writer.uint32(16).bool(message.state);
1309
+ }
1310
+ if (message.brightness !== 0) {
1311
+ writer.uint32(29).float(message.brightness);
1312
+ }
1313
+ if (message.red !== 0) {
1314
+ writer.uint32(37).float(message.red);
1315
+ }
1316
+ if (message.green !== 0) {
1317
+ writer.uint32(45).float(message.green);
1318
+ }
1319
+ if (message.blue !== 0) {
1320
+ writer.uint32(53).float(message.blue);
1321
+ }
1322
+ if (message.white !== 0) {
1323
+ writer.uint32(61).float(message.white);
1324
+ }
1325
+ if (message.colorTemperature !== 0) {
1326
+ writer.uint32(69).float(message.colorTemperature);
1327
+ }
1328
+ if (message.effect !== "") {
1329
+ writer.uint32(74).string(message.effect);
1330
+ }
1331
+ return writer;
1332
+ },
1333
+ decode(input, length) {
1334
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
1335
+ const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
1336
+ if (previousRecursionDepth >= 100) {
1337
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
1338
+ }
1339
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
1340
+ try {
1341
+ const end = length === void 0 ? reader.len : reader.pos + length;
1342
+ const message = createBaseLightStateResponse();
1343
+ while (reader.pos < end) {
1344
+ const tag = reader.uint32();
1345
+ switch (tag >>> 3) {
1346
+ case 1: {
1347
+ if (tag !== 13) {
1348
+ break;
1349
+ }
1350
+ message.key = reader.fixed32();
1351
+ continue;
1352
+ }
1353
+ case 2: {
1354
+ if (tag !== 16) {
1355
+ break;
1356
+ }
1357
+ message.state = reader.bool();
1358
+ continue;
1359
+ }
1360
+ case 3: {
1361
+ if (tag !== 29) {
1362
+ break;
1363
+ }
1364
+ message.brightness = reader.float();
1365
+ continue;
1366
+ }
1367
+ case 4: {
1368
+ if (tag !== 37) {
1369
+ break;
1370
+ }
1371
+ message.red = reader.float();
1372
+ continue;
1373
+ }
1374
+ case 5: {
1375
+ if (tag !== 45) {
1376
+ break;
1377
+ }
1378
+ message.green = reader.float();
1379
+ continue;
1380
+ }
1381
+ case 6: {
1382
+ if (tag !== 53) {
1383
+ break;
1384
+ }
1385
+ message.blue = reader.float();
1386
+ continue;
1387
+ }
1388
+ case 7: {
1389
+ if (tag !== 61) {
1390
+ break;
1391
+ }
1392
+ message.white = reader.float();
1393
+ continue;
1394
+ }
1395
+ case 8: {
1396
+ if (tag !== 69) {
1397
+ break;
1398
+ }
1399
+ message.colorTemperature = reader.float();
1400
+ continue;
1401
+ }
1402
+ case 9: {
1403
+ if (tag !== 74) {
1404
+ break;
1405
+ }
1406
+ message.effect = reader.string();
1407
+ continue;
1408
+ }
1409
+ }
1410
+ if ((tag & 7) === 4 || tag === 0) {
1411
+ break;
1412
+ }
1413
+ reader.skip(tag & 7);
1414
+ }
1415
+ return message;
1416
+ } finally {
1417
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
1418
+ }
1419
+ },
1420
+ fromJSON(object) {
1421
+ return {
1422
+ key: isSet(object.key) ? globalThis.Number(object.key) : 0,
1423
+ state: isSet(object.state) ? globalThis.Boolean(object.state) : false,
1424
+ brightness: isSet(object.brightness) ? globalThis.Number(object.brightness) : 0,
1425
+ red: isSet(object.red) ? globalThis.Number(object.red) : 0,
1426
+ green: isSet(object.green) ? globalThis.Number(object.green) : 0,
1427
+ blue: isSet(object.blue) ? globalThis.Number(object.blue) : 0,
1428
+ white: isSet(object.white) ? globalThis.Number(object.white) : 0,
1429
+ colorTemperature: isSet(object.colorTemperature) ? globalThis.Number(object.colorTemperature) : isSet(object.color_temperature) ? globalThis.Number(object.color_temperature) : 0,
1430
+ effect: isSet(object.effect) ? globalThis.String(object.effect) : ""
1431
+ };
1432
+ },
1433
+ toJSON(message) {
1434
+ const obj = {};
1435
+ if (message.key !== 0) {
1436
+ obj.key = Math.round(message.key);
1437
+ }
1438
+ if (message.state !== false) {
1439
+ obj.state = message.state;
1440
+ }
1441
+ if (message.brightness !== 0) {
1442
+ obj.brightness = message.brightness;
1443
+ }
1444
+ if (message.red !== 0) {
1445
+ obj.red = message.red;
1446
+ }
1447
+ if (message.green !== 0) {
1448
+ obj.green = message.green;
1449
+ }
1450
+ if (message.blue !== 0) {
1451
+ obj.blue = message.blue;
1452
+ }
1453
+ if (message.white !== 0) {
1454
+ obj.white = message.white;
1455
+ }
1456
+ if (message.colorTemperature !== 0) {
1457
+ obj.colorTemperature = message.colorTemperature;
1458
+ }
1459
+ if (message.effect !== "") {
1460
+ obj.effect = message.effect;
1461
+ }
1462
+ return obj;
1463
+ },
1464
+ create(base) {
1465
+ return LightStateResponse.fromPartial(base ?? {});
1466
+ },
1467
+ fromPartial(object) {
1468
+ const message = createBaseLightStateResponse();
1469
+ message.key = object.key ?? 0;
1470
+ message.state = object.state ?? false;
1471
+ message.brightness = object.brightness ?? 0;
1472
+ message.red = object.red ?? 0;
1473
+ message.green = object.green ?? 0;
1474
+ message.blue = object.blue ?? 0;
1475
+ message.white = object.white ?? 0;
1476
+ message.colorTemperature = object.colorTemperature ?? 0;
1477
+ message.effect = object.effect ?? "";
1478
+ return message;
1479
+ }
1480
+ };
1481
+ function createBaseLightCommandRequest() {
1482
+ return {
1483
+ key: 0,
1484
+ hasState: false,
1485
+ state: false,
1486
+ hasBrightness: false,
1487
+ brightness: 0,
1488
+ hasRgb: false,
1489
+ red: 0,
1490
+ green: 0,
1491
+ blue: 0,
1492
+ hasWhite: false,
1493
+ white: 0,
1494
+ hasColorTemperature: false,
1495
+ colorTemperature: 0,
1496
+ hasTransitionLength: false,
1497
+ transitionLength: 0,
1498
+ hasFlashLength: false,
1499
+ flashLength: 0,
1500
+ hasEffect: false,
1501
+ effect: ""
1502
+ };
1503
+ }
1504
+ var LightCommandRequest = {
1505
+ encode(message, writer = new BinaryWriter()) {
1506
+ if (message.key !== 0) {
1507
+ writer.uint32(13).fixed32(message.key);
1508
+ }
1509
+ if (message.hasState !== false) {
1510
+ writer.uint32(16).bool(message.hasState);
1511
+ }
1512
+ if (message.state !== false) {
1513
+ writer.uint32(24).bool(message.state);
1514
+ }
1515
+ if (message.hasBrightness !== false) {
1516
+ writer.uint32(32).bool(message.hasBrightness);
1517
+ }
1518
+ if (message.brightness !== 0) {
1519
+ writer.uint32(45).float(message.brightness);
1520
+ }
1521
+ if (message.hasRgb !== false) {
1522
+ writer.uint32(48).bool(message.hasRgb);
1523
+ }
1524
+ if (message.red !== 0) {
1525
+ writer.uint32(61).float(message.red);
1526
+ }
1527
+ if (message.green !== 0) {
1528
+ writer.uint32(69).float(message.green);
1529
+ }
1530
+ if (message.blue !== 0) {
1531
+ writer.uint32(77).float(message.blue);
1532
+ }
1533
+ if (message.hasWhite !== false) {
1534
+ writer.uint32(80).bool(message.hasWhite);
1535
+ }
1536
+ if (message.white !== 0) {
1537
+ writer.uint32(93).float(message.white);
1538
+ }
1539
+ if (message.hasColorTemperature !== false) {
1540
+ writer.uint32(96).bool(message.hasColorTemperature);
1541
+ }
1542
+ if (message.colorTemperature !== 0) {
1543
+ writer.uint32(109).float(message.colorTemperature);
1544
+ }
1545
+ if (message.hasTransitionLength !== false) {
1546
+ writer.uint32(112).bool(message.hasTransitionLength);
1547
+ }
1548
+ if (message.transitionLength !== 0) {
1549
+ writer.uint32(120).uint32(message.transitionLength);
1550
+ }
1551
+ if (message.hasFlashLength !== false) {
1552
+ writer.uint32(128).bool(message.hasFlashLength);
1553
+ }
1554
+ if (message.flashLength !== 0) {
1555
+ writer.uint32(136).uint32(message.flashLength);
1556
+ }
1557
+ if (message.hasEffect !== false) {
1558
+ writer.uint32(144).bool(message.hasEffect);
1559
+ }
1560
+ if (message.effect !== "") {
1561
+ writer.uint32(154).string(message.effect);
1562
+ }
1563
+ return writer;
1564
+ },
1565
+ decode(input, length) {
1566
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
1567
+ const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
1568
+ if (previousRecursionDepth >= 100) {
1569
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
1570
+ }
1571
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
1572
+ try {
1573
+ const end = length === void 0 ? reader.len : reader.pos + length;
1574
+ const message = createBaseLightCommandRequest();
1575
+ while (reader.pos < end) {
1576
+ const tag = reader.uint32();
1577
+ switch (tag >>> 3) {
1578
+ case 1: {
1579
+ if (tag !== 13) {
1580
+ break;
1581
+ }
1582
+ message.key = reader.fixed32();
1583
+ continue;
1584
+ }
1585
+ case 2: {
1586
+ if (tag !== 16) {
1587
+ break;
1588
+ }
1589
+ message.hasState = reader.bool();
1590
+ continue;
1591
+ }
1592
+ case 3: {
1593
+ if (tag !== 24) {
1594
+ break;
1595
+ }
1596
+ message.state = reader.bool();
1597
+ continue;
1598
+ }
1599
+ case 4: {
1600
+ if (tag !== 32) {
1601
+ break;
1602
+ }
1603
+ message.hasBrightness = reader.bool();
1604
+ continue;
1605
+ }
1606
+ case 5: {
1607
+ if (tag !== 45) {
1608
+ break;
1609
+ }
1610
+ message.brightness = reader.float();
1611
+ continue;
1612
+ }
1613
+ case 6: {
1614
+ if (tag !== 48) {
1615
+ break;
1616
+ }
1617
+ message.hasRgb = reader.bool();
1618
+ continue;
1619
+ }
1620
+ case 7: {
1621
+ if (tag !== 61) {
1622
+ break;
1623
+ }
1624
+ message.red = reader.float();
1625
+ continue;
1626
+ }
1627
+ case 8: {
1628
+ if (tag !== 69) {
1629
+ break;
1630
+ }
1631
+ message.green = reader.float();
1632
+ continue;
1633
+ }
1634
+ case 9: {
1635
+ if (tag !== 77) {
1636
+ break;
1637
+ }
1638
+ message.blue = reader.float();
1639
+ continue;
1640
+ }
1641
+ case 10: {
1642
+ if (tag !== 80) {
1643
+ break;
1644
+ }
1645
+ message.hasWhite = reader.bool();
1646
+ continue;
1647
+ }
1648
+ case 11: {
1649
+ if (tag !== 93) {
1650
+ break;
1651
+ }
1652
+ message.white = reader.float();
1653
+ continue;
1654
+ }
1655
+ case 12: {
1656
+ if (tag !== 96) {
1657
+ break;
1658
+ }
1659
+ message.hasColorTemperature = reader.bool();
1660
+ continue;
1661
+ }
1662
+ case 13: {
1663
+ if (tag !== 109) {
1664
+ break;
1665
+ }
1666
+ message.colorTemperature = reader.float();
1667
+ continue;
1668
+ }
1669
+ case 14: {
1670
+ if (tag !== 112) {
1671
+ break;
1672
+ }
1673
+ message.hasTransitionLength = reader.bool();
1674
+ continue;
1675
+ }
1676
+ case 15: {
1677
+ if (tag !== 120) {
1678
+ break;
1679
+ }
1680
+ message.transitionLength = reader.uint32();
1681
+ continue;
1682
+ }
1683
+ case 16: {
1684
+ if (tag !== 128) {
1685
+ break;
1686
+ }
1687
+ message.hasFlashLength = reader.bool();
1688
+ continue;
1689
+ }
1690
+ case 17: {
1691
+ if (tag !== 136) {
1692
+ break;
1693
+ }
1694
+ message.flashLength = reader.uint32();
1695
+ continue;
1696
+ }
1697
+ case 18: {
1698
+ if (tag !== 144) {
1699
+ break;
1700
+ }
1701
+ message.hasEffect = reader.bool();
1702
+ continue;
1703
+ }
1704
+ case 19: {
1705
+ if (tag !== 154) {
1706
+ break;
1707
+ }
1708
+ message.effect = reader.string();
1709
+ continue;
1710
+ }
1711
+ }
1712
+ if ((tag & 7) === 4 || tag === 0) {
1713
+ break;
1714
+ }
1715
+ reader.skip(tag & 7);
1716
+ }
1717
+ return message;
1718
+ } finally {
1719
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
1720
+ }
1721
+ },
1722
+ fromJSON(object) {
1723
+ return {
1724
+ key: isSet(object.key) ? globalThis.Number(object.key) : 0,
1725
+ hasState: isSet(object.hasState) ? globalThis.Boolean(object.hasState) : isSet(object.has_state) ? globalThis.Boolean(object.has_state) : false,
1726
+ state: isSet(object.state) ? globalThis.Boolean(object.state) : false,
1727
+ hasBrightness: isSet(object.hasBrightness) ? globalThis.Boolean(object.hasBrightness) : isSet(object.has_brightness) ? globalThis.Boolean(object.has_brightness) : false,
1728
+ brightness: isSet(object.brightness) ? globalThis.Number(object.brightness) : 0,
1729
+ hasRgb: isSet(object.hasRgb) ? globalThis.Boolean(object.hasRgb) : isSet(object.has_rgb) ? globalThis.Boolean(object.has_rgb) : false,
1730
+ red: isSet(object.red) ? globalThis.Number(object.red) : 0,
1731
+ green: isSet(object.green) ? globalThis.Number(object.green) : 0,
1732
+ blue: isSet(object.blue) ? globalThis.Number(object.blue) : 0,
1733
+ hasWhite: isSet(object.hasWhite) ? globalThis.Boolean(object.hasWhite) : isSet(object.has_white) ? globalThis.Boolean(object.has_white) : false,
1734
+ white: isSet(object.white) ? globalThis.Number(object.white) : 0,
1735
+ hasColorTemperature: isSet(object.hasColorTemperature) ? globalThis.Boolean(object.hasColorTemperature) : isSet(object.has_color_temperature) ? globalThis.Boolean(object.has_color_temperature) : false,
1736
+ colorTemperature: isSet(object.colorTemperature) ? globalThis.Number(object.colorTemperature) : isSet(object.color_temperature) ? globalThis.Number(object.color_temperature) : 0,
1737
+ hasTransitionLength: isSet(object.hasTransitionLength) ? globalThis.Boolean(object.hasTransitionLength) : isSet(object.has_transition_length) ? globalThis.Boolean(object.has_transition_length) : false,
1738
+ transitionLength: isSet(object.transitionLength) ? globalThis.Number(object.transitionLength) : isSet(object.transition_length) ? globalThis.Number(object.transition_length) : 0,
1739
+ hasFlashLength: isSet(object.hasFlashLength) ? globalThis.Boolean(object.hasFlashLength) : isSet(object.has_flash_length) ? globalThis.Boolean(object.has_flash_length) : false,
1740
+ flashLength: isSet(object.flashLength) ? globalThis.Number(object.flashLength) : isSet(object.flash_length) ? globalThis.Number(object.flash_length) : 0,
1741
+ hasEffect: isSet(object.hasEffect) ? globalThis.Boolean(object.hasEffect) : isSet(object.has_effect) ? globalThis.Boolean(object.has_effect) : false,
1742
+ effect: isSet(object.effect) ? globalThis.String(object.effect) : ""
1743
+ };
1744
+ },
1745
+ toJSON(message) {
1746
+ const obj = {};
1747
+ if (message.key !== 0) {
1748
+ obj.key = Math.round(message.key);
1749
+ }
1750
+ if (message.hasState !== false) {
1751
+ obj.hasState = message.hasState;
1752
+ }
1753
+ if (message.state !== false) {
1754
+ obj.state = message.state;
1755
+ }
1756
+ if (message.hasBrightness !== false) {
1757
+ obj.hasBrightness = message.hasBrightness;
1758
+ }
1759
+ if (message.brightness !== 0) {
1760
+ obj.brightness = message.brightness;
1761
+ }
1762
+ if (message.hasRgb !== false) {
1763
+ obj.hasRgb = message.hasRgb;
1764
+ }
1765
+ if (message.red !== 0) {
1766
+ obj.red = message.red;
1767
+ }
1768
+ if (message.green !== 0) {
1769
+ obj.green = message.green;
1770
+ }
1771
+ if (message.blue !== 0) {
1772
+ obj.blue = message.blue;
1773
+ }
1774
+ if (message.hasWhite !== false) {
1775
+ obj.hasWhite = message.hasWhite;
1776
+ }
1777
+ if (message.white !== 0) {
1778
+ obj.white = message.white;
1779
+ }
1780
+ if (message.hasColorTemperature !== false) {
1781
+ obj.hasColorTemperature = message.hasColorTemperature;
1782
+ }
1783
+ if (message.colorTemperature !== 0) {
1784
+ obj.colorTemperature = message.colorTemperature;
1785
+ }
1786
+ if (message.hasTransitionLength !== false) {
1787
+ obj.hasTransitionLength = message.hasTransitionLength;
1788
+ }
1789
+ if (message.transitionLength !== 0) {
1790
+ obj.transitionLength = Math.round(message.transitionLength);
1791
+ }
1792
+ if (message.hasFlashLength !== false) {
1793
+ obj.hasFlashLength = message.hasFlashLength;
1794
+ }
1795
+ if (message.flashLength !== 0) {
1796
+ obj.flashLength = Math.round(message.flashLength);
1797
+ }
1798
+ if (message.hasEffect !== false) {
1799
+ obj.hasEffect = message.hasEffect;
1800
+ }
1801
+ if (message.effect !== "") {
1802
+ obj.effect = message.effect;
1803
+ }
1804
+ return obj;
1805
+ },
1806
+ create(base) {
1807
+ return LightCommandRequest.fromPartial(base ?? {});
1808
+ },
1809
+ fromPartial(object) {
1810
+ const message = createBaseLightCommandRequest();
1811
+ message.key = object.key ?? 0;
1812
+ message.hasState = object.hasState ?? false;
1813
+ message.state = object.state ?? false;
1814
+ message.hasBrightness = object.hasBrightness ?? false;
1815
+ message.brightness = object.brightness ?? 0;
1816
+ message.hasRgb = object.hasRgb ?? false;
1817
+ message.red = object.red ?? 0;
1818
+ message.green = object.green ?? 0;
1819
+ message.blue = object.blue ?? 0;
1820
+ message.hasWhite = object.hasWhite ?? false;
1821
+ message.white = object.white ?? 0;
1822
+ message.hasColorTemperature = object.hasColorTemperature ?? false;
1823
+ message.colorTemperature = object.colorTemperature ?? 0;
1824
+ message.hasTransitionLength = object.hasTransitionLength ?? false;
1825
+ message.transitionLength = object.transitionLength ?? 0;
1826
+ message.hasFlashLength = object.hasFlashLength ?? false;
1827
+ message.flashLength = object.flashLength ?? 0;
1828
+ message.hasEffect = object.hasEffect ?? false;
1829
+ message.effect = object.effect ?? "";
1830
+ return message;
1831
+ }
1832
+ };
1833
+ function createBaseListEntitiesSensorResponse() {
1834
+ return {
1835
+ objectId: "",
1836
+ key: 0,
1837
+ name: "",
1838
+ uniqueId: "",
1839
+ icon: "",
1840
+ unitOfMeasurement: "",
1841
+ accuracyDecimals: 0,
1842
+ forceUpdate: false,
1843
+ deviceClass: ""
1844
+ };
1845
+ }
1846
+ var ListEntitiesSensorResponse = {
1847
+ encode(message, writer = new BinaryWriter()) {
1848
+ if (message.objectId !== "") {
1849
+ writer.uint32(10).string(message.objectId);
1850
+ }
1851
+ if (message.key !== 0) {
1852
+ writer.uint32(21).fixed32(message.key);
1853
+ }
1854
+ if (message.name !== "") {
1855
+ writer.uint32(26).string(message.name);
1856
+ }
1857
+ if (message.uniqueId !== "") {
1858
+ writer.uint32(34).string(message.uniqueId);
1859
+ }
1860
+ if (message.icon !== "") {
1861
+ writer.uint32(42).string(message.icon);
1862
+ }
1863
+ if (message.unitOfMeasurement !== "") {
1864
+ writer.uint32(50).string(message.unitOfMeasurement);
1865
+ }
1866
+ if (message.accuracyDecimals !== 0) {
1867
+ writer.uint32(56).int32(message.accuracyDecimals);
1868
+ }
1869
+ if (message.forceUpdate !== false) {
1870
+ writer.uint32(64).bool(message.forceUpdate);
1871
+ }
1872
+ if (message.deviceClass !== "") {
1873
+ writer.uint32(74).string(message.deviceClass);
1874
+ }
1875
+ return writer;
1876
+ },
1877
+ decode(input, length) {
1878
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
1879
+ const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
1880
+ if (previousRecursionDepth >= 100) {
1881
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
1882
+ }
1883
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
1884
+ try {
1885
+ const end = length === void 0 ? reader.len : reader.pos + length;
1886
+ const message = createBaseListEntitiesSensorResponse();
1887
+ while (reader.pos < end) {
1888
+ const tag = reader.uint32();
1889
+ switch (tag >>> 3) {
1890
+ case 1: {
1891
+ if (tag !== 10) {
1892
+ break;
1893
+ }
1894
+ message.objectId = reader.string();
1895
+ continue;
1896
+ }
1897
+ case 2: {
1898
+ if (tag !== 21) {
1899
+ break;
1900
+ }
1901
+ message.key = reader.fixed32();
1902
+ continue;
1903
+ }
1904
+ case 3: {
1905
+ if (tag !== 26) {
1906
+ break;
1907
+ }
1908
+ message.name = reader.string();
1909
+ continue;
1910
+ }
1911
+ case 4: {
1912
+ if (tag !== 34) {
1913
+ break;
1914
+ }
1915
+ message.uniqueId = reader.string();
1916
+ continue;
1917
+ }
1918
+ case 5: {
1919
+ if (tag !== 42) {
1920
+ break;
1921
+ }
1922
+ message.icon = reader.string();
1923
+ continue;
1924
+ }
1925
+ case 6: {
1926
+ if (tag !== 50) {
1927
+ break;
1928
+ }
1929
+ message.unitOfMeasurement = reader.string();
1930
+ continue;
1931
+ }
1932
+ case 7: {
1933
+ if (tag !== 56) {
1934
+ break;
1935
+ }
1936
+ message.accuracyDecimals = reader.int32();
1937
+ continue;
1938
+ }
1939
+ case 8: {
1940
+ if (tag !== 64) {
1941
+ break;
1942
+ }
1943
+ message.forceUpdate = reader.bool();
1944
+ continue;
1945
+ }
1946
+ case 9: {
1947
+ if (tag !== 74) {
1948
+ break;
1949
+ }
1950
+ message.deviceClass = reader.string();
1951
+ continue;
1952
+ }
1953
+ }
1954
+ if ((tag & 7) === 4 || tag === 0) {
1955
+ break;
1956
+ }
1957
+ reader.skip(tag & 7);
1958
+ }
1959
+ return message;
1960
+ } finally {
1961
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
1962
+ }
1963
+ },
1964
+ fromJSON(object) {
1965
+ return {
1966
+ objectId: isSet(object.objectId) ? globalThis.String(object.objectId) : isSet(object.object_id) ? globalThis.String(object.object_id) : "",
1967
+ key: isSet(object.key) ? globalThis.Number(object.key) : 0,
1968
+ name: isSet(object.name) ? globalThis.String(object.name) : "",
1969
+ uniqueId: isSet(object.uniqueId) ? globalThis.String(object.uniqueId) : isSet(object.unique_id) ? globalThis.String(object.unique_id) : "",
1970
+ icon: isSet(object.icon) ? globalThis.String(object.icon) : "",
1971
+ unitOfMeasurement: isSet(object.unitOfMeasurement) ? globalThis.String(object.unitOfMeasurement) : isSet(object.unit_of_measurement) ? globalThis.String(object.unit_of_measurement) : "",
1972
+ accuracyDecimals: isSet(object.accuracyDecimals) ? globalThis.Number(object.accuracyDecimals) : isSet(object.accuracy_decimals) ? globalThis.Number(object.accuracy_decimals) : 0,
1973
+ forceUpdate: isSet(object.forceUpdate) ? globalThis.Boolean(object.forceUpdate) : isSet(object.force_update) ? globalThis.Boolean(object.force_update) : false,
1974
+ deviceClass: isSet(object.deviceClass) ? globalThis.String(object.deviceClass) : isSet(object.device_class) ? globalThis.String(object.device_class) : ""
1975
+ };
1976
+ },
1977
+ toJSON(message) {
1978
+ const obj = {};
1979
+ if (message.objectId !== "") {
1980
+ obj.objectId = message.objectId;
1981
+ }
1982
+ if (message.key !== 0) {
1983
+ obj.key = Math.round(message.key);
1984
+ }
1985
+ if (message.name !== "") {
1986
+ obj.name = message.name;
1987
+ }
1988
+ if (message.uniqueId !== "") {
1989
+ obj.uniqueId = message.uniqueId;
1990
+ }
1991
+ if (message.icon !== "") {
1992
+ obj.icon = message.icon;
1993
+ }
1994
+ if (message.unitOfMeasurement !== "") {
1995
+ obj.unitOfMeasurement = message.unitOfMeasurement;
1996
+ }
1997
+ if (message.accuracyDecimals !== 0) {
1998
+ obj.accuracyDecimals = Math.round(message.accuracyDecimals);
1999
+ }
2000
+ if (message.forceUpdate !== false) {
2001
+ obj.forceUpdate = message.forceUpdate;
2002
+ }
2003
+ if (message.deviceClass !== "") {
2004
+ obj.deviceClass = message.deviceClass;
2005
+ }
2006
+ return obj;
2007
+ },
2008
+ create(base) {
2009
+ return ListEntitiesSensorResponse.fromPartial(base ?? {});
2010
+ },
2011
+ fromPartial(object) {
2012
+ const message = createBaseListEntitiesSensorResponse();
2013
+ message.objectId = object.objectId ?? "";
2014
+ message.key = object.key ?? 0;
2015
+ message.name = object.name ?? "";
2016
+ message.uniqueId = object.uniqueId ?? "";
2017
+ message.icon = object.icon ?? "";
2018
+ message.unitOfMeasurement = object.unitOfMeasurement ?? "";
2019
+ message.accuracyDecimals = object.accuracyDecimals ?? 0;
2020
+ message.forceUpdate = object.forceUpdate ?? false;
2021
+ message.deviceClass = object.deviceClass ?? "";
2022
+ return message;
2023
+ }
2024
+ };
2025
+ function createBaseSensorStateResponse() {
2026
+ return { key: 0, state: 0, missingState: false };
2027
+ }
2028
+ var SensorStateResponse = {
2029
+ encode(message, writer = new BinaryWriter()) {
2030
+ if (message.key !== 0) {
2031
+ writer.uint32(13).fixed32(message.key);
2032
+ }
2033
+ if (message.state !== 0) {
2034
+ writer.uint32(21).float(message.state);
2035
+ }
2036
+ if (message.missingState !== false) {
2037
+ writer.uint32(24).bool(message.missingState);
2038
+ }
2039
+ return writer;
2040
+ },
2041
+ decode(input, length) {
2042
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
2043
+ const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
2044
+ if (previousRecursionDepth >= 100) {
2045
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
2046
+ }
2047
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
2048
+ try {
2049
+ const end = length === void 0 ? reader.len : reader.pos + length;
2050
+ const message = createBaseSensorStateResponse();
2051
+ while (reader.pos < end) {
2052
+ const tag = reader.uint32();
2053
+ switch (tag >>> 3) {
2054
+ case 1: {
2055
+ if (tag !== 13) {
2056
+ break;
2057
+ }
2058
+ message.key = reader.fixed32();
2059
+ continue;
2060
+ }
2061
+ case 2: {
2062
+ if (tag !== 21) {
2063
+ break;
2064
+ }
2065
+ message.state = reader.float();
2066
+ continue;
2067
+ }
2068
+ case 3: {
2069
+ if (tag !== 24) {
2070
+ break;
2071
+ }
2072
+ message.missingState = reader.bool();
2073
+ continue;
2074
+ }
2075
+ }
2076
+ if ((tag & 7) === 4 || tag === 0) {
2077
+ break;
2078
+ }
2079
+ reader.skip(tag & 7);
2080
+ }
2081
+ return message;
2082
+ } finally {
2083
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
2084
+ }
2085
+ },
2086
+ fromJSON(object) {
2087
+ return {
2088
+ key: isSet(object.key) ? globalThis.Number(object.key) : 0,
2089
+ state: isSet(object.state) ? globalThis.Number(object.state) : 0,
2090
+ missingState: isSet(object.missingState) ? globalThis.Boolean(object.missingState) : isSet(object.missing_state) ? globalThis.Boolean(object.missing_state) : false
2091
+ };
2092
+ },
2093
+ toJSON(message) {
2094
+ const obj = {};
2095
+ if (message.key !== 0) {
2096
+ obj.key = Math.round(message.key);
2097
+ }
2098
+ if (message.state !== 0) {
2099
+ obj.state = message.state;
2100
+ }
2101
+ if (message.missingState !== false) {
2102
+ obj.missingState = message.missingState;
2103
+ }
2104
+ return obj;
2105
+ },
2106
+ create(base) {
2107
+ return SensorStateResponse.fromPartial(base ?? {});
2108
+ },
2109
+ fromPartial(object) {
2110
+ const message = createBaseSensorStateResponse();
2111
+ message.key = object.key ?? 0;
2112
+ message.state = object.state ?? 0;
2113
+ message.missingState = object.missingState ?? false;
2114
+ return message;
2115
+ }
2116
+ };
2117
+ function createBaseListEntitiesSwitchResponse() {
2118
+ return { objectId: "", key: 0, name: "", uniqueId: "", icon: "", assumedState: false };
2119
+ }
2120
+ var ListEntitiesSwitchResponse = {
2121
+ encode(message, writer = new BinaryWriter()) {
2122
+ if (message.objectId !== "") {
2123
+ writer.uint32(10).string(message.objectId);
2124
+ }
2125
+ if (message.key !== 0) {
2126
+ writer.uint32(21).fixed32(message.key);
2127
+ }
2128
+ if (message.name !== "") {
2129
+ writer.uint32(26).string(message.name);
2130
+ }
2131
+ if (message.uniqueId !== "") {
2132
+ writer.uint32(34).string(message.uniqueId);
2133
+ }
2134
+ if (message.icon !== "") {
2135
+ writer.uint32(42).string(message.icon);
2136
+ }
2137
+ if (message.assumedState !== false) {
2138
+ writer.uint32(48).bool(message.assumedState);
2139
+ }
2140
+ return writer;
2141
+ },
2142
+ decode(input, length) {
2143
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
2144
+ const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
2145
+ if (previousRecursionDepth >= 100) {
2146
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
2147
+ }
2148
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
2149
+ try {
2150
+ const end = length === void 0 ? reader.len : reader.pos + length;
2151
+ const message = createBaseListEntitiesSwitchResponse();
2152
+ while (reader.pos < end) {
2153
+ const tag = reader.uint32();
2154
+ switch (tag >>> 3) {
2155
+ case 1: {
2156
+ if (tag !== 10) {
2157
+ break;
2158
+ }
2159
+ message.objectId = reader.string();
2160
+ continue;
2161
+ }
2162
+ case 2: {
2163
+ if (tag !== 21) {
2164
+ break;
2165
+ }
2166
+ message.key = reader.fixed32();
2167
+ continue;
2168
+ }
2169
+ case 3: {
2170
+ if (tag !== 26) {
2171
+ break;
2172
+ }
2173
+ message.name = reader.string();
2174
+ continue;
2175
+ }
2176
+ case 4: {
2177
+ if (tag !== 34) {
2178
+ break;
2179
+ }
2180
+ message.uniqueId = reader.string();
2181
+ continue;
2182
+ }
2183
+ case 5: {
2184
+ if (tag !== 42) {
2185
+ break;
2186
+ }
2187
+ message.icon = reader.string();
2188
+ continue;
2189
+ }
2190
+ case 6: {
2191
+ if (tag !== 48) {
2192
+ break;
2193
+ }
2194
+ message.assumedState = reader.bool();
2195
+ continue;
2196
+ }
2197
+ }
2198
+ if ((tag & 7) === 4 || tag === 0) {
2199
+ break;
2200
+ }
2201
+ reader.skip(tag & 7);
2202
+ }
2203
+ return message;
2204
+ } finally {
2205
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
2206
+ }
2207
+ },
2208
+ fromJSON(object) {
2209
+ return {
2210
+ objectId: isSet(object.objectId) ? globalThis.String(object.objectId) : isSet(object.object_id) ? globalThis.String(object.object_id) : "",
2211
+ key: isSet(object.key) ? globalThis.Number(object.key) : 0,
2212
+ name: isSet(object.name) ? globalThis.String(object.name) : "",
2213
+ uniqueId: isSet(object.uniqueId) ? globalThis.String(object.uniqueId) : isSet(object.unique_id) ? globalThis.String(object.unique_id) : "",
2214
+ icon: isSet(object.icon) ? globalThis.String(object.icon) : "",
2215
+ assumedState: isSet(object.assumedState) ? globalThis.Boolean(object.assumedState) : isSet(object.assumed_state) ? globalThis.Boolean(object.assumed_state) : false
2216
+ };
2217
+ },
2218
+ toJSON(message) {
2219
+ const obj = {};
2220
+ if (message.objectId !== "") {
2221
+ obj.objectId = message.objectId;
2222
+ }
2223
+ if (message.key !== 0) {
2224
+ obj.key = Math.round(message.key);
2225
+ }
2226
+ if (message.name !== "") {
2227
+ obj.name = message.name;
2228
+ }
2229
+ if (message.uniqueId !== "") {
2230
+ obj.uniqueId = message.uniqueId;
2231
+ }
2232
+ if (message.icon !== "") {
2233
+ obj.icon = message.icon;
2234
+ }
2235
+ if (message.assumedState !== false) {
2236
+ obj.assumedState = message.assumedState;
2237
+ }
2238
+ return obj;
2239
+ },
2240
+ create(base) {
2241
+ return ListEntitiesSwitchResponse.fromPartial(base ?? {});
2242
+ },
2243
+ fromPartial(object) {
2244
+ const message = createBaseListEntitiesSwitchResponse();
2245
+ message.objectId = object.objectId ?? "";
2246
+ message.key = object.key ?? 0;
2247
+ message.name = object.name ?? "";
2248
+ message.uniqueId = object.uniqueId ?? "";
2249
+ message.icon = object.icon ?? "";
2250
+ message.assumedState = object.assumedState ?? false;
2251
+ return message;
2252
+ }
2253
+ };
2254
+ function createBaseSwitchStateResponse() {
2255
+ return { key: 0, state: false };
2256
+ }
2257
+ var SwitchStateResponse = {
2258
+ encode(message, writer = new BinaryWriter()) {
2259
+ if (message.key !== 0) {
2260
+ writer.uint32(13).fixed32(message.key);
2261
+ }
2262
+ if (message.state !== false) {
2263
+ writer.uint32(16).bool(message.state);
2264
+ }
2265
+ return writer;
2266
+ },
2267
+ decode(input, length) {
2268
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
2269
+ const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
2270
+ if (previousRecursionDepth >= 100) {
2271
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
2272
+ }
2273
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
2274
+ try {
2275
+ const end = length === void 0 ? reader.len : reader.pos + length;
2276
+ const message = createBaseSwitchStateResponse();
2277
+ while (reader.pos < end) {
2278
+ const tag = reader.uint32();
2279
+ switch (tag >>> 3) {
2280
+ case 1: {
2281
+ if (tag !== 13) {
2282
+ break;
2283
+ }
2284
+ message.key = reader.fixed32();
2285
+ continue;
2286
+ }
2287
+ case 2: {
2288
+ if (tag !== 16) {
2289
+ break;
2290
+ }
2291
+ message.state = reader.bool();
2292
+ continue;
2293
+ }
2294
+ }
2295
+ if ((tag & 7) === 4 || tag === 0) {
2296
+ break;
2297
+ }
2298
+ reader.skip(tag & 7);
2299
+ }
2300
+ return message;
2301
+ } finally {
2302
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
2303
+ }
2304
+ },
2305
+ fromJSON(object) {
2306
+ return {
2307
+ key: isSet(object.key) ? globalThis.Number(object.key) : 0,
2308
+ state: isSet(object.state) ? globalThis.Boolean(object.state) : false
2309
+ };
2310
+ },
2311
+ toJSON(message) {
2312
+ const obj = {};
2313
+ if (message.key !== 0) {
2314
+ obj.key = Math.round(message.key);
2315
+ }
2316
+ if (message.state !== false) {
2317
+ obj.state = message.state;
2318
+ }
2319
+ return obj;
2320
+ },
2321
+ create(base) {
2322
+ return SwitchStateResponse.fromPartial(base ?? {});
2323
+ },
2324
+ fromPartial(object) {
2325
+ const message = createBaseSwitchStateResponse();
2326
+ message.key = object.key ?? 0;
2327
+ message.state = object.state ?? false;
2328
+ return message;
2329
+ }
2330
+ };
2331
+ function createBaseSwitchCommandRequest() {
2332
+ return { key: 0, state: false };
2333
+ }
2334
+ var SwitchCommandRequest = {
2335
+ encode(message, writer = new BinaryWriter()) {
2336
+ if (message.key !== 0) {
2337
+ writer.uint32(13).fixed32(message.key);
2338
+ }
2339
+ if (message.state !== false) {
2340
+ writer.uint32(16).bool(message.state);
2341
+ }
2342
+ return writer;
2343
+ },
2344
+ decode(input, length) {
2345
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
2346
+ const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
2347
+ if (previousRecursionDepth >= 100) {
2348
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
2349
+ }
2350
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
2351
+ try {
2352
+ const end = length === void 0 ? reader.len : reader.pos + length;
2353
+ const message = createBaseSwitchCommandRequest();
2354
+ while (reader.pos < end) {
2355
+ const tag = reader.uint32();
2356
+ switch (tag >>> 3) {
2357
+ case 1: {
2358
+ if (tag !== 13) {
2359
+ break;
2360
+ }
2361
+ message.key = reader.fixed32();
2362
+ continue;
2363
+ }
2364
+ case 2: {
2365
+ if (tag !== 16) {
2366
+ break;
2367
+ }
2368
+ message.state = reader.bool();
2369
+ continue;
2370
+ }
2371
+ }
2372
+ if ((tag & 7) === 4 || tag === 0) {
2373
+ break;
2374
+ }
2375
+ reader.skip(tag & 7);
2376
+ }
2377
+ return message;
2378
+ } finally {
2379
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
2380
+ }
2381
+ },
2382
+ fromJSON(object) {
2383
+ return {
2384
+ key: isSet(object.key) ? globalThis.Number(object.key) : 0,
2385
+ state: isSet(object.state) ? globalThis.Boolean(object.state) : false
2386
+ };
2387
+ },
2388
+ toJSON(message) {
2389
+ const obj = {};
2390
+ if (message.key !== 0) {
2391
+ obj.key = Math.round(message.key);
2392
+ }
2393
+ if (message.state !== false) {
2394
+ obj.state = message.state;
2395
+ }
2396
+ return obj;
2397
+ },
2398
+ create(base) {
2399
+ return SwitchCommandRequest.fromPartial(base ?? {});
2400
+ },
2401
+ fromPartial(object) {
2402
+ const message = createBaseSwitchCommandRequest();
2403
+ message.key = object.key ?? 0;
2404
+ message.state = object.state ?? false;
2405
+ return message;
2406
+ }
2407
+ };
2408
+ function isSet(value) {
2409
+ return value !== null && value !== void 0;
2410
+ }
2411
+
2412
+ // src/api/espSocket.ts
2413
+ import { from } from "rxjs";
2414
+ import { filter, mergeMap, switchMap, take as take2, takeUntil as takeUntil2, timeout } from "rxjs/operators";
2415
+
2416
+ // src/api/requestResponseMatching.ts
2417
+ var MessageTypes = /* @__PURE__ */ ((MessageTypes4) => {
2418
+ MessageTypes4[MessageTypes4["HelloRequest"] = 1] = "HelloRequest";
2419
+ MessageTypes4[MessageTypes4["HelloResponse"] = 2] = "HelloResponse";
2420
+ MessageTypes4[MessageTypes4["ConnectRequest"] = 3] = "ConnectRequest";
2421
+ MessageTypes4[MessageTypes4["ConnectResponse"] = 4] = "ConnectResponse";
2422
+ MessageTypes4[MessageTypes4["DisconnectRequest"] = 5] = "DisconnectRequest";
2423
+ MessageTypes4[MessageTypes4["DisconnectResponse"] = 6] = "DisconnectResponse";
2424
+ MessageTypes4[MessageTypes4["PingRequest"] = 7] = "PingRequest";
2425
+ MessageTypes4[MessageTypes4["PingResponse"] = 8] = "PingResponse";
2426
+ MessageTypes4[MessageTypes4["DeviceInfoRequest"] = 9] = "DeviceInfoRequest";
2427
+ MessageTypes4[MessageTypes4["DeviceInfoResponse"] = 10] = "DeviceInfoResponse";
2428
+ MessageTypes4[MessageTypes4["ListEntitiesRequest"] = 11] = "ListEntitiesRequest";
2429
+ MessageTypes4[MessageTypes4["ListEntitiesBinarySensorResponse"] = 12] = "ListEntitiesBinarySensorResponse";
2430
+ MessageTypes4[MessageTypes4["ListEntitiesCoverResponse"] = 13] = "ListEntitiesCoverResponse";
2431
+ MessageTypes4[MessageTypes4["ListEntitiesFanResponse"] = 14] = "ListEntitiesFanResponse";
2432
+ MessageTypes4[MessageTypes4["ListEntitiesLightResponse"] = 15] = "ListEntitiesLightResponse";
2433
+ MessageTypes4[MessageTypes4["ListEntitiesSensorResponse"] = 16] = "ListEntitiesSensorResponse";
2434
+ MessageTypes4[MessageTypes4["ListEntitiesSwitchResponse"] = 17] = "ListEntitiesSwitchResponse";
2435
+ MessageTypes4[MessageTypes4["ListEntitiesTextSensorResponse"] = 18] = "ListEntitiesTextSensorResponse";
2436
+ MessageTypes4[MessageTypes4["ListEntitiesDoneResponse"] = 19] = "ListEntitiesDoneResponse";
2437
+ MessageTypes4[MessageTypes4["SubscribeStatesRequest"] = 20] = "SubscribeStatesRequest";
2438
+ MessageTypes4[MessageTypes4["BinarySensorStateResponse"] = 21] = "BinarySensorStateResponse";
2439
+ MessageTypes4[MessageTypes4["CoverStateResponse"] = 22] = "CoverStateResponse";
2440
+ MessageTypes4[MessageTypes4["FanStateResponse"] = 23] = "FanStateResponse";
2441
+ MessageTypes4[MessageTypes4["LightStateResponse"] = 24] = "LightStateResponse";
2442
+ MessageTypes4[MessageTypes4["SensorStateResponse"] = 25] = "SensorStateResponse";
2443
+ MessageTypes4[MessageTypes4["SwitchStateResponse"] = 26] = "SwitchStateResponse";
2444
+ MessageTypes4[MessageTypes4["TextSensorStateResponse"] = 27] = "TextSensorStateResponse";
2445
+ MessageTypes4[MessageTypes4["SubscribeLogsRequest"] = 28] = "SubscribeLogsRequest";
2446
+ MessageTypes4[MessageTypes4["SubscribeLogsResponse"] = 29] = "SubscribeLogsResponse";
2447
+ MessageTypes4[MessageTypes4["CoverCommandRequest"] = 30] = "CoverCommandRequest";
2448
+ MessageTypes4[MessageTypes4["FanCommandRequest"] = 31] = "FanCommandRequest";
2449
+ MessageTypes4[MessageTypes4["LightCommandRequest"] = 32] = "LightCommandRequest";
2450
+ MessageTypes4[MessageTypes4["SwitchCommandRequest"] = 33] = "SwitchCommandRequest";
2451
+ MessageTypes4[MessageTypes4["SubscribeHomeassistantServicesRequest"] = 34] = "SubscribeHomeassistantServicesRequest";
2452
+ MessageTypes4[MessageTypes4["HomeassistantServiceResponse"] = 35] = "HomeassistantServiceResponse";
2453
+ MessageTypes4[MessageTypes4["GetTimeRequest"] = 36] = "GetTimeRequest";
2454
+ MessageTypes4[MessageTypes4["GetTimeResponse"] = 37] = "GetTimeResponse";
2455
+ MessageTypes4[MessageTypes4["SubscribeHomeAssistantStatesRequest"] = 38] = "SubscribeHomeAssistantStatesRequest";
2456
+ MessageTypes4[MessageTypes4["SubscribeHomeAssistantStateResponse"] = 39] = "SubscribeHomeAssistantStateResponse";
2457
+ MessageTypes4[MessageTypes4["HomeAssistantStateResponse"] = 40] = "HomeAssistantStateResponse";
2458
+ MessageTypes4[MessageTypes4["ListEntitiesServicesResponse"] = 41] = "ListEntitiesServicesResponse";
2459
+ MessageTypes4[MessageTypes4["ExecuteServiceRequest"] = 42] = "ExecuteServiceRequest";
2460
+ MessageTypes4[MessageTypes4["ListEntitiesCameraResponse"] = 43] = "ListEntitiesCameraResponse";
2461
+ MessageTypes4[MessageTypes4["CameraImageResponse"] = 44] = "CameraImageResponse";
2462
+ MessageTypes4[MessageTypes4["CameraImageRequest"] = 45] = "CameraImageRequest";
2463
+ MessageTypes4[MessageTypes4["ListEntitiesClimateResponse"] = 46] = "ListEntitiesClimateResponse";
2464
+ MessageTypes4[MessageTypes4["ClimateStateResponse"] = 47] = "ClimateStateResponse";
2465
+ MessageTypes4[MessageTypes4["ClimateCommandRequest"] = 48] = "ClimateCommandRequest";
2466
+ return MessageTypes4;
2467
+ })(MessageTypes || {});
2468
+
2469
+ // src/api/socket.ts
2470
+ import { Socket } from "net";
2471
+ import { BehaviorSubject, fromEvent, Observable, Subject } from "rxjs";
2472
+ import { take, takeUntil, tap } from "rxjs/operators";
2473
+ var defaultConfig = {
2474
+ reconnectOnTimeout: false,
2475
+ disconnectOnTimeout: true
2476
+ };
2477
+ var RxjsSocket = class {
2478
+ constructor(host, port, config) {
2479
+ this.host = host;
2480
+ this.port = port;
2481
+ this.config = { ...defaultConfig, ...config };
2482
+ this.data$ = this.data.asObservable();
2483
+ this.connected$ = this.connected.asObservable();
2484
+ this.timeout$ = this.timeout.asObservable();
2485
+ this.error$ = this.error.asObservable();
2486
+ }
2487
+ host;
2488
+ port;
2489
+ socket;
2490
+ config;
2491
+ // RxJS
2492
+ data = new Subject();
2493
+ data$;
2494
+ connected = new BehaviorSubject(false);
2495
+ connected$;
2496
+ timeout = new Subject();
2497
+ timeout$;
2498
+ error = new Subject();
2499
+ error$;
2500
+ terminate = new Subject();
2501
+ open() {
2502
+ if (this.socket?.connecting) {
2503
+ return;
2504
+ }
2505
+ this.close(true);
2506
+ this.socket = new Socket();
2507
+ if (this.config.timeout) {
2508
+ this.socket.setTimeout(this.config.timeout);
2509
+ }
2510
+ this.setupSocketEvents();
2511
+ this.socket.connect(this.port, this.host);
2512
+ }
2513
+ close(forceDestroy) {
2514
+ if (!this.socket) {
2515
+ return;
2516
+ }
2517
+ this.connected.next(false);
2518
+ this.terminate.next();
2519
+ this.socket.end();
2520
+ if (forceDestroy) {
2521
+ this.destroySocket();
2522
+ }
2523
+ }
2524
+ isConnected() {
2525
+ return this.connected.getValue();
2526
+ }
2527
+ send(data, encoding) {
2528
+ return new Observable((subscriber) => {
2529
+ if (this.connected.getValue() && this.socket) {
2530
+ this.socket.write(data, encoding, (err) => {
2531
+ if (err) {
2532
+ subscriber.error(err);
2533
+ return;
2534
+ }
2535
+ subscriber.next();
2536
+ subscriber.complete();
2537
+ });
2538
+ return;
2539
+ }
2540
+ subscriber.next();
2541
+ subscriber.complete();
2542
+ });
2543
+ }
2544
+ setupSocketEvents() {
2545
+ if (!this.socket) {
2546
+ return;
2547
+ }
2548
+ this.socket.on("error", (err) => this.error.next(err));
2549
+ fromEvent(this.socket, "data").pipe(
2550
+ tap((buffer) => this.data.next(buffer)),
2551
+ takeUntil(this.terminate)
2552
+ ).subscribe();
2553
+ fromEvent(this.socket, "connect").pipe(
2554
+ take(1),
2555
+ tap(() => this.connected.next(true)),
2556
+ takeUntil(this.terminate)
2557
+ ).subscribe();
2558
+ fromEvent(this.socket, "close").pipe(
2559
+ take(1),
2560
+ tap(() => this.connected.next(false)),
2561
+ takeUntil(this.terminate)
2562
+ ).subscribe();
2563
+ fromEvent(this.socket, "end").pipe(
2564
+ take(1),
2565
+ tap(() => this.socket?.end()),
2566
+ tap(() => this.connected.next(false)),
2567
+ takeUntil(this.terminate)
2568
+ ).subscribe();
2569
+ if (this.config.timeout && this.config.timeout > 0) {
2570
+ fromEvent(this.socket, "timeout").pipe(
2571
+ tap(() => this.timeout.next()),
2572
+ tap(() => {
2573
+ if (this.config.disconnectOnTimeout) {
2574
+ this.destroySocket();
2575
+ }
2576
+ if (this.config.reconnectOnTimeout) {
2577
+ this.reconnect();
2578
+ }
2579
+ }),
2580
+ takeUntil(this.terminate)
2581
+ ).subscribe();
2582
+ }
2583
+ }
2584
+ reconnect() {
2585
+ this.terminate.next();
2586
+ this.destroySocket();
2587
+ this.open();
2588
+ }
2589
+ destroySocket() {
2590
+ this.socket?.destroy();
2591
+ this.socket = void 0;
2592
+ this.connected.next(false);
2593
+ }
2594
+ };
2595
+
2596
+ // src/api/framer.ts
2597
+ var encodeFrame = (type, payload) => {
2598
+ if (payload.length > 255) {
2599
+ throw new RangeError(`frame payload exceeds wire limit: ${payload.length} > 255 bytes`);
2600
+ }
2601
+ const frame = new Uint8Array(3 + payload.length);
2602
+ frame[0] = 0;
2603
+ frame[1] = payload.length;
2604
+ frame[2] = type;
2605
+ frame.set(payload, 3);
2606
+ return frame;
2607
+ };
2608
+ var createFrameParser = () => {
2609
+ let buffer = Buffer.alloc(0);
2610
+ return {
2611
+ push(chunk) {
2612
+ buffer = Buffer.concat([buffer, chunk]);
2613
+ const frames = [];
2614
+ while (buffer.length > 0) {
2615
+ if (buffer[0] !== 0) {
2616
+ const sync = buffer.indexOf(0);
2617
+ buffer = sync === -1 ? Buffer.alloc(0) : buffer.subarray(sync);
2618
+ continue;
2619
+ }
2620
+ if (buffer.length < 3) {
2621
+ break;
2622
+ }
2623
+ const total = 3 + buffer[1];
2624
+ if (buffer.length < total) {
2625
+ break;
2626
+ }
2627
+ frames.push({
2628
+ type: buffer[2],
2629
+ payload: new Uint8Array(buffer.subarray(3, total))
2630
+ });
2631
+ buffer = buffer.subarray(total);
2632
+ }
2633
+ return frames;
2634
+ }
2635
+ };
2636
+ };
2637
+
2638
+ // src/api/booleans.ts
2639
+ var isTrue = (val) => val === true;
2640
+ var isFalse = (val) => val === false;
2641
+
2642
+ // src/api/espSocket.ts
2643
+ var EspSocket = class extends RxjsSocket {
2644
+ espData$;
2645
+ constructor(host, port, config) {
2646
+ super(host, port, config);
2647
+ this.espData$ = this.connected$.pipe(
2648
+ filter(isTrue),
2649
+ switchMap(() => {
2650
+ const frameParser = createFrameParser();
2651
+ return this.data$.pipe(mergeMap((chunk) => from(frameParser.push(chunk))));
2652
+ })
2653
+ );
2654
+ }
2655
+ sendEspMessage(type, payload) {
2656
+ this.connected$.pipe(
2657
+ timeout(5e3),
2658
+ filter(isTrue),
2659
+ take2(1),
2660
+ switchMap(() => {
2661
+ const final = encodeFrame(type, payload);
2662
+ return this.send(final);
2663
+ }),
2664
+ takeUntil2(this.terminate)
2665
+ ).subscribe({
2666
+ error: (error) => {
2667
+ this.error.next(error instanceof Error ? error : new Error(String(error)));
2668
+ }
2669
+ });
2670
+ }
2671
+ };
2672
+
2673
+ // src/api/client.ts
2674
+ import { of, Subscription } from "rxjs";
2675
+ import { filter as filter2, map, take as take3, tap as tap2 } from "rxjs/operators";
2676
+ var Client = class {
2677
+ constructor(socket) {
2678
+ this.socket = socket;
2679
+ this.subscription = new Subscription();
2680
+ this.subscription.add(
2681
+ this.socket.espData$.pipe(
2682
+ tap2((data) => {
2683
+ if (data.type === 7 /* PingRequest */) {
2684
+ this.socket.sendEspMessage(8 /* PingResponse */, PingResponse.encode({}).finish());
2685
+ }
2686
+ })
2687
+ ).subscribe()
2688
+ );
2689
+ }
2690
+ socket;
2691
+ subscription;
2692
+ terminate() {
2693
+ this.subscription.unsubscribe();
2694
+ }
2695
+ hello(request) {
2696
+ return this.request(
2697
+ 1 /* HelloRequest */,
2698
+ 2 /* HelloResponse */,
2699
+ HelloRequest.encode(request).finish(),
2700
+ HelloResponse
2701
+ );
2702
+ }
2703
+ connect(request) {
2704
+ return this.request(
2705
+ 3 /* ConnectRequest */,
2706
+ 4 /* ConnectResponse */,
2707
+ ConnectRequest.encode(request).finish(),
2708
+ ConnectResponse
2709
+ );
2710
+ }
2711
+ ping() {
2712
+ return this.request(
2713
+ 7 /* PingRequest */,
2714
+ 8 /* PingResponse */,
2715
+ PingRequest.encode({}).finish(),
2716
+ PingResponse
2717
+ );
2718
+ }
2719
+ deviceInfo() {
2720
+ return this.request(
2721
+ 9 /* DeviceInfoRequest */,
2722
+ 10 /* DeviceInfoResponse */,
2723
+ DeviceInfoRequest.encode({}).finish(),
2724
+ DeviceInfoResponse
2725
+ );
2726
+ }
2727
+ // Fire-and-forget requests: the protocol answers ListEntitiesRequest with
2728
+ // an unbounded stream of list responses and SubscribeStatesRequest with
2729
+ // nothing at all, so there is no single response to await here. The
2730
+ // observables emit once the request is on the wire and complete — callers
2731
+ // that need the results watch EspDevice's discovery$ and component streams.
2732
+ listEntities() {
2733
+ this.socket.sendEspMessage(11 /* ListEntitiesRequest */, ListEntitiesRequest.encode({}).finish());
2734
+ return of(void 0);
2735
+ }
2736
+ subscribeStateChange() {
2737
+ this.socket.sendEspMessage(20 /* SubscribeStatesRequest */, SubscribeStatesRequest.encode({}).finish());
2738
+ return of(void 0);
2739
+ }
2740
+ request(type, responseType, payload, response) {
2741
+ this.socket.sendEspMessage(type, payload);
2742
+ return this.socket.espData$.pipe(
2743
+ filter2((data) => data.type === responseType),
2744
+ take3(1),
2745
+ map((data) => response.decode(data.payload))
2746
+ );
2747
+ }
2748
+ };
2749
+
2750
+ // src/api/espDevice.ts
2751
+ import {
2752
+ catchError,
2753
+ distinctUntilChanged,
2754
+ filter as filter5,
2755
+ map as map2,
2756
+ mapTo,
2757
+ shareReplay,
2758
+ switchMap as switchMap2,
2759
+ take as take5,
2760
+ takeUntil as takeUntil4,
2761
+ tap as tap4,
2762
+ timeout as timeout2
2763
+ } from "rxjs/operators";
2764
+
2765
+ // src/api/helpers.ts
2766
+ import "rxjs";
2767
+ import { filter as filter4 } from "rxjs/operators";
2768
+
2769
+ // src/components/base.ts
2770
+ import { BehaviorSubject as BehaviorSubject2, Subject as Subject2 } from "rxjs";
2771
+ import { debounceTime, filter as filter3, take as take4, takeUntil as takeUntil3, tap as tap3 } from "rxjs/operators";
2772
+ var BaseComponent = class {
2773
+ constructor(listEntity, state, commandInterface) {
2774
+ this.listEntity = listEntity;
2775
+ this.commandInterface = commandInterface;
2776
+ this.commandInPipeline = new BehaviorSubject2(false);
2777
+ this.state$ = this.state.pipe(filter3((state2) => state2 !== void 0));
2778
+ this.provideStateObservable(state);
2779
+ this.commandInPipeline.pipe(
2780
+ debounceTime(30 * 1e3),
2781
+ filter3(isTrue),
2782
+ tap3(() => this.commandInPipeline.next(false)),
2783
+ takeUntil3(this.teardown)
2784
+ ).subscribe();
2785
+ }
2786
+ listEntity;
2787
+ commandInterface;
2788
+ state = new BehaviorSubject2(void 0);
2789
+ state$;
2790
+ terminatePreviousStateSubscription = new Subject2();
2791
+ commandInPipeline;
2792
+ teardown = new Subject2();
2793
+ provideStateObservable(state$) {
2794
+ this.terminatePreviousStateSubscription.next();
2795
+ state$.pipe(
2796
+ tap3((state) => this.state.next(state)),
2797
+ tap3(() => this.commandInPipeline.next(false)),
2798
+ takeUntil3(this.terminatePreviousStateSubscription),
2799
+ takeUntil3(this.teardown)
2800
+ ).subscribe();
2801
+ }
2802
+ get ready() {
2803
+ return this.state.getValue() !== void 0;
2804
+ }
2805
+ get name() {
2806
+ return this.listEntity.name;
2807
+ }
2808
+ get key() {
2809
+ return this.listEntity.key;
2810
+ }
2811
+ toString() {
2812
+ return this.listEntity.name;
2813
+ }
2814
+ terminate() {
2815
+ this.teardown.next();
2816
+ }
2817
+ queueCommand(type, dataFn, disableSerialise = false) {
2818
+ this.commandInPipeline.pipe(
2819
+ filter3((x) => !x || disableSerialise),
2820
+ take4(1),
2821
+ tap3(() => {
2822
+ this.commandInterface.sendEspMessage(type, dataFn());
2823
+ this.commandInPipeline.next(true);
2824
+ }),
2825
+ takeUntil3(this.teardown)
2826
+ ).subscribe();
2827
+ }
2828
+ };
2829
+
2830
+ // src/components/binarySensorTypes.ts
2831
+ var BinarySensorTypes = /* @__PURE__ */ ((BinarySensorTypes2) => {
2832
+ BinarySensorTypes2["NONE"] = "None";
2833
+ BinarySensorTypes2["BATTERY"] = "battery";
2834
+ BinarySensorTypes2["COLD"] = "cold";
2835
+ BinarySensorTypes2["CONNECTIVITY"] = "connectivity";
2836
+ BinarySensorTypes2["DOOR"] = "door";
2837
+ BinarySensorTypes2["GARAGE_DOOR"] = "garage_door";
2838
+ BinarySensorTypes2["GAS"] = "gas";
2839
+ BinarySensorTypes2["HEAT"] = "heat";
2840
+ BinarySensorTypes2["LIGHT"] = "light";
2841
+ BinarySensorTypes2["LOCK"] = "lock";
2842
+ BinarySensorTypes2["MOISTURE"] = "moisture";
2843
+ BinarySensorTypes2["MOTION"] = "motion";
2844
+ BinarySensorTypes2["MOVING"] = "moving";
2845
+ BinarySensorTypes2["OCCUPANCY"] = "occupancy";
2846
+ BinarySensorTypes2["OPENING"] = "opening";
2847
+ BinarySensorTypes2["PLUG"] = "plug";
2848
+ BinarySensorTypes2["POWER"] = "power";
2849
+ BinarySensorTypes2["PRESENCE"] = "presence";
2850
+ BinarySensorTypes2["PROBLEM"] = "problem";
2851
+ BinarySensorTypes2["SAFETY"] = "safety";
2852
+ BinarySensorTypes2["SMOKE"] = "smoke";
2853
+ BinarySensorTypes2["SOUND"] = "sound";
2854
+ BinarySensorTypes2["VIBRATION"] = "vibration";
2855
+ BinarySensorTypes2["WINDOW"] = "window";
2856
+ return BinarySensorTypes2;
2857
+ })(BinarySensorTypes || {});
2858
+
2859
+ // src/components/binarySensor.ts
2860
+ var BinarySensorComponent = class extends BaseComponent {
2861
+ get deviceClass() {
2862
+ return this.listEntity.deviceClass ?? "None" /* NONE */;
2863
+ }
2864
+ get status() {
2865
+ const state = this.state.getValue();
2866
+ return !!state?.state;
2867
+ }
2868
+ get type() {
2869
+ return "binarySensor";
2870
+ }
2871
+ };
2872
+
2873
+ // src/components/helpers.ts
2874
+ var convertNumbers = (num, max = 255, fromEsp = false) => {
2875
+ if (fromEsp) {
2876
+ return Math.floor(num * max);
2877
+ } else {
2878
+ return Math.min(Math.max(num, 0), max) / max;
2879
+ }
2880
+ };
2881
+
2882
+ // src/components/light.ts
2883
+ import convert from "color-convert";
2884
+ var hsvConvert = convert.hsv;
2885
+ var rgbConvert = convert.rgb;
2886
+ var DEFAULT_NO_EFFECT = "None";
2887
+ var LightComponent = class extends BaseComponent {
2888
+ turnOn() {
2889
+ this.queueCommand(
2890
+ 32 /* LightCommandRequest */,
2891
+ () => LightCommandRequest.encode(this.generateState(1)).finish()
2892
+ );
2893
+ }
2894
+ turnOff() {
2895
+ this.queueCommand(
2896
+ 32 /* LightCommandRequest */,
2897
+ () => LightCommandRequest.encode(this.generateState(0, false)).finish()
2898
+ );
2899
+ }
2900
+ getBrightness() {
2901
+ const state = this.state.getValue();
2902
+ if (state?.brightness === void 0 || !this.listEntity.supportsBrightness) {
2903
+ return void 0;
2904
+ } else if (this.listEntity.supportsRgb) {
2905
+ return this.hsv.value;
2906
+ } else if (this.listEntity.supportsBrightness) {
2907
+ return convertNumbers(state.brightness, 100, true);
2908
+ }
2909
+ }
2910
+ setBrightness(brightness) {
2911
+ if (this.listEntity.supportsRgb) {
2912
+ const { hue, saturation } = this.hsv;
2913
+ this.hsv = {
2914
+ hue,
2915
+ saturation,
2916
+ value: brightness
2917
+ };
2918
+ } else if (this.listEntity.supportsBrightness) {
2919
+ const bright = convertNumbers(brightness, 100, false);
2920
+ const state = this.generateState(1);
2921
+ state.brightness = bright;
2922
+ this.queueCommand(32 /* LightCommandRequest */, () => LightCommandRequest.encode(state).finish());
2923
+ }
2924
+ }
2925
+ get hsv() {
2926
+ const state = this.state.getValue();
2927
+ if (!state || !this.supportsRgb) {
2928
+ return {
2929
+ hue: 0,
2930
+ saturation: 0,
2931
+ value: 0
2932
+ };
2933
+ }
2934
+ const [hue, saturation] = rgbConvert.hsv([state.red ?? 0, state.green ?? 0, state.blue ?? 0]);
2935
+ return {
2936
+ hue,
2937
+ saturation,
2938
+ value: (state.brightness ?? 0) * 100
2939
+ };
2940
+ }
2941
+ set hsv(hsv) {
2942
+ if (!this.listEntity.supportsRgb) {
2943
+ return;
2944
+ }
2945
+ const [red, green, blue] = hsvConvert.rgb([hsv.hue, hsv.saturation, 100]);
2946
+ const newState = {
2947
+ red: convertNumbers(red, 255, false),
2948
+ green: convertNumbers(green, 255, false),
2949
+ blue: convertNumbers(blue, 255, false),
2950
+ brightness: convertNumbers(hsv.value, 100, false)
2951
+ };
2952
+ this.queueCommand(
2953
+ 32 /* LightCommandRequest */,
2954
+ () => LightCommandRequest.encode(Object.assign(this.generateState(1), newState)).finish()
2955
+ );
2956
+ }
2957
+ get rgb() {
2958
+ if (!this.listEntity.supportsRgb) {
2959
+ return {
2960
+ red: 0,
2961
+ green: 0,
2962
+ blue: 0
2963
+ };
2964
+ }
2965
+ const { hue, saturation, value } = this.hsv;
2966
+ const [red, green, blue] = hsvConvert.rgb([hue, saturation, value]);
2967
+ return {
2968
+ red,
2969
+ green,
2970
+ blue
2971
+ };
2972
+ }
2973
+ set rgb({ red, green, blue }) {
2974
+ if (!this.listEntity.supportsRgb) {
2975
+ return;
2976
+ }
2977
+ const [hue, saturation, value] = rgbConvert.hsv([red, green, blue]);
2978
+ this.hsv = {
2979
+ hue,
2980
+ saturation,
2981
+ value
2982
+ };
2983
+ }
2984
+ get type() {
2985
+ return "light";
2986
+ }
2987
+ get supportsRgb() {
2988
+ return this.listEntity.supportsRgb;
2989
+ }
2990
+ get supportsBrightness() {
2991
+ return this.listEntity.supportsBrightness;
2992
+ }
2993
+ availableEffects() {
2994
+ return this.listEntity.effects ?? [];
2995
+ }
2996
+ get effect() {
2997
+ const state = this.state.getValue();
2998
+ return state?.effect ?? DEFAULT_NO_EFFECT;
2999
+ }
3000
+ set effect(effect) {
3001
+ const effects = this.listEntity.effects ?? [];
3002
+ if (effects.includes(effect)) {
3003
+ this.queueCommand(32 /* LightCommandRequest */, () => {
3004
+ const command = this.generateState(1, true);
3005
+ command.effect = effect;
3006
+ command.hasRgb = false;
3007
+ command.hasEffect = true;
3008
+ return LightCommandRequest.encode(command).finish();
3009
+ });
3010
+ }
3011
+ }
3012
+ generateState(num, turnOn = true) {
3013
+ const state = this.state.getValue();
3014
+ return {
3015
+ blue: state?.blue ?? num,
3016
+ brightness: state?.brightness ?? num,
3017
+ colorTemperature: 0,
3018
+ effect: "",
3019
+ flashLength: 0,
3020
+ green: state?.green ?? num,
3021
+ hasBrightness: this.listEntity.supportsBrightness,
3022
+ hasColorTemperature: false,
3023
+ hasEffect: false,
3024
+ hasFlashLength: false,
3025
+ hasRgb: this.listEntity.supportsRgb,
3026
+ hasState: true,
3027
+ hasTransitionLength: false,
3028
+ hasWhite: false,
3029
+ red: state?.red ?? num,
3030
+ transitionLength: 1,
3031
+ white: 0,
3032
+ key: this.key,
3033
+ state: turnOn
3034
+ };
3035
+ }
3036
+ };
3037
+
3038
+ // src/components/sensor.ts
3039
+ var SensorComponent = class extends BaseComponent {
3040
+ get value() {
3041
+ const state = this.state.getValue();
3042
+ return state?.state;
3043
+ }
3044
+ get type() {
3045
+ return "sensor";
3046
+ }
3047
+ get deviceClass() {
3048
+ return this.listEntity.deviceClass;
3049
+ }
3050
+ get unitOfMeasurement() {
3051
+ return this.listEntity.unitOfMeasurement;
3052
+ }
3053
+ get icon() {
3054
+ return this.listEntity.icon;
3055
+ }
3056
+ };
3057
+
3058
+ // src/components/switch.ts
3059
+ var SwitchComponent = class extends BaseComponent {
3060
+ get status() {
3061
+ const state = this.state.getValue();
3062
+ return !!state?.state;
3063
+ }
3064
+ turnOn() {
3065
+ this.queueCommand(
3066
+ 33 /* SwitchCommandRequest */,
3067
+ () => SwitchCommandRequest.encode({
3068
+ state: true,
3069
+ key: this.key
3070
+ }).finish(),
3071
+ true
3072
+ );
3073
+ }
3074
+ turnOff() {
3075
+ this.queueCommand(
3076
+ 33 /* SwitchCommandRequest */,
3077
+ () => SwitchCommandRequest.encode({
3078
+ state: false,
3079
+ key: this.key
3080
+ }).finish(),
3081
+ true
3082
+ );
3083
+ }
3084
+ get type() {
3085
+ return "switch";
3086
+ }
3087
+ };
3088
+
3089
+ // src/api/helpers.ts
3090
+ var stateParser = (data) => {
3091
+ try {
3092
+ switch (data.type) {
3093
+ case 21 /* BinarySensorStateResponse */: {
3094
+ return BinarySensorStateResponse.decode(data.payload);
3095
+ }
3096
+ case 24 /* LightStateResponse */: {
3097
+ return LightStateResponse.decode(data.payload);
3098
+ }
3099
+ case 25 /* SensorStateResponse */: {
3100
+ return SensorStateResponse.decode(data.payload);
3101
+ }
3102
+ case 26 /* SwitchStateResponse */: {
3103
+ return SwitchStateResponse.decode(data.payload);
3104
+ }
3105
+ case 22 /* CoverStateResponse */: {
3106
+ return CoverStateResponse.decode(data.payload);
3107
+ }
3108
+ }
3109
+ } catch {
3110
+ return void 0;
3111
+ }
3112
+ return void 0;
3113
+ };
3114
+ var createComponents = (data, stateEvents$, connection, knownComponents) => {
3115
+ switch (data.type) {
3116
+ case 12 /* ListEntitiesBinarySensorResponse */: {
3117
+ const response = ListEntitiesBinarySensorResponse.decode(data.payload);
3118
+ const state$ = transformStates(stateEvents$, response);
3119
+ return knownComponents.has(response.objectId) ? {
3120
+ id: response.objectId,
3121
+ state$
3122
+ } : {
3123
+ id: response.objectId,
3124
+ component: new BinarySensorComponent(response, state$, emptyCommandInterface)
3125
+ };
3126
+ }
3127
+ case 17 /* ListEntitiesSwitchResponse */: {
3128
+ const response = ListEntitiesSwitchResponse.decode(data.payload);
3129
+ const state$ = transformStates(stateEvents$, response);
3130
+ return knownComponents.has(response.objectId) ? {
3131
+ id: response.objectId,
3132
+ state$
3133
+ } : {
3134
+ id: response.objectId,
3135
+ component: new SwitchComponent(response, state$, connection)
3136
+ };
3137
+ }
3138
+ case 15 /* ListEntitiesLightResponse */: {
3139
+ const response = ListEntitiesLightResponse.decode(data.payload);
3140
+ const state$ = transformStates(stateEvents$, response);
3141
+ return knownComponents.has(response.objectId) ? {
3142
+ id: response.objectId,
3143
+ state$
3144
+ } : {
3145
+ id: response.objectId,
3146
+ component: new LightComponent(response, state$, connection)
3147
+ };
3148
+ }
3149
+ case 16 /* ListEntitiesSensorResponse */: {
3150
+ const response = ListEntitiesSensorResponse.decode(data.payload);
3151
+ const state$ = transformStates(stateEvents$, response);
3152
+ return knownComponents.has(response.objectId) ? {
3153
+ id: response.objectId,
3154
+ state$
3155
+ } : {
3156
+ id: response.objectId,
3157
+ component: new SensorComponent(response, state$, emptyCommandInterface)
3158
+ };
3159
+ }
3160
+ }
3161
+ return { id: "" };
3162
+ };
3163
+ var emptyCommandInterface = {
3164
+ sendEspMessage: () => void 0
3165
+ };
3166
+ var transformStates = (stateEvents$, listEntityResponse) => {
3167
+ return stateEvents$.pipe(filter4((stateEvent) => stateEvent.key === listEntityResponse.key));
3168
+ };
3169
+
3170
+ // src/api/responses.ts
3171
+ var listResponses = /* @__PURE__ */ new Set([
3172
+ 12 /* ListEntitiesBinarySensorResponse */,
3173
+ 15 /* ListEntitiesLightResponse */,
3174
+ 16 /* ListEntitiesSensorResponse */,
3175
+ 17 /* ListEntitiesSwitchResponse */,
3176
+ 19 /* ListEntitiesDoneResponse */
3177
+ ]);
3178
+ var stateResponses = /* @__PURE__ */ new Set([
3179
+ 21 /* BinarySensorStateResponse */,
3180
+ 22 /* CoverStateResponse */,
3181
+ 24 /* LightStateResponse */,
3182
+ 25 /* SensorStateResponse */,
3183
+ 26 /* SwitchStateResponse */
3184
+ ]);
3185
+
3186
+ // src/api/espDevice.ts
3187
+ import { BehaviorSubject as BehaviorSubject3, concat, EMPTY, merge, of as of2, Subject as Subject3, Subscription as Subscription2, timer } from "rxjs";
3188
+ var PING_TIMEOUT = 90 * 1e3;
3189
+ var RETRY_DELAY = 1e3;
3190
+ var InvalidPasswordError = class extends Error {
3191
+ constructor(host) {
3192
+ super(`The ESPHome device at ${host} rejected the connection password`);
3193
+ this.name = "InvalidPasswordError";
3194
+ }
3195
+ };
3196
+ var EspDevice = class {
3197
+ constructor(host, password = "", port = 6053) {
3198
+ this.host = host;
3199
+ this.password = password;
3200
+ this.port = port;
3201
+ this.subscription = new Subscription2();
3202
+ this.discovery = new BehaviorSubject3(false);
3203
+ this.discovery$ = this.discovery.asObservable();
3204
+ this.error$ = this.errors.asObservable();
3205
+ this.socket = new EspSocket(host, port, {
3206
+ timeout: PING_TIMEOUT
3207
+ });
3208
+ this.client = new Client(this.socket);
3209
+ this.stateEvents$ = this.socket.espData$.pipe(
3210
+ filter5((data) => stateResponses.has(data.type)),
3211
+ map2((data) => stateParser(data)),
3212
+ filter5((parsed) => !!parsed)
3213
+ );
3214
+ this.subscription.add(
3215
+ this.socket.espData$.pipe(
3216
+ tap4((data) => {
3217
+ try {
3218
+ if (listResponses.has(data.type)) {
3219
+ this.parseListResponse(data);
3220
+ } else if (data.type === 10 /* DeviceInfoResponse */) {
3221
+ this.deviceInfo = DeviceInfoResponse.decode(data.payload);
3222
+ }
3223
+ } catch (error) {
3224
+ this.errors.next(error);
3225
+ }
3226
+ })
3227
+ ).subscribe()
3228
+ );
3229
+ this.subscription.add(
3230
+ this.socket.connected$.pipe(
3231
+ distinctUntilChanged(),
3232
+ tap4((connected) => {
3233
+ if (!connected) {
3234
+ this.socket.open();
3235
+ }
3236
+ }),
3237
+ filter5(isTrue),
3238
+ switchMap2(() => this.client.hello({ clientInfo: "esphome-ts" })),
3239
+ switchMap2(() => this.client.connect({ password })),
3240
+ map2((response) => {
3241
+ if (response.invalidPassword) {
3242
+ throw new InvalidPasswordError(this.host);
3243
+ }
3244
+ return response;
3245
+ }),
3246
+ switchMap2(() => this.client.deviceInfo()),
3247
+ switchMap2(() => this.client.listEntities()),
3248
+ switchMap2(() => this.client.subscribeStateChange()),
3249
+ catchError((error, caught) => {
3250
+ this.errors.next(error);
3251
+ if (error instanceof InvalidPasswordError) {
3252
+ return EMPTY;
3253
+ }
3254
+ return timer(RETRY_DELAY).pipe(switchMap2(() => caught));
3255
+ })
3256
+ ).subscribe()
3257
+ );
3258
+ this.subscription.add(
3259
+ this.socket.error$.pipe(
3260
+ switchMap2(() => timer(RETRY_DELAY)),
3261
+ filter5(() => !this.socket.isConnected())
3262
+ ).subscribe(() => this.socket.open())
3263
+ );
3264
+ this.alive$ = merge(
3265
+ this.socket.connected$,
3266
+ this.socket.espData$.pipe(
3267
+ switchMap2(() => {
3268
+ return concat(
3269
+ of2(true),
3270
+ this.socket.espData$.pipe(
3271
+ mapTo(true),
3272
+ timeout2(PING_TIMEOUT),
3273
+ catchError(() => of2(false)),
3274
+ take5(1)
3275
+ )
3276
+ );
3277
+ })
3278
+ )
3279
+ ).pipe(distinctUntilChanged(), shareReplay(1));
3280
+ }
3281
+ host;
3282
+ password;
3283
+ port;
3284
+ socket;
3285
+ client;
3286
+ stateEvents$;
3287
+ deviceInfo;
3288
+ components = {};
3289
+ discovery;
3290
+ discovery$;
3291
+ errors = new Subject3();
3292
+ /**
3293
+ * Device level failures: frames that could not be decoded and handshake
3294
+ * problems such as an `InvalidPasswordError`. Socket level errors are
3295
+ * available on the socket itself.
3296
+ */
3297
+ error$;
3298
+ subscription;
3299
+ alive$;
3300
+ provideRetryObservable(retryWhen$) {
3301
+ this.subscription.add(
3302
+ this.alive$.pipe(
3303
+ filter5(isFalse),
3304
+ switchMap2(
3305
+ () => retryWhen$.pipe(
3306
+ tap4(() => this.socket.open()),
3307
+ takeUntil4(this.alive$.pipe(filter5(isTrue)))
3308
+ )
3309
+ )
3310
+ ).subscribe()
3311
+ );
3312
+ }
3313
+ terminate() {
3314
+ Object.values(this.components).forEach((component) => {
3315
+ component.terminate();
3316
+ });
3317
+ this.client.terminate();
3318
+ this.subscription.unsubscribe();
3319
+ this.errors.complete();
3320
+ this.socket.close(true);
3321
+ }
3322
+ parseListResponse(data) {
3323
+ if (data.type === 19 /* ListEntitiesDoneResponse */) {
3324
+ this.discovery.next(true);
3325
+ } else {
3326
+ const knownComponents = new Set(Object.keys(this.components));
3327
+ const { id, component, state$ } = createComponents(data, this.stateEvents$, this.socket, knownComponents);
3328
+ if (component) {
3329
+ this.components[id] = this.components[id] ?? component;
3330
+ } else if (state$) {
3331
+ this.components[id].provideStateObservable(state$);
3332
+ }
3333
+ }
3334
+ }
3335
+ };
3336
+
3337
+ // src/api/typeGuards.ts
3338
+ var isSwitchComponent = (component) => component.type === "switch";
3339
+ export {
3340
+ BaseComponent,
3341
+ BinarySensorComponent,
3342
+ BinarySensorTypes,
3343
+ Client,
3344
+ EspDevice,
3345
+ EspSocket,
3346
+ InvalidPasswordError,
3347
+ LightComponent,
3348
+ MessageTypes,
3349
+ RxjsSocket,
3350
+ SensorComponent,
3351
+ SwitchComponent,
3352
+ isFalse,
3353
+ isSwitchComponent,
3354
+ isTrue
3355
+ };