edilkamin 1.9.0 → 1.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/src/cli.js +209 -6
- package/dist/cjs/src/index.d.ts +3 -2
- package/dist/cjs/src/index.js +4 -1
- package/dist/cjs/src/library.d.ts +16 -3
- package/dist/cjs/src/library.js +248 -117
- package/dist/cjs/src/library.test.js +230 -3
- package/dist/cjs/src/types.d.ts +127 -1
- package/dist/cjs/src/types.js +64 -0
- package/dist/esm/package.json +1 -1
- package/dist/esm/src/cli.js +209 -6
- package/dist/esm/src/index.d.ts +3 -2
- package/dist/esm/src/index.js +1 -0
- package/dist/esm/src/library.d.ts +16 -3
- package/dist/esm/src/library.js +248 -117
- package/dist/esm/src/library.test.js +230 -3
- package/dist/esm/src/types.d.ts +127 -1
- package/dist/esm/src/types.js +63 -1
- package/package.json +1 -1
- package/src/cli.ts +332 -6
- package/src/index.ts +10 -0
- package/src/library.test.ts +297 -2
- package/src/library.ts +343 -121
- package/src/types.ts +180 -0
package/src/library.ts
CHANGED
|
@@ -6,11 +6,18 @@ import { cognitoUserPoolsTokenProvider } from "aws-amplify/auth/cognito";
|
|
|
6
6
|
import { processResponse } from "./buffer-utils";
|
|
7
7
|
import { API_URL } from "./constants";
|
|
8
8
|
import {
|
|
9
|
+
AlarmsLogType,
|
|
9
10
|
DeviceAssociationBody,
|
|
10
11
|
DeviceAssociationResponse,
|
|
11
12
|
DeviceInfoRawType,
|
|
12
13
|
DeviceInfoType,
|
|
13
14
|
EditDeviceAssociationBody,
|
|
15
|
+
PowerDistributionType,
|
|
16
|
+
RegenerationDataType,
|
|
17
|
+
ServiceCountersType,
|
|
18
|
+
ServiceStatusType,
|
|
19
|
+
TotalCountersType,
|
|
20
|
+
UsageAnalyticsType,
|
|
14
21
|
} from "./types";
|
|
15
22
|
|
|
16
23
|
/**
|
|
@@ -236,95 +243,71 @@ const getPowerLevel =
|
|
|
236
243
|
return info.nvm.user_parameters.manual_power;
|
|
237
244
|
};
|
|
238
245
|
|
|
239
|
-
const
|
|
246
|
+
const setFanSpeed =
|
|
240
247
|
(baseURL: string) =>
|
|
241
248
|
/**
|
|
242
|
-
* Sets the speed of fan
|
|
249
|
+
* Sets the speed of a fan by index.
|
|
243
250
|
*
|
|
244
251
|
* @param {string} jwtToken - The JWT token for authentication.
|
|
245
252
|
* @param {string} macAddress - The MAC address of the device.
|
|
253
|
+
* @param {1 | 2 | 3} fanIndex - The fan index (1, 2, or 3).
|
|
246
254
|
* @param {number} speed - The fan speed (0-5, 0=auto on some models).
|
|
247
255
|
* @returns {Promise<unknown>} - A promise that resolves to the command response.
|
|
248
256
|
*/
|
|
249
|
-
(jwtToken: string, macAddress: string, speed: number) =>
|
|
257
|
+
(jwtToken: string, macAddress: string, fanIndex: 1 | 2 | 3, speed: number) =>
|
|
250
258
|
mqttCommand(baseURL)(jwtToken, macAddress, {
|
|
251
|
-
name:
|
|
259
|
+
name: `fan_${fanIndex}_speed`,
|
|
252
260
|
value: speed,
|
|
253
261
|
});
|
|
254
262
|
|
|
255
|
-
const
|
|
263
|
+
const getFanSpeed =
|
|
256
264
|
(baseURL: string) =>
|
|
257
265
|
/**
|
|
258
|
-
*
|
|
266
|
+
* Retrieves the current speed of a fan by index.
|
|
259
267
|
*
|
|
260
268
|
* @param {string} jwtToken - The JWT token for authentication.
|
|
261
269
|
* @param {string} macAddress - The MAC address of the device.
|
|
262
|
-
* @param {
|
|
263
|
-
* @returns {Promise<
|
|
270
|
+
* @param {1 | 2 | 3} fanIndex - The fan index (1, 2, or 3).
|
|
271
|
+
* @returns {Promise<number>} - A promise that resolves to the fan speed.
|
|
264
272
|
*/
|
|
265
|
-
(
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
273
|
+
async (
|
|
274
|
+
jwtToken: string,
|
|
275
|
+
macAddress: string,
|
|
276
|
+
fanIndex: 1 | 2 | 3,
|
|
277
|
+
): Promise<number> => {
|
|
278
|
+
const info = await deviceInfo(baseURL)(jwtToken, macAddress);
|
|
279
|
+
const fields: Record<1 | 2 | 3, number> = {
|
|
280
|
+
1: info.nvm.user_parameters.fan_1_ventilation,
|
|
281
|
+
2: info.nvm.user_parameters.fan_2_ventilation,
|
|
282
|
+
3: info.nvm.user_parameters.fan_3_ventilation,
|
|
283
|
+
};
|
|
284
|
+
return fields[fanIndex];
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
// Fan speed aliases for convenience
|
|
288
|
+
const setFan1Speed =
|
|
289
|
+
(baseURL: string) => (jwtToken: string, macAddress: string, speed: number) =>
|
|
290
|
+
setFanSpeed(baseURL)(jwtToken, macAddress, 1, speed);
|
|
291
|
+
|
|
292
|
+
const setFan2Speed =
|
|
293
|
+
(baseURL: string) => (jwtToken: string, macAddress: string, speed: number) =>
|
|
294
|
+
setFanSpeed(baseURL)(jwtToken, macAddress, 2, speed);
|
|
270
295
|
|
|
271
296
|
const setFan3Speed =
|
|
272
|
-
(baseURL: string) =>
|
|
273
|
-
|
|
274
|
-
* Sets the speed of fan 3.
|
|
275
|
-
*
|
|
276
|
-
* @param {string} jwtToken - The JWT token for authentication.
|
|
277
|
-
* @param {string} macAddress - The MAC address of the device.
|
|
278
|
-
* @param {number} speed - The fan speed (0-5, 0=auto on some models).
|
|
279
|
-
* @returns {Promise<unknown>} - A promise that resolves to the command response.
|
|
280
|
-
*/
|
|
281
|
-
(jwtToken: string, macAddress: string, speed: number) =>
|
|
282
|
-
mqttCommand(baseURL)(jwtToken, macAddress, {
|
|
283
|
-
name: "fan_3_speed",
|
|
284
|
-
value: speed,
|
|
285
|
-
});
|
|
297
|
+
(baseURL: string) => (jwtToken: string, macAddress: string, speed: number) =>
|
|
298
|
+
setFanSpeed(baseURL)(jwtToken, macAddress, 3, speed);
|
|
286
299
|
|
|
287
300
|
const getFan1Speed =
|
|
288
|
-
(baseURL: string) =>
|
|
289
|
-
|
|
290
|
-
* Retrieves the current speed of fan 1.
|
|
291
|
-
*
|
|
292
|
-
* @param {string} jwtToken - The JWT token for authentication.
|
|
293
|
-
* @param {string} macAddress - The MAC address of the device.
|
|
294
|
-
* @returns {Promise<number>} - A promise that resolves to the fan speed.
|
|
295
|
-
*/
|
|
296
|
-
async (jwtToken: string, macAddress: string): Promise<number> => {
|
|
297
|
-
const info = await deviceInfo(baseURL)(jwtToken, macAddress);
|
|
298
|
-
return info.nvm.user_parameters.fan_1_ventilation;
|
|
299
|
-
};
|
|
301
|
+
(baseURL: string) => (jwtToken: string, macAddress: string) =>
|
|
302
|
+
getFanSpeed(baseURL)(jwtToken, macAddress, 1);
|
|
300
303
|
|
|
301
304
|
const getFan2Speed =
|
|
302
|
-
(baseURL: string) =>
|
|
303
|
-
|
|
304
|
-
* Retrieves the current speed of fan 2.
|
|
305
|
-
*
|
|
306
|
-
* @param {string} jwtToken - The JWT token for authentication.
|
|
307
|
-
* @param {string} macAddress - The MAC address of the device.
|
|
308
|
-
* @returns {Promise<number>} - A promise that resolves to the fan speed.
|
|
309
|
-
*/
|
|
310
|
-
async (jwtToken: string, macAddress: string): Promise<number> => {
|
|
311
|
-
const info = await deviceInfo(baseURL)(jwtToken, macAddress);
|
|
312
|
-
return info.nvm.user_parameters.fan_2_ventilation;
|
|
313
|
-
};
|
|
305
|
+
(baseURL: string) => (jwtToken: string, macAddress: string) =>
|
|
306
|
+
getFanSpeed(baseURL)(jwtToken, macAddress, 2);
|
|
314
307
|
|
|
315
308
|
const getFan3Speed =
|
|
316
|
-
(baseURL: string) =>
|
|
317
|
-
|
|
318
|
-
* Retrieves the current speed of fan 3.
|
|
319
|
-
*
|
|
320
|
-
* @param {string} jwtToken - The JWT token for authentication.
|
|
321
|
-
* @param {string} macAddress - The MAC address of the device.
|
|
322
|
-
* @returns {Promise<number>} - A promise that resolves to the fan speed.
|
|
323
|
-
*/
|
|
324
|
-
async (jwtToken: string, macAddress: string): Promise<number> => {
|
|
325
|
-
const info = await deviceInfo(baseURL)(jwtToken, macAddress);
|
|
326
|
-
return info.nvm.user_parameters.fan_3_ventilation;
|
|
327
|
-
};
|
|
309
|
+
(baseURL: string) => (jwtToken: string, macAddress: string) =>
|
|
310
|
+
getFanSpeed(baseURL)(jwtToken, macAddress, 3);
|
|
328
311
|
|
|
329
312
|
const setAirkare =
|
|
330
313
|
(baseURL: string) =>
|
|
@@ -479,92 +462,76 @@ const getEnvironmentTemperature =
|
|
|
479
462
|
const getTargetTemperature =
|
|
480
463
|
(baseURL: string) =>
|
|
481
464
|
/**
|
|
482
|
-
* Retrieves the target temperature
|
|
465
|
+
* Retrieves the target temperature for an environment zone.
|
|
483
466
|
*
|
|
484
467
|
* @param {string} jwtToken - The JWT token for authentication.
|
|
485
468
|
* @param {string} macAddress - The MAC address of the device.
|
|
486
|
-
* @
|
|
469
|
+
* @param {1 | 2 | 3} envIndex - The environment zone index (1, 2, or 3).
|
|
470
|
+
* @returns {Promise<number>} - A promise that resolves to the target temperature (degrees Celsius).
|
|
487
471
|
*/
|
|
488
|
-
async (
|
|
472
|
+
async (
|
|
473
|
+
jwtToken: string,
|
|
474
|
+
macAddress: string,
|
|
475
|
+
envIndex: 1 | 2 | 3,
|
|
476
|
+
): Promise<number> => {
|
|
489
477
|
const info = await deviceInfo(baseURL)(jwtToken, macAddress);
|
|
490
|
-
|
|
478
|
+
const fields: Record<1 | 2 | 3, number> = {
|
|
479
|
+
1: info.nvm.user_parameters.enviroment_1_temperature,
|
|
480
|
+
2: info.nvm.user_parameters.enviroment_2_temperature,
|
|
481
|
+
3: info.nvm.user_parameters.enviroment_3_temperature,
|
|
482
|
+
};
|
|
483
|
+
return fields[envIndex];
|
|
491
484
|
};
|
|
492
485
|
|
|
493
486
|
const setTargetTemperature =
|
|
494
487
|
(baseURL: string) =>
|
|
495
488
|
/**
|
|
496
|
-
*
|
|
489
|
+
* Sets the target temperature for an environment zone.
|
|
497
490
|
*
|
|
498
491
|
* @param {string} jwtToken - The JWT token for authentication.
|
|
499
492
|
* @param {string} macAddress - The MAC address of the device.
|
|
500
|
-
* @param {
|
|
501
|
-
* @
|
|
493
|
+
* @param {1 | 2 | 3} envIndex - The environment zone index (1, 2, or 3).
|
|
494
|
+
* @param {number} temperature - The desired target temperature (degrees Celsius).
|
|
495
|
+
* @returns {Promise<unknown>} - A promise that resolves to the command response.
|
|
502
496
|
*/
|
|
503
|
-
(
|
|
497
|
+
(
|
|
498
|
+
jwtToken: string,
|
|
499
|
+
macAddress: string,
|
|
500
|
+
envIndex: 1 | 2 | 3,
|
|
501
|
+
temperature: number,
|
|
502
|
+
) =>
|
|
504
503
|
mqttCommand(baseURL)(jwtToken, macAddress, {
|
|
505
|
-
name:
|
|
504
|
+
name: `enviroment_${envIndex}_temperature`,
|
|
506
505
|
value: temperature,
|
|
507
506
|
});
|
|
508
507
|
|
|
509
|
-
|
|
508
|
+
// Environment temperature aliases for convenience
|
|
509
|
+
const setEnvironment1Temperature =
|
|
510
510
|
(baseURL: string) =>
|
|
511
|
-
/**
|
|
512
|
-
* Sets the target temperature for Environment 2 zone.
|
|
513
|
-
*
|
|
514
|
-
* @param {string} jwtToken - The JWT token for authentication.
|
|
515
|
-
* @param {string} macAddress - The MAC address of the device.
|
|
516
|
-
* @param {number} temperature - The target temperature in degrees Celsius.
|
|
517
|
-
* @returns {Promise<unknown>} - A promise that resolves to the command response.
|
|
518
|
-
*/
|
|
519
511
|
(jwtToken: string, macAddress: string, temperature: number) =>
|
|
520
|
-
|
|
521
|
-
name: "enviroment_2_temperature",
|
|
522
|
-
value: temperature,
|
|
523
|
-
});
|
|
512
|
+
setTargetTemperature(baseURL)(jwtToken, macAddress, 1, temperature);
|
|
524
513
|
|
|
525
|
-
const
|
|
514
|
+
const setEnvironment2Temperature =
|
|
526
515
|
(baseURL: string) =>
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
*
|
|
530
|
-
* @param {string} jwtToken - The JWT token for authentication.
|
|
531
|
-
* @param {string} macAddress - The MAC address of the device.
|
|
532
|
-
* @returns {Promise<number>} - A promise that resolves to the temperature in degrees Celsius.
|
|
533
|
-
*/
|
|
534
|
-
async (jwtToken: string, macAddress: string): Promise<number> => {
|
|
535
|
-
const info = await deviceInfo(baseURL)(jwtToken, macAddress);
|
|
536
|
-
return info.nvm.user_parameters.enviroment_2_temperature;
|
|
537
|
-
};
|
|
516
|
+
(jwtToken: string, macAddress: string, temperature: number) =>
|
|
517
|
+
setTargetTemperature(baseURL)(jwtToken, macAddress, 2, temperature);
|
|
538
518
|
|
|
539
519
|
const setEnvironment3Temperature =
|
|
540
520
|
(baseURL: string) =>
|
|
541
|
-
/**
|
|
542
|
-
* Sets the target temperature for Environment 3 zone.
|
|
543
|
-
*
|
|
544
|
-
* @param {string} jwtToken - The JWT token for authentication.
|
|
545
|
-
* @param {string} macAddress - The MAC address of the device.
|
|
546
|
-
* @param {number} temperature - The target temperature in degrees Celsius.
|
|
547
|
-
* @returns {Promise<unknown>} - A promise that resolves to the command response.
|
|
548
|
-
*/
|
|
549
521
|
(jwtToken: string, macAddress: string, temperature: number) =>
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
522
|
+
setTargetTemperature(baseURL)(jwtToken, macAddress, 3, temperature);
|
|
523
|
+
|
|
524
|
+
const getEnvironment1Temperature =
|
|
525
|
+
(baseURL: string) => (jwtToken: string, macAddress: string) =>
|
|
526
|
+
getTargetTemperature(baseURL)(jwtToken, macAddress, 1);
|
|
527
|
+
|
|
528
|
+
const getEnvironment2Temperature =
|
|
529
|
+
(baseURL: string) => (jwtToken: string, macAddress: string) =>
|
|
530
|
+
getTargetTemperature(baseURL)(jwtToken, macAddress, 2);
|
|
554
531
|
|
|
555
532
|
const getEnvironment3Temperature =
|
|
556
|
-
(baseURL: string) =>
|
|
557
|
-
|
|
558
|
-
* Retrieves the target temperature for Environment 3 zone.
|
|
559
|
-
*
|
|
560
|
-
* @param {string} jwtToken - The JWT token for authentication.
|
|
561
|
-
* @param {string} macAddress - The MAC address of the device.
|
|
562
|
-
* @returns {Promise<number>} - A promise that resolves to the temperature in degrees Celsius.
|
|
563
|
-
*/
|
|
564
|
-
async (jwtToken: string, macAddress: string): Promise<number> => {
|
|
565
|
-
const info = await deviceInfo(baseURL)(jwtToken, macAddress);
|
|
566
|
-
return info.nvm.user_parameters.enviroment_3_temperature;
|
|
567
|
-
};
|
|
533
|
+
(baseURL: string) => (jwtToken: string, macAddress: string) =>
|
|
534
|
+
getTargetTemperature(baseURL)(jwtToken, macAddress, 3);
|
|
568
535
|
|
|
569
536
|
const setMeasureUnit =
|
|
570
537
|
(baseURL: string) =>
|
|
@@ -664,6 +631,246 @@ const getPelletAutonomyTime =
|
|
|
664
631
|
return info.status.pellet.autonomy_time;
|
|
665
632
|
};
|
|
666
633
|
|
|
634
|
+
const getTotalCounters =
|
|
635
|
+
(baseURL: string) =>
|
|
636
|
+
/**
|
|
637
|
+
* Retrieves lifetime operating counters.
|
|
638
|
+
* Includes power-on count and runtime hours per power level.
|
|
639
|
+
* These counters are never reset.
|
|
640
|
+
*
|
|
641
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
642
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
643
|
+
* @returns {Promise<TotalCountersType>} - Lifetime operating statistics.
|
|
644
|
+
*/
|
|
645
|
+
async (jwtToken: string, macAddress: string): Promise<TotalCountersType> => {
|
|
646
|
+
const info = await deviceInfo(baseURL)(jwtToken, macAddress);
|
|
647
|
+
return info.nvm.total_counters;
|
|
648
|
+
};
|
|
649
|
+
|
|
650
|
+
const getServiceCounters =
|
|
651
|
+
(baseURL: string) =>
|
|
652
|
+
/**
|
|
653
|
+
* Retrieves service counters (runtime since last maintenance).
|
|
654
|
+
* These counters track hours per power level since last service reset.
|
|
655
|
+
*
|
|
656
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
657
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
658
|
+
* @returns {Promise<ServiceCountersType>} - Service tracking statistics.
|
|
659
|
+
*/
|
|
660
|
+
async (
|
|
661
|
+
jwtToken: string,
|
|
662
|
+
macAddress: string,
|
|
663
|
+
): Promise<ServiceCountersType> => {
|
|
664
|
+
const info = await deviceInfo(baseURL)(jwtToken, macAddress);
|
|
665
|
+
return info.nvm.service_counters;
|
|
666
|
+
};
|
|
667
|
+
|
|
668
|
+
const getAlarmHistory =
|
|
669
|
+
(baseURL: string) =>
|
|
670
|
+
/**
|
|
671
|
+
* Retrieves the alarm history log.
|
|
672
|
+
* Contains a circular buffer of recent alarms with timestamps.
|
|
673
|
+
*
|
|
674
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
675
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
676
|
+
* @returns {Promise<AlarmsLogType>} - Alarm history log.
|
|
677
|
+
*/
|
|
678
|
+
async (jwtToken: string, macAddress: string): Promise<AlarmsLogType> => {
|
|
679
|
+
const info = await deviceInfo(baseURL)(jwtToken, macAddress);
|
|
680
|
+
return info.nvm.alarms_log;
|
|
681
|
+
};
|
|
682
|
+
|
|
683
|
+
const getRegenerationData =
|
|
684
|
+
(baseURL: string) =>
|
|
685
|
+
/**
|
|
686
|
+
* Retrieves regeneration and maintenance data.
|
|
687
|
+
* Includes blackout counter and last intervention timestamp.
|
|
688
|
+
*
|
|
689
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
690
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
691
|
+
* @returns {Promise<RegenerationDataType>} - Maintenance tracking data.
|
|
692
|
+
*/
|
|
693
|
+
async (
|
|
694
|
+
jwtToken: string,
|
|
695
|
+
macAddress: string,
|
|
696
|
+
): Promise<RegenerationDataType> => {
|
|
697
|
+
const info = await deviceInfo(baseURL)(jwtToken, macAddress);
|
|
698
|
+
return info.nvm.regeneration;
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
const getServiceTime =
|
|
702
|
+
(baseURL: string) =>
|
|
703
|
+
/**
|
|
704
|
+
* Retrieves the total service time in hours.
|
|
705
|
+
*
|
|
706
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
707
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
708
|
+
* @returns {Promise<number>} - Total service hours.
|
|
709
|
+
*/
|
|
710
|
+
async (jwtToken: string, macAddress: string): Promise<number> => {
|
|
711
|
+
const info = await deviceInfo(baseURL)(jwtToken, macAddress);
|
|
712
|
+
return info.status.counters.service_time;
|
|
713
|
+
};
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Default service threshold in hours (from OEM parameters).
|
|
717
|
+
* Most devices use 2000 hours.
|
|
718
|
+
*/
|
|
719
|
+
const DEFAULT_SERVICE_THRESHOLD = 2000;
|
|
720
|
+
|
|
721
|
+
const getTotalOperatingHours =
|
|
722
|
+
(baseURL: string) =>
|
|
723
|
+
/**
|
|
724
|
+
* Calculates total operating hours across all power levels.
|
|
725
|
+
*
|
|
726
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
727
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
728
|
+
* @returns {Promise<number>} - Total operating hours.
|
|
729
|
+
*/
|
|
730
|
+
async (jwtToken: string, macAddress: string): Promise<number> => {
|
|
731
|
+
const counters = await getTotalCounters(baseURL)(jwtToken, macAddress);
|
|
732
|
+
return (
|
|
733
|
+
counters.p1_working_time +
|
|
734
|
+
counters.p2_working_time +
|
|
735
|
+
counters.p3_working_time +
|
|
736
|
+
counters.p4_working_time +
|
|
737
|
+
counters.p5_working_time
|
|
738
|
+
);
|
|
739
|
+
};
|
|
740
|
+
|
|
741
|
+
const getPowerDistribution =
|
|
742
|
+
(baseURL: string) =>
|
|
743
|
+
/**
|
|
744
|
+
* Calculates power level usage distribution as percentages.
|
|
745
|
+
*
|
|
746
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
747
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
748
|
+
* @returns {Promise<PowerDistributionType>} - Percentage time at each power level.
|
|
749
|
+
*/
|
|
750
|
+
async (
|
|
751
|
+
jwtToken: string,
|
|
752
|
+
macAddress: string,
|
|
753
|
+
): Promise<PowerDistributionType> => {
|
|
754
|
+
const counters = await getTotalCounters(baseURL)(jwtToken, macAddress);
|
|
755
|
+
const total =
|
|
756
|
+
counters.p1_working_time +
|
|
757
|
+
counters.p2_working_time +
|
|
758
|
+
counters.p3_working_time +
|
|
759
|
+
counters.p4_working_time +
|
|
760
|
+
counters.p5_working_time;
|
|
761
|
+
|
|
762
|
+
if (total === 0) {
|
|
763
|
+
return { p1: 0, p2: 0, p3: 0, p4: 0, p5: 0 };
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
return {
|
|
767
|
+
p1: (counters.p1_working_time / total) * 100,
|
|
768
|
+
p2: (counters.p2_working_time / total) * 100,
|
|
769
|
+
p3: (counters.p3_working_time / total) * 100,
|
|
770
|
+
p4: (counters.p4_working_time / total) * 100,
|
|
771
|
+
p5: (counters.p5_working_time / total) * 100,
|
|
772
|
+
};
|
|
773
|
+
};
|
|
774
|
+
|
|
775
|
+
const getServiceStatus =
|
|
776
|
+
(baseURL: string) =>
|
|
777
|
+
/**
|
|
778
|
+
* Calculates service status including whether maintenance is due.
|
|
779
|
+
*
|
|
780
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
781
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
782
|
+
* @param {number} [thresholdHours=2000] - Service threshold in hours.
|
|
783
|
+
* @returns {Promise<ServiceStatusType>} - Service status with computed fields.
|
|
784
|
+
*/
|
|
785
|
+
async (
|
|
786
|
+
jwtToken: string,
|
|
787
|
+
macAddress: string,
|
|
788
|
+
thresholdHours: number = DEFAULT_SERVICE_THRESHOLD,
|
|
789
|
+
): Promise<ServiceStatusType> => {
|
|
790
|
+
const info = await deviceInfo(baseURL)(jwtToken, macAddress);
|
|
791
|
+
const serviceCounters = info.nvm.service_counters;
|
|
792
|
+
const hoursSinceService =
|
|
793
|
+
serviceCounters.p1_working_time +
|
|
794
|
+
serviceCounters.p2_working_time +
|
|
795
|
+
serviceCounters.p3_working_time +
|
|
796
|
+
serviceCounters.p4_working_time +
|
|
797
|
+
serviceCounters.p5_working_time;
|
|
798
|
+
|
|
799
|
+
return {
|
|
800
|
+
totalServiceHours: info.status.counters.service_time,
|
|
801
|
+
hoursSinceService,
|
|
802
|
+
serviceThresholdHours: thresholdHours,
|
|
803
|
+
isServiceDue: hoursSinceService >= thresholdHours,
|
|
804
|
+
};
|
|
805
|
+
};
|
|
806
|
+
|
|
807
|
+
const getUsageAnalytics =
|
|
808
|
+
(baseURL: string) =>
|
|
809
|
+
/**
|
|
810
|
+
* Retrieves comprehensive usage analytics in a single call.
|
|
811
|
+
* Combines multiple statistics into a unified analytics object.
|
|
812
|
+
*
|
|
813
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
814
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
815
|
+
* @param {number} [serviceThreshold=2000] - Service threshold in hours.
|
|
816
|
+
* @returns {Promise<UsageAnalyticsType>} - Comprehensive usage analytics.
|
|
817
|
+
*/
|
|
818
|
+
async (
|
|
819
|
+
jwtToken: string,
|
|
820
|
+
macAddress: string,
|
|
821
|
+
serviceThreshold: number = DEFAULT_SERVICE_THRESHOLD,
|
|
822
|
+
): Promise<UsageAnalyticsType> => {
|
|
823
|
+
const info = await deviceInfo(baseURL)(jwtToken, macAddress);
|
|
824
|
+
|
|
825
|
+
const totalCounters = info.nvm.total_counters;
|
|
826
|
+
const serviceCounters = info.nvm.service_counters;
|
|
827
|
+
const regeneration = info.nvm.regeneration;
|
|
828
|
+
const alarmsLog = info.nvm.alarms_log;
|
|
829
|
+
|
|
830
|
+
const totalOperatingHours =
|
|
831
|
+
totalCounters.p1_working_time +
|
|
832
|
+
totalCounters.p2_working_time +
|
|
833
|
+
totalCounters.p3_working_time +
|
|
834
|
+
totalCounters.p4_working_time +
|
|
835
|
+
totalCounters.p5_working_time;
|
|
836
|
+
|
|
837
|
+
const hoursSinceService =
|
|
838
|
+
serviceCounters.p1_working_time +
|
|
839
|
+
serviceCounters.p2_working_time +
|
|
840
|
+
serviceCounters.p3_working_time +
|
|
841
|
+
serviceCounters.p4_working_time +
|
|
842
|
+
serviceCounters.p5_working_time;
|
|
843
|
+
|
|
844
|
+
const powerDistribution: PowerDistributionType =
|
|
845
|
+
totalOperatingHours === 0
|
|
846
|
+
? { p1: 0, p2: 0, p3: 0, p4: 0, p5: 0 }
|
|
847
|
+
: {
|
|
848
|
+
p1: (totalCounters.p1_working_time / totalOperatingHours) * 100,
|
|
849
|
+
p2: (totalCounters.p2_working_time / totalOperatingHours) * 100,
|
|
850
|
+
p3: (totalCounters.p3_working_time / totalOperatingHours) * 100,
|
|
851
|
+
p4: (totalCounters.p4_working_time / totalOperatingHours) * 100,
|
|
852
|
+
p5: (totalCounters.p5_working_time / totalOperatingHours) * 100,
|
|
853
|
+
};
|
|
854
|
+
|
|
855
|
+
return {
|
|
856
|
+
totalPowerOns: totalCounters.power_ons,
|
|
857
|
+
totalOperatingHours,
|
|
858
|
+
powerDistribution,
|
|
859
|
+
serviceStatus: {
|
|
860
|
+
totalServiceHours: info.status.counters.service_time,
|
|
861
|
+
hoursSinceService,
|
|
862
|
+
serviceThresholdHours: serviceThreshold,
|
|
863
|
+
isServiceDue: hoursSinceService >= serviceThreshold,
|
|
864
|
+
},
|
|
865
|
+
blackoutCount: regeneration.blackout_counter,
|
|
866
|
+
lastMaintenanceDate:
|
|
867
|
+
regeneration.last_intervention > 0
|
|
868
|
+
? new Date(regeneration.last_intervention * 1000)
|
|
869
|
+
: null,
|
|
870
|
+
alarmCount: alarmsLog.number,
|
|
871
|
+
};
|
|
872
|
+
};
|
|
873
|
+
|
|
667
874
|
const registerDevice =
|
|
668
875
|
(baseURL: string) =>
|
|
669
876
|
/**
|
|
@@ -757,6 +964,8 @@ const configure = (baseURL: string = API_URL) => ({
|
|
|
757
964
|
getPower: getPower(baseURL),
|
|
758
965
|
setPowerLevel: setPowerLevel(baseURL),
|
|
759
966
|
getPowerLevel: getPowerLevel(baseURL),
|
|
967
|
+
setFanSpeed: setFanSpeed(baseURL),
|
|
968
|
+
getFanSpeed: getFanSpeed(baseURL),
|
|
760
969
|
setFan1Speed: setFan1Speed(baseURL),
|
|
761
970
|
setFan2Speed: setFan2Speed(baseURL),
|
|
762
971
|
setFan3Speed: setFan3Speed(baseURL),
|
|
@@ -774,6 +983,8 @@ const configure = (baseURL: string = API_URL) => ({
|
|
|
774
983
|
getEnvironmentTemperature: getEnvironmentTemperature(baseURL),
|
|
775
984
|
getTargetTemperature: getTargetTemperature(baseURL),
|
|
776
985
|
setTargetTemperature: setTargetTemperature(baseURL),
|
|
986
|
+
setEnvironment1Temperature: setEnvironment1Temperature(baseURL),
|
|
987
|
+
getEnvironment1Temperature: getEnvironment1Temperature(baseURL),
|
|
777
988
|
setEnvironment2Temperature: setEnvironment2Temperature(baseURL),
|
|
778
989
|
getEnvironment2Temperature: getEnvironment2Temperature(baseURL),
|
|
779
990
|
setEnvironment3Temperature: setEnvironment3Temperature(baseURL),
|
|
@@ -784,6 +995,17 @@ const configure = (baseURL: string = API_URL) => ({
|
|
|
784
995
|
getLanguage: getLanguage(baseURL),
|
|
785
996
|
getPelletInReserve: getPelletInReserve(baseURL),
|
|
786
997
|
getPelletAutonomyTime: getPelletAutonomyTime(baseURL),
|
|
998
|
+
// Statistics getters
|
|
999
|
+
getTotalCounters: getTotalCounters(baseURL),
|
|
1000
|
+
getServiceCounters: getServiceCounters(baseURL),
|
|
1001
|
+
getAlarmHistory: getAlarmHistory(baseURL),
|
|
1002
|
+
getRegenerationData: getRegenerationData(baseURL),
|
|
1003
|
+
getServiceTime: getServiceTime(baseURL),
|
|
1004
|
+
// Analytics functions
|
|
1005
|
+
getTotalOperatingHours: getTotalOperatingHours(baseURL),
|
|
1006
|
+
getPowerDistribution: getPowerDistribution(baseURL),
|
|
1007
|
+
getServiceStatus: getServiceStatus(baseURL),
|
|
1008
|
+
getUsageAnalytics: getUsageAnalytics(baseURL),
|
|
787
1009
|
});
|
|
788
1010
|
|
|
789
1011
|
export {
|