-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.js
1407 lines (1280 loc) · 52.2 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'use strict';
const utils = require('@iobroker/adapter-core');
const axios = require('axios').default;
const signalR = require('@microsoft/signalr');
const objEnum = require('./lib/enum.js');
//Eigene Variablen
const apiUrl = 'https://api.easee.com';
const adapterIntervals = {}; //halten von allen Intervallen
let accessToken = '';
let refreshToken = '';
let expireTime = Date.now();
let polltime = 30;
let logtype = false;
const minPollTimeEnergy = 120;
let roundCounter = 0;
const arrCharger = [];
//Variable für dynamicCircuitCurrentPX
let dynamicCircuitCurrentP1 = 0;
let dynamicCircuitCurrentP2 = 0;
let dynamicCircuitCurrentP3 = 0;
class Easee extends utils.Adapter {
/**
* @param {Partial<utils.AdapterOptions>} [options={}]
*/
constructor(options) {
super({
...options,
name: 'easee',
});
this.on('ready', this.onReady.bind(this));
this.on('stateChange', this.onStateChange.bind(this));
this.on('unload', this.onUnload.bind(this));
}
/**
* SignalR
*/
startSignal() {
const connection = new signalR.HubConnectionBuilder()
.withUrl('https://streams.easee.com/hubs/chargers', { accessTokenFactory: () => accessToken })
.withAutomaticReconnect()
.build();
connection.on('ProductUpdate', data => {
//haben einen neuen Wert über SignalR erhalten
const data_name = objEnum.getNameByEnum(data.id);
if (data_name == undefined) {
this.log.debug('New SignalR-ID, possible new Value: ' + data.id);
this.log.debug(JSON.stringify(data));
} else {
//Value is in ioBroker, update it
const tmpValueId = data.mid + data_name;
this.log.debug('New value over SignalR for: ' + tmpValueId + ', value: ' + data.value);
switch (data.dataType) {
case 2:
data.value = data.value == '1';
break;
case 3:
data.value = parseFloat(data.value);
break;
case 4:
data.value = parseInt(data.value);
break;
//case 6: JSON
}
this.setStateAsync(tmpValueId, { val: data.value, ack: true });
}
});
connection.start().then(() => {
//for each charger subscribe SignalR
arrCharger.forEach(charger_id => {
connection.send('SubscribeWithCurrentState', charger_id, true).then(() => {
this.log.info('Charger registrate in SignalR: ' + charger_id);
});
});
});
connection.onclose(() => {
this.log.error('SignalR Verbindung beendet!!!- restart');
this.startSignal();
});
}
/**
* Starten den Adapter
*/
async onReady() {
//initial Status melden
await this.setStateAsync('info.connection', false, true);
//Schauen ob die Polltime realistisch ist
if (this.config.polltime < 1) {
this.log.error('Interval in seconds to short -> got to default 30');
} else {
polltime = this.config.polltime;
}
logtype = this.config.logtype;
// Testen ob der Login funktioniert
if (this.config.username == '' || this.config.username == '+49') {
this.log.error('No username set');
} else if (this.config.client_secret == '') {
this.log.error('No password set');
} else {
this.log.debug('Api login started');
const login = await this.login(this.config.username, this.config.client_secret);
if (login) {
//Erstes Objekt erstellen
await this.setObjectNotExistsAsync('lastUpdate', {
type: 'state',
common: {
name: 'lastUpdate',
type: 'string',
role: 'indicator',
read: true,
write: false,
},
native: {},
});
//reset all to start
this.arrCharger = [];
// starten den Statuszyklus der API neu
await this.readAllStates();
if (this.config.signalR) {
this.log.info('Starting SignalR');
this.startSignal();
}
}
}
}
/**
* Clear all Timeouts an inform the USers
*/
onUnload(callback) {
try {
clearTimeout(adapterIntervals.readAllStates);
clearTimeout(adapterIntervals.updateDynamicCircuitCurrent);
this.log.info('Adaptor easee cleaned up everything...');
this.setStateAsync('info.connection', false, true);
callback();
} catch (e) {
callback();
}
}
/*****************************************************************************************/
async readAllStates() {
if(expireTime <= Date.now()) {
//Token ist expired!
if (logtype) this.log.info('Token has expired - refresh');
await this.refreshToken();
}
this.log.debug('read new states from the API');
//Lesen alle Charger aus
const tmpAllChargers = await this.getAllCharger();
if (tmpAllChargers != undefined) {
tmpAllChargers.forEach(async charger => {
//Prüfen ob wir das Object kennen
if (!arrCharger.includes(charger.id)) {
//setzen als erstes alle Objekte
await this.setAllStatusObjects(charger);
await this.setAllConfigObjects(charger);
//merken uns den charger
arrCharger.push(charger.id);
}
this.log.debug('Charger found');
this.log.debug(JSON.stringify(charger));
try {
//Lesen den Status aus
const tmpChargerState = await this.getChargerState(charger.id);
//Lesen die config
const tmpChargerConfig = await this.getChargerConfig(charger.id);
//Setzen die Daten der Charger
await this.setNewStatusToCharger(charger, tmpChargerState);
//Setzen die Config zum Charger
await this.setConfigStatus(charger, tmpChargerConfig);
//setzen und erechnen der Energiedaten, aber gebremste
if (roundCounter > (minPollTimeEnergy/polltime)) {
//lesen der Energiedaten
const tmpChargerSession = await this.getChargerSession(charger.id);
//etzen die Objekte
this.setNewSessionToCharger(charger, tmpChargerSession);
}
} catch (error) {
if (typeof error === 'string') {
this.log.error(error);
} else if (error instanceof Error) {
this.log.error(error.message);
}
}
});
} else {
this.log.warn('No Chargers found!');
}
//Energiedaten dürfen nur einmal in der Minute aufgerufen werden, daher müssen wir das bremsen
if(roundCounter > (minPollTimeEnergy/polltime)) {
this.log.debug('Hole Energiedaten: ' + roundCounter);
roundCounter = 0;
}
//Zählen die Runde!
roundCounter = roundCounter + 1;
//Melden das Update
await this.setStateAsync('lastUpdate', new Date().toLocaleTimeString(), true);
adapterIntervals.readAllStates = setTimeout(this.readAllStates.bind(this), polltime * 1000);
}
/**
* Is called if a subscribed state changes
* @param {string} id
* @param {ioBroker.State | null | undefined} state
*/
onStateChange(id, state) {
if (state) {
// The state was changed
this.log.debug(`state ${id} changed: ${state.val} (ack = ${state.ack})`);
const tmpControl = id.split('.');
if (tmpControl[3] == 'config') {
// change config, wenn ack = false
if (!state.ack) {
if (tmpControl[4] == 'circuitMaxCurrentP1' || tmpControl[4] == 'circuitMaxCurrentP2' || tmpControl[4] == 'circuitMaxCurrentP3') {
//Load site for Charger
this.getChargerSite(tmpControl[2]).then((site) => {
this.log.debug('Update circuitMaxCurrent to: ' + state.val);
this.log.debug('Get infos from site:');
this.log.debug(JSON.stringify(site));
this.changeMaxCircuitConfig(site.id, site.circuits[0].id, state.val);
this.log.debug('Changes sent to API');
});
} else if (tmpControl[4] == 'dynamicCircuitCurrentP1' || tmpControl[4] == 'dynamicCircuitCurrentP2' || tmpControl[4] == 'dynamicCircuitCurrentP3') {
this.getChargerSite(tmpControl[2]).then((site) => {
this.log.debug('Update dynamicCircuitCurrent to: ' + state.val);
this.log.debug('Get infos from site:');
this.log.debug(JSON.stringify(site));
//Setze die Werte für das Update
switch (tmpControl[4]) {
case 'dynamicCircuitCurrentP1':
dynamicCircuitCurrentP1 = Number(state.val);
break;
case 'dynamicCircuitCurrentP2':
dynamicCircuitCurrentP2 = Number(state.val);
break;
case 'dynamicCircuitCurrentP3':
dynamicCircuitCurrentP3 = Number(state.val);
break;
}
//Warten mit dem Update 500ms um weitere Phasen zu setzen:
if (adapterIntervals.updateDynamicCircuitCurrent != null) {
clearTimeout(adapterIntervals.updateDynamicCircuitCurrent);
adapterIntervals.updateDynamicCircuitCurrent = null;
}
adapterIntervals.updateDynamicCircuitCurrent = setTimeout( async () => {
await this.changeCircuitConfig(site.id, site.circuits[0].id);
}, 500);
});
} else {
this.log.debug('update config to API: ' + id);
if (tmpControl[4] == 'isEnabled') {
this.changeConfig(tmpControl[2], 'enabled', state.val);
} else {
this.changeConfig(tmpControl[2], tmpControl[4], state.val);
}
this.log.debug('Changes sent to API');
}
}
} else {
// control charger
switch (tmpControl[4]) {
case 'start':
// Starten Ladevorgang
this.log.info('Starting charging for Charger.id: ' + tmpControl[2]);
this.startCharging(tmpControl[2]);
break;
case 'stop':
// Stopen Ladevorgang
this.log.info('Stopping charging for Charger.id: ' + tmpControl[2]);
this.stopCharging(tmpControl[2]);
break;
case 'pause':
// Pausiere Ladevorgang
this.log.info('Pause charging for Charger.id: ' + tmpControl[2]);
this.pauseCharging(tmpControl[2]);
break;
case 'resume':
// Resume Ladevorgang
this.log.info('Resume charging for Charger.id: ' + tmpControl[2]);
this.resumeCharging(tmpControl[2]);
break;
case 'reboot':
// Reboot Charger
this.log.info('Reboot Charger.id: ' + tmpControl[2]);
this.rebootCharging(tmpControl[2]);
break;
default:
this.log.error('No command for Control found for: ' + id);
}
}
} else {
// The state was deleted
this.log.info(`state ${id} deleted`);
}
}
/***********************************************************************
* Funktionen für Status der Reading um den Code aufgeräumter zu machen
***********************************************************************/
//Setzen alle Status für Charger
async setNewStatusToCharger(charger, charger_states) {
await this.setStateAsync(charger.id + '.name', charger.name, true);
await this.setStateAsync(charger.id + '.status.cableLocked', charger_states.cableLocked, true);
await this.setStateAsync(charger.id + '.status.chargerOpMode', charger_states.chargerOpMode, true);
await this.setStateAsync(charger.id + '.status.totalPower', charger_states.totalPower, true);
await this.setStateAsync(charger.id + '.status.wiFiRSSI', charger_states.wiFiRSSI, true);
await this.setStateAsync(charger.id + '.status.chargerFirmware', charger_states.chargerFirmware, true);
await this.setStateAsync(charger.id + '.status.reasonForNoCurrent', charger_states.reasonForNoCurrent, true);
await this.setStateAsync(charger.id + '.status.voltage', charger_states.voltage, true);
await this.setStateAsync(charger.id + '.status.outputCurrent', charger_states.outputCurrent, true);
await this.setStateAsync(charger.id + '.status.isOnline', charger_states.isOnline, true);
await this.setStateAsync(charger.id + '.status.wiFiAPEnabled', charger_states.wiFiAPEnabled, true);
await this.setStateAsync(charger.id + '.status.ledMode', charger_states.ledMode, true);
await this.setStateAsync(charger.id + '.status.lifetimeEnergy', charger_states.lifetimeEnergy, true);
await this.setStateAsync(charger.id + '.status.energyPerHour', charger_states.energyPerHour, true);
await this.setStateAsync(charger.id + '.status.inCurrentT2', charger_states.inCurrentT2, true);
await this.setStateAsync(charger.id + '.status.inCurrentT3', charger_states.inCurrentT3, true);
await this.setStateAsync(charger.id + '.status.inCurrentT4', charger_states.inCurrentT4, true);
await this.setStateAsync(charger.id + '.status.inCurrentT5', charger_states.inCurrentT5, true);
await this.setStateAsync(charger.id + '.status.inVoltageT1T2', charger_states.inVoltageT1T2, true);
await this.setStateAsync(charger.id + '.status.inVoltageT1T3', charger_states.inVoltageT1T3, true);
await this.setStateAsync(charger.id + '.status.inVoltageT1T4', charger_states.inVoltageT1T4, true);
await this.setStateAsync(charger.id + '.status.inVoltageT1T5', charger_states.inVoltageT1T5, true);
await this.setStateAsync(charger.id + '.status.inVoltageT2T3', charger_states.inVoltageT2T3, true);
await this.setStateAsync(charger.id + '.status.inVoltageT2T4', charger_states.inVoltageT2T4, true);
await this.setStateAsync(charger.id + '.status.inVoltageT2T5', charger_states.inVoltageT2T5, true);
await this.setStateAsync(charger.id + '.status.inVoltageT3T4', charger_states.inVoltageT3T4, true);
await this.setStateAsync(charger.id + '.status.inVoltageT3T5', charger_states.inVoltageT3T5, true);
await this.setStateAsync(charger.id + '.status.inVoltageT4T5', charger_states.inVoltageT4T5, true);
//wert der config wird nur hier gesendet
await this.setStateAsync(charger.id + '.config.dynamicChargerCurrent', { val: charger_states.dynamicChargerCurrent, ack: true });
await this.setStateAsync(charger.id + '.config.dynamicCircuitCurrentP1', { val: charger_states.dynamicCircuitCurrentP1, ack: true });
await this.setStateAsync(charger.id + '.config.dynamicCircuitCurrentP2', { val: charger_states.dynamicCircuitCurrentP2, ack: true });
await this.setStateAsync(charger.id + '.config.dynamicCircuitCurrentP3', { val: charger_states.dynamicCircuitCurrentP3, ack: true });
await this.setStateAsync(charger.id + '.config.smartCharging', charger_states.smartCharging, true);
}
//Setzen alle Status für Config
async setConfigStatus(charger, charger_config) {
await this.setStateAsync(charger.id + '.config.isEnabled', { val: charger_config.isEnabled, ack: true } );
await this.setStateAsync(charger.id + '.config.phaseMode', { val: charger_config.phaseMode, ack: true });
await this.setStateAsync(charger.id + '.config.ledStripBrightness', { val: charger_config.ledStripBrightness, ack: true });
await this.setStateAsync(charger.id + '.config.smartButtonEnabled', { val: charger_config.smartButtonEnabled, ack: true });
await this.setStateAsync(charger.id + '.config.wiFiSSID', { val: charger_config.wiFiSSID, ack: true });
await this.setStateAsync(charger.id + '.config.maxChargerCurrent', { val: charger_config.maxChargerCurrent, ack: true });
//Values for sites
await this.setStateAsync(charger.id + '.config.circuitMaxCurrentP1', { val: charger_config.circuitMaxCurrentP1, ack: true });
await this.setStateAsync(charger.id + '.config.circuitMaxCurrentP2', { val: charger_config.circuitMaxCurrentP3, ack: true });
await this.setStateAsync(charger.id + '.config.circuitMaxCurrentP3', { val: charger_config.circuitMaxCurrentP3, ack: true });
}
/*************************************************************************
* API CALLS
* //Todo auslagern in eigene Datei ?
**************************************************************************/
//Get Token from API
async login(username, password) {
try {
const response = await axios.post(apiUrl + '/api/accounts/login', {
userName: username,
password: password
});
this.log.info('Easee Api Login successful');
accessToken = response.data.accessToken;
refreshToken = response.data.refreshToken;
expireTime = Date.now() + (response.data.expiresIn - 500);
this.log.debug(JSON.stringify(response.data));
await this.setStateAsync('info.connection', true, true);
return true;
} catch (error) {
this.log.error('Api login error - check Username and password');
if (typeof error === 'string') {
this.log.error(error);
} else if (error instanceof Error) {
this.log.error(error.message);
}
await this.setStateAsync('info.connection', false, true);
return false;
}
}
//GET net Token from API
async refreshToken() {
return await axios.post(apiUrl + '/api/accounts/refresh_token', {
accessToken: accessToken,
refreshToken: refreshToken
}).then(async response => {
if (logtype) this.log.info('RefreshToken successful');
accessToken = response.data.accessToken;
refreshToken = response.data.refreshToken;
expireTime = Date.now() + (response.data.expiresIn - 500);
await this.setStateAsync('info.connection', true, true);
this.log.debug(JSON.stringify(response.data));
}).catch(async (error) => {
this.log.error('RefreshToken error');
this.log.error(error);
await this.setStateAsync('info.connection', false, true);
});
}
//Lese alle Charger aus
async getAllCharger(){
return await axios.get(apiUrl + '/api/chargers' ,
{ headers: {'Authorization' : `Bearer ${accessToken}`}
}).then(response => {
this.log.debug('Chargers ausgelesen');
this.log.debug(JSON.stringify(response.data));
return response.data;
}).catch((error) => {
this.log.error(error);
});
}
// Lese den Charger aus
async getChargerState(charger_id){
return await axios.get(apiUrl + '/api/chargers/' + charger_id +'/state',
{ headers: {'Authorization' : `Bearer ${accessToken}`}
}).then(response => {
this.log.debug('Charger status ausgelesen mit id: ' + charger_id);
this.log.debug(JSON.stringify(response.data));
return response.data;
}).catch((error) => {
this.log.error(error);
throw new Error('Easee API error on charger state - stop refresh');
});
}
async getChargerConfig(charger_id){
return await axios.get(apiUrl + '/api/chargers/' + charger_id +'/config',
{ headers: {'Authorization' : `Bearer ${accessToken}`}
}).then(response => {
this.log.debug('Charger config ausgelesen mit id: ' + charger_id);
this.log.debug(JSON.stringify(response.data));
return response.data;
}).catch((error) => {
this.log.error(error);
throw new Error('Easee API error on charger config - stop refresh');
});
}
async getChargerSite(charger_id){
return await axios.get(apiUrl + '/api/chargers/' + charger_id +'/site',
{ headers: {'Authorization' : `Bearer ${accessToken}`}
}).then(response => {
this.log.debug('Charger site ausgelesen mit id: ' + charger_id);
this.log.debug(JSON.stringify(response.data));
return response.data;
}).catch((error) => {
this.log.error(error);
throw new Error('Easee API error on charger site - stop refresh');
});
}
async getChargerSession(charger_id){
return await axios.get(apiUrl + '/api/sessions/charger/' + charger_id +'/monthly',
{ headers: {'Authorization' : `Bearer ${accessToken}`}
}).then(response => {
this.log.debug('Charger session ausgelesen mit id: ' + charger_id);
this.log.debug(JSON.stringify(response.data));
return response.data;
}).catch((error) => {
this.log.error(error);
throw new Error('Easee API error on charger session - stop refresh');
});
}
async startCharging(id) {
return await axios.post(apiUrl + '/api/chargers/' + id + '/commands/start_charging', {},
{ headers: {'Authorization' : `Bearer ${accessToken}`}}
).then(response => {
this.log.info('Start charging successful');
this.log.debug(JSON.stringify(response.data));
}).catch((error) => {
this.log.error('Start charging error');
this.log.error(error);
});
}
async stopCharging(id) {
return await axios.post(apiUrl + '/api/chargers/' + id + '/commands/stop_charging', {},
{ headers: {'Authorization' : `Bearer ${accessToken}`}}
).then(response => {
this.log.info('Stop charging successful');
this.log.debug(JSON.stringify(response.data));
}).catch((error) => {
this.log.error('Stop charging error');
this.log.error(error);
});
}
async pauseCharging(id) {
return await axios.post(apiUrl + '/api/chargers/' + id + '/commands/pause_charging', {},
{ headers: {'Authorization' : `Bearer ${accessToken}`}}
).then(response => {
this.log.info('Pause charging successful');
this.log.debug(JSON.stringify(response.data));
}).catch((error) => {
this.log.error('Pause charging error');
this.log.error(error);
});
}
async resumeCharging(id) {
return await axios.post(apiUrl + '/api/chargers/' + id + '/commands/resume_charging', {},
{ headers: {'Authorization' : `Bearer ${accessToken}`}}
).then(response => {
this.log.info('Resume charging successful');
this.log.debug(JSON.stringify(response.data));
}).catch((error) => {
this.log.error('Resume charging error');
this.log.error(error);
});
}
async rebootCharging(id) {
return await axios.post(apiUrl + '/api/chargers/' + id + '/commands/reboot', {},
{ headers: {'Authorization' : `Bearer ${accessToken}`}}
).then(response => {
this.log.info('Reboot charging successful');
this.log.debug(JSON.stringify(response.data));
}).catch((error) => {
this.log.error('Reboot charging error');
this.log.error(error);
});
}
async changeConfig(id, configvalue, value) {
this.log.debug(JSON.stringify( {
[configvalue]: value
}));
return await axios.post(apiUrl + '/api/chargers/' + id + '/settings', {
[configvalue]: value
},
{ headers: {'Authorization' : `Bearer ${accessToken}`}}
).then(response => {
this.log.info('Config update successful');
this.log.debug(JSON.stringify(response.data));
}).catch((error) => {
this.log.error('Config update error');
this.log.error(error);
});
}
//circuitMaxCurrentPX
async changeMaxCircuitConfig(site_id, circuit_id, value) {
return await axios.post(apiUrl + '/api/sites/' + site_id + '/circuits/' + circuit_id + '/settings', {
'maxCircuitCurrentP1': value,
'maxCircuitCurrentP2': value,
'maxCircuitCurrentP3': value,
},
{ headers: {'Authorization' : `Bearer ${accessToken}`}}
).then(response => {
this.log.info('CircuitMax update successful');
this.log.debug(JSON.stringify(response.data));
}).catch((error) => {
this.log.error('CircuitMax update error');
this.log.error(error);
});
}
//dynamicCircuitCurrentPX
async changeCircuitConfig(site_id, circuit_id) {
//Der Wert darf nur für 3 Fach Werte aktualisiert werden
await axios.post(apiUrl + '/api/sites/' + site_id + '/circuits/' + circuit_id + '/settings', {
'dynamicCircuitCurrentP1': dynamicCircuitCurrentP1,
'dynamicCircuitCurrentP2': dynamicCircuitCurrentP2,
'dynamicCircuitCurrentP3': dynamicCircuitCurrentP3
},
{ headers: {'Authorization' : `Bearer ${accessToken}`}}
).then(response => {
this.log.info('Circuit update successful');
this.log.debug(JSON.stringify(response.data));
}).catch((error) => {
this.log.error('Circuit update error');
this.log.error(error);
});
//setze Werte zurück
adapterIntervals.updateDynamicCircuitCurrent = null;
dynamicCircuitCurrentP1 = 0;
dynamicCircuitCurrentP2 = 0;
dynamicCircuitCurrentP3 = 0;
}
/***********************************************************************
* Funktionen zum erstellen der Objekte der Reading
***********************************************************************/
async setAllStatusObjects(charger) {
//Legen die Steuerungsbutton für jeden Charger an
await this.setObjectNotExistsAsync(charger.id + '.control.start', {
type: 'state',
common: {
name: 'Start charging',
type: 'boolean',
role: 'button',
read: true,
write: true,
},
native: {},
});
this.subscribeStates(charger.id + '.control.start');
await this.setObjectNotExistsAsync(charger.id + '.control.stop', {
type: 'state',
common: {
name: 'Stop charging',
type: 'boolean',
role: 'button',
read: false,
write: true,
},
native: {},
});
this.subscribeStates(charger.id + '.control.stop');
await this.setObjectNotExistsAsync(charger.id + '.control.pause', {
type: 'state',
common: {
name: 'Pause charging',
type: 'boolean',
role: 'button',
read: false,
write: true,
},
native: {},
});
this.subscribeStates(charger.id + '.control.pause');
await this.setObjectNotExistsAsync(charger.id + '.control.resume', {
type: 'state',
common: {
name: 'Resume charging',
type: 'boolean',
role: 'button',
read: false,
write: true,
},
native: {},
});
this.subscribeStates(charger.id + '.control.resume');
await this.setObjectNotExistsAsync(charger.id + '.control.reboot', {
type: 'state',
common: {
name: 'Reboot Charger',
type: 'boolean',
role: 'button',
read: true,
write: true,
},
native: {},
});
this.subscribeStates(charger.id + '.control.reboot');
//id
await this.setObjectNotExistsAsync(charger.id + '.id', {
type: 'state',
common: {
name: 'id',
type: 'string',
role: 'info.name',
read: true,
write: false,
},
native: {},
});
await this.setStateAsync(charger.id + '.id', charger.id, true);
//name
await this.setObjectNotExistsAsync(charger.id + '.name', {
type: 'state',
common: {
name: 'name',
type: 'string',
role: 'info.name',
read: true,
write: false,
},
native: {},
});
//"cableLocked": true,
await this.setObjectNotExistsAsync(charger.id + '.status.cableLocked', {
type: 'state',
common: {
name: 'Cable lock state',
type: 'boolean',
role: 'sensor.lock',
read: true,
write: false,
},
native: {},
});
//"chargerOpMode": 1,
await this.setObjectNotExistsAsync(charger.id + '.status.chargerOpMode', {
type: 'state',
common: {
name: 'Charger operation mode according to charger mode table',
type: 'number',
role: 'value',
read: true,
write: false,
},
native: {},
});
//"totalPower": 0,
await this.setObjectNotExistsAsync(charger.id + '.status.totalPower', {
type: 'state',
common: {
name: 'Total power [kW]',
type: 'number',
role: 'value.power',
read: true,
write: false,
unit: 'kW'
},
native: {},
});
//"wiFiRSSI": 0,
await this.setObjectNotExistsAsync(charger.id + '.status.wiFiRSSI', {
type: 'state',
common: {
name: 'WiFi signal strength [dBm]',
type: 'number',
role: 'value',
read: true,
write: false,
unit: 'dBm'
},
native: {},
});
//"chargerFirmware": 0,
await this.setObjectNotExistsAsync(charger.id + '.status.chargerFirmware', {
type: 'state',
common: {
name: 'Modem firmware version',
type: 'number',
role: 'info.firmware',
read: true,
write: false,
},
native: {},
});
//"reasonForNoCurrent": 0,
await this.setObjectNotExistsAsync(charger.id + '.status.reasonForNoCurrent', {
type: 'state',
common: {
name: 'Reason for not offering current to the car',
type: 'number',
role: 'value',
read: true,
write: false,
},
native: {},
});
//"voltage": 0,
await this.setObjectNotExistsAsync(charger.id + '.status.voltage', {
type: 'state',
common: {
name: 'voltage',
type: 'number',
role: 'value.voltage',
read: true,
write: false,
unit: 'V'
},
native: {},
});
//"outputCurrent": 0,
await this.setObjectNotExistsAsync(charger.id + '.status.outputCurrent', {
type: 'state',
common: {
name: 'Active output phase(s) to EV according to output phase type table.',
type: 'number',
role: 'value.current',
read: true,
write: false,
unit: 'A'
},
native: {},
});
//"inCurrentT2": 0,
await this.setObjectNotExistsAsync(charger.id + '.status.inCurrentT2', {
type: 'state',
common: {
name: 'Current RMS for input T2 [Amperes]',
type: 'number',
role: 'value.current',
read: true,
write: false,
unit: 'A'
},
native: {},
});
//"inCurrentT3": 0,
await this.setObjectNotExistsAsync(charger.id + '.status.inCurrentT3', {
type: 'state',
common: {
name: 'Current RMS for input T3 [Amperes]',
type: 'number',
role: 'value.current',
read: true,
write: false,
unit: 'A'
},
native: {},
});
//"inCurrentT4": 0,
await this.setObjectNotExistsAsync(charger.id + '.status.inCurrentT4', {
type: 'state',
common: {
name: 'Current RMS for input T4 [Amperes]',
type: 'number',
role: 'value.current',
read: true,
write: false,
unit: 'A'
},
native: {},
});
//"inCurrentT5": 0,
await this.setObjectNotExistsAsync(charger.id + '.status.inCurrentT5', {
type: 'state',
common: {
name: 'Current RMS for input T5 [Amperes]',
type: 'number',
role: 'value.current',
read: true,
write: false,
unit: 'A'
},
native: {},
});
//"inVoltageT1T2": 0,
await this.setObjectNotExistsAsync(charger.id + '.status.inVoltageT1T2', {
type: 'state',
common: {
name: 'Current Voltage for between inputs T1 and T2 [Volts]',
type: 'number',
role: 'value.voltage',
read: true,
write: false,
unit: 'V'
},
native: {},
});
//"inVoltageT1T3": 0,
await this.setObjectNotExistsAsync(charger.id + '.status.inVoltageT1T3', {
type: 'state',
common: {
name: 'Current Voltage for between inputs T1 and T3 [Volts]',
type: 'number',
role: 'value.voltage',
read: true,
write: false,
unit: 'V'
},
native: {},
});
//"inVoltageT1T4": 0,
await this.setObjectNotExistsAsync(charger.id + '.status.inVoltageT1T4', {
type: 'state',
common: {
name: 'Current Voltage for between inputs T1 and T4 [Volts]',
type: 'number',
role: 'value.voltage',
read: true,
write: false,
unit: 'V'
},
native: {},
});
//"inVoltageT1T5": 0,
await this.setObjectNotExistsAsync(charger.id + '.status.inVoltageT1T5', {
type: 'state',
common: {
name: 'Current Voltage for between inputs T1 and T5 [Volts]',
type: 'number',
role: 'value.voltage',
read: true,
write: false,
unit: 'V'
},
native: {},
});
//"inVoltageT2T3": 0,
await this.setObjectNotExistsAsync(charger.id + '.status.inVoltageT2T3', {
type: 'state',
common: {
name: 'Current Voltage for between inputs T2 and T3 [Volts]',
type: 'number',
role: 'value.voltage',
read: true,
write: false,
unit: 'V'
},
native: {},
});
//"inVoltageT2T4": 0,
await this.setObjectNotExistsAsync(charger.id + '.status.inVoltageT2T4', {
type: 'state',
common: {
name: 'Current Voltage for between inputs T2 and T4 [Volts]',
type: 'number',
role: 'value.voltage',
read: true,
write: false,
unit: 'V'
},
native: {},
});
//"inVoltageT2T5": 0,
await this.setObjectNotExistsAsync(charger.id + '.status.inVoltageT2T5', {
type: 'state',
common: {
name: 'Current Voltage for between inputs T2 and T5 [Volts]',
type: 'number',
role: 'value.voltage',
read: true,
write: false,
unit: 'V'
},
native: {},
});
//"inVoltageT3T4": 0,
await this.setObjectNotExistsAsync(charger.id + '.status.inVoltageT3T4', {
type: 'state',
common: {
name: 'Current Voltage for between inputs T3 and T4 [Volts]',
type: 'number',
role: 'value.voltage',
read: true,
write: false,
unit: 'V'
},
native: {},
});