edilkamin 1.10.2 → 1.12.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 (52) hide show
  1. package/dist/cjs/package.json +1 -1
  2. package/dist/cjs/src/bluetooth-protocol.d.ts +178 -0
  3. package/dist/cjs/src/bluetooth-protocol.js +423 -0
  4. package/dist/cjs/src/bluetooth-protocol.test.d.ts +1 -0
  5. package/dist/cjs/src/bluetooth-protocol.test.js +389 -0
  6. package/dist/cjs/src/bluetooth-utils.js +2 -6
  7. package/dist/cjs/src/bluetooth.d.ts +2 -0
  8. package/dist/cjs/src/bluetooth.js +17 -1
  9. package/dist/cjs/src/cli.js +9 -8
  10. package/dist/cjs/src/index.d.ts +4 -3
  11. package/dist/cjs/src/index.js +14 -1
  12. package/dist/cjs/src/library.d.ts +30 -0
  13. package/dist/cjs/src/library.js +97 -3
  14. package/dist/cjs/src/library.test.js +225 -4
  15. package/dist/cjs/src/mac-utils.d.ts +15 -0
  16. package/dist/cjs/src/mac-utils.js +24 -0
  17. package/dist/cjs/src/mac-utils.test.d.ts +1 -0
  18. package/dist/cjs/src/mac-utils.test.js +41 -0
  19. package/dist/cjs/src/types.d.ts +94 -2
  20. package/dist/cjs/src/types.js +95 -1
  21. package/dist/esm/package.json +1 -1
  22. package/dist/esm/src/bluetooth-protocol.d.ts +178 -0
  23. package/dist/esm/src/bluetooth-protocol.js +415 -0
  24. package/dist/esm/src/bluetooth-protocol.test.d.ts +1 -0
  25. package/dist/esm/src/bluetooth-protocol.test.js +387 -0
  26. package/dist/esm/src/bluetooth-utils.js +2 -6
  27. package/dist/esm/src/bluetooth.d.ts +2 -0
  28. package/dist/esm/src/bluetooth.js +8 -0
  29. package/dist/esm/src/cli.js +9 -8
  30. package/dist/esm/src/index.d.ts +4 -3
  31. package/dist/esm/src/index.js +3 -2
  32. package/dist/esm/src/library.d.ts +30 -0
  33. package/dist/esm/src/library.js +94 -2
  34. package/dist/esm/src/library.test.js +226 -5
  35. package/dist/esm/src/mac-utils.d.ts +15 -0
  36. package/dist/esm/src/mac-utils.js +21 -0
  37. package/dist/esm/src/mac-utils.test.d.ts +1 -0
  38. package/dist/esm/src/mac-utils.test.js +39 -0
  39. package/dist/esm/src/types.d.ts +94 -2
  40. package/dist/esm/src/types.js +89 -1
  41. package/package.json +1 -1
  42. package/src/bluetooth-protocol.test.ts +497 -0
  43. package/src/bluetooth-protocol.ts +524 -0
  44. package/src/bluetooth-utils.ts +3 -7
  45. package/src/bluetooth.ts +21 -0
  46. package/src/cli.ts +9 -8
  47. package/src/index.ts +24 -2
  48. package/src/library.test.ts +325 -4
  49. package/src/library.ts +109 -2
  50. package/src/mac-utils.test.ts +60 -0
  51. package/src/mac-utils.ts +22 -0
  52. package/src/types.ts +144 -1
@@ -13,6 +13,8 @@ import * as amplifyAuth from "aws-amplify/auth";
13
13
  import { cognitoUserPoolsTokenProvider } from "aws-amplify/auth/cognito";
14
14
  import { processResponse } from "./buffer-utils";
15
15
  import { API_URL } from "./constants";
