edilkamin 1.8.0 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/dependabot.yml +5 -1
- package/README.md +56 -1
- package/dist/cjs/package.json +4 -4
- package/dist/cjs/src/cli.js +234 -6
- package/dist/cjs/src/index.d.ts +1 -1
- package/dist/cjs/src/library.d.ts +32 -2
- package/dist/cjs/src/library.js +302 -9
- package/dist/cjs/src/library.test.js +273 -3
- package/dist/cjs/src/types.d.ts +17 -1
- package/dist/esm/package.json +4 -4
- package/dist/esm/src/cli.js +234 -6
- package/dist/esm/src/index.d.ts +1 -1
- package/dist/esm/src/library.d.ts +32 -2
- package/dist/esm/src/library.js +302 -9
- package/dist/esm/src/library.test.js +273 -3
- package/dist/esm/src/types.d.ts +17 -1
- package/package.json +4 -4
- package/src/cli.ts +425 -6
- package/src/library.test.ts +379 -2
- package/src/library.ts +399 -9
- package/src/types.ts +20 -0
package/src/library.test.ts
CHANGED
|
@@ -209,9 +209,39 @@ describe("library", () => {
|
|
|
209
209
|
"setPowerOff",
|
|
210
210
|
"setPowerOn",
|
|
211
211
|
"getPower",
|
|
212
|
+
"setPowerLevel",
|
|
213
|
+
"getPowerLevel",
|
|
214
|
+
"setFanSpeed",
|
|
215
|
+
"getFanSpeed",
|
|
216
|
+
"setFan1Speed",
|
|
217
|
+
"setFan2Speed",
|
|
218
|
+
"setFan3Speed",
|
|
219
|
+
"getFan1Speed",
|
|
220
|
+
"getFan2Speed",
|
|
221
|
+
"getFan3Speed",
|
|
222
|
+
"setAirkare",
|
|
223
|
+
"setRelax",
|
|
224
|
+
"setStandby",
|
|
225
|
+
"getStandby",
|
|
226
|
+
"setStandbyTime",
|
|
227
|
+
"getStandbyTime",
|
|
228
|
+
"setAuto",
|
|
229
|
+
"getAuto",
|
|
212
230
|
"getEnvironmentTemperature",
|
|
213
231
|
"getTargetTemperature",
|
|
214
232
|
"setTargetTemperature",
|
|
233
|
+
"setEnvironment1Temperature",
|
|
234
|
+
"getEnvironment1Temperature",
|
|
235
|
+
"setEnvironment2Temperature",
|
|
236
|
+
"getEnvironment2Temperature",
|
|
237
|
+
"setEnvironment3Temperature",
|
|
238
|
+
"getEnvironment3Temperature",
|
|
239
|
+
"setMeasureUnit",
|
|
240
|
+
"getMeasureUnit",
|
|
241
|
+
"setLanguage",
|
|
242
|
+
"getLanguage",
|
|
243
|
+
"getPelletInReserve",
|
|
244
|
+
"getPelletAutonomyTime",
|
|
215
245
|
];
|
|
216
246
|
it("should create API methods with the correct baseURL", async () => {
|
|
217
247
|
const baseURL = "https://example.com/api/";
|
|
@@ -243,10 +273,27 @@ describe("library", () => {
|
|
|
243
273
|
temperatures: {
|
|
244
274
|
enviroment: 19,
|
|
245
275
|
},
|
|
276
|
+
flags: {
|
|
277
|
+
is_pellet_in_reserve: false,
|
|
278
|
+
},
|
|
279
|
+
pellet: {
|
|
280
|
+
autonomy_time: 180,
|
|
281
|
+
},
|
|
246
282
|
},
|
|
247
283
|
nvm: {
|
|
248
284
|
user_parameters: {
|
|
249
285
|
enviroment_1_temperature: 22,
|
|
286
|
+
enviroment_2_temperature: 18,
|
|
287
|
+
enviroment_3_temperature: 20,
|
|
288
|
+
manual_power: 3,
|
|
289
|
+
fan_1_ventilation: 2,
|
|
290
|
+
fan_2_ventilation: 3,
|
|
291
|
+
fan_3_ventilation: 4,
|
|
292
|
+
is_standby_active: true,
|
|
293
|
+
standby_waiting_time: 30,
|
|
294
|
+
is_auto: true,
|
|
295
|
+
is_fahrenheit: false,
|
|
296
|
+
language: 2,
|
|
250
297
|
},
|
|
251
298
|
},
|
|
252
299
|
};
|
|
@@ -315,6 +362,30 @@ describe("library", () => {
|
|
|
315
362
|
api.getPower(token, mac),
|
|
316
363
|
expectedResult: true,
|
|
317
364
|
},
|
|
365
|
+
{
|
|
366
|
+
method: "getPowerLevel",
|
|
367
|
+
call: (api: ReturnType<typeof configure>, token: string, mac: string) =>
|
|
368
|
+
api.getPowerLevel(token, mac),
|
|
369
|
+
expectedResult: 3,
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
method: "getFan1Speed",
|
|
373
|
+
call: (api: ReturnType<typeof configure>, token: string, mac: string) =>
|
|
374
|
+
api.getFan1Speed(token, mac),
|
|
375
|
+
expectedResult: 2,
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
method: "getFan2Speed",
|
|
379
|
+
call: (api: ReturnType<typeof configure>, token: string, mac: string) =>
|
|
380
|
+
api.getFan2Speed(token, mac),
|
|
381
|
+
expectedResult: 3,
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
method: "getFan3Speed",
|
|
385
|
+
call: (api: ReturnType<typeof configure>, token: string, mac: string) =>
|
|
386
|
+
api.getFan3Speed(token, mac),
|
|
387
|
+
expectedResult: 4,
|
|
388
|
+
},
|
|
318
389
|
{
|
|
319
390
|
method: "getEnvironmentTemperature",
|
|
320
391
|
call: (api: ReturnType<typeof configure>, token: string, mac: string) =>
|
|
@@ -324,9 +395,63 @@ describe("library", () => {
|
|
|
324
395
|
{
|
|
325
396
|
method: "getTargetTemperature",
|
|
326
397
|
call: (api: ReturnType<typeof configure>, token: string, mac: string) =>
|
|
327
|
-
api.getTargetTemperature(token, mac),
|
|
398
|
+
api.getTargetTemperature(token, mac, 1),
|
|
328
399
|
expectedResult: 22,
|
|
329
400
|
},
|
|
401
|
+
{
|
|
402
|
+
method: "getStandby",
|
|
403
|
+
call: (api: ReturnType<typeof configure>, token: string, mac: string) =>
|
|
404
|
+
api.getStandby(token, mac),
|
|
405
|
+
expectedResult: true,
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
method: "getStandbyTime",
|
|
409
|
+
call: (api: ReturnType<typeof configure>, token: string, mac: string) =>
|
|
410
|
+
api.getStandbyTime(token, mac),
|
|
411
|
+
expectedResult: 30,
|
|
412
|
+
},
|
|
413
|
+
{
|
|
414
|
+
method: "getAuto",
|
|
415
|
+
call: (api: ReturnType<typeof configure>, token: string, mac: string) =>
|
|
416
|
+
api.getAuto(token, mac),
|
|
417
|
+
expectedResult: true,
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
method: "getEnvironment2Temperature",
|
|
421
|
+
call: (api: ReturnType<typeof configure>, token: string, mac: string) =>
|
|
422
|
+
api.getEnvironment2Temperature(token, mac),
|
|
423
|
+
expectedResult: 18,
|
|
424
|
+
},
|
|
425
|
+
{
|
|
426
|
+
method: "getEnvironment3Temperature",
|
|
427
|
+
call: (api: ReturnType<typeof configure>, token: string, mac: string) =>
|
|
428
|
+
api.getEnvironment3Temperature(token, mac),
|
|
429
|
+
expectedResult: 20,
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
method: "getMeasureUnit",
|
|
433
|
+
call: (api: ReturnType<typeof configure>, token: string, mac: string) =>
|
|
434
|
+
api.getMeasureUnit(token, mac),
|
|
435
|
+
expectedResult: false,
|
|
436
|
+
},
|
|
437
|
+
{
|
|
438
|
+
method: "getLanguage",
|
|
439
|
+
call: (api: ReturnType<typeof configure>, token: string, mac: string) =>
|
|
440
|
+
api.getLanguage(token, mac),
|
|
441
|
+
expectedResult: 2,
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
method: "getPelletInReserve",
|
|
445
|
+
call: (api: ReturnType<typeof configure>, token: string, mac: string) =>
|
|
446
|
+
api.getPelletInReserve(token, mac),
|
|
447
|
+
expectedResult: false,
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
method: "getPelletAutonomyTime",
|
|
451
|
+
call: (api: ReturnType<typeof configure>, token: string, mac: string) =>
|
|
452
|
+
api.getPelletAutonomyTime(token, mac),
|
|
453
|
+
expectedResult: 180,
|
|
454
|
+
},
|
|
330
455
|
];
|
|
331
456
|
getterTests.forEach(({ method, call, expectedResult }) => {
|
|
332
457
|
it(`should call fetch and return the correct value for ${method}`, async () => {
|
|
@@ -349,6 +474,58 @@ describe("library", () => {
|
|
|
349
474
|
});
|
|
350
475
|
// Setter tests
|
|
351
476
|
const setterTests = [
|
|
477
|
+
{
|
|
478
|
+
method: "setPowerLevel",
|
|
479
|
+
call: (
|
|
480
|
+
api: ReturnType<typeof configure>,
|
|
481
|
+
token: string,
|
|
482
|
+
mac: string,
|
|
483
|
+
value: number,
|
|
484
|
+
) => api.setPowerLevel(token, mac, value),
|
|
485
|
+
payload: {
|
|
486
|
+
name: "power_level",
|
|
487
|
+
value: 4,
|
|
488
|
+
},
|
|
489
|
+
},
|
|
490
|
+
{
|
|
491
|
+
method: "setFan1Speed",
|
|
492
|
+
call: (
|
|
493
|
+
api: ReturnType<typeof configure>,
|
|
494
|
+
token: string,
|
|
495
|
+
mac: string,
|
|
496
|
+
value: number,
|
|
497
|
+
) => api.setFan1Speed(token, mac, value),
|
|
498
|
+
payload: {
|
|
499
|
+
name: "fan_1_speed",
|
|
500
|
+
value: 3,
|
|
501
|
+
},
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
method: "setFan2Speed",
|
|
505
|
+
call: (
|
|
506
|
+
api: ReturnType<typeof configure>,
|
|
507
|
+
token: string,
|
|
508
|
+
mac: string,
|
|
509
|
+
value: number,
|
|
510
|
+
) => api.setFan2Speed(token, mac, value),
|
|
511
|
+
payload: {
|
|
512
|
+
name: "fan_2_speed",
|
|
513
|
+
value: 4,
|
|
514
|
+
},
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
method: "setFan3Speed",
|
|
518
|
+
call: (
|
|
519
|
+
api: ReturnType<typeof configure>,
|
|
520
|
+
token: string,
|
|
521
|
+
mac: string,
|
|
522
|
+
value: number,
|
|
523
|
+
) => api.setFan3Speed(token, mac, value),
|
|
524
|
+
payload: {
|
|
525
|
+
name: "fan_3_speed",
|
|
526
|
+
value: 5,
|
|
527
|
+
},
|
|
528
|
+
},
|
|
352
529
|
{
|
|
353
530
|
method: "setTargetTemperature",
|
|
354
531
|
call: (
|
|
@@ -356,12 +533,64 @@ describe("library", () => {
|
|
|
356
533
|
token: string,
|
|
357
534
|
mac: string,
|
|
358
535
|
value: number,
|
|
359
|
-
) => api.setTargetTemperature(token, mac, value),
|
|
536
|
+
) => api.setTargetTemperature(token, mac, 1, value),
|
|
360
537
|
payload: {
|
|
361
538
|
name: "enviroment_1_temperature",
|
|
362
539
|
value: 20,
|
|
363
540
|
},
|
|
364
541
|
},
|
|
542
|
+
{
|
|
543
|
+
method: "setStandbyTime",
|
|
544
|
+
call: (
|
|
545
|
+
api: ReturnType<typeof configure>,
|
|
546
|
+
token: string,
|
|
547
|
+
mac: string,
|
|
548
|
+
value: number,
|
|
549
|
+
) => api.setStandbyTime(token, mac, value),
|
|
550
|
+
payload: {
|
|
551
|
+
name: "standby_time",
|
|
552
|
+
value: 45,
|
|
553
|
+
},
|
|
554
|
+
},
|
|
555
|
+
{
|
|
556
|
+
method: "setEnvironment2Temperature",
|
|
557
|
+
call: (
|
|
558
|
+
api: ReturnType<typeof configure>,
|
|
559
|
+
token: string,
|
|
560
|
+
mac: string,
|
|
561
|
+
value: number,
|
|
562
|
+
) => api.setEnvironment2Temperature(token, mac, value),
|
|
563
|
+
payload: {
|
|
564
|
+
name: "enviroment_2_temperature",
|
|
565
|
+
value: 21,
|
|
566
|
+
},
|
|
567
|
+
},
|
|
568
|
+
{
|
|
569
|
+
method: "setEnvironment3Temperature",
|
|
570
|
+
call: (
|
|
571
|
+
api: ReturnType<typeof configure>,
|
|
572
|
+
token: string,
|
|
573
|
+
mac: string,
|
|
574
|
+
value: number,
|
|
575
|
+
) => api.setEnvironment3Temperature(token, mac, value),
|
|
576
|
+
payload: {
|
|
577
|
+
name: "enviroment_3_temperature",
|
|
578
|
+
value: 23,
|
|
579
|
+
},
|
|
580
|
+
},
|
|
581
|
+
{
|
|
582
|
+
method: "setLanguage",
|
|
583
|
+
call: (
|
|
584
|
+
api: ReturnType<typeof configure>,
|
|
585
|
+
token: string,
|
|
586
|
+
mac: string,
|
|
587
|
+
value: number,
|
|
588
|
+
) => api.setLanguage(token, mac, value),
|
|
589
|
+
payload: {
|
|
590
|
+
name: "language",
|
|
591
|
+
value: 2,
|
|
592
|
+
},
|
|
593
|
+
},
|
|
365
594
|
];
|
|
366
595
|
setterTests.forEach(({ method, call, payload }) => {
|
|
367
596
|
it(`should call fetch and send the correct payload for ${method}`, async () => {
|
|
@@ -388,6 +617,108 @@ describe("library", () => {
|
|
|
388
617
|
});
|
|
389
618
|
});
|
|
390
619
|
});
|
|
620
|
+
|
|
621
|
+
// Boolean setter tests (for mode controls)
|
|
622
|
+
const booleanSetterTests = [
|
|
623
|
+
{
|
|
624
|
+
method: "setAirkare",
|
|
625
|
+
call: (
|
|
626
|
+
api: ReturnType<typeof configure>,
|
|
627
|
+
token: string,
|
|
628
|
+
mac: string,
|
|
629
|
+
enabled: boolean,
|
|
630
|
+
) => api.setAirkare(token, mac, enabled),
|
|
631
|
+
truePayload: { name: "airkare_function", value: 1 },
|
|
632
|
+
falsePayload: { name: "airkare_function", value: 0 },
|
|
633
|
+
},
|
|
634
|
+
{
|
|
635
|
+
method: "setRelax",
|
|
636
|
+
call: (
|
|
637
|
+
api: ReturnType<typeof configure>,
|
|
638
|
+
token: string,
|
|
639
|
+
mac: string,
|
|
640
|
+
enabled: boolean,
|
|
641
|
+
) => api.setRelax(token, mac, enabled),
|
|
642
|
+
truePayload: { name: "relax_mode", value: true },
|
|
643
|
+
falsePayload: { name: "relax_mode", value: false },
|
|
644
|
+
},
|
|
645
|
+
{
|
|
646
|
+
method: "setStandby",
|
|
647
|
+
call: (
|
|
648
|
+
api: ReturnType<typeof configure>,
|
|
649
|
+
token: string,
|
|
650
|
+
mac: string,
|
|
651
|
+
enabled: boolean,
|
|
652
|
+
) => api.setStandby(token, mac, enabled),
|
|
653
|
+
truePayload: { name: "standby_mode", value: true },
|
|
654
|
+
falsePayload: { name: "standby_mode", value: false },
|
|
655
|
+
},
|
|
656
|
+
{
|
|
657
|
+
method: "setAuto",
|
|
658
|
+
call: (
|
|
659
|
+
api: ReturnType<typeof configure>,
|
|
660
|
+
token: string,
|
|
661
|
+
mac: string,
|
|
662
|
+
enabled: boolean,
|
|
663
|
+
) => api.setAuto(token, mac, enabled),
|
|
664
|
+
truePayload: { name: "auto_mode", value: true },
|
|
665
|
+
falsePayload: { name: "auto_mode", value: false },
|
|
666
|
+
},
|
|
667
|
+
{
|
|
668
|
+
method: "setMeasureUnit",
|
|
669
|
+
call: (
|
|
670
|
+
api: ReturnType<typeof configure>,
|
|
671
|
+
token: string,
|
|
672
|
+
mac: string,
|
|
673
|
+
enabled: boolean,
|
|
674
|
+
) => api.setMeasureUnit(token, mac, enabled),
|
|
675
|
+
truePayload: { name: "measure_unit", value: true },
|
|
676
|
+
falsePayload: { name: "measure_unit", value: false },
|
|
677
|
+
},
|
|
678
|
+
];
|
|
679
|
+
booleanSetterTests.forEach(
|
|
680
|
+
({ method, call, truePayload, falsePayload }) => {
|
|
681
|
+
it(`should call fetch with correct payload for ${method}(true)`, async () => {
|
|
682
|
+
fetchStub.resolves(mockResponse({ success: true }));
|
|
683
|
+
const api = configure("https://example.com/api/");
|
|
684
|
+
|
|
685
|
+
await call(api, expectedToken, "mockMacAddress", true);
|
|
686
|
+
|
|
687
|
+
assert.ok(fetchStub.calledOnce);
|
|
688
|
+
assert.deepEqual(fetchStub.firstCall.args[1], {
|
|
689
|
+
method: "PUT",
|
|
690
|
+
headers: {
|
|
691
|
+
"Content-Type": "application/json",
|
|
692
|
+
Authorization: `Bearer ${expectedToken}`,
|
|
693
|
+
},
|
|
694
|
+
body: JSON.stringify({
|
|
695
|
+
mac_address: "mockMacAddress",
|
|
696
|
+
...truePayload,
|
|
697
|
+
}),
|
|
698
|
+
});
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
it(`should call fetch with correct payload for ${method}(false)`, async () => {
|
|
702
|
+
fetchStub.resolves(mockResponse({ success: true }));
|
|
703
|
+
const api = configure("https://example.com/api/");
|
|
704
|
+
|
|
705
|
+
await call(api, expectedToken, "mockMacAddress", false);
|
|
706
|
+
|
|
707
|
+
assert.ok(fetchStub.calledOnce);
|
|
708
|
+
assert.deepEqual(fetchStub.firstCall.args[1], {
|
|
709
|
+
method: "PUT",
|
|
710
|
+
headers: {
|
|
711
|
+
"Content-Type": "application/json",
|
|
712
|
+
Authorization: `Bearer ${expectedToken}`,
|
|
713
|
+
},
|
|
714
|
+
body: JSON.stringify({
|
|
715
|
+
mac_address: "mockMacAddress",
|
|
716
|
+
...falsePayload,
|
|
717
|
+
}),
|
|
718
|
+
});
|
|
719
|
+
});
|
|
720
|
+
},
|
|
721
|
+
);
|
|
391
722
|
});
|
|
392
723
|
|
|
393
724
|
describe("registerDevice", () => {
|
|
@@ -634,10 +965,56 @@ describe("library", () => {
|
|
|
634
965
|
const result = await api.getTargetTemperature(
|
|
635
966
|
expectedToken,
|
|
636
967
|
"mockMacAddress",
|
|
968
|
+
1,
|
|
637
969
|
);
|
|
638
970
|
|
|
639
971
|
assert.equal(result, 22);
|
|
640
972
|
});
|
|
973
|
+
|
|
974
|
+
it("should work with getPelletInReserve on compressed response", async () => {
|
|
975
|
+
const statusData = {
|
|
976
|
+
commands: { power: true },
|
|
977
|
+
temperatures: { enviroment: 19 },
|
|
978
|
+
flags: { is_pellet_in_reserve: true },
|
|
979
|
+
pellet: { autonomy_time: 120 },
|
|
980
|
+
};
|
|
981
|
+
const mockResponseData = {
|
|
982
|
+
status: createGzippedBuffer(statusData),
|
|
983
|
+
nvm: { user_parameters: { enviroment_1_temperature: 22 } },
|
|
984
|
+
};
|
|
985
|
+
|
|
986
|
+
fetchStub.resolves(mockResponse(mockResponseData));
|
|
987
|
+
const api = configure("https://example.com/api/");
|
|
988
|
+
|
|
989
|
+
const result = await api.getPelletInReserve(
|
|
990
|
+
expectedToken,
|
|
991
|
+
"mockMacAddress",
|
|
992
|
+
);
|
|
993
|
+
|
|
994
|
+
assert.equal(result, true);
|
|
995
|
+
});
|
|
996
|
+
|
|
997
|
+
it("should work with getPelletAutonomyTime on response", async () => {
|
|
998
|
+
const mockResponseData = {
|
|
999
|
+
status: {
|
|
1000
|
+
commands: { power: true },
|
|
1001
|
+
temperatures: { enviroment: 19 },
|
|
1002
|
+
flags: { is_pellet_in_reserve: false },
|
|
1003
|
+
pellet: { autonomy_time: 240 },
|
|
1004
|
+
},
|
|
1005
|
+
nvm: { user_parameters: { enviroment_1_temperature: 22 } },
|
|
1006
|
+
};
|
|
1007
|
+
|
|
1008
|
+
fetchStub.resolves(mockResponse(mockResponseData));
|
|
1009
|
+
const api = configure("https://example.com/api/");
|
|
1010
|
+
|
|
1011
|
+
const result = await api.getPelletAutonomyTime(
|
|
1012
|
+
expectedToken,
|
|
1013
|
+
"mockMacAddress",
|
|
1014
|
+
);
|
|
1015
|
+
|
|
1016
|
+
assert.equal(result, 240);
|
|
1017
|
+
});
|
|
641
1018
|
});
|
|
642
1019
|
|
|
643
1020
|
describe("Error Handling", () => {
|