edilkamin 1.10.0 → 1.10.2
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 +105 -0
- package/dist/cjs/src/index.d.ts +3 -2
- package/dist/cjs/src/index.js +5 -1
- package/dist/cjs/src/library.d.ts +26 -1
- package/dist/cjs/src/library.js +219 -1
- package/dist/cjs/src/library.test.js +356 -0
- 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 +105 -0
- package/dist/esm/src/index.d.ts +3 -2
- package/dist/esm/src/index.js +2 -1
- package/dist/esm/src/library.d.ts +26 -1
- package/dist/esm/src/library.js +217 -0
- package/dist/esm/src/library.test.js +357 -1
- 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 +156 -0
- package/src/index.ts +11 -1
- package/src/library.test.ts +463 -1
- package/src/library.ts +279 -0
- package/src/types.ts +180 -0
package/dist/esm/src/cli.js
CHANGED
|
@@ -14,6 +14,7 @@ import { version } from "../package.json";
|
|
|
14
14
|
import { NEW_API_URL, OLD_API_URL } from "./constants";
|
|
15
15
|
import { configure, configureAmplify, getSession, signIn } from "./library";
|
|
16
16
|
import { clearSession, createFileStorage } from "./token-storage";
|
|
17
|
+
import { AlarmCode, AlarmDescriptions } from "./types";
|
|
17
18
|
const promptPassword = () => {
|
|
18
19
|
const rl = readline.createInterface({
|
|
19
20
|
input: process.stdin,
|
|
@@ -222,6 +223,84 @@ const createProgram = () => {
|
|
|
222
223
|
description: "Retrieve estimated pellet autonomy time",
|
|
223
224
|
getter: (api, jwtToken, mac) => api.getPelletAutonomyTime(jwtToken, mac),
|
|
224
225
|
},
|
|
226
|
+
// Statistics getters
|
|
227
|
+
{
|
|
228
|
+
commandName: "getTotalCounters",
|
|
229
|
+
description: "Get lifetime operating counters (power-ons, runtime by power level)",
|
|
230
|
+
getter: (api, jwtToken, mac) => api.getTotalCounters(jwtToken, mac),
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
commandName: "getServiceCounters",
|
|
234
|
+
description: "Get service counters (runtime since last maintenance)",
|
|
235
|
+
getter: (api, jwtToken, mac) => api.getServiceCounters(jwtToken, mac),
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
commandName: "getRegenerationData",
|
|
239
|
+
description: "Get regeneration and maintenance data",
|
|
240
|
+
getter: (api, jwtToken, mac) => api.getRegenerationData(jwtToken, mac),
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
commandName: "getServiceTime",
|
|
244
|
+
description: "Get total service time in hours",
|
|
245
|
+
getter: (api, jwtToken, mac) => api.getServiceTime(jwtToken, mac),
|
|
246
|
+
},
|
|
247
|
+
// Analytics getters
|
|
248
|
+
{
|
|
249
|
+
commandName: "getTotalOperatingHours",
|
|
250
|
+
description: "Get total operating hours across all power levels",
|
|
251
|
+
getter: (api, jwtToken, mac) => api.getTotalOperatingHours(jwtToken, mac),
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
commandName: "getPowerDistribution",
|
|
255
|
+
description: "Get power level usage distribution as percentages",
|
|
256
|
+
getter: (api, jwtToken, mac) => __awaiter(void 0, void 0, void 0, function* () {
|
|
257
|
+
const result = yield api.getPowerDistribution(jwtToken, mac);
|
|
258
|
+
return {
|
|
259
|
+
p1: `${result.p1.toFixed(1)}%`,
|
|
260
|
+
p2: `${result.p2.toFixed(1)}%`,
|
|
261
|
+
p3: `${result.p3.toFixed(1)}%`,
|
|
262
|
+
p4: `${result.p4.toFixed(1)}%`,
|
|
263
|
+
p5: `${result.p5.toFixed(1)}%`,
|
|
264
|
+
};
|
|
265
|
+
}),
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
commandName: "getServiceStatus",
|
|
269
|
+
description: "Get service status including whether maintenance is due",
|
|
270
|
+
getter: (api, jwtToken, mac) => api.getServiceStatus(jwtToken, mac),
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
commandName: "getUsageAnalytics",
|
|
274
|
+
description: "Get comprehensive usage analytics in single response",
|
|
275
|
+
getter: (api, jwtToken, mac) => __awaiter(void 0, void 0, void 0, function* () {
|
|
276
|
+
var _a;
|
|
277
|
+
const analytics = yield api.getUsageAnalytics(jwtToken, mac);
|
|
278
|
+
return {
|
|
279
|
+
lifetime: {
|
|
280
|
+
powerOnCount: analytics.totalPowerOns,
|
|
281
|
+
totalOperatingHours: analytics.totalOperatingHours,
|
|
282
|
+
blackoutCount: analytics.blackoutCount,
|
|
283
|
+
},
|
|
284
|
+
powerDistribution: {
|
|
285
|
+
p1: `${analytics.powerDistribution.p1.toFixed(1)}%`,
|
|
286
|
+
p2: `${analytics.powerDistribution.p2.toFixed(1)}%`,
|
|
287
|
+
p3: `${analytics.powerDistribution.p3.toFixed(1)}%`,
|
|
288
|
+
p4: `${analytics.powerDistribution.p4.toFixed(1)}%`,
|
|
289
|
+
p5: `${analytics.powerDistribution.p5.toFixed(1)}%`,
|
|
290
|
+
},
|
|
291
|
+
service: {
|
|
292
|
+
totalServiceHours: analytics.serviceStatus.totalServiceHours,
|
|
293
|
+
hoursSinceLastService: analytics.serviceStatus.hoursSinceService,
|
|
294
|
+
thresholdHours: analytics.serviceStatus.serviceThresholdHours,
|
|
295
|
+
isServiceDue: analytics.serviceStatus.isServiceDue,
|
|
296
|
+
lastMaintenanceDate: ((_a = analytics.lastMaintenanceDate) === null || _a === void 0 ? void 0 : _a.toISOString()) || "Never",
|
|
297
|
+
},
|
|
298
|
+
alarms: {
|
|
299
|
+
totalCount: analytics.alarmCount,
|
|
300
|
+
},
|
|
301
|
+
};
|
|
302
|
+
}),
|
|
303
|
+
},
|
|
225
304
|
].forEach(({ commandName, description, getter }) => {
|
|
226
305
|
addLegacyOption(addMacOption(addAuthOptions(program.command(commandName).description(description)))).action((options) => executeGetter(options, getter));
|
|
227
306
|
});
|
|
@@ -403,6 +482,32 @@ const createProgram = () => {
|
|
|
403
482
|
const result = yield api.setTargetTemperature(jwtToken, normalizedMac, index, value);
|
|
404
483
|
console.log(JSON.stringify(result, null, 2));
|
|
405
484
|
}));
|
|
485
|
+
// Alarm history command with human-readable descriptions
|
|
486
|
+
addLegacyOption(addMacOption(addAuthOptions(program
|
|
487
|
+
.command("getAlarmHistory")
|
|
488
|
+
.description("Get alarm history log with human-readable descriptions")))).action((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
489
|
+
const { username, password, mac, legacy = false } = options;
|
|
490
|
+
const normalizedMac = mac.replace(/:/g, "");
|
|
491
|
+
const storage = createFileStorage();
|
|
492
|
+
configureAmplify(storage);
|
|
493
|
+
let jwtToken;
|
|
494
|
+
try {
|
|
495
|
+
jwtToken = yield getSession(false, legacy);
|
|
496
|
+
}
|
|
497
|
+
catch (_a) {
|
|
498
|
+
if (!username) {
|
|
499
|
+
throw new Error("No session found. Please provide --username to sign in.");
|
|
500
|
+
}
|
|
501
|
+
const pwd = password || (yield promptPassword());
|
|
502
|
+
jwtToken = yield signIn(username, pwd, legacy);
|
|
503
|
+
}
|
|
504
|
+
const apiUrl = legacy ? OLD_API_URL : NEW_API_URL;
|
|
505
|
+
const api = configure(apiUrl);
|
|
506
|
+
const result = yield api.getAlarmHistory(jwtToken, normalizedMac);
|
|
507
|
+
// Format alarms with human-readable descriptions
|
|
508
|
+
const formattedAlarms = result.alarms.map((alarm) => (Object.assign(Object.assign({}, alarm), { typeName: AlarmCode[alarm.type] || "UNKNOWN", description: AlarmDescriptions[alarm.type] || "Unknown alarm", date: new Date(alarm.timestamp * 1000).toISOString() })));
|
|
509
|
+
console.log(JSON.stringify(Object.assign(Object.assign({}, result), { alarms: formattedAlarms }), null, 2));
|
|
510
|
+
}));
|
|
406
511
|
// Command: register
|
|
407
512
|
addLegacyOption(addAuthOptions(program
|
|
408
513
|
.command("register")
|
package/dist/esm/src/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { bleToWifiMac } from "./bluetooth-utils";
|
|
2
2
|
export { decompressBuffer, isBuffer, processResponse } from "./buffer-utils";
|
|
3
3
|
export { API_URL, NEW_API_URL, OLD_API_URL } from "./constants";
|
|
4
|
-
export { configure, getSession, signIn } from "./library";
|
|
4
|
+
export { configure, deriveUsageAnalytics, getSession, signIn } from "./library";
|
|
5
5
|
export { serialNumberDisplay, serialNumberFromHex, serialNumberToHex, } from "./serial-utils";
|
|
6
|
-
export { BufferEncodedType, CommandsType, DeviceAssociationBody, DeviceAssociationResponse, DeviceInfoRawType, DeviceInfoType, DiscoveredDevice, EditDeviceAssociationBody, StatusType, TemperaturesType, UserParametersType, } from "./types";
|
|
6
|
+
export { AlarmEntryType, AlarmsLogType, BufferEncodedType, CommandsType, DeviceAssociationBody, DeviceAssociationResponse, DeviceInfoRawType, DeviceInfoType, DiscoveredDevice, EditDeviceAssociationBody, PowerDistributionType, RegenerationDataType, ServiceCountersType, ServiceStatusType, StatusCountersType, StatusType, TemperaturesType, TotalCountersType, UsageAnalyticsType, UserParametersType, } from "./types";
|
|
7
|
+
export { AlarmCode, AlarmDescriptions } from "./types";
|
|
7
8
|
export declare const deviceInfo: (jwtToken: string, macAddress: string) => Promise<import("./types").DeviceInfoType>, registerDevice: (jwtToken: string, macAddress: string, serialNumber: string, deviceName?: string, deviceRoom?: string) => Promise<import("./types").DeviceAssociationResponse>, editDevice: (jwtToken: string, macAddress: string, deviceName?: string, deviceRoom?: string) => Promise<import("./types").DeviceAssociationResponse>, setPower: (jwtToken: string, macAddress: string, value: number) => Promise<unknown>, setPowerOff: (jwtToken: string, macAddress: string) => Promise<unknown>, setPowerOn: (jwtToken: string, macAddress: string) => Promise<unknown>, getPower: (jwtToken: string, macAddress: string) => Promise<boolean>, getEnvironmentTemperature: (jwtToken: string, macAddress: string) => Promise<number>, getTargetTemperature: (jwtToken: string, macAddress: string, envIndex: 1 | 2 | 3) => Promise<number>, setTargetTemperature: (jwtToken: string, macAddress: string, envIndex: 1 | 2 | 3, temperature: number) => Promise<unknown>;
|
package/dist/esm/src/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { configure } from "./library";
|
|
|
2
2
|
export { bleToWifiMac } from "./bluetooth-utils";
|
|
3
3
|
export { decompressBuffer, isBuffer, processResponse } from "./buffer-utils";
|
|
4
4
|
export { API_URL, NEW_API_URL, OLD_API_URL } from "./constants";
|
|
5
|
-
export { configure, getSession, signIn } from "./library";
|
|
5
|
+
export { configure, deriveUsageAnalytics, getSession, signIn } from "./library";
|
|
6
6
|
export { serialNumberDisplay, serialNumberFromHex, serialNumberToHex, } from "./serial-utils";
|
|
7
|
+
export { AlarmCode, AlarmDescriptions } from "./types";
|
|
7
8
|
export const { deviceInfo, registerDevice, editDevice, setPower, setPowerOff, setPowerOn, getPower, getEnvironmentTemperature, getTargetTemperature, setTargetTemperature, } = configure();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as amplifyAuth from "aws-amplify/auth";
|
|
2
|
-
import { DeviceAssociationResponse, DeviceInfoType } from "./types";
|
|
2
|
+
import { AlarmsLogType, DeviceAssociationResponse, DeviceInfoType, PowerDistributionType, RegenerationDataType, ServiceCountersType, ServiceStatusType, TotalCountersType, UsageAnalyticsType } from "./types";
|
|
3
3
|
/**
|
|
4
4
|
* Generates headers with a JWT token for authenticated requests.
|
|
5
5
|
* @param {string} jwtToken - The JWT token for authorization.
|
|
@@ -29,6 +29,22 @@ declare const createAuthService: (auth: typeof amplifyAuth) => {
|
|
|
29
29
|
getSession: (forceRefresh?: boolean, legacy?: boolean) => Promise<string>;
|
|
30
30
|
};
|
|
31
31
|
declare const signIn: (username: string, password: string, legacy?: boolean) => Promise<string>, getSession: (forceRefresh?: boolean, legacy?: boolean) => Promise<string>;
|
|
32
|
+
/**
|
|
33
|
+
* Derives usage analytics from an existing DeviceInfo response.
|
|
34
|
+
* This is a pure function that performs client-side calculations without API calls.
|
|
35
|
+
*
|
|
36
|
+
* Use this when you already have a DeviceInfo object (e.g., from a previous deviceInfo() call)
|
|
37
|
+
* to avoid making an additional API request.
|
|
38
|
+
*
|
|
39
|
+
* @param {DeviceInfoType} deviceInfo - The device info response object.
|
|
40
|
+
* @param {number} [serviceThreshold=2000] - Service threshold in hours.
|
|
41
|
+
* @returns {UsageAnalyticsType} - Comprehensive usage analytics.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* const info = await api.deviceInfo(token, mac);
|
|
45
|
+
* const analytics = deriveUsageAnalytics(info);
|
|
46
|
+
*/
|
|
47
|
+
export declare const deriveUsageAnalytics: (deviceInfo: DeviceInfoType, serviceThreshold?: number) => UsageAnalyticsType;
|
|
32
48
|
/**
|
|
33
49
|
* Configures the library for API interactions.
|
|
34
50
|
* Initializes API methods with a specified base URL.
|
|
@@ -81,5 +97,14 @@ declare const configure: (baseURL?: string) => {
|
|
|
81
97
|
getLanguage: (jwtToken: string, macAddress: string) => Promise<number>;
|
|
82
98
|
getPelletInReserve: (jwtToken: string, macAddress: string) => Promise<boolean>;
|
|
83
99
|
getPelletAutonomyTime: (jwtToken: string, macAddress: string) => Promise<number>;
|
|
100
|
+
getTotalCounters: (jwtToken: string, macAddress: string) => Promise<TotalCountersType>;
|
|
101
|
+
getServiceCounters: (jwtToken: string, macAddress: string) => Promise<ServiceCountersType>;
|
|
102
|
+
getAlarmHistory: (jwtToken: string, macAddress: string) => Promise<AlarmsLogType>;
|
|
103
|
+
getRegenerationData: (jwtToken: string, macAddress: string) => Promise<RegenerationDataType>;
|
|
104
|
+
getServiceTime: (jwtToken: string, macAddress: string) => Promise<number>;
|
|
105
|
+
getTotalOperatingHours: (jwtToken: string, macAddress: string) => Promise<number>;
|
|
106
|
+
getPowerDistribution: (jwtToken: string, macAddress: string) => Promise<PowerDistributionType>;
|
|
107
|
+
getServiceStatus: (jwtToken: string, macAddress: string, thresholdHours?: number) => Promise<ServiceStatusType>;
|
|
108
|
+
getUsageAnalytics: (jwtToken: string, macAddress: string, serviceThreshold?: number) => Promise<UsageAnalyticsType>;
|
|
84
109
|
};
|
|
85
110
|
export { configure, configureAmplify, createAuthService, getSession, headers, signIn, };
|
package/dist/esm/src/library.js
CHANGED
|
@@ -473,6 +473,212 @@ const getPelletAutonomyTime = (baseURL) =>
|
|
|
473
473
|
const info = yield deviceInfo(baseURL)(jwtToken, macAddress);
|
|
474
474
|
return info.status.pellet.autonomy_time;
|
|
475
475
|
});
|
|
476
|
+
const getTotalCounters = (baseURL) =>
|
|
477
|
+
/**
|
|
478
|
+
* Retrieves lifetime operating counters.
|
|
479
|
+
* Includes power-on count and runtime hours per power level.
|
|
480
|
+
* These counters are never reset.
|
|
481
|
+
*
|
|
482
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
483
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
484
|
+
* @returns {Promise<TotalCountersType>} - Lifetime operating statistics.
|
|
485
|
+
*/
|
|
486
|
+
(jwtToken, macAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
487
|
+
const info = yield deviceInfo(baseURL)(jwtToken, macAddress);
|
|
488
|
+
return info.nvm.total_counters;
|
|
489
|
+
});
|
|
490
|
+
const getServiceCounters = (baseURL) =>
|
|
491
|
+
/**
|
|
492
|
+
* Retrieves service counters (runtime since last maintenance).
|
|
493
|
+
* These counters track hours per power level since last service reset.
|
|
494
|
+
*
|
|
495
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
496
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
497
|
+
* @returns {Promise<ServiceCountersType>} - Service tracking statistics.
|
|
498
|
+
*/
|
|
499
|
+
(jwtToken, macAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
500
|
+
const info = yield deviceInfo(baseURL)(jwtToken, macAddress);
|
|
501
|
+
return info.nvm.service_counters;
|
|
502
|
+
});
|
|
503
|
+
const getAlarmHistory = (baseURL) =>
|
|
504
|
+
/**
|
|
505
|
+
* Retrieves the alarm history log.
|
|
506
|
+
* Contains a circular buffer of recent alarms with timestamps.
|
|
507
|
+
*
|
|
508
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
509
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
510
|
+
* @returns {Promise<AlarmsLogType>} - Alarm history log.
|
|
511
|
+
*/
|
|
512
|
+
(jwtToken, macAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
513
|
+
const info = yield deviceInfo(baseURL)(jwtToken, macAddress);
|
|
514
|
+
return info.nvm.alarms_log;
|
|
515
|
+
});
|
|
516
|
+
const getRegenerationData = (baseURL) =>
|
|
517
|
+
/**
|
|
518
|
+
* Retrieves regeneration and maintenance data.
|
|
519
|
+
* Includes blackout counter and last intervention timestamp.
|
|
520
|
+
*
|
|
521
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
522
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
523
|
+
* @returns {Promise<RegenerationDataType>} - Maintenance tracking data.
|
|
524
|
+
*/
|
|
525
|
+
(jwtToken, macAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
526
|
+
const info = yield deviceInfo(baseURL)(jwtToken, macAddress);
|
|
527
|
+
return info.nvm.regeneration;
|
|
528
|
+
});
|
|
529
|
+
const getServiceTime = (baseURL) =>
|
|
530
|
+
/**
|
|
531
|
+
* Retrieves the total service time in hours.
|
|
532
|
+
*
|
|
533
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
534
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
535
|
+
* @returns {Promise<number>} - Total service hours.
|
|
536
|
+
*/
|
|
537
|
+
(jwtToken, macAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
538
|
+
const info = yield deviceInfo(baseURL)(jwtToken, macAddress);
|
|
539
|
+
return info.status.counters.service_time;
|
|
540
|
+
});
|
|
541
|
+
/**
|
|
542
|
+
* Default service threshold in hours (from OEM parameters).
|
|
543
|
+
* Most devices use 2000 hours.
|
|
544
|
+
*/
|
|
545
|
+
const DEFAULT_SERVICE_THRESHOLD = 2000;
|
|
546
|
+
/**
|
|
547
|
+
* Derives usage analytics from an existing DeviceInfo response.
|
|
548
|
+
* This is a pure function that performs client-side calculations without API calls.
|
|
549
|
+
*
|
|
550
|
+
* Use this when you already have a DeviceInfo object (e.g., from a previous deviceInfo() call)
|
|
551
|
+
* to avoid making an additional API request.
|
|
552
|
+
*
|
|
553
|
+
* @param {DeviceInfoType} deviceInfo - The device info response object.
|
|
554
|
+
* @param {number} [serviceThreshold=2000] - Service threshold in hours.
|
|
555
|
+
* @returns {UsageAnalyticsType} - Comprehensive usage analytics.
|
|
556
|
+
*
|
|
557
|
+
* @example
|
|
558
|
+
* const info = await api.deviceInfo(token, mac);
|
|
559
|
+
* const analytics = deriveUsageAnalytics(info);
|
|
560
|
+
*/
|
|
561
|
+
export const deriveUsageAnalytics = (deviceInfo, serviceThreshold = DEFAULT_SERVICE_THRESHOLD) => {
|
|
562
|
+
const totalCounters = deviceInfo.nvm.total_counters;
|
|
563
|
+
const serviceCounters = deviceInfo.nvm.service_counters;
|
|
564
|
+
const regeneration = deviceInfo.nvm.regeneration;
|
|
565
|
+
const alarmsLog = deviceInfo.nvm.alarms_log;
|
|
566
|
+
const totalOperatingHours = totalCounters.p1_working_time +
|
|
567
|
+
totalCounters.p2_working_time +
|
|
568
|
+
totalCounters.p3_working_time +
|
|
569
|
+
totalCounters.p4_working_time +
|
|
570
|
+
totalCounters.p5_working_time;
|
|
571
|
+
const hoursSinceService = serviceCounters.p1_working_time +
|
|
572
|
+
serviceCounters.p2_working_time +
|
|
573
|
+
serviceCounters.p3_working_time +
|
|
574
|
+
serviceCounters.p4_working_time +
|
|
575
|
+
serviceCounters.p5_working_time;
|
|
576
|
+
const powerDistribution = totalOperatingHours === 0
|
|
577
|
+
? { p1: 0, p2: 0, p3: 0, p4: 0, p5: 0 }
|
|
578
|
+
: {
|
|
579
|
+
p1: (totalCounters.p1_working_time / totalOperatingHours) * 100,
|
|
580
|
+
p2: (totalCounters.p2_working_time / totalOperatingHours) * 100,
|
|
581
|
+
p3: (totalCounters.p3_working_time / totalOperatingHours) * 100,
|
|
582
|
+
p4: (totalCounters.p4_working_time / totalOperatingHours) * 100,
|
|
583
|
+
p5: (totalCounters.p5_working_time / totalOperatingHours) * 100,
|
|
584
|
+
};
|
|
585
|
+
return {
|
|
586
|
+
totalPowerOns: totalCounters.power_ons,
|
|
587
|
+
totalOperatingHours,
|
|
588
|
+
powerDistribution,
|
|
589
|
+
serviceStatus: {
|
|
590
|
+
totalServiceHours: deviceInfo.status.counters.service_time,
|
|
591
|
+
hoursSinceService,
|
|
592
|
+
serviceThresholdHours: serviceThreshold,
|
|
593
|
+
isServiceDue: hoursSinceService >= serviceThreshold,
|
|
594
|
+
},
|
|
595
|
+
blackoutCount: regeneration.blackout_counter,
|
|
596
|
+
lastMaintenanceDate: regeneration.last_intervention > 0
|
|
597
|
+
? new Date(regeneration.last_intervention * 1000)
|
|
598
|
+
: null,
|
|
599
|
+
alarmCount: alarmsLog.number,
|
|
600
|
+
};
|
|
601
|
+
};
|
|
602
|
+
const getTotalOperatingHours = (baseURL) =>
|
|
603
|
+
/**
|
|
604
|
+
* Calculates total operating hours across all power levels.
|
|
605
|
+
*
|
|
606
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
607
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
608
|
+
* @returns {Promise<number>} - Total operating hours.
|
|
609
|
+
*/
|
|
610
|
+
(jwtToken, macAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
611
|
+
const counters = yield getTotalCounters(baseURL)(jwtToken, macAddress);
|
|
612
|
+
return (counters.p1_working_time +
|
|
613
|
+
counters.p2_working_time +
|
|
614
|
+
counters.p3_working_time +
|
|
615
|
+
counters.p4_working_time +
|
|
616
|
+
counters.p5_working_time);
|
|
617
|
+
});
|
|
618
|
+
const getPowerDistribution = (baseURL) =>
|
|
619
|
+
/**
|
|
620
|
+
* Calculates power level usage distribution as percentages.
|
|
621
|
+
*
|
|
622
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
623
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
624
|
+
* @returns {Promise<PowerDistributionType>} - Percentage time at each power level.
|
|
625
|
+
*/
|
|
626
|
+
(jwtToken, macAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
627
|
+
const counters = yield getTotalCounters(baseURL)(jwtToken, macAddress);
|
|
628
|
+
const total = counters.p1_working_time +
|
|
629
|
+
counters.p2_working_time +
|
|
630
|
+
counters.p3_working_time +
|
|
631
|
+
counters.p4_working_time +
|
|
632
|
+
counters.p5_working_time;
|
|
633
|
+
if (total === 0) {
|
|
634
|
+
return { p1: 0, p2: 0, p3: 0, p4: 0, p5: 0 };
|
|
635
|
+
}
|
|
636
|
+
return {
|
|
637
|
+
p1: (counters.p1_working_time / total) * 100,
|
|
638
|
+
p2: (counters.p2_working_time / total) * 100,
|
|
639
|
+
p3: (counters.p3_working_time / total) * 100,
|
|
640
|
+
p4: (counters.p4_working_time / total) * 100,
|
|
641
|
+
p5: (counters.p5_working_time / total) * 100,
|
|
642
|
+
};
|
|
643
|
+
});
|
|
644
|
+
const getServiceStatus = (baseURL) =>
|
|
645
|
+
/**
|
|
646
|
+
* Calculates service status including whether maintenance is due.
|
|
647
|
+
*
|
|
648
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
649
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
650
|
+
* @param {number} [thresholdHours=2000] - Service threshold in hours.
|
|
651
|
+
* @returns {Promise<ServiceStatusType>} - Service status with computed fields.
|
|
652
|
+
*/
|
|
653
|
+
(jwtToken_1, macAddress_1, ...args_1) => __awaiter(void 0, [jwtToken_1, macAddress_1, ...args_1], void 0, function* (jwtToken, macAddress, thresholdHours = DEFAULT_SERVICE_THRESHOLD) {
|
|
654
|
+
const info = yield deviceInfo(baseURL)(jwtToken, macAddress);
|
|
655
|
+
const serviceCounters = info.nvm.service_counters;
|
|
656
|
+
const hoursSinceService = serviceCounters.p1_working_time +
|
|
657
|
+
serviceCounters.p2_working_time +
|
|
658
|
+
serviceCounters.p3_working_time +
|
|
659
|
+
serviceCounters.p4_working_time +
|
|
660
|
+
serviceCounters.p5_working_time;
|
|
661
|
+
return {
|
|
662
|
+
totalServiceHours: info.status.counters.service_time,
|
|
663
|
+
hoursSinceService,
|
|
664
|
+
serviceThresholdHours: thresholdHours,
|
|
665
|
+
isServiceDue: hoursSinceService >= thresholdHours,
|
|
666
|
+
};
|
|
667
|
+
});
|
|
668
|
+
const getUsageAnalytics = (baseURL) =>
|
|
669
|
+
/**
|
|
670
|
+
* Retrieves comprehensive usage analytics in a single call.
|
|
671
|
+
* Combines multiple statistics into a unified analytics object.
|
|
672
|
+
*
|
|
673
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
674
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
675
|
+
* @param {number} [serviceThreshold=2000] - Service threshold in hours.
|
|
676
|
+
* @returns {Promise<UsageAnalyticsType>} - Comprehensive usage analytics.
|
|
677
|
+
*/
|
|
678
|
+
(jwtToken_1, macAddress_1, ...args_1) => __awaiter(void 0, [jwtToken_1, macAddress_1, ...args_1], void 0, function* (jwtToken, macAddress, serviceThreshold = DEFAULT_SERVICE_THRESHOLD) {
|
|
679
|
+
const info = yield deviceInfo(baseURL)(jwtToken, macAddress);
|
|
680
|
+
return deriveUsageAnalytics(info, serviceThreshold);
|
|
681
|
+
});
|
|
476
682
|
const registerDevice = (baseURL) =>
|
|
477
683
|
/**
|
|
478
684
|
* Registers a device with the user's account.
|
|
@@ -572,5 +778,16 @@ const configure = (baseURL = API_URL) => ({
|
|
|
572
778
|
getLanguage: getLanguage(baseURL),
|
|
573
779
|
getPelletInReserve: getPelletInReserve(baseURL),
|
|
574
780
|
getPelletAutonomyTime: getPelletAutonomyTime(baseURL),
|
|
781
|
+
// Statistics getters
|
|
782
|
+
getTotalCounters: getTotalCounters(baseURL),
|
|
783
|
+
getServiceCounters: getServiceCounters(baseURL),
|
|
784
|
+
getAlarmHistory: getAlarmHistory(baseURL),
|
|
785
|
+
getRegenerationData: getRegenerationData(baseURL),
|
|
786
|
+
getServiceTime: getServiceTime(baseURL),
|
|
787
|
+
// Analytics functions
|
|
788
|
+
getTotalOperatingHours: getTotalOperatingHours(baseURL),
|
|
789
|
+
getPowerDistribution: getPowerDistribution(baseURL),
|
|
790
|
+
getServiceStatus: getServiceStatus(baseURL),
|
|
791
|
+
getUsageAnalytics: getUsageAnalytics(baseURL),
|
|
575
792
|
});
|
|
576
793
|
export { configure, configureAmplify, createAuthService, getSession, headers, signIn, };
|