16
+ import { normalizeMac } from "./mac-utils";
17
+ import { getIgnitionSubPhaseDescription, getOperationalPhaseDescription, OperationalPhase, } from "./types";
16
18
  /**
17
19
  * Makes a fetch request and returns parsed JSON response.
18
20
  * Throws an error for non-2xx status codes.
@@ -473,6 +475,56 @@ const getPelletAutonomyTime = (baseURL) =>
473
475
  const info = yield deviceInfo(baseURL)(jwtToken, macAddress);
474
476
  return info.status.pellet.autonomy_time;
475
477
  });
478
+ const getOperationalPhase = (baseURL) =>
479
+ /**
480
+ * Retrieves the current operational phase of the stove.
481
+ *
482
+ * @param {string} jwtToken - The JWT token for authentication.
483
+ * @param {string} macAddress - The MAC address of the device.
484
+ * @returns {Promise<number>} - The operational phase (0=Off, 1=Standby, 2=Ignition, 6=On).
485
+ */
486
+ (jwtToken, macAddress) => __awaiter(void 0, void 0, void 0, function* () {
487
+ const info = yield deviceInfo(baseURL)(jwtToken, macAddress);
488
+ return info.status.state.operational_phase;
489
+ });
490
+ const getSubOperationalPhase = (baseURL) =>
491
+ /**
492
+ * Retrieves the current sub-operational phase of the stove.
493
+ * Only meaningful during ignition (operational_phase === 2).
494
+ *
495
+ * @param {string} jwtToken - The JWT token for authentication.
496
+ * @param {string} macAddress - The MAC address of the device.
497
+ * @returns {Promise<number>} - The sub-operational phase (0-6 during ignition).
498
+ */
499
+ (jwtToken, macAddress) => __awaiter(void 0, void 0, void 0, function* () {
500
+ const info = yield deviceInfo(baseURL)(jwtToken, macAddress);
501
+ return info.status.state.sub_operational_phase;
502
+ });
503
+ const getStoveState = (baseURL) =>
504
+ /**
505
+ * Retrieves the combined stove state code.
506
+ *
507
+ * @param {string} jwtToken - The JWT token for authentication.
508
+ * @param {string} macAddress - The MAC address of the device.
509
+ * @returns {Promise<number>} - The stove state code.
510
+ */
511
+ (jwtToken, macAddress) => __awaiter(void 0, void 0, void 0, function* () {
512
+ const info = yield deviceInfo(baseURL)(jwtToken, macAddress);
513
+ return info.status.state.stove_state;
514
+ });
515
+ const getActualPower = (baseURL) =>
516
+ /**
517
+ * Retrieves the actual power level the stove is currently running at.
518
+ * This may differ from the requested power level during transitions.
519
+ *
520
+ * @param {string} jwtToken - The JWT token for authentication.
521
+ * @param {string} macAddress - The MAC address of the device.
522
+ * @returns {Promise<number>} - The actual power level (1-5).
523
+ */
524
+ (jwtToken, macAddress) => __awaiter(void 0, void 0, void 0, function* () {
525
+ const info = yield deviceInfo(baseURL)(jwtToken, macAddress);
526
+ return info.status.state.actual_power;
527
+ });
476
528
  const getTotalCounters = (baseURL) =>
477
529
  /**
478
530
  * Retrieves lifetime operating counters.
@@ -693,7 +745,7 @@ const registerDevice = (baseURL) =>
693
745
  */
