esphome-ts 4.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -5
- package/dist/index.d.ts +121 -31
- package/dist/index.js +810 -203
- package/package.json +6 -2
package/dist/index.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
// src/api/protobuf/api.ts
|
|
2
2
|
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
|
|
3
|
+
var LegacyCoverState = /* @__PURE__ */ ((LegacyCoverState2) => {
|
|
4
|
+
LegacyCoverState2[LegacyCoverState2["LEGACY_COVER_STATE_OPEN"] = 0] = "LEGACY_COVER_STATE_OPEN";
|
|
5
|
+
LegacyCoverState2[LegacyCoverState2["LEGACY_COVER_STATE_CLOSED"] = 1] = "LEGACY_COVER_STATE_CLOSED";
|
|
6
|
+
LegacyCoverState2[LegacyCoverState2["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
|
|
7
|
+
return LegacyCoverState2;
|
|
8
|
+
})(LegacyCoverState || {});
|
|
3
9
|
function legacyCoverStateFromJSON(object) {
|
|
4
10
|
switch (object) {
|
|
5
11
|
case 0:
|
|
@@ -25,6 +31,13 @@ function legacyCoverStateToJSON(object) {
|
|
|
25
31
|
return "UNRECOGNIZED";
|
|
26
32
|
}
|
|
27
33
|
}
|
|
34
|
+
var CoverOperation = /* @__PURE__ */ ((CoverOperation2) => {
|
|
35
|
+
CoverOperation2[CoverOperation2["COVER_OPERATION_IDLE"] = 0] = "COVER_OPERATION_IDLE";
|
|
36
|
+
CoverOperation2[CoverOperation2["COVER_OPERATION_IS_OPENING"] = 1] = "COVER_OPERATION_IS_OPENING";
|
|
37
|
+
CoverOperation2[CoverOperation2["COVER_OPERATION_IS_CLOSING"] = 2] = "COVER_OPERATION_IS_CLOSING";
|
|
38
|
+
CoverOperation2[CoverOperation2["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
|
|
39
|
+
return CoverOperation2;
|
|
40
|
+
})(CoverOperation || {});
|
|
28
41
|
function coverOperationFromJSON(object) {
|
|
29
42
|
switch (object) {
|
|
30
43
|
case 0:
|
|
@@ -55,6 +68,36 @@ function coverOperationToJSON(object) {
|
|
|
55
68
|
return "UNRECOGNIZED";
|
|
56
69
|
}
|
|
57
70
|
}
|
|
71
|
+
function legacyCoverCommandFromJSON(object) {
|
|
72
|
+
switch (object) {
|
|
73
|
+
case 0:
|
|
74
|
+
case "LEGACY_COVER_COMMAND_OPEN":
|
|
75
|
+
return 0 /* LEGACY_COVER_COMMAND_OPEN */;
|
|
76
|
+
case 1:
|
|
77
|
+
case "LEGACY_COVER_COMMAND_CLOSE":
|
|
78
|
+
return 1 /* LEGACY_COVER_COMMAND_CLOSE */;
|
|
79
|
+
case 2:
|
|
80
|
+
case "LEGACY_COVER_COMMAND_STOP":
|
|
81
|
+
return 2 /* LEGACY_COVER_COMMAND_STOP */;
|
|
82
|
+
case -1:
|
|
83
|
+
case "UNRECOGNIZED":
|
|
84
|
+
default:
|
|
85
|
+
return -1 /* UNRECOGNIZED */;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function legacyCoverCommandToJSON(object) {
|
|
89
|
+
switch (object) {
|
|
90
|
+
case 0 /* LEGACY_COVER_COMMAND_OPEN */:
|
|
91
|
+
return "LEGACY_COVER_COMMAND_OPEN";
|
|
92
|
+
case 1 /* LEGACY_COVER_COMMAND_CLOSE */:
|
|
93
|
+
return "LEGACY_COVER_COMMAND_CLOSE";
|
|
94
|
+
case 2 /* LEGACY_COVER_COMMAND_STOP */:
|
|
95
|
+
return "LEGACY_COVER_COMMAND_STOP";
|
|
96
|
+
case -1 /* UNRECOGNIZED */:
|
|
97
|
+
default:
|
|
98
|
+
return "UNRECOGNIZED";
|
|
99
|
+
}
|
|
100
|
+
}
|
|
58
101
|
function createBaseHelloRequest() {
|
|
59
102
|
return { clientInfo: "" };
|
|
60
103
|
}
|
|
@@ -950,6 +993,182 @@ var BinarySensorStateResponse = {
|
|
|
950
993
|
return message;
|
|
951
994
|
}
|
|
952
995
|
};
|
|
996
|
+
function createBaseListEntitiesCoverResponse() {
|
|
997
|
+
return {
|
|
998
|
+
objectId: "",
|
|
999
|
+
key: 0,
|
|
1000
|
+
name: "",
|
|
1001
|
+
uniqueId: "",
|
|
1002
|
+
assumedState: false,
|
|
1003
|
+
supportsPosition: false,
|
|
1004
|
+
supportsTilt: false,
|
|
1005
|
+
deviceClass: ""
|
|
1006
|
+
};
|
|
1007
|
+
}
|
|
1008
|
+
var ListEntitiesCoverResponse = {
|
|
1009
|
+
encode(message, writer = new BinaryWriter()) {
|
|
1010
|
+
if (message.objectId !== "") {
|
|
1011
|
+
writer.uint32(10).string(message.objectId);
|
|
1012
|
+
}
|
|
1013
|
+
if (message.key !== 0) {
|
|
1014
|
+
writer.uint32(21).fixed32(message.key);
|
|
1015
|
+
}
|
|
1016
|
+
if (message.name !== "") {
|
|
1017
|
+
writer.uint32(26).string(message.name);
|
|
1018
|
+
}
|
|
1019
|
+
if (message.uniqueId !== "") {
|
|
1020
|
+
writer.uint32(34).string(message.uniqueId);
|
|
1021
|
+
}
|
|
1022
|
+
if (message.assumedState !== false) {
|
|
1023
|
+
writer.uint32(40).bool(message.assumedState);
|
|
1024
|
+
}
|
|
1025
|
+
if (message.supportsPosition !== false) {
|
|
1026
|
+
writer.uint32(48).bool(message.supportsPosition);
|
|
1027
|
+
}
|
|
1028
|
+
if (message.supportsTilt !== false) {
|
|
1029
|
+
writer.uint32(56).bool(message.supportsTilt);
|
|
1030
|
+
}
|
|
1031
|
+
if (message.deviceClass !== "") {
|
|
1032
|
+
writer.uint32(66).string(message.deviceClass);
|
|
1033
|
+
}
|
|
1034
|
+
return writer;
|
|
1035
|
+
},
|
|
1036
|
+
decode(input, length) {
|
|
1037
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
1038
|
+
const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
|
|
1039
|
+
if (previousRecursionDepth >= 100) {
|
|
1040
|
+
throw new globalThis.Error("protobuf decode recursion limit exceeded");
|
|
1041
|
+
}
|
|
1042
|
+
reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
|
|
1043
|
+
try {
|
|
1044
|
+
const end = length === void 0 ? reader.len : reader.pos + length;
|
|
1045
|
+
const message = createBaseListEntitiesCoverResponse();
|
|
1046
|
+
while (reader.pos < end) {
|
|
1047
|
+
const tag = reader.uint32();
|
|
1048
|
+
switch (tag >>> 3) {
|
|
1049
|
+
case 1: {
|
|
1050
|
+
if (tag !== 10) {
|
|
1051
|
+
break;
|
|
1052
|
+
}
|
|
1053
|
+
message.objectId = reader.string();
|
|
1054
|
+
continue;
|
|
1055
|
+
}
|
|
1056
|
+
case 2: {
|
|
1057
|
+
if (tag !== 21) {
|
|
1058
|
+
break;
|
|
1059
|
+
}
|
|
1060
|
+
message.key = reader.fixed32();
|
|
1061
|
+
continue;
|
|
1062
|
+
}
|
|
1063
|
+
case 3: {
|
|
1064
|
+
if (tag !== 26) {
|
|
1065
|
+
break;
|
|
1066
|
+
}
|
|
1067
|
+
message.name = reader.string();
|
|
1068
|
+
continue;
|
|
1069
|
+
}
|
|
1070
|
+
case 4: {
|
|
1071
|
+
if (tag !== 34) {
|
|
1072
|
+
break;
|
|
1073
|
+
}
|
|
1074
|
+
message.uniqueId = reader.string();
|
|
1075
|
+
continue;
|
|
1076
|
+
}
|
|
1077
|
+
case 5: {
|
|
1078
|
+
if (tag !== 40) {
|
|
1079
|
+
break;
|
|
1080
|
+
}
|
|
1081
|
+
message.assumedState = reader.bool();
|
|
1082
|
+
continue;
|
|
1083
|
+
}
|
|
1084
|
+
case 6: {
|
|
1085
|
+
if (tag !== 48) {
|
|
1086
|
+
break;
|
|
1087
|
+
}
|
|
1088
|
+
message.supportsPosition = reader.bool();
|
|
1089
|
+
continue;
|
|
1090
|
+
}
|
|
1091
|
+
case 7: {
|
|
1092
|
+
if (tag !== 56) {
|
|
1093
|
+
break;
|
|
1094
|
+
}
|
|
1095
|
+
message.supportsTilt = reader.bool();
|
|
1096
|
+
continue;
|
|
1097
|
+
}
|
|
1098
|
+
case 8: {
|
|
1099
|
+
if (tag !== 66) {
|
|
1100
|
+
break;
|
|
1101
|
+
}
|
|
1102
|
+
message.deviceClass = reader.string();
|
|
1103
|
+
continue;
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
1107
|
+
break;
|
|
1108
|
+
}
|
|
1109
|
+
reader.skip(tag & 7);
|
|
1110
|
+
}
|
|
1111
|
+
return message;
|
|
1112
|
+
} finally {
|
|
1113
|
+
reader.__tsProtoDecodeDepth = previousRecursionDepth;
|
|
1114
|
+
}
|
|
1115
|
+
},
|
|
1116
|
+
fromJSON(object) {
|
|
1117
|
+
return {
|
|
1118
|
+
objectId: isSet(object.objectId) ? globalThis.String(object.objectId) : isSet(object.object_id) ? globalThis.String(object.object_id) : "",
|
|
1119
|
+
key: isSet(object.key) ? globalThis.Number(object.key) : 0,
|
|
1120
|
+
name: isSet(object.name) ? globalThis.String(object.name) : "",
|
|
1121
|
+
uniqueId: isSet(object.uniqueId) ? globalThis.String(object.uniqueId) : isSet(object.unique_id) ? globalThis.String(object.unique_id) : "",
|
|
1122
|
+
assumedState: isSet(object.assumedState) ? globalThis.Boolean(object.assumedState) : isSet(object.assumed_state) ? globalThis.Boolean(object.assumed_state) : false,
|
|
1123
|
+
supportsPosition: isSet(object.supportsPosition) ? globalThis.Boolean(object.supportsPosition) : isSet(object.supports_position) ? globalThis.Boolean(object.supports_position) : false,
|
|
1124
|
+
supportsTilt: isSet(object.supportsTilt) ? globalThis.Boolean(object.supportsTilt) : isSet(object.supports_tilt) ? globalThis.Boolean(object.supports_tilt) : false,
|
|
1125
|
+
deviceClass: isSet(object.deviceClass) ? globalThis.String(object.deviceClass) : isSet(object.device_class) ? globalThis.String(object.device_class) : ""
|
|
1126
|
+
};
|
|
1127
|
+
},
|
|
1128
|
+
toJSON(message) {
|
|
1129
|
+
const obj = {};
|
|
1130
|
+
if (message.objectId !== "") {
|
|
1131
|
+
obj.objectId = message.objectId;
|
|
1132
|
+
}
|
|
1133
|
+
if (message.key !== 0) {
|
|
1134
|
+
obj.key = Math.round(message.key);
|
|
1135
|
+
}
|
|
1136
|
+
if (message.name !== "") {
|
|
1137
|
+
obj.name = message.name;
|
|
1138
|
+
}
|
|
1139
|
+
if (message.uniqueId !== "") {
|
|
1140
|
+
obj.uniqueId = message.uniqueId;
|
|
1141
|
+
}
|
|
1142
|
+
if (message.assumedState !== false) {
|
|
1143
|
+
obj.assumedState = message.assumedState;
|
|
1144
|
+
}
|
|
1145
|
+
if (message.supportsPosition !== false) {
|
|
1146
|
+
obj.supportsPosition = message.supportsPosition;
|
|
1147
|
+
}
|
|
1148
|
+
if (message.supportsTilt !== false) {
|
|
1149
|
+
obj.supportsTilt = message.supportsTilt;
|
|
1150
|
+
}
|
|
1151
|
+
if (message.deviceClass !== "") {
|
|
1152
|
+
obj.deviceClass = message.deviceClass;
|
|
1153
|
+
}
|
|
1154
|
+
return obj;
|
|
1155
|
+
},
|
|
1156
|
+
create(base) {
|
|
1157
|
+
return ListEntitiesCoverResponse.fromPartial(base ?? {});
|
|
1158
|
+
},
|
|
1159
|
+
fromPartial(object) {
|
|
1160
|
+
const message = createBaseListEntitiesCoverResponse();
|
|
1161
|
+
message.objectId = object.objectId ?? "";
|
|
1162
|
+
message.key = object.key ?? 0;
|
|
1163
|
+
message.name = object.name ?? "";
|
|
1164
|
+
message.uniqueId = object.uniqueId ?? "";
|
|
1165
|
+
message.assumedState = object.assumedState ?? false;
|
|
1166
|
+
message.supportsPosition = object.supportsPosition ?? false;
|
|
1167
|
+
message.supportsTilt = object.supportsTilt ?? false;
|
|
1168
|
+
message.deviceClass = object.deviceClass ?? "";
|
|
1169
|
+
return message;
|
|
1170
|
+
}
|
|
1171
|
+
};
|
|
953
1172
|
function createBaseCoverStateResponse() {
|
|
954
1173
|
return { key: 0, legacyState: 0, position: 0, tilt: 0, currentOperation: 0 };
|
|
955
1174
|
}
|
|
@@ -1072,6 +1291,182 @@ var CoverStateResponse = {
|
|
|
1072
1291
|
return message;
|
|
1073
1292
|
}
|
|
1074
1293
|
};
|
|
1294
|
+
function createBaseCoverCommandRequest() {
|
|
1295
|
+
return {
|
|
1296
|
+
key: 0,
|
|
1297
|
+
hasLegacyCommand: false,
|
|
1298
|
+
legacyCommand: 0,
|
|
1299
|
+
hasPosition: false,
|
|
1300
|
+
position: 0,
|
|
1301
|
+
hasTilt: false,
|
|
1302
|
+
tilt: 0,
|
|
1303
|
+
stop: false
|
|
1304
|
+
};
|
|
1305
|
+
}
|
|
1306
|
+
var CoverCommandRequest = {
|
|
1307
|
+
encode(message, writer = new BinaryWriter()) {
|
|
1308
|
+
if (message.key !== 0) {
|
|
1309
|
+
writer.uint32(13).fixed32(message.key);
|
|
1310
|
+
}
|
|
1311
|
+
if (message.hasLegacyCommand !== false) {
|
|
1312
|
+
writer.uint32(16).bool(message.hasLegacyCommand);
|
|
1313
|
+
}
|
|
1314
|
+
if (message.legacyCommand !== 0) {
|
|
1315
|
+
writer.uint32(24).int32(message.legacyCommand);
|
|
1316
|
+
}
|
|
1317
|
+
if (message.hasPosition !== false) {
|
|
1318
|
+
writer.uint32(32).bool(message.hasPosition);
|
|
1319
|
+
}
|
|
1320
|
+
if (message.position !== 0) {
|
|
1321
|
+
writer.uint32(45).float(message.position);
|
|
1322
|
+
}
|
|
1323
|
+
if (message.hasTilt !== false) {
|
|
1324
|
+
writer.uint32(48).bool(message.hasTilt);
|
|
1325
|
+
}
|
|
1326
|
+
if (message.tilt !== 0) {
|
|
1327
|
+
writer.uint32(61).float(message.tilt);
|
|
1328
|
+
}
|
|
1329
|
+
if (message.stop !== false) {
|
|
1330
|
+
writer.uint32(64).bool(message.stop);
|
|
1331
|
+
}
|
|
1332
|
+
return writer;
|
|
1333
|
+
},
|
|
1334
|
+
decode(input, length) {
|
|
1335
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
1336
|
+
const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
|
|
1337
|
+
if (previousRecursionDepth >= 100) {
|
|
1338
|
+
throw new globalThis.Error("protobuf decode recursion limit exceeded");
|
|
1339
|
+
}
|
|
1340
|
+
reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
|
|
1341
|
+
try {
|
|
1342
|
+
const end = length === void 0 ? reader.len : reader.pos + length;
|
|
1343
|
+
const message = createBaseCoverCommandRequest();
|
|
1344
|
+
while (reader.pos < end) {
|
|
1345
|
+
const tag = reader.uint32();
|
|
1346
|
+
switch (tag >>> 3) {
|
|
1347
|
+
case 1: {
|
|
1348
|
+
if (tag !== 13) {
|
|
1349
|
+
break;
|
|
1350
|
+
}
|
|
1351
|
+
message.key = reader.fixed32();
|
|
1352
|
+
continue;
|
|
1353
|
+
}
|
|
1354
|
+
case 2: {
|
|
1355
|
+
if (tag !== 16) {
|
|
1356
|
+
break;
|
|
1357
|
+
}
|
|
1358
|
+
message.hasLegacyCommand = reader.bool();
|
|
1359
|
+
continue;
|
|
1360
|
+
}
|
|
1361
|
+
case 3: {
|
|
1362
|
+
if (tag !== 24) {
|
|
1363
|
+
break;
|
|
1364
|
+
}
|
|
1365
|
+
message.legacyCommand = reader.int32();
|
|
1366
|
+
continue;
|
|
1367
|
+
}
|
|
1368
|
+
case 4: {
|
|
1369
|
+
if (tag !== 32) {
|
|
1370
|
+
break;
|
|
1371
|
+
}
|
|
1372
|
+
message.hasPosition = reader.bool();
|
|
1373
|
+
continue;
|
|
1374
|
+
}
|
|
1375
|
+
case 5: {
|
|
1376
|
+
if (tag !== 45) {
|
|
1377
|
+
break;
|
|
1378
|
+
}
|
|
1379
|
+
message.position = reader.float();
|
|
1380
|
+
continue;
|
|
1381
|
+
}
|
|
1382
|
+
case 6: {
|
|
1383
|
+
if (tag !== 48) {
|
|
1384
|
+
break;
|
|
1385
|
+
}
|
|
1386
|
+
message.hasTilt = reader.bool();
|
|
1387
|
+
continue;
|
|
1388
|
+
}
|
|
1389
|
+
case 7: {
|
|
1390
|
+
if (tag !== 61) {
|
|
1391
|
+
break;
|
|
1392
|
+
}
|
|
1393
|
+
message.tilt = reader.float();
|
|
1394
|
+
continue;
|
|
1395
|
+
}
|
|
1396
|
+
case 8: {
|
|
1397
|
+
if (tag !== 64) {
|
|
1398
|
+
break;
|
|
1399
|
+
}
|
|
1400
|
+
message.stop = reader.bool();
|
|
1401
|
+
continue;
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
1405
|
+
break;
|
|
1406
|
+
}
|
|
1407
|
+
reader.skip(tag & 7);
|
|
1408
|
+
}
|
|
1409
|
+
return message;
|
|
1410
|
+
} finally {
|
|
1411
|
+
reader.__tsProtoDecodeDepth = previousRecursionDepth;
|
|
1412
|
+
}
|
|
1413
|
+
},
|
|
1414
|
+
fromJSON(object) {
|
|
1415
|
+
return {
|
|
1416
|
+
key: isSet(object.key) ? globalThis.Number(object.key) : 0,
|
|
1417
|
+
hasLegacyCommand: isSet(object.hasLegacyCommand) ? globalThis.Boolean(object.hasLegacyCommand) : isSet(object.has_legacy_command) ? globalThis.Boolean(object.has_legacy_command) : false,
|
|
1418
|
+
legacyCommand: isSet(object.legacyCommand) ? legacyCoverCommandFromJSON(object.legacyCommand) : isSet(object.legacy_command) ? legacyCoverCommandFromJSON(object.legacy_command) : 0,
|
|
1419
|
+
hasPosition: isSet(object.hasPosition) ? globalThis.Boolean(object.hasPosition) : isSet(object.has_position) ? globalThis.Boolean(object.has_position) : false,
|
|
1420
|
+
position: isSet(object.position) ? globalThis.Number(object.position) : 0,
|
|
1421
|
+
hasTilt: isSet(object.hasTilt) ? globalThis.Boolean(object.hasTilt) : isSet(object.has_tilt) ? globalThis.Boolean(object.has_tilt) : false,
|
|
1422
|
+
tilt: isSet(object.tilt) ? globalThis.Number(object.tilt) : 0,
|
|
1423
|
+
stop: isSet(object.stop) ? globalThis.Boolean(object.stop) : false
|
|
1424
|
+
};
|
|
1425
|
+
},
|
|
1426
|
+
toJSON(message) {
|
|
1427
|
+
const obj = {};
|
|
1428
|
+
if (message.key !== 0) {
|
|
1429
|
+
obj.key = Math.round(message.key);
|
|
1430
|
+
}
|
|
1431
|
+
if (message.hasLegacyCommand !== false) {
|
|
1432
|
+
obj.hasLegacyCommand = message.hasLegacyCommand;
|
|
1433
|
+
}
|
|
1434
|
+
if (message.legacyCommand !== 0) {
|
|
1435
|
+
obj.legacyCommand = legacyCoverCommandToJSON(message.legacyCommand);
|
|
1436
|
+
}
|
|
1437
|
+
if (message.hasPosition !== false) {
|
|
1438
|
+
obj.hasPosition = message.hasPosition;
|
|
1439
|
+
}
|
|
1440
|
+
if (message.position !== 0) {
|
|
1441
|
+
obj.position = message.position;
|
|
1442
|
+
}
|
|
1443
|
+
if (message.hasTilt !== false) {
|
|
1444
|
+
obj.hasTilt = message.hasTilt;
|
|
1445
|
+
}
|
|
1446
|
+
if (message.tilt !== 0) {
|
|
1447
|
+
obj.tilt = message.tilt;
|
|
1448
|
+
}
|
|
1449
|
+
if (message.stop !== false) {
|
|
1450
|
+
obj.stop = message.stop;
|
|
1451
|
+
}
|
|
1452
|
+
return obj;
|
|
1453
|
+
},
|
|
1454
|
+
create(base) {
|
|
1455
|
+
return CoverCommandRequest.fromPartial(base ?? {});
|
|
1456
|
+
},
|
|
1457
|
+
fromPartial(object) {
|
|
1458
|
+
const message = createBaseCoverCommandRequest();
|
|
1459
|
+
message.key = object.key ?? 0;
|
|
1460
|
+
message.hasLegacyCommand = object.hasLegacyCommand ?? false;
|
|
1461
|
+
message.legacyCommand = object.legacyCommand ?? 0;
|
|
1462
|
+
message.hasPosition = object.hasPosition ?? false;
|
|
1463
|
+
message.position = object.position ?? 0;
|
|
1464
|
+
message.hasTilt = object.hasTilt ?? false;
|
|
1465
|
+
message.tilt = object.tilt ?? 0;
|
|
1466
|
+
message.stop = object.stop ?? false;
|
|
1467
|
+
return message;
|
|
1468
|
+
}
|
|
1469
|
+
};
|
|
1075
1470
|
function createBaseListEntitiesLightResponse() {
|
|
1076
1471
|
return {
|
|
1077
1472
|
objectId: "",
|
|
@@ -2410,181 +2805,204 @@ function isSet(value) {
|
|
|
2410
2805
|
}
|
|
2411
2806
|
|
|
2412
2807
|
// src/api/espSocket.ts
|
|
2413
|
-
import {
|
|
2414
|
-
|
|
2808
|
+
import {
|
|
2809
|
+
EMPTY,
|
|
2810
|
+
filter,
|
|
2811
|
+
from,
|
|
2812
|
+
merge,
|
|
2813
|
+
mergeMap,
|
|
2814
|
+
share,
|
|
2815
|
+
Subject as Subject2,
|
|
2816
|
+
switchMap,
|
|
2817
|
+
take as take2,
|
|
2818
|
+
takeUntil as takeUntil2,
|
|
2819
|
+
timeout
|
|
2820
|
+
} from "rxjs";
|
|
2415
2821
|
|
|
2416
2822
|
// src/api/requestResponseMatching.ts
|
|
2417
|
-
var MessageTypes = /* @__PURE__ */ ((
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
return
|
|
2823
|
+
var MessageTypes = /* @__PURE__ */ ((MessageTypes2) => {
|
|
2824
|
+
MessageTypes2[MessageTypes2["HelloRequest"] = 1] = "HelloRequest";
|
|
2825
|
+
MessageTypes2[MessageTypes2["HelloResponse"] = 2] = "HelloResponse";
|
|
2826
|
+
MessageTypes2[MessageTypes2["ConnectRequest"] = 3] = "ConnectRequest";
|
|
2827
|
+
MessageTypes2[MessageTypes2["ConnectResponse"] = 4] = "ConnectResponse";
|
|
2828
|
+
MessageTypes2[MessageTypes2["DisconnectRequest"] = 5] = "DisconnectRequest";
|
|
2829
|
+
MessageTypes2[MessageTypes2["DisconnectResponse"] = 6] = "DisconnectResponse";
|
|
2830
|
+
MessageTypes2[MessageTypes2["PingRequest"] = 7] = "PingRequest";
|
|
2831
|
+
MessageTypes2[MessageTypes2["PingResponse"] = 8] = "PingResponse";
|
|
2832
|
+
MessageTypes2[MessageTypes2["DeviceInfoRequest"] = 9] = "DeviceInfoRequest";
|
|
2833
|
+
MessageTypes2[MessageTypes2["DeviceInfoResponse"] = 10] = "DeviceInfoResponse";
|
|
2834
|
+
MessageTypes2[MessageTypes2["ListEntitiesRequest"] = 11] = "ListEntitiesRequest";
|
|
2835
|
+
MessageTypes2[MessageTypes2["ListEntitiesBinarySensorResponse"] = 12] = "ListEntitiesBinarySensorResponse";
|
|
2836
|
+
MessageTypes2[MessageTypes2["ListEntitiesCoverResponse"] = 13] = "ListEntitiesCoverResponse";
|
|
2837
|
+
MessageTypes2[MessageTypes2["ListEntitiesFanResponse"] = 14] = "ListEntitiesFanResponse";
|
|
2838
|
+
MessageTypes2[MessageTypes2["ListEntitiesLightResponse"] = 15] = "ListEntitiesLightResponse";
|
|
2839
|
+
MessageTypes2[MessageTypes2["ListEntitiesSensorResponse"] = 16] = "ListEntitiesSensorResponse";
|
|
2840
|
+
MessageTypes2[MessageTypes2["ListEntitiesSwitchResponse"] = 17] = "ListEntitiesSwitchResponse";
|
|
2841
|
+
MessageTypes2[MessageTypes2["ListEntitiesTextSensorResponse"] = 18] = "ListEntitiesTextSensorResponse";
|
|
2842
|
+
MessageTypes2[MessageTypes2["ListEntitiesDoneResponse"] = 19] = "ListEntitiesDoneResponse";
|
|
2843
|
+
MessageTypes2[MessageTypes2["SubscribeStatesRequest"] = 20] = "SubscribeStatesRequest";
|
|
2844
|
+
MessageTypes2[MessageTypes2["BinarySensorStateResponse"] = 21] = "BinarySensorStateResponse";
|
|
2845
|
+
MessageTypes2[MessageTypes2["CoverStateResponse"] = 22] = "CoverStateResponse";
|
|
2846
|
+
MessageTypes2[MessageTypes2["FanStateResponse"] = 23] = "FanStateResponse";
|
|
2847
|
+
MessageTypes2[MessageTypes2["LightStateResponse"] = 24] = "LightStateResponse";
|
|
2848
|
+
MessageTypes2[MessageTypes2["SensorStateResponse"] = 25] = "SensorStateResponse";
|
|
2849
|
+
MessageTypes2[MessageTypes2["SwitchStateResponse"] = 26] = "SwitchStateResponse";
|
|
2850
|
+
MessageTypes2[MessageTypes2["TextSensorStateResponse"] = 27] = "TextSensorStateResponse";
|
|
2851
|
+
MessageTypes2[MessageTypes2["SubscribeLogsRequest"] = 28] = "SubscribeLogsRequest";
|
|
2852
|
+
MessageTypes2[MessageTypes2["SubscribeLogsResponse"] = 29] = "SubscribeLogsResponse";
|
|
2853
|
+
MessageTypes2[MessageTypes2["CoverCommandRequest"] = 30] = "CoverCommandRequest";
|
|
2854
|
+
MessageTypes2[MessageTypes2["FanCommandRequest"] = 31] = "FanCommandRequest";
|
|
2855
|
+
MessageTypes2[MessageTypes2["LightCommandRequest"] = 32] = "LightCommandRequest";
|
|
2856
|
+
MessageTypes2[MessageTypes2["SwitchCommandRequest"] = 33] = "SwitchCommandRequest";
|
|
2857
|
+
MessageTypes2[MessageTypes2["SubscribeHomeassistantServicesRequest"] = 34] = "SubscribeHomeassistantServicesRequest";
|
|
2858
|
+
MessageTypes2[MessageTypes2["HomeassistantServiceResponse"] = 35] = "HomeassistantServiceResponse";
|
|
2859
|
+
MessageTypes2[MessageTypes2["GetTimeRequest"] = 36] = "GetTimeRequest";
|
|
2860
|
+
MessageTypes2[MessageTypes2["GetTimeResponse"] = 37] = "GetTimeResponse";
|
|
2861
|
+
MessageTypes2[MessageTypes2["SubscribeHomeAssistantStatesRequest"] = 38] = "SubscribeHomeAssistantStatesRequest";
|
|
2862
|
+
MessageTypes2[MessageTypes2["SubscribeHomeAssistantStateResponse"] = 39] = "SubscribeHomeAssistantStateResponse";
|
|
2863
|
+
MessageTypes2[MessageTypes2["HomeAssistantStateResponse"] = 40] = "HomeAssistantStateResponse";
|
|
2864
|
+
MessageTypes2[MessageTypes2["ListEntitiesServicesResponse"] = 41] = "ListEntitiesServicesResponse";
|
|
2865
|
+
MessageTypes2[MessageTypes2["ExecuteServiceRequest"] = 42] = "ExecuteServiceRequest";
|
|
2866
|
+
MessageTypes2[MessageTypes2["ListEntitiesCameraResponse"] = 43] = "ListEntitiesCameraResponse";
|
|
2867
|
+
MessageTypes2[MessageTypes2["CameraImageResponse"] = 44] = "CameraImageResponse";
|
|
2868
|
+
MessageTypes2[MessageTypes2["CameraImageRequest"] = 45] = "CameraImageRequest";
|
|
2869
|
+
MessageTypes2[MessageTypes2["ListEntitiesClimateResponse"] = 46] = "ListEntitiesClimateResponse";
|
|
2870
|
+
MessageTypes2[MessageTypes2["ClimateStateResponse"] = 47] = "ClimateStateResponse";
|
|
2871
|
+
MessageTypes2[MessageTypes2["ClimateCommandRequest"] = 48] = "ClimateCommandRequest";
|
|
2872
|
+
return MessageTypes2;
|
|
2467
2873
|
})(MessageTypes || {});
|
|
2468
2874
|
|
|
2469
|
-
// src/api/
|
|
2875
|
+
// src/api/tcpConnection.ts
|
|
2470
2876
|
import { Socket } from "net";
|
|
2471
|
-
import { BehaviorSubject, fromEvent,
|
|
2472
|
-
|
|
2473
|
-
var defaultConfig = {
|
|
2474
|
-
reconnectOnTimeout: false,
|
|
2475
|
-
disconnectOnTimeout: true
|
|
2476
|
-
};
|
|
2477
|
-
var RxjsSocket = class {
|
|
2877
|
+
import { BehaviorSubject, fromEvent, Subject, take, takeUntil, tap } from "rxjs";
|
|
2878
|
+
var TcpConnection = class {
|
|
2478
2879
|
constructor(host, port, config) {
|
|
2479
2880
|
this.host = host;
|
|
2480
2881
|
this.port = port;
|
|
2481
|
-
this.
|
|
2482
|
-
this.
|
|
2882
|
+
this.timeout = config?.timeout;
|
|
2883
|
+
this.chunks$ = this.chunks.asObservable();
|
|
2483
2884
|
this.connected$ = this.connected.asObservable();
|
|
2484
|
-
this.timeout$ = this.timeout.asObservable();
|
|
2485
2885
|
this.error$ = this.error.asObservable();
|
|
2486
2886
|
}
|
|
2487
2887
|
host;
|
|
2488
2888
|
port;
|
|
2489
2889
|
socket;
|
|
2490
|
-
|
|
2890
|
+
timeout;
|
|
2491
2891
|
// RxJS
|
|
2492
|
-
|
|
2493
|
-
|
|
2892
|
+
chunks = new Subject();
|
|
2893
|
+
chunks$;
|
|
2494
2894
|
connected = new BehaviorSubject(false);
|
|
2495
2895
|
connected$;
|
|
2496
|
-
timeout = new Subject();
|
|
2497
|
-
timeout$;
|
|
2498
2896
|
error = new Subject();
|
|
2499
2897
|
error$;
|
|
2500
|
-
|
|
2898
|
+
// Internal teardown signal; ends the socket event subscriptions.
|
|
2899
|
+
teardown = new Subject();
|
|
2900
|
+
// Cancel closure for a pending graceful termination; invoked when a new
|
|
2901
|
+
// connection is opened to cancel it.
|
|
2902
|
+
pendingGracefulDestroy;
|
|
2501
2903
|
open() {
|
|
2502
2904
|
if (this.socket?.connecting) {
|
|
2503
2905
|
return;
|
|
2504
2906
|
}
|
|
2505
|
-
this.
|
|
2907
|
+
this.teardownSocket();
|
|
2506
2908
|
this.socket = new Socket();
|
|
2507
|
-
if (this.
|
|
2508
|
-
this.socket.setTimeout(this.
|
|
2909
|
+
if (this.timeout) {
|
|
2910
|
+
this.socket.setTimeout(this.timeout);
|
|
2509
2911
|
}
|
|
2510
2912
|
this.setupSocketEvents();
|
|
2511
2913
|
this.socket.connect(this.port, this.host);
|
|
2512
2914
|
}
|
|
2513
|
-
|
|
2514
|
-
if (!this.socket) {
|
|
2915
|
+
terminate() {
|
|
2916
|
+
if (!this.socket || this.pendingGracefulDestroy) {
|
|
2515
2917
|
return;
|
|
2516
2918
|
}
|
|
2517
2919
|
this.connected.next(false);
|
|
2518
|
-
this.
|
|
2920
|
+
this.teardown.next();
|
|
2519
2921
|
this.socket.end();
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2922
|
+
const socket = this.socket;
|
|
2923
|
+
let settled = false;
|
|
2924
|
+
const finish = () => {
|
|
2925
|
+
clearTimeout(safety);
|
|
2926
|
+
if (settled) {
|
|
2927
|
+
return;
|
|
2928
|
+
}
|
|
2929
|
+
settled = true;
|
|
2930
|
+
this.pendingGracefulDestroy = void 0;
|
|
2931
|
+
if (this.socket === socket) {
|
|
2932
|
+
this.destroySocket();
|
|
2933
|
+
}
|
|
2934
|
+
};
|
|
2935
|
+
const safety = setTimeout(finish, 250);
|
|
2936
|
+
safety.unref();
|
|
2937
|
+
socket.once("close", finish);
|
|
2938
|
+
const cancel = () => {
|
|
2939
|
+
settled = true;
|
|
2940
|
+
clearTimeout(safety);
|
|
2941
|
+
socket.removeListener("close", finish);
|
|
2942
|
+
this.pendingGracefulDestroy = void 0;
|
|
2943
|
+
};
|
|
2944
|
+
this.pendingGracefulDestroy = cancel;
|
|
2523
2945
|
}
|
|
2524
2946
|
isConnected() {
|
|
2525
2947
|
return this.connected.getValue();
|
|
2526
2948
|
}
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
});
|
|
2538
|
-
return;
|
|
2949
|
+
// Fire-and-forget: a write while disconnected is silently dropped, a write
|
|
2950
|
+
// error is surfaced on error$ instead of escaping into Node's write-completion
|
|
2951
|
+
// context as an uncaught exception.
|
|
2952
|
+
write(data) {
|
|
2953
|
+
if (!this.isConnected() || !this.socket) {
|
|
2954
|
+
return;
|
|
2955
|
+
}
|
|
2956
|
+
this.socket.write(data, (err) => {
|
|
2957
|
+
if (err) {
|
|
2958
|
+
this.error.next(err);
|
|
2539
2959
|
}
|
|
2540
|
-
subscriber.next();
|
|
2541
|
-
subscriber.complete();
|
|
2542
2960
|
});
|
|
2543
2961
|
}
|
|
2544
2962
|
setupSocketEvents() {
|
|
2545
|
-
|
|
2963
|
+
const socket = this.socket;
|
|
2964
|
+
if (!socket) {
|
|
2546
2965
|
return;
|
|
2547
2966
|
}
|
|
2548
|
-
|
|
2549
|
-
fromEvent(
|
|
2550
|
-
tap((buffer) => this.
|
|
2551
|
-
takeUntil(this.
|
|
2967
|
+
socket.on("error", (err) => this.error.next(err));
|
|
2968
|
+
fromEvent(socket, "data").pipe(
|
|
2969
|
+
tap((buffer) => this.chunks.next(buffer)),
|
|
2970
|
+
takeUntil(this.teardown)
|
|
2552
2971
|
).subscribe();
|
|
2553
|
-
fromEvent(
|
|
2972
|
+
fromEvent(socket, "connect").pipe(
|
|
2554
2973
|
take(1),
|
|
2555
2974
|
tap(() => this.connected.next(true)),
|
|
2556
|
-
takeUntil(this.
|
|
2975
|
+
takeUntil(this.teardown)
|
|
2557
2976
|
).subscribe();
|
|
2558
|
-
fromEvent(
|
|
2977
|
+
fromEvent(socket, "close").pipe(
|
|
2559
2978
|
take(1),
|
|
2560
2979
|
tap(() => this.connected.next(false)),
|
|
2561
|
-
takeUntil(this.
|
|
2980
|
+
takeUntil(this.teardown)
|
|
2562
2981
|
).subscribe();
|
|
2563
|
-
fromEvent(
|
|
2982
|
+
fromEvent(socket, "end").pipe(
|
|
2564
2983
|
take(1),
|
|
2565
2984
|
tap(() => this.socket?.end()),
|
|
2566
2985
|
tap(() => this.connected.next(false)),
|
|
2567
|
-
takeUntil(this.
|
|
2986
|
+
takeUntil(this.teardown)
|
|
2568
2987
|
).subscribe();
|
|
2569
|
-
if (this.
|
|
2570
|
-
fromEvent(
|
|
2571
|
-
tap(() => this.timeout.next()),
|
|
2988
|
+
if (this.timeout && this.timeout > 0) {
|
|
2989
|
+
fromEvent(socket, "timeout").pipe(
|
|
2572
2990
|
tap(() => {
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
}
|
|
2576
|
-
if (this.config.reconnectOnTimeout) {
|
|
2577
|
-
this.reconnect();
|
|
2578
|
-
}
|
|
2991
|
+
this.teardown.next();
|
|
2992
|
+
this.destroySocket();
|
|
2579
2993
|
}),
|
|
2580
|
-
takeUntil(this.
|
|
2994
|
+
takeUntil(this.teardown)
|
|
2581
2995
|
).subscribe();
|
|
2582
2996
|
}
|
|
2583
2997
|
}
|
|
2584
|
-
|
|
2585
|
-
this.
|
|
2998
|
+
teardownSocket() {
|
|
2999
|
+
this.pendingGracefulDestroy?.();
|
|
3000
|
+
this.pendingGracefulDestroy = void 0;
|
|
3001
|
+
if (!this.socket) {
|
|
3002
|
+
return;
|
|
3003
|
+
}
|
|
3004
|
+
this.teardown.next();
|
|
2586
3005
|
this.destroySocket();
|
|
2587
|
-
this.open();
|
|
2588
3006
|
}
|
|
2589
3007
|
destroySocket() {
|
|
2590
3008
|
this.socket?.destroy();
|
|
@@ -2640,39 +3058,61 @@ var isTrue = (val) => val === true;
|
|
|
2640
3058
|
var isFalse = (val) => val === false;
|
|
2641
3059
|
|
|
2642
3060
|
// src/api/espSocket.ts
|
|
2643
|
-
var EspSocket = class
|
|
3061
|
+
var EspSocket = class {
|
|
3062
|
+
connection;
|
|
3063
|
+
teardown = new Subject2();
|
|
3064
|
+
errors = new Subject2();
|
|
3065
|
+
connected$;
|
|
2644
3066
|
espData$;
|
|
3067
|
+
error$;
|
|
2645
3068
|
constructor(host, port, config) {
|
|
2646
|
-
|
|
2647
|
-
this.
|
|
3069
|
+
this.connection = config?.connection ?? new TcpConnection(host, port, { timeout: config?.timeout });
|
|
3070
|
+
this.connected$ = this.connection.connected$;
|
|
3071
|
+
this.error$ = merge(this.errors, this.connection.error$);
|
|
3072
|
+
this.espData$ = this.connection.connected$.pipe(
|
|
2648
3073
|
filter(isTrue),
|
|
2649
3074
|
switchMap(() => {
|
|
2650
3075
|
const frameParser = createFrameParser();
|
|
2651
|
-
return this.
|
|
2652
|
-
})
|
|
3076
|
+
return this.connection.chunks$.pipe(mergeMap((chunk) => from(frameParser.push(chunk))));
|
|
3077
|
+
}),
|
|
3078
|
+
share()
|
|
2653
3079
|
);
|
|
2654
3080
|
}
|
|
3081
|
+
open() {
|
|
3082
|
+
this.connection.open();
|
|
3083
|
+
}
|
|
3084
|
+
isConnected() {
|
|
3085
|
+
return this.connection.isConnected();
|
|
3086
|
+
}
|
|
3087
|
+
terminate() {
|
|
3088
|
+
this.teardown.next();
|
|
3089
|
+
this.connection.terminate();
|
|
3090
|
+
}
|
|
2655
3091
|
sendEspMessage(type, payload) {
|
|
2656
|
-
this.connected$.pipe(
|
|
3092
|
+
this.connection.connected$.pipe(
|
|
2657
3093
|
timeout(5e3),
|
|
2658
3094
|
filter(isTrue),
|
|
2659
3095
|
take2(1),
|
|
2660
3096
|
switchMap(() => {
|
|
2661
3097
|
const final = encodeFrame(type, payload);
|
|
2662
|
-
|
|
3098
|
+
this.connection.write(final);
|
|
3099
|
+
return EMPTY;
|
|
2663
3100
|
}),
|
|
2664
|
-
|
|
3101
|
+
// terminate() kills a pending send, but open() deliberately does
|
|
3102
|
+
// NOT: a command issued during a blip rides the reconnect within
|
|
3103
|
+
// its 5-second window — the commands are idempotent absolute-state
|
|
3104
|
+
// writes, so a ≤5s-old resend is safe.
|
|
3105
|
+
takeUntil2(this.teardown)
|
|
2665
3106
|
).subscribe({
|
|
2666
3107
|
error: (error) => {
|
|
2667
|
-
this.
|
|
3108
|
+
this.errors.next(error instanceof Error ? error : new Error(String(error)));
|
|
2668
3109
|
}
|
|
2669
3110
|
});
|
|
2670
3111
|
}
|
|
2671
3112
|
};
|
|
2672
3113
|
|
|
2673
3114
|
// 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";
|
|
3115
|
+
import { filter as filter2, map, of, Subscription, take as take3, tap as tap2 } from "rxjs";
|
|
2676
3116
|
var Client = class {
|
|
2677
3117
|
constructor(socket) {
|
|
2678
3118
|
this.socket = socket;
|
|
@@ -2747,34 +3187,38 @@ var Client = class {
|
|
|
2747
3187
|
}
|
|
2748
3188
|
};
|
|
2749
3189
|
|
|
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
3190
|
// src/api/helpers.ts
|
|
2766
|
-
import "rxjs";
|
|
2767
|
-
import { filter as filter4 } from "rxjs/operators";
|
|
3191
|
+
import { filter as filter4 } from "rxjs";
|
|
2768
3192
|
|
|
2769
3193
|
// src/components/base.ts
|
|
2770
|
-
import {
|
|
2771
|
-
|
|
3194
|
+
import {
|
|
3195
|
+
BehaviorSubject as BehaviorSubject2,
|
|
3196
|
+
debounceTime,
|
|
3197
|
+
distinctUntilChanged,
|
|
3198
|
+
filter as filter3,
|
|
3199
|
+
Subject as Subject3,
|
|
3200
|
+
take as take4,
|
|
3201
|
+
takeUntil as takeUntil3,
|
|
3202
|
+
tap as tap3
|
|
3203
|
+
} from "rxjs";
|
|
3204
|
+
var shallowEqualStates = (previous, current) => {
|
|
3205
|
+
const previousKeys = Object.keys(previous);
|
|
3206
|
+
const currentKeys = Object.keys(current);
|
|
3207
|
+
return previousKeys.length === currentKeys.length && previousKeys.every((key) => Object.is(previous[key], current[key]));
|
|
3208
|
+
};
|
|
2772
3209
|
var BaseComponent = class {
|
|
2773
3210
|
constructor(listEntity, state, commandInterface) {
|
|
2774
3211
|
this.listEntity = listEntity;
|
|
2775
3212
|
this.commandInterface = commandInterface;
|
|
2776
3213
|
this.commandInPipeline = new BehaviorSubject2(false);
|
|
2777
|
-
this.state$ = this.state.pipe(
|
|
3214
|
+
this.state$ = this.state.pipe(
|
|
3215
|
+
filter3((state2) => state2 !== void 0),
|
|
3216
|
+
// ESPHome re-sends identical states (e.g. a sensor polling a stable
|
|
3217
|
+
// reading): shallow-compare the flat state events so subscribers only
|
|
3218
|
+
// observe actual changes. Object.is is used per field so an identical
|
|
3219
|
+
// NaN-valued state also compares equal instead of re-emitting.
|
|
3220
|
+
distinctUntilChanged(shallowEqualStates)
|
|
3221
|
+
);
|
|
2778
3222
|
this.provideStateObservable(state);
|
|
2779
3223
|
this.commandInPipeline.pipe(
|
|
2780
3224
|
debounceTime(30 * 1e3),
|
|
@@ -2787,9 +3231,9 @@ var BaseComponent = class {
|
|
|
2787
3231
|
commandInterface;
|
|
2788
3232
|
state = new BehaviorSubject2(void 0);
|
|
2789
3233
|
state$;
|
|
2790
|
-
terminatePreviousStateSubscription = new
|
|
3234
|
+
terminatePreviousStateSubscription = new Subject3();
|
|
2791
3235
|
commandInPipeline;
|
|
2792
|
-
teardown = new
|
|
3236
|
+
teardown = new Subject3();
|
|
2793
3237
|
provideStateObservable(state$) {
|
|
2794
3238
|
this.terminatePreviousStateSubscription.next();
|
|
2795
3239
|
state$.pipe(
|
|
@@ -2870,6 +3314,113 @@ var BinarySensorComponent = class extends BaseComponent {
|
|
|
2870
3314
|
}
|
|
2871
3315
|
};
|
|
2872
3316
|
|
|
3317
|
+
// src/components/cover.ts
|
|
3318
|
+
var CoverComponent = class extends BaseComponent {
|
|
3319
|
+
open() {
|
|
3320
|
+
this.sendCommand({ position: 1 });
|
|
3321
|
+
}
|
|
3322
|
+
close() {
|
|
3323
|
+
this.sendCommand({ position: 0 });
|
|
3324
|
+
}
|
|
3325
|
+
stop() {
|
|
3326
|
+
this.sendCommand({ stop: true });
|
|
3327
|
+
}
|
|
3328
|
+
setPosition(position) {
|
|
3329
|
+
if (!this.supportsPosition) {
|
|
3330
|
+
return;
|
|
3331
|
+
}
|
|
3332
|
+
this.sendCommand({ position });
|
|
3333
|
+
}
|
|
3334
|
+
setTilt(tilt) {
|
|
3335
|
+
if (!this.supportsTilt) {
|
|
3336
|
+
return;
|
|
3337
|
+
}
|
|
3338
|
+
this.sendCommand({ tilt });
|
|
3339
|
+
}
|
|
3340
|
+
get type() {
|
|
3341
|
+
return "cover";
|
|
3342
|
+
}
|
|
3343
|
+
get assumedState() {
|
|
3344
|
+
return this.listEntity.assumedState;
|
|
3345
|
+
}
|
|
3346
|
+
get supportsPosition() {
|
|
3347
|
+
return this.listEntity.supportsPosition;
|
|
3348
|
+
}
|
|
3349
|
+
get supportsTilt() {
|
|
3350
|
+
return this.listEntity.supportsTilt;
|
|
3351
|
+
}
|
|
3352
|
+
/**
|
|
3353
|
+
* Current position between 0 (closed) and 1 (open). Undefined until the
|
|
3354
|
+
* first state was received or when the cover does not support positions.
|
|
3355
|
+
*/
|
|
3356
|
+
get position() {
|
|
3357
|
+
if (!this.supportsPosition) {
|
|
3358
|
+
return void 0;
|
|
3359
|
+
}
|
|
3360
|
+
return this.state.getValue()?.position;
|
|
3361
|
+
}
|
|
3362
|
+
/**
|
|
3363
|
+
* Current tilt between 0 and 1. Undefined until the first state was
|
|
3364
|
+
* received or when the cover does not support tilt.
|
|
3365
|
+
*/
|
|
3366
|
+
get tilt() {
|
|
3367
|
+
if (!this.supportsTilt) {
|
|
3368
|
+
return void 0;
|
|
3369
|
+
}
|
|
3370
|
+
return this.state.getValue()?.tilt;
|
|
3371
|
+
}
|
|
3372
|
+
/**
|
|
3373
|
+
* Whether the cover is fully closed. Derived from the position field the
|
|
3374
|
+
* device always sends, exactly like aioesphomeapi derives is_closed
|
|
3375
|
+
* (position == 0). Undefined until the first state was received.
|
|
3376
|
+
*/
|
|
3377
|
+
get isClosed() {
|
|
3378
|
+
const position = this.state.getValue()?.position;
|
|
3379
|
+
return position === void 0 ? void 0 : position === 0;
|
|
3380
|
+
}
|
|
3381
|
+
/**
|
|
3382
|
+
* Whether the cover is fully open. Derived from the position field the
|
|
3383
|
+
* device always sends. Undefined until the first state was received; a
|
|
3384
|
+
* partially open cover is neither open nor closed.
|
|
3385
|
+
*/
|
|
3386
|
+
get isOpen() {
|
|
3387
|
+
const position = this.state.getValue()?.position;
|
|
3388
|
+
return position === void 0 ? void 0 : position === 1;
|
|
3389
|
+
}
|
|
3390
|
+
/**
|
|
3391
|
+
* What the cover is currently doing. Undefined until the first state was
|
|
3392
|
+
* received.
|
|
3393
|
+
*/
|
|
3394
|
+
get operation() {
|
|
3395
|
+
return this.state.getValue()?.currentOperation;
|
|
3396
|
+
}
|
|
3397
|
+
sendCommand(command) {
|
|
3398
|
+
this.queueCommand(
|
|
3399
|
+
30 /* CoverCommandRequest */,
|
|
3400
|
+
() => CoverCommandRequest.encode({
|
|
3401
|
+
key: this.key,
|
|
3402
|
+
// The legacy command fields are dead: Home Assistant last
|
|
3403
|
+
// sent them to pre-2019 devices and firmware dropped their
|
|
3404
|
+
// handling in 2025.8.0. Only the values below reach the
|
|
3405
|
+
// wire; these two are wire-inert defaults that satisfy
|
|
3406
|
+
// the generated message type.
|
|
3407
|
+
hasLegacyCommand: false,
|
|
3408
|
+
legacyCommand: 0 /* LEGACY_COVER_COMMAND_OPEN */,
|
|
3409
|
+
hasPosition: command.position !== void 0,
|
|
3410
|
+
position: command.position ?? 0,
|
|
3411
|
+
hasTilt: command.tilt !== void 0,
|
|
3412
|
+
tilt: command.tilt ?? 0,
|
|
3413
|
+
stop: command.stop ?? false
|
|
3414
|
+
}).finish(),
|
|
3415
|
+
// Covers without position feedback never confirm a command with a
|
|
3416
|
+
// state response, so a serialized command would wait for the 30
|
|
3417
|
+
// second pipeline fallback. Like switch commands, cover commands
|
|
3418
|
+
// are cheap idempotent intents and go out immediately.
|
|
3419
|
+
true
|
|
3420
|
+
);
|
|
3421
|
+
}
|
|
3422
|
+
};
|
|
3423
|
+
|
|
2873
3424
|
// src/components/helpers.ts
|
|
2874
3425
|
var convertNumbers = (num, max = 255, fromEsp = false) => {
|
|
2875
3426
|
if (fromEsp) {
|
|
@@ -3124,6 +3675,17 @@ var createComponents = (data, stateEvents$, connection, knownComponents) => {
|
|
|
3124
3675
|
component: new BinarySensorComponent(response, state$, emptyCommandInterface)
|
|
3125
3676
|
};
|
|
3126
3677
|
}
|
|
3678
|
+
case 13 /* ListEntitiesCoverResponse */: {
|
|
3679
|
+
const response = ListEntitiesCoverResponse.decode(data.payload);
|
|
3680
|
+
const state$ = transformStates(stateEvents$, response);
|
|
3681
|
+
return knownComponents.has(response.objectId) ? {
|
|
3682
|
+
id: response.objectId,
|
|
3683
|
+
state$
|
|
3684
|
+
} : {
|
|
3685
|
+
id: response.objectId,
|
|
3686
|
+
component: new CoverComponent(response, state$, connection)
|
|
3687
|
+
};
|
|
3688
|
+
}
|
|
3127
3689
|
case 17 /* ListEntitiesSwitchResponse */: {
|
|
3128
3690
|
const response = ListEntitiesSwitchResponse.decode(data.payload);
|
|
3129
3691
|
const state$ = transformStates(stateEvents$, response);
|
|
@@ -3170,6 +3732,7 @@ var transformStates = (stateEvents$, listEntityResponse) => {
|
|
|
3170
3732
|
// src/api/responses.ts
|
|
3171
3733
|
var listResponses = /* @__PURE__ */ new Set([
|
|
3172
3734
|
12 /* ListEntitiesBinarySensorResponse */,
|
|
3735
|
+
13 /* ListEntitiesCoverResponse */,
|
|
3173
3736
|
15 /* ListEntitiesLightResponse */,
|
|
3174
3737
|
16 /* ListEntitiesSensorResponse */,
|
|
3175
3738
|
17 /* ListEntitiesSwitchResponse */,
|
|
@@ -3184,7 +3747,26 @@ var stateResponses = /* @__PURE__ */ new Set([
|
|
|
3184
3747
|
]);
|
|
3185
3748
|
|
|
3186
3749
|
// src/api/espDevice.ts
|
|
3187
|
-
import {
|
|
3750
|
+
import {
|
|
3751
|
+
BehaviorSubject as BehaviorSubject3,
|
|
3752
|
+
concat,
|
|
3753
|
+
defer,
|
|
3754
|
+
distinctUntilChanged as distinctUntilChanged2,
|
|
3755
|
+
EMPTY as EMPTY2,
|
|
3756
|
+
filter as filter5,
|
|
3757
|
+
map as map2,
|
|
3758
|
+
merge as merge2,
|
|
3759
|
+
of as of2,
|
|
3760
|
+
retry,
|
|
3761
|
+
share as share2,
|
|
3762
|
+
shareReplay,
|
|
3763
|
+
Subject as Subject4,
|
|
3764
|
+
Subscription as Subscription2,
|
|
3765
|
+
switchMap as switchMap2,
|
|
3766
|
+
takeUntil as takeUntil4,
|
|
3767
|
+
tap as tap4,
|
|
3768
|
+
timer
|
|
3769
|
+
} from "rxjs";
|
|
3188
3770
|
var PING_TIMEOUT = 90 * 1e3;
|
|
3189
3771
|
var RETRY_DELAY = 1e3;
|
|
3190
3772
|
var InvalidPasswordError = class extends Error {
|
|
@@ -3194,7 +3776,7 @@ var InvalidPasswordError = class extends Error {
|
|
|
3194
3776
|
}
|
|
3195
3777
|
};
|
|
3196
3778
|
var EspDevice = class {
|
|
3197
|
-
constructor(host, password = "", port = 6053) {
|
|
3779
|
+
constructor(host, password = "", port = 6053, options) {
|
|
3198
3780
|
this.host = host;
|
|
3199
3781
|
this.password = password;
|
|
3200
3782
|
this.port = port;
|
|
@@ -3203,13 +3785,17 @@ var EspDevice = class {
|
|
|
3203
3785
|
this.discovery$ = this.discovery.asObservable();
|
|
3204
3786
|
this.error$ = this.errors.asObservable();
|
|
3205
3787
|
this.socket = new EspSocket(host, port, {
|
|
3206
|
-
timeout: PING_TIMEOUT
|
|
3788
|
+
timeout: PING_TIMEOUT,
|
|
3789
|
+
connection: options?.connection
|
|
3207
3790
|
});
|
|
3208
3791
|
this.client = new Client(this.socket);
|
|
3209
3792
|
this.stateEvents$ = this.socket.espData$.pipe(
|
|
3210
3793
|
filter5((data) => stateResponses.has(data.type)),
|
|
3211
3794
|
map2((data) => stateParser(data)),
|
|
3212
|
-
filter5((parsed) => !!parsed)
|
|
3795
|
+
filter5((parsed) => !!parsed),
|
|
3796
|
+
// One decode shared by all components: without this, every discovered
|
|
3797
|
+
// component re-runs the filter+decode chain for the same state frame.
|
|
3798
|
+
share2()
|
|
3213
3799
|
);
|
|
3214
3800
|
this.subscription.add(
|
|
3215
3801
|
this.socket.espData$.pipe(
|
|
@@ -3228,55 +3814,63 @@ var EspDevice = class {
|
|
|
3228
3814
|
);
|
|
3229
3815
|
this.subscription.add(
|
|
3230
3816
|
this.socket.connected$.pipe(
|
|
3231
|
-
|
|
3817
|
+
distinctUntilChanged2(),
|
|
3232
3818
|
tap4((connected) => {
|
|
3233
|
-
if (!connected) {
|
|
3819
|
+
if (!connected && !this.passwordRejected) {
|
|
3234
3820
|
this.socket.open();
|
|
3235
3821
|
}
|
|
3236
3822
|
}),
|
|
3237
|
-
filter5(
|
|
3238
|
-
switchMap2(
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3823
|
+
filter5((connected) => connected && !this.passwordRejected),
|
|
3824
|
+
switchMap2(
|
|
3825
|
+
() => (
|
|
3826
|
+
// defer() re-runs this factory on every retry:
|
|
3827
|
+
// Client.request() sends eagerly when called (not on
|
|
3828
|
+
// subscription), so without it a retried handshake
|
|
3829
|
+
// would never put a fresh HelloRequest on the wire —
|
|
3830
|
+
// and a real device only answers HelloRequest, never
|
|
3831
|
+
// speaks first.
|
|
3832
|
+
defer(() => this.client.hello({ clientInfo: "esphome-ts" })).pipe(
|
|
3833
|
+
switchMap2(() => this.client.connect({ password })),
|
|
3834
|
+
map2((response) => {
|
|
3835
|
+
if (response.invalidPassword) {
|
|
3836
|
+
throw new InvalidPasswordError(this.host);
|
|
3837
|
+
}
|
|
3838
|
+
return response;
|
|
3839
|
+
}),
|
|
3840
|
+
switchMap2(() => this.client.deviceInfo()),
|
|
3841
|
+
switchMap2(() => this.client.listEntities()),
|
|
3842
|
+
switchMap2(() => this.client.subscribeStateChange()),
|
|
3843
|
+
retry({
|
|
3844
|
+
delay: (error) => {
|
|
3845
|
+
this.errors.next(error);
|
|
3846
|
+
if (error instanceof InvalidPasswordError) {
|
|
3847
|
+
this.passwordRejected = true;
|
|
3848
|
+
this.socket.terminate();
|
|
3849
|
+
return EMPTY2;
|
|
3850
|
+
}
|
|
3851
|
+
return timer(RETRY_DELAY);
|
|
3852
|
+
}
|
|
3853
|
+
})
|
|
3854
|
+
)
|
|
3855
|
+
)
|
|
3856
|
+
)
|
|
3256
3857
|
).subscribe()
|
|
3257
3858
|
);
|
|
3258
3859
|
this.subscription.add(
|
|
3259
3860
|
this.socket.error$.pipe(
|
|
3260
3861
|
switchMap2(() => timer(RETRY_DELAY)),
|
|
3261
|
-
filter5(() => !this.socket.isConnected())
|
|
3862
|
+
filter5(() => !this.passwordRejected && !this.socket.isConnected())
|
|
3262
3863
|
).subscribe(() => this.socket.open())
|
|
3263
3864
|
);
|
|
3264
|
-
this.alive$ =
|
|
3865
|
+
this.alive$ = merge2(
|
|
3265
3866
|
this.socket.connected$,
|
|
3266
|
-
this.socket.espData$.pipe(
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
catchError(() => of2(false)),
|
|
3274
|
-
take5(1)
|
|
3275
|
-
)
|
|
3276
|
-
);
|
|
3277
|
-
})
|
|
3278
|
-
)
|
|
3279
|
-
).pipe(distinctUntilChanged(), shareReplay(1));
|
|
3867
|
+
this.socket.espData$.pipe(switchMap2(() => concat(of2(true), timer(PING_TIMEOUT).pipe(map2(() => false)))))
|
|
3868
|
+
).pipe(
|
|
3869
|
+
distinctUntilChanged2(),
|
|
3870
|
+
// refCount releases the watchdog source and its pending timer when
|
|
3871
|
+
// the last subscriber leaves, e.g. after terminate().
|
|
3872
|
+
shareReplay({ bufferSize: 1, refCount: true })
|
|
3873
|
+
);
|
|
3280
3874
|
}
|
|
3281
3875
|
host;
|
|
3282
3876
|
password;
|
|
@@ -3288,7 +3882,7 @@ var EspDevice = class {
|
|
|
3288
3882
|
components = {};
|
|
3289
3883
|
discovery;
|
|
3290
3884
|
discovery$;
|
|
3291
|
-
errors = new
|
|
3885
|
+
errors = new Subject4();
|
|
3292
3886
|
/**
|
|
3293
3887
|
* Device level failures: frames that could not be decoded and handshake
|
|
3294
3888
|
* problems such as an `InvalidPasswordError`. Socket level errors are
|
|
@@ -3296,19 +3890,30 @@ var EspDevice = class {
|
|
|
3296
3890
|
*/
|
|
3297
3891
|
error$;
|
|
3298
3892
|
subscription;
|
|
3893
|
+
retrySubscription;
|
|
3894
|
+
// Latched when the device rejects the constructed password: terminal for
|
|
3895
|
+
// auto-reconnect until provideRetryObservable() explicitly re-arms it.
|
|
3896
|
+
passwordRejected = false;
|
|
3299
3897
|
alive$;
|
|
3898
|
+
/**
|
|
3899
|
+
* Provides the reconnect cadence used while the device is unreachable.
|
|
3900
|
+
* Calling this again replaces the previously provided retry signal, so
|
|
3901
|
+
* repeated calls cannot stack parallel reconnect loops. Providing a cadence
|
|
3902
|
+
* is also the explicit opt-in re-arm after a password rejection.
|
|
3903
|
+
*/
|
|
3300
3904
|
provideRetryObservable(retryWhen$) {
|
|
3301
|
-
this.
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
)
|
|
3905
|
+
this.passwordRejected = false;
|
|
3906
|
+
this.retrySubscription?.unsubscribe();
|
|
3907
|
+
this.retrySubscription = this.alive$.pipe(
|
|
3908
|
+
filter5(isFalse),
|
|
3909
|
+
switchMap2(
|
|
3910
|
+
() => retryWhen$.pipe(
|
|
3911
|
+
tap4(() => this.socket.open()),
|
|
3912
|
+
takeUntil4(this.alive$.pipe(filter5(isTrue)))
|
|
3309
3913
|
)
|
|
3310
|
-
)
|
|
3311
|
-
);
|
|
3914
|
+
)
|
|
3915
|
+
).subscribe();
|
|
3916
|
+
this.subscription.add(this.retrySubscription);
|
|
3312
3917
|
}
|
|
3313
3918
|
terminate() {
|
|
3314
3919
|
Object.values(this.components).forEach((component) => {
|
|
@@ -3317,7 +3922,7 @@ var EspDevice = class {
|
|
|
3317
3922
|
this.client.terminate();
|
|
3318
3923
|
this.subscription.unsubscribe();
|
|
3319
3924
|
this.errors.complete();
|
|
3320
|
-
this.socket.
|
|
3925
|
+
this.socket.terminate();
|
|
3321
3926
|
}
|
|
3322
3927
|
parseListResponse(data) {
|
|
3323
3928
|
if (data.type === 19 /* ListEntitiesDoneResponse */) {
|
|
@@ -3341,12 +3946,14 @@ export {
|
|
|
3341
3946
|
BinarySensorComponent,
|
|
3342
3947
|
BinarySensorTypes,
|
|
3343
3948
|
Client,
|
|
3949
|
+
CoverComponent,
|
|
3950
|
+
CoverOperation,
|
|
3344
3951
|
EspDevice,
|
|
3345
3952
|
EspSocket,
|
|
3346
3953
|
InvalidPasswordError,
|
|
3954
|
+
LegacyCoverState,
|
|
3347
3955
|
LightComponent,
|
|
3348
3956
|
MessageTypes,
|
|
3349
|
-
RxjsSocket,
|
|
3350
3957
|
SensorComponent,
|
|
3351
3958
|
SwitchComponent,
|
|
3352
3959
|
isFalse,
|