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/cjs/package.json
CHANGED
package/dist/cjs/src/cli.js
CHANGED
|
@@ -20,6 +20,7 @@ const package_json_1 = require("../package.json");
|
|
|
20
20
|
const constants_1 = require("./constants");
|
|
21
21
|
const library_1 = require("./library");
|
|
22
22
|
const token_storage_1 = require("./token-storage");
|
|
23
|
+
const types_1 = require("./types");
|
|
23
24
|
const promptPassword = () => {
|
|
24
25
|
const rl = readline_1.default.createInterface({
|
|
25
26
|
input: process.stdin,
|
|
@@ -228,6 +229,84 @@ const createProgram = () => {
|
|
|
228
229
|
description: "Retrieve estimated pellet autonomy time",
|
|
229
230
|
getter: (api, jwtToken, mac) => api.getPelletAutonomyTime(jwtToken, mac),
|
|
230
231
|
},
|
|
232
|
+
// Statistics getters
|
|
233
|
+
{
|
|
234
|
+
commandName: "getTotalCounters",
|
|
235
|
+
description: "Get lifetime operating counters (power-ons, runtime by power level)",
|
|
236
|
+
getter: (api, jwtToken, mac) => api.getTotalCounters(jwtToken, mac),
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
commandName: "getServiceCounters",
|
|
240
|
+
description: "Get service counters (runtime since last maintenance)",
|
|
241
|
+
getter: (api, jwtToken, mac) => api.getServiceCounters(jwtToken, mac),
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
commandName: "getRegenerationData",
|
|
245
|
+
description: "Get regeneration and maintenance data",
|
|
246
|
+
getter: (api, jwtToken, mac) => api.getRegenerationData(jwtToken, mac),
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
commandName: "getServiceTime",
|
|
250
|
+
description: "Get total service time in hours",
|
|
251
|
+
getter: (api, jwtToken, mac) => api.getServiceTime(jwtToken, mac),
|
|
252
|
+
},
|
|
253
|
+
// Analytics getters
|
|
254
|
+
{
|
|
255
|
+
commandName: "getTotalOperatingHours",
|
|
256
|
+
description: "Get total operating hours across all power levels",
|
|
257
|
+
getter: (api, jwtToken, mac) => api.getTotalOperatingHours(jwtToken, mac),
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
commandName: "getPowerDistribution",
|
|
261
|
+
description: "Get power level usage distribution as percentages",
|
|
262
|
+
getter: (api, jwtToken, mac) => __awaiter(void 0, void 0, void 0, function* () {
|
|
263
|
+
const result = yield api.getPowerDistribution(jwtToken, mac);
|
|
264
|
+
return {
|
|
265
|
+
p1: `${result.p1.toFixed(1)}%`,
|
|
266
|
+
p2: `${result.p2.toFixed(1)}%`,
|
|
267
|
+
p3: `${result.p3.toFixed(1)}%`,
|
|
268
|
+
p4: `${result.p4.toFixed(1)}%`,
|
|
269
|
+
p5: `${result.p5.toFixed(1)}%`,
|
|
270
|
+
};
|
|
271
|
+
}),
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
commandName: "getServiceStatus",
|
|
275
|
+
description: "Get service status including whether maintenance is due",
|
|
276
|
+
getter: (api, jwtToken, mac) => api.getServiceStatus(jwtToken, mac),
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
commandName: "getUsageAnalytics",
|
|
280
|
+
description: "Get comprehensive usage analytics in single response",
|
|
281
|
+
getter: (api, jwtToken, mac) => __awaiter(void 0, void 0, void 0, function* () {
|
|
282
|
+
var _a;
|
|
283
|
+
const analytics = yield api.getUsageAnalytics(jwtToken, mac);
|
|
284
|
+
return {
|
|
285
|
+
lifetime: {
|
|
286
|
+
powerOnCount: analytics.totalPowerOns,
|
|
287
|
+
totalOperatingHours: analytics.totalOperatingHours,
|
|
288
|
+
blackoutCount: analytics.blackoutCount,
|
|
289
|
+
},
|
|
290
|
+
powerDistribution: {
|
|
291
|
+
p1: `${analytics.powerDistribution.p1.toFixed(1)}%`,
|
|
292
|
+
p2: `${analytics.powerDistribution.p2.toFixed(1)}%`,
|
|
293
|
+
p3: `${analytics.powerDistribution.p3.toFixed(1)}%`,
|
|
294
|
+
p4: `${analytics.powerDistribution.p4.toFixed(1)}%`,
|
|
295
|
+
p5: `${analytics.powerDistribution.p5.toFixed(1)}%`,
|
|
296
|
+
},
|
|
297
|
+
service: {
|
|
298
|
+
totalServiceHours: analytics.serviceStatus.totalServiceHours,
|
|
299
|
+
hoursSinceLastService: analytics.serviceStatus.hoursSinceService,
|
|
300
|
+
thresholdHours: analytics.serviceStatus.serviceThresholdHours,
|
|
301
|
+
isServiceDue: analytics.serviceStatus.isServiceDue,
|
|
302
|
+
lastMaintenanceDate: ((_a = analytics.lastMaintenanceDate) === null || _a === void 0 ? void 0 : _a.toISOString()) || "Never",
|
|
303
|
+
},
|
|
304
|
+
alarms: {
|
|
305
|
+
totalCount: analytics.alarmCount,
|
|
306
|
+
},
|
|
307
|
+
};
|
|
308
|
+
}),
|
|
309
|
+
},
|
|
231
310
|
].forEach(({ commandName, description, getter }) => {
|
|
232
311
|
addLegacyOption(addMacOption(addAuthOptions(program.command(commandName).description(description)))).action((options) => executeGetter(options, getter));
|
|
233
312
|
});
|
|
@@ -409,6 +488,32 @@ const createProgram = () => {
|
|
|
409
488
|
const result = yield api.setTargetTemperature(jwtToken, normalizedMac, index, value);
|
|
410
489
|
console.log(JSON.stringify(result, null, 2));
|
|
411
490
|
}));
|
|
491
|
+
// Alarm history command with human-readable descriptions
|
|
492
|
+
addLegacyOption(addMacOption(addAuthOptions(program
|
|
493
|
+
.command("getAlarmHistory")
|
|
494
|
+
.description("Get alarm history log with human-readable descriptions")))).action((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
495
|
+
const { username, password, mac, legacy = false } = options;
|
|
496
|
+
const normalizedMac = mac.replace(/:/g, "");
|
|
497
|
+
const storage = (0, token_storage_1.createFileStorage)();
|
|
498
|
+
(0, library_1.configureAmplify)(storage);
|
|
499
|
+
let jwtToken;
|
|
500
|
+
try {
|
|
501
|
+
jwtToken = yield (0, library_1.getSession)(false, legacy);
|
|
502
|
+
}
|
|
503
|
+
catch (_a) {
|
|
504
|
+
if (!username) {
|
|
505
|
+
throw new Error("No session found. Please provide --username to sign in.");
|
|
506
|
+
}
|
|
507
|
+
const pwd = password || (yield promptPassword());
|
|
508
|
+
jwtToken = yield (0, library_1.signIn)(username, pwd, legacy);
|
|
509
|
+
}
|
|
510
|
+
const apiUrl = legacy ? constants_1.OLD_API_URL : constants_1.NEW_API_URL;
|
|
511
|
+
const api = (0, library_1.configure)(apiUrl);
|
|
512
|
+
const result = yield api.getAlarmHistory(jwtToken, normalizedMac);
|
|
513
|
+
// Format alarms with human-readable descriptions
|
|
514
|
+
const formattedAlarms = result.alarms.map((alarm) => (Object.assign(Object.assign({}, alarm), { typeName: types_1.AlarmCode[alarm.type] || "UNKNOWN", description: types_1.AlarmDescriptions[alarm.type] || "Unknown alarm", date: new Date(alarm.timestamp * 1000).toISOString() })));
|
|
515
|
+
console.log(JSON.stringify(Object.assign(Object.assign({}, result), { alarms: formattedAlarms }), null, 2));
|
|
516
|
+
}));
|
|
412
517
|
// Command: register
|
|
413
518
|
addLegacyOption(addAuthOptions(program
|
|
414
519
|
.command("register")
|
package/dist/cjs/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/cjs/src/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.setTargetTemperature = exports.getTargetTemperature = exports.getEnvironmentTemperature = exports.getPower = exports.setPowerOn = exports.setPowerOff = exports.setPower = exports.editDevice = exports.registerDevice = exports.deviceInfo = exports.serialNumberToHex = exports.serialNumberFromHex = exports.serialNumberDisplay = exports.signIn = exports.getSession = exports.configure = exports.OLD_API_URL = exports.NEW_API_URL = exports.API_URL = exports.processResponse = exports.isBuffer = exports.decompressBuffer = exports.bleToWifiMac = void 0;
|
|
4
|
+
exports.setTargetTemperature = exports.getTargetTemperature = exports.getEnvironmentTemperature = exports.getPower = exports.setPowerOn = exports.setPowerOff = exports.setPower = exports.editDevice = exports.registerDevice = exports.deviceInfo = exports.AlarmDescriptions = exports.AlarmCode = exports.serialNumberToHex = exports.serialNumberFromHex = exports.serialNumberDisplay = exports.signIn = exports.getSession = exports.deriveUsageAnalytics = exports.configure = exports.OLD_API_URL = exports.NEW_API_URL = exports.API_URL = exports.processResponse = exports.isBuffer = exports.decompressBuffer = exports.bleToWifiMac = void 0;
|
|
5
5
|
const library_1 = require("./library");
|
|
6
6
|
var bluetooth_utils_1 = require("./bluetooth-utils");
|
|
7
7
|
Object.defineProperty(exports, "bleToWifiMac", { enumerable: true, get: function () { return bluetooth_utils_1.bleToWifiMac; } });
|
|
@@ -15,10 +15,14 @@ Object.defineProperty(exports, "NEW_API_URL", { enumerable: true, get: function
|
|
|
15
15
|
Object.defineProperty(exports, "OLD_API_URL", { enumerable: true, get: function () { return constants_1.OLD_API_URL; } });
|
|
16
16
|
var library_2 = require("./library");
|
|
17
17
|
Object.defineProperty(exports, "configure", { enumerable: true, get: function () { return library_2.configure; } });
|
|
18
|
+
Object.defineProperty(exports, "deriveUsageAnalytics", { enumerable: true, get: function () { return library_2.deriveUsageAnalytics; } });
|
|
18
19
|
Object.defineProperty(exports, "getSession", { enumerable: true, get: function () { return library_2.getSession; } });
|
|
19
20
|
Object.defineProperty(exports, "signIn", { enumerable: true, get: function () { return library_2.signIn; } });
|
|
20
21
|
var serial_utils_1 = require("./serial-utils");
|
|
21
22
|
Object.defineProperty(exports, "serialNumberDisplay", { enumerable: true, get: function () { return serial_utils_1.serialNumberDisplay; } });
|
|
22
23
|
Object.defineProperty(exports, "serialNumberFromHex", { enumerable: true, get: function () { return serial_utils_1.serialNumberFromHex; } });
|
|
23
24
|
Object.defineProperty(exports, "serialNumberToHex", { enumerable: true, get: function () { return serial_utils_1.serialNumberToHex; } });
|
|
25
|
+
var types_1 = require("./types");
|
|
26
|
+
Object.defineProperty(exports, "AlarmCode", { enumerable: true, get: function () { return types_1.AlarmCode; } });
|
|
27
|
+
Object.defineProperty(exports, "AlarmDescriptions", { enumerable: true, get: function () { return types_1.AlarmDescriptions; } });
|
|
24
28
|
_a = (0, library_1.configure)(), exports.deviceInfo = _a.deviceInfo, exports.registerDevice = _a.registerDevice, exports.editDevice = _a.editDevice, exports.setPower = _a.setPower, exports.setPowerOff = _a.setPowerOff, exports.setPowerOn = _a.setPowerOn, exports.getPower = _a.getPower, exports.getEnvironmentTemperature = _a.getEnvironmentTemperature, exports.getTargetTemperature = _a.getTargetTemperature, exports.setTargetTemperature = _a.setTargetTemperature;
|
|
@@ -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/cjs/src/library.js
CHANGED
|
@@ -42,7 +42,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
42
42
|
});
|
|
43
43
|
};
|
|
44
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
-
exports.signIn = exports.headers = exports.getSession = exports.createAuthService = exports.configureAmplify = exports.configure = void 0;
|
|
45
|
+
exports.signIn = exports.headers = exports.getSession = exports.createAuthService = exports.configureAmplify = exports.configure = exports.deriveUsageAnalytics = void 0;
|
|
46
46
|
const assert_1 = require("assert");
|
|
47
47
|
const aws_amplify_1 = require("aws-amplify");
|
|
48
48
|
const amplifyAuth = __importStar(require("aws-amplify/auth"));
|
|
@@ -514,6 +514,213 @@ const getPelletAutonomyTime = (baseURL) =>
|
|
|
514
514
|
const info = yield deviceInfo(baseURL)(jwtToken, macAddress);
|
|
515
515
|
return info.status.pellet.autonomy_time;
|
|
516
516
|
});
|
|
517
|
+
const getTotalCounters = (baseURL) =>
|
|
518
|
+
/**
|
|
519
|
+
* Retrieves lifetime operating counters.
|
|
520
|
+
* Includes power-on count and runtime hours per power level.
|
|
521
|
+
* These counters are never reset.
|
|
522
|
+
*
|
|
523
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
524
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
525
|
+
* @returns {Promise<TotalCountersType>} - Lifetime operating statistics.
|
|
526
|
+
*/
|
|
527
|
+
(jwtToken, macAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
528
|
+
const info = yield deviceInfo(baseURL)(jwtToken, macAddress);
|
|
529
|
+
return info.nvm.total_counters;
|
|
530
|
+
});
|
|
531
|
+
const getServiceCounters = (baseURL) =>
|
|
532
|
+
/**
|
|
533
|
+
* Retrieves service counters (runtime since last maintenance).
|
|
534
|
+
* These counters track hours per power level since last service reset.
|
|
535
|
+
*
|
|
536
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
537
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
538
|
+
* @returns {Promise<ServiceCountersType>} - Service tracking statistics.
|
|
539
|
+
*/
|
|
540
|
+
(jwtToken, macAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
541
|
+
const info = yield deviceInfo(baseURL)(jwtToken, macAddress);
|
|
542
|
+
return info.nvm.service_counters;
|
|
543
|
+
});
|
|
544
|
+
const getAlarmHistory = (baseURL) =>
|
|
545
|
+
/**
|
|
546
|
+
* Retrieves the alarm history log.
|
|
547
|
+
* Contains a circular buffer of recent alarms with timestamps.
|
|
548
|
+
*
|
|
549
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
550
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
551
|
+
* @returns {Promise<AlarmsLogType>} - Alarm history log.
|
|
552
|
+
*/
|
|
553
|
+
(jwtToken, macAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
554
|
+
const info = yield deviceInfo(baseURL)(jwtToken, macAddress);
|
|
555
|
+
return info.nvm.alarms_log;
|
|
556
|
+
});
|
|
557
|
+
const getRegenerationData = (baseURL) =>
|
|
558
|
+
/**
|
|
559
|
+
* Retrieves regeneration and maintenance data.
|
|
560
|
+
* Includes blackout counter and last intervention timestamp.
|
|
561
|
+
*
|
|
562
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
563
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
564
|
+
* @returns {Promise<RegenerationDataType>} - Maintenance tracking data.
|
|
565
|
+
*/
|
|
566
|
+
(jwtToken, macAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
567
|
+
const info = yield deviceInfo(baseURL)(jwtToken, macAddress);
|
|
568
|
+
return info.nvm.regeneration;
|
|
569
|
+
});
|
|
570
|
+
const getServiceTime = (baseURL) =>
|
|
571
|
+
/**
|
|
572
|
+
* Retrieves the total service time in hours.
|
|
573
|
+
*
|
|
574
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
575
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
576
|
+
* @returns {Promise<number>} - Total service hours.
|
|
577
|
+
*/
|
|
578
|
+
(jwtToken, macAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
579
|
+
const info = yield deviceInfo(baseURL)(jwtToken, macAddress);
|
|
580
|
+
return info.status.counters.service_time;
|
|
581
|
+
});
|
|
582
|
+
/**
|
|
583
|
+
* Default service threshold in hours (from OEM parameters).
|
|
584
|
+
* Most devices use 2000 hours.
|
|
585
|
+
*/
|
|
586
|
+
const DEFAULT_SERVICE_THRESHOLD = 2000;
|
|
587
|
+
/**
|
|
588
|
+
* Derives usage analytics from an existing DeviceInfo response.
|
|
589
|
+
* This is a pure function that performs client-side calculations without API calls.
|
|
590
|
+
*
|
|
591
|
+
* Use this when you already have a DeviceInfo object (e.g., from a previous deviceInfo() call)
|
|
592
|
+
* to avoid making an additional API request.
|
|
593
|
+
*
|
|
594
|
+
* @param {DeviceInfoType} deviceInfo - The device info response object.
|
|
595
|
+
* @param {number} [serviceThreshold=2000] - Service threshold in hours.
|
|
596
|
+
* @returns {UsageAnalyticsType} - Comprehensive usage analytics.
|
|
597
|
+
*
|
|
598
|
+
* @example
|
|
599
|
+
* const info = await api.deviceInfo(token, mac);
|
|
600
|
+
* const analytics = deriveUsageAnalytics(info);
|
|
601
|
+
*/
|
|
602
|
+
const deriveUsageAnalytics = (deviceInfo, serviceThreshold = DEFAULT_SERVICE_THRESHOLD) => {
|
|
603
|
+
const totalCounters = deviceInfo.nvm.total_counters;
|
|
604
|
+
const serviceCounters = deviceInfo.nvm.service_counters;
|
|
605
|
+
const regeneration = deviceInfo.nvm.regeneration;
|
|
606
|
+
const alarmsLog = deviceInfo.nvm.alarms_log;
|
|
607
|
+
const totalOperatingHours = totalCounters.p1_working_time +
|
|
608
|
+
totalCounters.p2_working_time +
|
|
609
|
+
totalCounters.p3_working_time +
|
|
610
|
+
totalCounters.p4_working_time +
|
|
611
|
+
totalCounters.p5_working_time;
|
|
612
|
+
const hoursSinceService = serviceCounters.p1_working_time +
|
|
613
|
+
serviceCounters.p2_working_time +
|
|
614
|
+
serviceCounters.p3_working_time +
|
|
615
|
+
serviceCounters.p4_working_time +
|
|
616
|
+
serviceCounters.p5_working_time;
|
|
617
|
+
const powerDistribution = totalOperatingHours === 0
|
|
618
|
+
? { p1: 0, p2: 0, p3: 0, p4: 0, p5: 0 }
|
|
619
|
+
: {
|
|
620
|
+
p1: (totalCounters.p1_working_time / totalOperatingHours) * 100,
|
|
621
|
+
p2: (totalCounters.p2_working_time / totalOperatingHours) * 100,
|
|
622
|
+
p3: (totalCounters.p3_working_time / totalOperatingHours) * 100,
|
|
623
|
+
p4: (totalCounters.p4_working_time / totalOperatingHours) * 100,
|
|
624
|
+
p5: (totalCounters.p5_working_time / totalOperatingHours) * 100,
|
|
625
|
+
};
|
|
626
|
+
return {
|
|
627
|
+
totalPowerOns: totalCounters.power_ons,
|
|
628
|
+
totalOperatingHours,
|
|
629
|
+
powerDistribution,
|
|
630
|
+
serviceStatus: {
|
|
631
|
+
totalServiceHours: deviceInfo.status.counters.service_time,
|
|
632
|
+
hoursSinceService,
|
|
633
|
+
serviceThresholdHours: serviceThreshold,
|
|
634
|
+
isServiceDue: hoursSinceService >= serviceThreshold,
|
|
635
|
+
},
|
|
636
|
+
blackoutCount: regeneration.blackout_counter,
|
|
637
|
+
lastMaintenanceDate: regeneration.last_intervention > 0
|
|
638
|
+
? new Date(regeneration.last_intervention * 1000)
|
|
639
|
+
: null,
|
|
640
|
+
alarmCount: alarmsLog.number,
|
|
641
|
+
};
|
|
642
|
+
};
|
|
643
|
+
exports.deriveUsageAnalytics = deriveUsageAnalytics;
|
|
644
|
+
const getTotalOperatingHours = (baseURL) =>
|
|
645
|
+
/**
|
|
646
|
+
* Calculates total operating hours across all power levels.
|
|
647
|
+
*
|
|
648
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
649
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
650
|
+
* @returns {Promise<number>} - Total operating hours.
|
|
651
|
+
*/
|
|
652
|
+
(jwtToken, macAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
653
|
+
const counters = yield getTotalCounters(baseURL)(jwtToken, macAddress);
|
|
654
|
+
return (counters.p1_working_time +
|
|
655
|
+
counters.p2_working_time +
|
|
656
|
+
counters.p3_working_time +
|
|
657
|
+
counters.p4_working_time +
|
|
658
|
+
counters.p5_working_time);
|
|
659
|
+
});
|
|
660
|
+
const getPowerDistribution = (baseURL) =>
|
|
661
|
+
/**
|
|
662
|
+
* Calculates power level usage distribution as percentages.
|
|
663
|
+
*
|
|
664
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
665
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
666
|
+
* @returns {Promise<PowerDistributionType>} - Percentage time at each power level.
|
|
667
|
+
*/
|
|
668
|
+
(jwtToken, macAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
669
|
+
const counters = yield getTotalCounters(baseURL)(jwtToken, macAddress);
|
|
670
|
+
const total = counters.p1_working_time +
|
|
671
|
+
counters.p2_working_time +
|
|
672
|
+
counters.p3_working_time +
|
|
673
|
+
counters.p4_working_time +
|
|
674
|
+
counters.p5_working_time;
|
|
675
|
+
if (total === 0) {
|
|
676
|
+
return { p1: 0, p2: 0, p3: 0, p4: 0, p5: 0 };
|
|
677
|
+
}
|
|
678
|
+
return {
|
|
679
|
+
p1: (counters.p1_working_time / total) * 100,
|
|
680
|
+
p2: (counters.p2_working_time / total) * 100,
|
|
681
|
+
p3: (counters.p3_working_time / total) * 100,
|
|
682
|
+
p4: (counters.p4_working_time / total) * 100,
|
|
683
|
+
p5: (counters.p5_working_time / total) * 100,
|
|
684
|
+
};
|
|
685
|
+
});
|
|
686
|
+
const getServiceStatus = (baseURL) =>
|
|
687
|
+
/**
|
|
688
|
+
* Calculates service status including whether maintenance is due.
|
|
689
|
+
*
|
|
690
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
691
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
692
|
+
* @param {number} [thresholdHours=2000] - Service threshold in hours.
|
|
693
|
+
* @returns {Promise<ServiceStatusType>} - Service status with computed fields.
|
|
694
|
+
*/
|
|
695
|
+
(jwtToken_1, macAddress_1, ...args_1) => __awaiter(void 0, [jwtToken_1, macAddress_1, ...args_1], void 0, function* (jwtToken, macAddress, thresholdHours = DEFAULT_SERVICE_THRESHOLD) {
|
|
696
|
+
const info = yield deviceInfo(baseURL)(jwtToken, macAddress);
|
|
697
|
+
const serviceCounters = info.nvm.service_counters;
|
|
698
|
+
const hoursSinceService = serviceCounters.p1_working_time +
|
|
699
|
+
serviceCounters.p2_working_time +
|
|
700
|
+
serviceCounters.p3_working_time +
|
|
701
|
+
serviceCounters.p4_working_time +
|
|
702
|
+
serviceCounters.p5_working_time;
|
|
703
|
+
return {
|
|
704
|
+
totalServiceHours: info.status.counters.service_time,
|
|
705
|
+
hoursSinceService,
|
|
706
|
+
serviceThresholdHours: thresholdHours,
|
|
707
|
+
isServiceDue: hoursSinceService >= thresholdHours,
|
|
708
|
+
};
|
|
709
|
+
});
|
|
710
|
+
const getUsageAnalytics = (baseURL) =>
|
|
711
|
+
/**
|
|
712
|
+
* Retrieves comprehensive usage analytics in a single call.
|
|
713
|
+
* Combines multiple statistics into a unified analytics object.
|
|
714
|
+
*
|
|
715
|
+
* @param {string} jwtToken - The JWT token for authentication.
|
|
716
|
+
* @param {string} macAddress - The MAC address of the device.
|
|
717
|
+
* @param {number} [serviceThreshold=2000] - Service threshold in hours.
|
|
718
|
+
* @returns {Promise<UsageAnalyticsType>} - Comprehensive usage analytics.
|
|
719
|
+
*/
|
|
720
|
+
(jwtToken_1, macAddress_1, ...args_1) => __awaiter(void 0, [jwtToken_1, macAddress_1, ...args_1], void 0, function* (jwtToken, macAddress, serviceThreshold = DEFAULT_SERVICE_THRESHOLD) {
|
|
721
|
+
const info = yield deviceInfo(baseURL)(jwtToken, macAddress);
|
|
722
|
+
return (0, exports.deriveUsageAnalytics)(info, serviceThreshold);
|
|
723
|
+
});
|
|
517
724
|
const registerDevice = (baseURL) =>
|
|
518
725
|
/**
|
|
519
726
|
* Registers a device with the user's account.
|
|
@@ -613,5 +820,16 @@ const configure = (baseURL = constants_1.API_URL) => ({
|
|
|
613
820
|
getLanguage: getLanguage(baseURL),
|
|
614
821
|
getPelletInReserve: getPelletInReserve(baseURL),
|
|
615
822
|
getPelletAutonomyTime: getPelletAutonomyTime(baseURL),
|
|
823
|
+
// Statistics getters
|
|
824
|
+
getTotalCounters: getTotalCounters(baseURL),
|
|
825
|
+
getServiceCounters: getServiceCounters(baseURL),
|
|
826
|
+
getAlarmHistory: getAlarmHistory(baseURL),
|
|
827
|
+
getRegenerationData: getRegenerationData(baseURL),
|
|
828
|
+
getServiceTime: getServiceTime(baseURL),
|
|
829
|
+
// Analytics functions
|
|
830
|
+
getTotalOperatingHours: getTotalOperatingHours(baseURL),
|
|
831
|
+
getPowerDistribution: getPowerDistribution(baseURL),
|
|
832
|
+
getServiceStatus: getServiceStatus(baseURL),
|
|
833
|
+
getUsageAnalytics: getUsageAnalytics(baseURL),
|
|
616
834
|
});
|
|
617
835
|
exports.configure = configure;
|