694
746
  (jwtToken_1, macAddress_1, serialNumber_1, ...args_1) => __awaiter(void 0, [jwtToken_1, macAddress_1, serialNumber_1, ...args_1], void 0, function* (jwtToken, macAddress, serialNumber, deviceName = "", deviceRoom = "") {
695
747
  const body = {
696
- macAddress: macAddress.replace(/:/g, ""),
748
+ macAddress: normalizeMac(macAddress),
697
749
  deviceName,
698
750
  deviceRoom,
699
751
  serialNumber,
@@ -715,7 +767,7 @@ const editDevice = (baseURL) =>
715
767
  * @returns {Promise<DeviceAssociationResponse>} - A promise that resolves to the update response.
716
768
  */
717
769
  (jwtToken_1, macAddress_1, ...args_1) => __awaiter(void 0, [jwtToken_1, macAddress_1, ...args_1], void 0, function* (jwtToken, macAddress, deviceName = "", deviceRoom = "") {
718
- const normalizedMac = macAddress.replace(/:/g, "");
770
+ const normalizedMac = normalizeMac(macAddress);
719
771
  const body = {
720
772
  deviceName,
721
773
  deviceRoom,
@@ -726,6 +778,41 @@ const editDevice = (baseURL) =>
726
778
  body: JSON.stringify(body),
727
779
  });
728
780
  });
781
+ /**
782
+ * Get human-readable description of the current device phase.
783
+ * Combines operational_phase and sub_operational_phase for context.
784
+ *
785
+ * @param {number} operationalPhase - The main operational phase.
786
+ * @param {number} subOperationalPhase - The sub-phase (used during ignition).
787
+ * @returns {string} - Human-readable phase description.
788
+ *
789
+ * @example
790
+ * const desc = getPhaseDescription(2, 1);
791
+ * // Returns: "Ignition - Pellet load"
792
+ */
793
+ export const getPhaseDescription = (operationalPhase, subOperationalPhase) => {
794
+ if (operationalPhase === OperationalPhase.IGNITION) {
795
+ const subDesc = getIgnitionSubPhaseDescription(subOperationalPhase);
796
+ return `Ignition - ${subDesc}`;
797
+ }
798
+ return getOperationalPhaseDescription(operationalPhase);
799
+ };
800
+ /**
801
+ * Derive phase description from existing DeviceInfo.
802
+ * Pure function - no API calls required.
803
+ *
804
+ * @param {DeviceInfoType} deviceInfo - The device info object.
805
+ * @returns {string} - Human-readable phase description.
806
+ *
807
+ * @example
808
+ * const info = await api.deviceInfo(token, mac);
809
+ * const desc = derivePhaseDescription(info);
810
+ * // Returns: "On" or "Ignition - Warmup" etc.
811
+ */
812
+ export const derivePhaseDescription = (deviceInfo) => {
813
+ const { operational_phase, sub_operational_phase } = deviceInfo.status.state;
814
+ return getPhaseDescription(operational_phase, sub_operational_phase);
815
+ };
729
816
  /**
730
817
  * Configures the library for API interactions.
731
818
  * Initializes API methods with a specified base URL.
@@ -778,6 +865,11 @@ const configure = (baseURL = API_URL) => ({
778
865
  getLanguage: getLanguage(baseURL),
779
866
  getPelletInReserve: getPelletInReserve(baseURL),
780
867
  getPelletAutonomyTime: getPelletAutonomyTime(baseURL),
868
+ // Phase/state getters
869
+ getOperationalPhase: getOperationalPhase(baseURL),
870
+ getSubOperationalPhase: getSubOperationalPhase(baseURL),
871
+ getStoveState: getStoveState(baseURL),
872
+ getActualPower: getActualPower(baseURL),
781
873
  // Statistics getters
782
874
  getTotalCounters: getTotalCounters(baseURL),
783
875
  getServiceCounters: getServiceCounters(baseURL),
@@ -10,7 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { strict as assert } from "assert";
11
11
  import pako from "pako";
12
12
  import sinon from "sinon";
13
- import { configure, createAuthService, deriveUsageAnalytics, } from "../src/library";
13
+ import { configure, createAuthService, derivePhaseDescription, deriveUsageAnalytics, getPhaseDescription, } from "../src/library";
14
+ import { getIgnitionSubPhaseDescription, getOperationalPhaseDescription, getStoveStateDescription, IgnitionSubPhase, OperationalPhase, StoveState, } from "../src/types";
14
15
  import { API_URL } from "./constants";
15
16
  /**
16
17
  * Helper to create a gzip-compressed Buffer object for testing.
@@ -215,6 +216,11 @@ describe("library", () => {
215
216
  "getLanguage",
216
217
  "getPelletInReserve",
217
218
  "getPelletAutonomyTime",
219
+ // Phase/state getters
220
+ "getOperationalPhase",
221
+ "getSubOperationalPhase",
222
+ "getStoveState",
223
+ "getActualPower",
218
224
  // Statistics getters
219
225
  "getTotalCounters",
220
226
  "getServiceCounters",
@@ -598,7 +604,7 @@ describe("library", () => {
598
604
  Authorization: `Bearer ${expectedToken}`,
599
605
  },
600
606
  body: JSON.stringify({
601
- macAddress: "AABBCCDDEEFF",
607
+ macAddress: "aabbccddeeff",
602
608
  deviceName: "Test Stove",
603
609
  deviceRoom: "Living Room",
604
610
  serialNumber: "EDK123",
@@ -606,12 +612,12 @@ describe("library", () => {
606
612
  });
607
613
  assert.deepEqual(result, mockResponseData);
608
614
  }));
609
- it("should normalize MAC address by removing colons", () => __awaiter(void 0, void 0, void 0, function* () {
615
+ it("should normalize MAC address by removing colons and converting to lowercase", () => __awaiter(void 0, void 0, void 0, function* () {
610
616
  fetchStub.resolves(mockResponse({}));
611
617
  const api = configure("https://example.com/api/");
612
618
  yield api.registerDevice(expectedToken, "AA:BB:CC:DD:EE:FF", "EDK123");
613
619
  const body = JSON.parse(fetchStub.firstCall.args[1].body);
614
- assert.equal(body.macAddress, "AABBCCDDEEFF");
620
+ assert.equal(body.macAddress, "aabbccddeeff");
615
621
  }));
616
622
  it("should use empty strings as defaults for name and room", () => __awaiter(void 0, void 0, void 0, function* () {
617
623
  fetchStub.resolves(mockResponse({}));
@@ -634,7 +640,7 @@ describe("library", () => {
634
640
  const api = configure("https://example.com/api/");
635
641
  const result = yield api.editDevice(expectedToken, "AA:BB:CC:DD:EE:FF", "Updated Name", "Basement");
636
642
  assert.ok(fetchStub.calledOnce);
637
- assert.equal(fetchStub.firstCall.args[0], "https://example.com/api/device/AABBCCDDEEFF");
643
+ assert.equal(fetchStub.firstCall.args[0], "https://example.com/api/device/aabbccddeeff");
638
644
  assert.deepEqual(fetchStub.firstCall.args[1], {
639
645
  method: "PUT",
640
646
  headers: {
@@ -1142,6 +1148,221 @@ describe("library", () => {
1142
1148
  assert.equal(analytics.lastMaintenanceDate, null);
1143
1149
  });
1144
1150
  });
1151
+ describe("phase getters", () => {
1152
+ const mockDeviceInfoWithState = {
1153
+ status: {
1154
+ commands: { power: true },
1155
+ temperatures: { board: 25, enviroment: 20 },
1156
+ flags: { is_pellet_in_reserve: false },
1157
+ pellet: { autonomy_time: 900 },
1158
+ counters: { service_time: 1108 },
1159
+ state: {
1160
+ operational_phase: 2,
1161
+ sub_operational_phase: 3,
1162
+ stove_state: 4,
1163
+ alarm_type: 0,
1164
+ actual_power: 3,
1165
+ },
1166
+ fans: { fan_1_speed: 3, fan_2_speed: 0, fan_3_speed: 0 },
1167
+ },
1168
+ nvm: {
1169
+ user_parameters: {
1170
+ language: 1,
1171
+ is_auto: false,
1172
+ is_fahrenheit: false,
1173
+ is_sound_active: false,
1174
+ enviroment_1_temperature: 19,
1175
+ enviroment_2_temperature: 20,
1176
+ enviroment_3_temperature: 20,
1177
+ manual_power: 1,
1178
+ fan_1_ventilation: 3,
1179
+ fan_2_ventilation: 0,
1180
+ fan_3_ventilation: 0,
1181
+ is_standby_active: false,
1182
+ standby_waiting_time: 60,
1183
+ },
1184
+ total_counters: {
1185
+ power_ons: 278,
1186
+ p1_working_time: 833,
1187
+ p2_working_time: 15,
1188
+ p3_working_time: 19,
1189
+ p4_working_time: 8,
1190
+ p5_working_time: 17,
1191
+ },
1192
+ service_counters: {
1193
+ p1_working_time: 100,
1194
+ p2_working_time: 10,
1195
+ p3_working_time: 5,
1196
+ p4_working_time: 2,
1197
+ p5_working_time: 1,
1198
+ },
1199
+ alarms_log: {
1200
+ number: 2,
1201
+ index: 2,
1202
+ alarms: [],
1203
+ },
1204
+ regeneration: {
1205
+ time: 0,
1206
+ last_intervention: 1577836800,
1207
+ daylight_time_flag: 0,
1208
+ blackout_counter: 43,
1209
+ airkare_working_hours_counter: 0,
1210
+ },
1211
+ },
1212
+ };
1213
+ it("should get operational phase", () => __awaiter(void 0, void 0, void 0, function* () {
1214
+ fetchStub.resolves(mockResponse(mockDeviceInfoWithState));
1215
+ const api = configure(API_URL);
1216
+ const result = yield api.getOperationalPhase(expectedToken, "00:11:22:33:44:55");
1217
+ assert.equal(result, 2);
1218
+ }));
1219
+ it("should get sub-operational phase", () => __awaiter(void 0, void 0, void 0, function* () {
1220
+ fetchStub.resolves(mockResponse(mockDeviceInfoWithState));
1221
+ const api = configure(API_URL);
1222
+ const result = yield api.getSubOperationalPhase(expectedToken, "00:11:22:33:44:55");
1223
+ assert.equal(result, 3);
1224
+ }));
1225
+ it("should get stove state", () => __awaiter(void 0, void 0, void 0, function* () {
1226
+ fetchStub.resolves(mockResponse(mockDeviceInfoWithState));
1227
+ const api = configure(API_URL);
1228
+ const result = yield api.getStoveState(expectedToken, "00:11:22:33:44:55");
1229
+ assert.equal(result, 4);
1230
+ }));
1231
+ it("should get actual power", () => __awaiter(void 0, void 0, void 0, function* () {
1232
+ fetchStub.resolves(mockResponse(mockDeviceInfoWithState));
1233
+ const api = configure(API_URL);
1234
+ const result = yield api.getActualPower(expectedToken, "00:11:22:33:44:55");
1235
+ assert.equal(result, 3);
1236
+ }));
1237
+ });
1238
+ describe("getPhaseDescription", () => {
1239
+ it("should return 'Off' for phase 0", () => {
1240
+ assert.equal(getPhaseDescription(0, 0), "Off");
1241
+ });
1242
+ it("should return 'Standby' for phase 1", () => {
1243
+ assert.equal(getPhaseDescription(1, 0), "Standby");
1244
+ });
1245
+ it("should return 'On' for phase 6", () => {
1246
+ assert.equal(getPhaseDescription(6, 0), "On");
1247
+ });
1248
+ it("should return combined description for ignition phase", () => {
1249
+ assert.equal(getPhaseDescription(2, 0), "Ignition - Starting cleaning");
1250
+ assert.equal(getPhaseDescription(2, 1), "Ignition - Pellet load");
1251
+ assert.equal(getPhaseDescription(2, 2), "Ignition - Loading break");
1252
+ assert.equal(getPhaseDescription(2, 3), "Ignition - Smoke temperature check");
1253
+ assert.equal(getPhaseDescription(2, 4), "Ignition - Threshold exceeding check");
1254
+ assert.equal(getPhaseDescription(2, 5), "Ignition - Warmup");
1255
+ assert.equal(getPhaseDescription(2, 6), "Ignition - Starting up");
1256
+ });
1257
+ it("should return fallback for unknown operational phase", () => {
1258
+ assert.equal(getPhaseDescription(99, 0), "Unknown phase (99)");
1259
+ });
1260
+ it("should return fallback for unknown ignition sub-phase", () => {
1261
+ assert.equal(getPhaseDescription(2, 99), "Ignition - Unknown sub-phase (99)");
1262
+ });
1263
+ });
1264
+ describe("derivePhaseDescription", () => {
1265
+ it("should derive phase description from device info", () => {
1266
+ const mockDeviceInfo = {
1267
+ status: {
1268
+ commands: { power: true },
1269
+ temperatures: { board: 25, enviroment: 22 },
1270
+ flags: { is_pellet_in_reserve: true },
1271
+ pellet: { autonomy_time: 120 },
1272
+ counters: { service_time: 100 },
1273
+ state: {
1274
+ operational_phase: 2,
1275
+ sub_operational_phase: 5,
1276
+ stove_state: 5,
1277
+ alarm_type: 0,
1278
+ actual_power: 3,
1279
+ },
1280
+ fans: { fan_1_speed: 3, fan_2_speed: 0, fan_3_speed: 0 },
1281
+ },
1282
+ nvm: {
1283
+ user_parameters: {},
1284
+ total_counters: {},
1285
+ service_counters: {},
1286
+ alarms_log: { number: 0, index: 0, alarms: [] },
1287
+ regeneration: {},
1288
+ },
1289
+ };
1290
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1291
+ const desc = derivePhaseDescription(mockDeviceInfo);
1292
+ assert.equal(desc, "Ignition - Warmup");
1293
+ });
1294
+ it("should return 'On' for device in On state", () => {
1295
+ const mockDeviceInfo = {
1296
+ status: {
1297
+ commands: { power: true },
1298
+ temperatures: { board: 25, enviroment: 22 },
1299
+ flags: { is_pellet_in_reserve: false },
1300
+ pellet: { autonomy_time: 120 },
1301
+ counters: { service_time: 100 },
1302
+ state: {
1303
+ operational_phase: 6,
1304
+ sub_operational_phase: 0,
1305
+ stove_state: 6,
1306
+ alarm_type: 0,
1307
+ actual_power: 3,
1308
+ },
1309
+ fans: { fan_1_speed: 3, fan_2_speed: 0, fan_3_speed: 0 },
1310
+ },
1311
+ nvm: {
1312
+ user_parameters: {},
1313
+ total_counters: {},
1314
+ service_counters: {},
1315
+ alarms_log: { number: 0, index: 0, alarms: [] },
1316
+ regeneration: {},
1317
+ },
1318
+ };
1319
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1320
+ const desc = derivePhaseDescription(mockDeviceInfo);
1321
+ assert.equal(desc, "On");
1322
+ });
1323
+ });
1324
+ describe("OperationalPhase descriptions", () => {
1325
+ it("should return descriptions for known phases", () => {
1326
+ assert.equal(getOperationalPhaseDescription(OperationalPhase.OFF), "Off");
1327
+ assert.equal(getOperationalPhaseDescription(OperationalPhase.STANDBY), "Standby");
1328
+ assert.equal(getOperationalPhaseDescription(OperationalPhase.IGNITION), "Ignition");
1329
+ assert.equal(getOperationalPhaseDescription(OperationalPhase.ON), "On");
1330
+ });
1331
+ it("should return fallback for unknown phases", () => {
1332
+ assert.equal(getOperationalPhaseDescription(3), "Unknown phase (3)");
1333
+ assert.equal(getOperationalPhaseDescription(99), "Unknown phase (99)");
1334
+ });
1335
+ });
1336
+ describe("IgnitionSubPhase descriptions", () => {
1337
+ it("should return descriptions for all ignition sub-phases", () => {
1338
+ assert.equal(getIgnitionSubPhaseDescription(IgnitionSubPhase.STARTING_CLEANING), "Starting cleaning");
1339
+ assert.equal(getIgnitionSubPhaseDescription(IgnitionSubPhase.PELLET_LOAD), "Pellet load");
1340
+ assert.equal(getIgnitionSubPhaseDescription(IgnitionSubPhase.LOADING_BREAK), "Loading break");
1341
+ assert.equal(getIgnitionSubPhaseDescription(IgnitionSubPhase.SMOKE_TEMPERATURE_CHECK), "Smoke temperature check");
1342
+ assert.equal(getIgnitionSubPhaseDescription(IgnitionSubPhase.THRESHOLD_EXCEEDING_CHECK), "Threshold exceeding check");
1343
+ assert.equal(getIgnitionSubPhaseDescription(IgnitionSubPhase.WARMUP), "Warmup");
1344
+ assert.equal(getIgnitionSubPhaseDescription(IgnitionSubPhase.TRANSITION_TO_ON), "Starting up");
1345
+ });
1346
+ it("should return fallback for unknown sub-phases", () => {
1347
+ assert.equal(getIgnitionSubPhaseDescription(99), "Unknown sub-phase (99)");
1348
+ });
1349
+ });
1350
+ describe("StoveState descriptions", () => {
1351
+ it("should return descriptions for known states", () => {
1352
+ assert.equal(getStoveStateDescription(StoveState.OFF), "Off");
1353
+ assert.equal(getStoveStateDescription(StoveState.STANDBY), "Standby");
1354
+ assert.equal(getStoveStateDescription(StoveState.IGNITION_CLEANING), "Ignition - Cleaning");
1355
+ assert.equal(getStoveStateDescription(StoveState.IGNITION_LOADING), "Ignition - Loading pellets");
1356
+ assert.equal(getStoveStateDescription(StoveState.IGNITION_WAITING), "Ignition - Waiting");
1357
+ assert.equal(getStoveStateDescription(StoveState.IGNITION_WARMUP), "Ignition - Warming up");
1358
+ assert.equal(getStoveStateDescription(StoveState.ON), "On");
1359
+ assert.equal(getStoveStateDescription(StoveState.COOLING), "Cooling down");
1360
+ assert.equal(getStoveStateDescription(StoveState.ALARM), "Alarm");
1361
+ });
1362
+ it("should return fallback for unknown states", () => {
1363
+ assert.equal(getStoveStateDescription(99), "Unknown state (99)");
1364
+ });
1365
+ });
1145
1366
  describe("Error Handling", () => {
1146
1367
  const errorTests = [
1147
1368
  { status: 400, statusText: "Bad Request" },
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Normalizes a MAC address by removing separators and converting to lowercase.
3
+ * Accepts formats: AA:BB:CC:DD:EE:FF, AA-BB-CC-DD-EE-FF, AABBCCDDEEFF
4
+ *
5
+ * @param mac - MAC address in any common format
6
+ * @returns Normalized MAC address (12 lowercase hex chars, no separators)
7
+ * @throws Error if MAC address format is invalid
8
+ *
9
+ * @example
10
+ * normalizeMac("AA:BB:CC:DD:EE:FF") // returns "aabbccddeeff"
11
+ * normalizeMac("AA-BB-CC-DD-EE-FF") // returns "aabbccddeeff"
12
+ * normalizeMac("AABBCCDDEEFF") // returns "aabbccddeeff"
13
+ */
14
+ declare const normalizeMac: (mac: string) => string;
15
+ export { normalizeMac };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Normalizes a MAC address by removing separators and converting to lowercase.
3
+ * Accepts formats: AA:BB:CC:DD:EE:FF, AA-BB-CC-DD-EE-FF, AABBCCDDEEFF
4
+ *
5
+ * @param mac - MAC address in any common format
6
+ * @returns Normalized MAC address (12 lowercase hex chars, no separators)
7
+ * @throws Error if MAC address format is invalid
8
+ *
9
+ * @example
10
+ * normalizeMac("AA:BB:CC:DD:EE:FF") // returns "aabbccddeeff"
11
+ * normalizeMac("AA-BB-CC-DD-EE-FF") // returns "aabbccddeeff"
12
+ * normalizeMac("AABBCCDDEEFF") // returns "aabbccddeeff"
13
+ */
14
+ const normalizeMac = (mac) => {
15
+ const normalized = mac.replace(/[:-]/g, "").toLowerCase();
16
+ if (!/^[0-9a-f]{12}$/.test(normalized)) {
17
+ throw new Error(`Invalid MAC address format: ${mac}`);
18
+ }
19
+ return normalized;
20
+ };
21
+ export { normalizeMac };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,39 @@
1
+ import { strict as assert } from "assert";
2
+ import { normalizeMac } from "./mac-utils";
3
+ describe("mac-utils", () => {
4
+ describe("normalizeMac", () => {
5
+ it("should normalize MAC address with colons", () => {
6
+ assert.equal(normalizeMac("AA:BB:CC:DD:EE:FF"), "aabbccddeeff");
7
+ });
8
+ it("should normalize MAC address with dashes", () => {
9
+ assert.equal(normalizeMac("AA-BB-CC-DD-EE-FF"), "aabbccddeeff");
10
+ });
11
+ it("should normalize MAC address without separators", () => {
12
+ assert.equal(normalizeMac("AABBCCDDEEFF"), "aabbccddeeff");
13
+ });
14
+ it("should normalize lowercase MAC address", () => {
15
+ assert.equal(normalizeMac("aa:bb:cc:dd:ee:ff"), "aabbccddeeff");
16
+ });
17
+ it("should normalize mixed case MAC address", () => {
18
+ assert.equal(normalizeMac("Aa:Bb:Cc:Dd:Ee:Ff"), "aabbccddeeff");
19
+ });
20
+ it("should normalize MAC address with mixed separators", () => {
21
+ assert.equal(normalizeMac("AA:BB-CC:DD-EE:FF"), "aabbccddeeff");
22
+ });
23
+ it("should throw on MAC address with invalid length (too short)", () => {
24
+ assert.throws(() => normalizeMac("AA:BB:CC:DD:EE"), /Invalid MAC address format: AA:BB:CC:DD:EE/);
25
+ });
26
+ it("should throw on MAC address with invalid length (too long)", () => {
27
+ assert.throws(() => normalizeMac("AA:BB:CC:DD:EE:FF:00"), /Invalid MAC address format: AA:BB:CC:DD:EE:FF:00/);
28
+ });
29
+ it("should throw on MAC address with invalid characters", () => {
30
+ assert.throws(() => normalizeMac("GG:HH:II:JJ:KK:LL"), /Invalid MAC address format: GG:HH:II:JJ:KK:LL/);
31
+ });
32
+ it("should throw on empty string", () => {
33
+ assert.throws(() => normalizeMac(""), /Invalid MAC address format: /);
34
+ });
35
+ it("should throw on whitespace-only string", () => {
36
+ assert.throws(() => normalizeMac(" "), /Invalid MAC address format:/);
37
+ });
38
+ });
39
+ });
@@ -25,12 +25,42 @@ interface PelletAutonomyType {
25
25
  interface StatusCountersType {
26
26
  service_time: number;
27
27
  }
28
+ /**
29
+ * Device operational state information.
30
+ * Retrieved from status.state in the API response.
31
+ */
32
+ interface StateType {
33
+ /** Main operational phase (0=Off, 1=Standby, 2=Ignition, 6=On) */
34
+ operational_phase: number;
35
+ /** Sub-phase within current operation (0-6 during ignition) */
36
+ sub_operational_phase: number;
37
+ /** Combined stove state code */
38
+ stove_state: number;
39
+ /** Current alarm code (0 = no alarm) */
40
+ alarm_type: number;
41
+ /** Current actual power level (1-5) */
42
+ actual_power: number;
43
+ }
44
+ /**
45
+ * Fan speed information for all three fans.
46
+ * Retrieved from status.fans in the API response.
47
+ */
48
+ interface FansType {
49
+ /** Fan 1 speed (0-5) */
50
+ fan_1_speed: number;
51
+ /** Fan 2 speed (0-5) */
52
+ fan_2_speed: number;
53
+ /** Fan 3 speed (0-5) */
54
+ fan_3_speed: number;
55
+ }
28
56
  interface StatusType {
29
57
  commands: CommandsType;
30
58
  temperatures: TemperaturesType;
31
59
  flags: GeneralFlagsType;
32
60
  pellet: PelletAutonomyType;
33
61
  counters: StatusCountersType;
62
+ state: StateType;
63
+ fans: FansType;
34
64
  }
35
65
  interface UserParametersType {
36
66
  enviroment_1_temperature: number;
@@ -161,6 +191,68 @@ declare enum AlarmCode {
161
191
  * Human-readable descriptions for alarm codes.
162
192
  */
163
193
  declare const AlarmDescriptions: Record<AlarmCode, string>;
194
+ /**
195
+ * Main operational phases of the stove.
196
+ * Values derived from device behavior observation.
197
+ */
198
+ declare enum OperationalPhase {
199
+ OFF = 0,
200
+ STANDBY = 1,
201
+ IGNITION = 2,
202
+ ON = 6
203
+ }
204
+ /**
205
+ * Human-readable descriptions for operational phases.
206
+ */
207
+ declare const OperationalPhaseDescriptions: Record<number, string>;
208
+ /**
209
+ * Get description for an operational phase, with fallback for unknown values.
210
+ */
211
+ declare const getOperationalPhaseDescription: (phase: number) => string;
212
+ /**
213
+ * Sub-phases during ignition sequence.
214
+ * These are only meaningful when operational_phase === IGNITION.
215
+ */
216
+ declare enum IgnitionSubPhase {
217
+ STARTING_CLEANING = 0,
218
+ PELLET_LOAD = 1,
219
+ LOADING_BREAK = 2,
220
+ SMOKE_TEMPERATURE_CHECK = 3,
221
+ THRESHOLD_EXCEEDING_CHECK = 4,
222
+ WARMUP = 5,
223
+ TRANSITION_TO_ON = 6
224
+ }
225
+ /**
226
+ * Human-readable descriptions for ignition sub-phases.
227
+ */
228
+ declare const IgnitionSubPhaseDescriptions: Record<number, string>;
229
+ /**
230
+ * Get description for an ignition sub-phase, with fallback for unknown values.
231
+ */
232
+ declare const getIgnitionSubPhaseDescription: (subPhase: number) => string;
233
+ /**
234
+ * Combined stove states.
235
+ * This is a composite value combining operational phase and sub-phase.
236
+ */
237
+ declare enum StoveState {
238
+ OFF = 0,
239
+ STANDBY = 1,
240
+ IGNITION_CLEANING = 2,
241
+ IGNITION_LOADING = 3,
242
+ IGNITION_WAITING = 4,
243
+ IGNITION_WARMUP = 5,
244
+ ON = 6,
245
+ COOLING = 7,
246
+ ALARM = 8
247
+ }
248
+ /**
249
+ * Human-readable descriptions for stove states.
250
+ */
251
+ declare const StoveStateDescriptions: Record<number, string>;
252
+ /**
253
+ * Get description for a stove state, with fallback for unknown values.
254
+ */
255
+ declare const getStoveStateDescription: (state: number) => string;
164
256
  interface DeviceInfoType {
165
257
  status: StatusType;
166
258
  nvm: {
@@ -224,5 +316,5 @@ interface DiscoveredDevice {
224
316
  /** Signal strength in dBm (optional, not all platforms provide this) */
225
317
  rssi?: number;
226
318
  }
227
- export type { AlarmEntryType, AlarmsLogType, BufferEncodedType, CommandsType, DeviceAssociationBody, DeviceAssociationResponse, DeviceInfoRawType, DeviceInfoType, DiscoveredDevice, EditDeviceAssociationBody, GeneralFlagsType, PelletAutonomyType, PowerDistributionType, RegenerationDataType, ServiceCountersType, ServiceStatusType, StatusCountersType, StatusType, TemperaturesType, TotalCountersType, UsageAnalyticsType, UserParametersType, };
228
- export { AlarmCode, AlarmDescriptions };
319
+ export type { AlarmEntryType, AlarmsLogType, BufferEncodedType, CommandsType, DeviceAssociationBody, DeviceAssociationResponse, DeviceInfoRawType, DeviceInfoType, DiscoveredDevice, EditDeviceAssociationBody, FansType, GeneralFlagsType, PelletAutonomyType, PowerDistributionType, RegenerationDataType, ServiceCountersType, ServiceStatusType, StateType, StatusCountersType, StatusType, TemperaturesType, TotalCountersType, UsageAnalyticsType, UserParametersType, };
320
+ export { AlarmCode, AlarmDescriptions, getIgnitionSubPhaseDescription, getOperationalPhaseDescription, getStoveStateDescription, IgnitionSubPhase, IgnitionSubPhaseDescriptions, OperationalPhase, OperationalPhaseDescriptions, StoveState, StoveStateDescriptions, };