forked from DrozmotiX/ioBroker.tado
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
1593 lines (1226 loc) · 46.5 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';
/*
* Created with @iobroker/create-adapter v1.16.0
*/
// The adapter-core module gives you access to the core ioBroker functions
// you need to create an adapter
const utils = require('@iobroker/adapter-core');
// Load your modules here, e.g.:
const EXPIRATION_WINDOW_IN_SECONDS = 300;
const tado_auth_url = 'https://auth.tado.com';
const tado_url = 'https://my.tado.com';
const tado_config = {
client: {
id: 'tado-web-app',
secret: 'wZaRN7rpjn3FoNyF5IFuxg9uMzYJcvOoQ8QWiIqS3hfk6gLhVlG57j5YNoZL2Rtc',
},
auth: {
tokenHost: tado_auth_url,
}
};
const oauth2 = require('simple-oauth2').create(tado_config);
const state_attr = require(__dirname + '/lib/state_attr.js');
const axios = require('axios');
let polling; // Polling timer
const counter = []; // counter timer
// const fs = require('fs');
class Tado extends utils.Adapter {
/**
* @param {Partial<ioBroker.AdapterOptions>} [options={}]
*/
constructor(options) {
super({
...options,
name: 'tado',
});
this.on('ready', this.onReady.bind(this));
this.on('stateChange', this.onStateChange.bind(this));
this.on('unload', this.onUnload.bind(this));
this._accessToken = null;
this.getMe_data = null;
this.Home_data = null;
}
/**
* Is called when databases are connected and adapter received configuration.
*/
async onReady() {
// Reset the connection indicator during startup
this.setState('info.connection', false, true);
await this.DoConnect();
}
/**
* Is called when adapter shuts down - callback has to be called under any circumstances!
* @param {() => void} callback
*/
onUnload(callback) {
try {
this.log.info('cleaned everything up...');
callback();
} catch (e) {
callback();
}
}
/**
* Is called if a subscribed state changes
* @param {string} id
* @param {ioBroker.State | null | undefined} state
*/
async onStateChange(id, state) {
if (state) {
// The state was changed
if (state.ack === false) {
try {
// const deviceId = id.split('.');
const deviceId = id.split('.');
// let stateNameToSend = '';
for (const x in deviceId){
this.log.debug('Device id channel : ' + deviceId[x]);
let set_temp = null;
let set_mode = null;
const temperature = await this.getStateAsync(deviceId[2] + '.Rooms.' + deviceId[4] + '.setting.temperature');
const mode = await this.getStateAsync(deviceId[2] + '.Rooms.' + deviceId[4] + '.overlay.type');
if (temperature !== null && temperature !== undefined){
set_temp = temperature.val;
} else {
set_temp = '20';
}
this.log.debug('Room Temperature set : ' + set_temp);
if (mode !== null || mode !== undefined){
set_mode = 'auto';
} else {
set_mode = mode;
}
this.log.debug('Room mode set : ' + set_mode);
switch (deviceId[x]) {
case ('clearZoneOverlay'):
this.log.info('Overlay cleared for room : ' + deviceId[4] + ' in home : ' + deviceId[2]);
await this.clearZoneOverlay(deviceId[2],deviceId[4]);
await this.DoConnect();
break;
case ('temperature'):
this.log.info('Temperature changed for room : ' + deviceId[4] + ' in home : ' + deviceId[2] + ' to API with : ' + state.val);
await this.setZoneOverlay(deviceId[2], deviceId[4],'on',state.val, set_mode);
this.DoConnect();
break;
case ('power'):
if(set_mode === 'auto' && state.val === 'ON' ) {
await this.clearZoneOverlay(deviceId[2],deviceId[4]);
} else {
try {
this.log.info('Power changed for room : ' + deviceId[4] + ' in home : ' + deviceId[2] + ' to API with : ' + state.val + ' and Temperature : ' + set_temp + ' and mode : ' + set_mode);
await this.setZoneOverlay(deviceId[2], deviceId[4],state.val,set_temp, mode);
} catch (error) {
this.log.error('Power changed for room : ' + deviceId[4] + ' in home : ' + deviceId[2] + ' to API with : ' + state.val + ' error from temperature : ' + error);
await this.setZoneOverlay(deviceId[2], deviceId[4], state.val, '20', 'manual');
}
}
this.DoConnect();
break;
default:
}
}
this.log.debug('State change detected from different source then adapter');
this.log.debug(`state ${id} changed: ${state.val} (ack = ${state.ack})`);
} catch (error) {
this.log.error('Issue at state change : ' + error);
}
} else {
this.log.debug(`state ${id} changed: ${state.val} (ack = ${state.ack})`);
}
} else {
// The state was deleted
this.log.info(`state ${id} deleted`);
}
}
async DoConnect(){
// this.log.info('Username : ' + user + ' Password : ' + pass);
const user = this.config.Username;
let pass = this.config.Password;
// Check if credentials are not empty and decrypt stored password
if (user !== '' && pass !== ''){
this.getForeignObject('system.config', (err, obj) => {
if (obj && obj.native && obj.native.secret) {
//noinspection JSUnresolvedVariable
pass = this.decrypt(obj.native.secret, pass);
} else {
//noinspection JSUnresolvedVariable
pass = this.decrypt('Zgfr56gFe87jJOM', pass);
}
try {
this.DoData_Refresh(user,pass);
} catch (error) {
this.log.error(error);
}
});
} else {
this.log.error('*** Adapter deactivated, credentials missing in Adaptper Settings !!! ***');
this.setForeignState('system.adapter.' + this.namespace + '.alive', false);
}
}
async DoData_Refresh(user,pass){
const intervall_time = (this.config.intervall * 1000);
// Get login token
try {
await this.login(user,pass);
const conn_state = await this.getStateAsync('info.connection');
if (conn_state === undefined || conn_state === null) {
return;
} else {
if (conn_state.val === false) {
this.log.info('Connected to Tado cloud, initialyzing ... ');
}
}
// Get Basic data needed for all other querys and store to global variable
if(this.getMe_data === null){
this.getMe_data = await this.getMe();
}
this.log.debug('GetMe result : ' + JSON.stringify(this.getMe_data));
for (const i in this.getMe_data.homes) {
this.DoWriteJsonRespons(this.getMe_data.homes[i].id,'Stage_01_GetMe_Data', this.getMe_data);
// create device channel for each Home found in getMe
await this.setObjectNotExistsAsync(this.getMe_data.homes[i].id.toString(), {
type: 'device',
common: {
name: this.getMe_data.homes[i].name,
},
native: {},
});
// Write basic data to home specific info channel states
await this.DoHome(this.getMe_data.homes[i].id);
await this.DoDevices(this.getMe_data.homes[i].id);
await this.DoWeather(this.getMe_data.homes[i].id);
await this.DoInstallations(this.getMe_data.homes[i].id);
// this.getInstallations(this.getMe_data.homes[i].id);
// await this.DoUsers(this.getMe_data.homes[i].id) // User information equal to Weather, ignoring function but keep for history/feature functionality
try {
await this.DoStates(this.getMe_data.homes[i].id);
} catch (error) {
// no info
}
this.log.silly('Get all mobile devices');
try {
await this.DoMobileDevices(this.getMe_data.homes[i].id);
} catch (error) {
this.log.silly('Issue in Get all mobile devices' + error);
}
this.log.silly('Get all rooms');
try {
await this.DoZones(this.getMe_data.homes[i].id);
} catch (error) {
this.log.error('Issue in Get all rooms ' + error);
}
}
if (conn_state === undefined || conn_state === null) {
return;
} else {
if (conn_state.val === false) {
this.log.info('Initialisation finished, connected to Tado Cloud service refreshing every : ' + this.config.intervall + ' seconds');
this.setState('info.connection', true, true);
}
}
// Clear running timer
(function () {if (polling) {clearTimeout(polling); polling = null;}})();
// timer
polling = setTimeout( () => {
this.DoConnect();
}, intervall_time);
} catch (error) {
this.log.error(`Error in data refresh : ${error}`);
this.log.error('Disconnected from Tado cloud service ..., retry in 30 seconds ! ');
this.setState('info.connection', false, true);
// retry connection
polling = setTimeout( () => {
this.DoConnect();
}, 30000);
}
}
// Function to decrypt passwords
decrypt(key, value) {
let result = '';
for (let i = 0; i < value.length; ++i) {
result += String.fromCharCode(key[i % key.length].charCodeAt(0) ^ value.charCodeAt(i));
}
this.log.debug('client_secret decrypt ready');
return result;
}
_refreshToken() {
const { token } = this._accessToken;
const expirationTimeInSeconds = token.expires_at.getTime() / 1000;
const expirationWindowStart = expirationTimeInSeconds - EXPIRATION_WINDOW_IN_SECONDS;
// If the start of the window has passed, refresh the token
const nowInSeconds = (new Date()).getTime() / 1000;
const shouldRefresh = nowInSeconds >= expirationWindowStart;
return new Promise((resolve, reject) => {
if (shouldRefresh) {
this._accessToken.refresh()
.then(result => {
this._accessToken = result;
resolve(this._accessToken);
})
.catch(error => {
reject(error);
});
} else {
resolve(this._accessToken);
}
});
}
login(username, password) {
return new Promise((resolve, reject) => {
const credentials = {
scope: 'home.user',
username: username,
password: password
};
oauth2.ownerPassword.getToken(credentials)
.then(result => {
this._accessToken = oauth2.accessToken.create(result);
// const token = oauth2.accessToken.create(result);
// JSON.stringify(result);
// JSON.stringify(this._accessToken);
resolve(this._accessToken);
})
.catch(error => {
reject(error);
});
});
}
apiCall(url, method='get', data={}) {
return new Promise((resolve, reject) => {
if (this._accessToken) {
this._refreshToken().then(() => {
axios({
url: tado_url + url,
method: method,
data: data,
headers: {
Authorization: 'Bearer ' + this._accessToken.token.access_token
}
}).then(response => {
resolve(response.data);
}).catch(error => {
reject(error);
});
});
} else {
reject(new Error('Not yet logged in'));
}
});
}
getMe() {
return this.apiCall('/api/v2/me');
}
// Read account information and all home related data
getHome(home_id) {
return this.apiCall(`/api/v2/homes/${home_id}`);
}
// Get weather information for home location
getWeather(home_id) {
return this.apiCall(`/api/v2/homes/${home_id}/weather`);
}
// Function disabled, no data in API ?
// getDevices(home_id) {
// this.log.info('getDevices called')
// return this.apiCall(`/api/v2/homes/${home_id}/devices`);
// }
// Function disabled, no data in API ?
getInstallations(home_id) {
return this.apiCall(`/api/v2/homes/${home_id}/installations`);
}
// User information equal to Weather, ignoring function but keep for history/feature functionality
getUsers(home_id) {
return this.apiCall(`/api/v2/homes/${home_id}/users`);
}
// Function disabled, no data in API ?
getState_info(home_id) {
return this.apiCall(`/api/v2/homes/${home_id}/state`);
}
getMobileDevices(home_id) {
return this.apiCall(`/api/v2/homes/${home_id}/mobileDevices`);
}
getMobileDevice(home_id, device_id) {
return this.apiCall(`/api/v2/homes/${home_id}/mobileDevices/${device_id}`);
}
getMobileDeviceSettings(home_id, device_id) {
return this.apiCall(`/api/v2/homes/${home_id}/mobileDevices/${device_id}/settings`);
}
getZones(home_id) {
return this.apiCall(`/api/v2/homes/${home_id}/zones`);
}
// Coding break point of functionality
getZoneState(home_id, zone_id) {
return this.apiCall(`/api/v2/homes/${home_id}/zones/${zone_id}/state`);
}
getAwayConfiguration(home_id, zone_id) {
return this.apiCall(`/api/v2/homes/${home_id}/zones/${zone_id}/awayConfiguration`);
}
clearZoneOverlay(home_id, zone_id) {
return this.apiCall(`/api/v2/homes/${home_id}/zones/${zone_id}/overlay`, 'delete');
}
setZoneOverlay(home_id, zone_id, power, temperature, termination) {
const config = {
setting: {
type: 'HEATING',
},
termination: {
}
};
if (power.toLowerCase() == 'on') {
config.setting.power = 'ON';
if (temperature) {
config.setting.temperature = {};
config.setting.temperature.celsius = temperature;
}
} else {
config.setting.power = 'OFF';
}
// if (!isNaN(parseInt(termination))) {
// config.termination.type = 'TIMER';
// config.termination.durationInSeconds = termination;
// } else
if(termination === 'manual') {
config.termination.type = 'MANUAL';
} else {
config.termination.type = 'TADO_MODE';
}
this.log.debug('Send API ZoneOverlay API call Home : ' + home_id + ' zone : ' + zone_id + ' config : ' + JSON.stringify(config));
return this.apiCall(`/api/v2/homes/${home_id}/zones/${zone_id}/overlay`, 'put', config);
}
// Unclear purpose, ignore for now
getZoneCapabilities(home_id, zone_id) {
return this.apiCall(`/api/v2/homes/${home_id}/zones/${zone_id}/capabilities`);
}
// Unclear purpose, ignore for now
getZoneOverlay(home_id, zone_id) {
return this.apiCall(`/api/v2/homes/${home_id}/zones/${zone_id}/overlay`);
}
// Coding break point of functionality
// getZoneDayReport(home_id, zone_id, reportDate) {
// return this.apiCall(`/api/v2/homes/${home_id}/zones/${zone_id}/dayReport?date=${reportDate}`);
// }
getTimeTables(home_id, zone_id) {
return this.apiCall(`/api/v2/homes/${home_id}/zones/${zone_id}/schedule/activeTimetable`);
}
// getTimeTable(home_id, zone_id, timetable_id) {
// return this.apiCall(`/api/v2/homes/${home_id}/zones/${zone_id}/schedule/timetables/${timetable_id}/blocks`);
// }
// identifyDevice(device_id) {
// return this.apiCall(`/api/v2/devices/${device_id}/identify`, 'post');
// }
async DoHome(HomeId){
// Get additional basic data for all homes
if (this.Home_data === null){
this.Home_data = await this.getHome(HomeId);
}
this.log.debug('Home_data Result : ' + JSON.stringify(this.Home_data));
this.DoWriteJsonRespons(HomeId,'Stage_02_HomeData', this.Home_data);
for (const i in this.Home_data){
this.log.debug('Home_data ' + i + ' with value : ' + JSON.stringify(this.Home_data[i]));
// Info channel for Each Home
await this.setObjectNotExistsAsync(HomeId + '._info', {
type: 'channel',
common: {
name: 'Basic information',
},
native: {},
});
// if(this.Home_data[i] != 'null'){ ==> issue in IF repair later
switch (i){
case ('id'):
this.create_state(HomeId + '._info.' + i, i, this.Home_data[i]);
break;
case ('name'):
this.create_state(HomeId + '._info.' + i, i, this.Home_data[i]);
break;
case ('boilerId'):
this.create_state(HomeId + '._info.' + i, i, this.Home_data[i]);
break;
case ('dateTimeZone'):
this.create_state(HomeId + '._info.' + i, i, this.Home_data[i]);
break;
case ('consentRequired'):
// handle all contact details and write to states
for (const y in this.Home_data[i]){
this.create_state(HomeId + '._info.' + i + '.' + y, y, this.Home_data[i][y]);
}
break;
case ('consentGranted'):
// handle all contact details and write to states
for (const y in this.Home_data[i]){
this.create_state(HomeId + '._info.' + i + '.' + y, y, this.Home_data[i][y]);
}
break;
case ('dateCreated'):
this.create_state(HomeId + '._info.' + i, i, this.Home_data[i]);
break;
case ('temperatureUnit'):
this.create_state(HomeId + '._info.' + i, i, this.Home_data[i]);
break;
case ('installationCompleted'):
this.create_state(HomeId + '._info.' + i, i, this.Home_data[i]);
break;
case ('partner'):
this.create_state(HomeId + '._info.' + i, i, this.Home_data[i]);
break;
case ('usePreSkillsApps'):
this.create_state(HomeId + '._info.' + i, i, this.Home_data[i]);
break;
case ('simpleSmartScheduleEnabled'):
this.create_state(HomeId + '._info.' + i, i, this.Home_data[i]);
break;
case ('awayRadiusInMeters'):
this.create_state(HomeId + '._info.' + i, i, this.Home_data[i]);
break;
case ('preventFromSubscribing'):
this.create_state(HomeId + '._info.' + i, i, this.Home_data[i]);
break;
case ('skills'):
this.create_state(HomeId + '._info.' + i, i, this.Home_data[i]);
break;
case ('christmasModeEnabled'):
this.create_state(HomeId + '._info.' + i, i, this.Home_data[i]);
break;
case ('showAutoAssistReminders'):
this.create_state(HomeId + '._info.' + i, i, this.Home_data[i]);
break;
case ('contactDetails'):
await this.setObjectNotExistsAsync(HomeId + '._info.contactDetails', {
type: 'channel',
common: {
name: 'Contact Details',
},
native: {},
});
// handle all contact details and write to states
for (const y in this.Home_data[i]){
this.create_state(HomeId + '._info.contactDetails.' + y, y, this.Home_data[i][y]);
}
break;
case ('address'):
await this.setObjectNotExistsAsync(HomeId + '._info.address', {
type: 'channel',
common: {
name: 'Contact Details',
},
native: {},
});
// handle all adress details and write to states
for (const y in this.Home_data[i]){
this.create_state(HomeId + '._info.address.' + y, y, this.Home_data[i][y]);
}
break;
case ('geolocation'):
this.create_state(HomeId + '._info.latitude', i, this.Home_data[i].latitude);
this.create_state(HomeId + '._info.longitude', i, this.Home_data[i].longitude);
break;
case ('consentGrantSkippable'):
break;
case ('legacyHeatingInstallationsEnabled'):
this.create_state(HomeId + '._info. ' + i, i, this.Home_data[i]);
break;
default:
this.log.error('Send this info to developer !!! { Unhandable information found in DoHome : ' + JSON.stringify(i) + ' with value : ' + JSON.stringify(this.Home_data[i]));
}
// }
}
}
async DoWeather(HomeId){
const weather_data = await this.getWeather(HomeId);
this.log.debug('Weather_data Result : ' + JSON.stringify(weather_data));
this.DoWriteJsonRespons(HomeId,'Stage_04_Weather', weather_data);
for (const i in weather_data){
this.log.debug('Weather' + i + ' with value : ' + JSON.stringify(weather_data[i]));
// Info channel for Each Home
await this.setObjectNotExistsAsync(HomeId + '.Weather', {
type: 'channel',
common: {
name: 'Local weather conditions',
},
native: {},
});
switch (i){
case ('outsideTemperature'):
this.create_state(HomeId + '.Weather.' + i, i, weather_data[i].celsius);
break;
case ('solarIntensity'):
this.create_state(HomeId + '.Weather.' + i, i, weather_data[i].percentage);
break;
case ('weatherState'):
this.create_state(HomeId + '.Weather.' + i, i, weather_data[i].value);
break;
default:
this.log.error('Send this info to developer !!! { Unhandable information found in DoHWeather : ' + JSON.stringify(i) + ' with value : ' + JSON.stringify(weather_data[i]));
}
}
}
async DoDevices(HomeId){
const Devices_data = await this.getDevices(HomeId);
this.log.debug('Users_data Result : ' + JSON.stringify(Devices_data));
this.DoWriteJsonRespons(HomeId,'Stage_03_Devices', Devices_data);
}
async DoInstallations(HomeId){
const Installations_data = await this.getInstallations(HomeId);
this.log.debug('Installations_data Result : ' + JSON.stringify(Installations_data));
this.DoWriteJsonRespons(HomeId,'Stage_05_Installations', Installations_data);
}
// Function disabled, no data in API ?
async DoStates(HomeId){
this.States_data = await this.getState_info(HomeId);
this.log.debug('States_data Result : ' + JSON.stringify(this.States_data));
this.DoWriteJsonRespons(HomeId,'Stage_14_StatesData', this.States_data);
}
// User information equal to Weather, ignoring function but keep for history/feature functionality
// async DoUsers(HomeId){
// const users_data = await this.getWeather(HomeId);
// this.log.debug('Users_data Result : ' + JSON.stringify(users_data));
// for (const i in users_data){
// }
// }
async DoMobileDevices(HomeId){
this.MobileDevices_data = await this.getMobileDevices(HomeId);
this.log.debug('MobileDevices_data Result : ' + JSON.stringify(this.MobileDevices_data));
this.DoWriteJsonRespons(HomeId,'Stage_06_MobileDevicesData', this.MobileDevices_data);
for (const i in this.MobileDevices_data){
this.log.debug('Mobiel Device' + i + ' with value : ' + JSON.stringify(this.MobileDevices_data[i]));
// // Info channel for Each Home
await this.setObjectNotExistsAsync(HomeId + '.Mobile_Devices', {
type: 'channel',
common: {
name: 'Mobile devices connected to Tado',
},
native: {},
});
// Info channel for Each Home
await this.setObjectNotExistsAsync(HomeId + '.Mobile_Devices.' + this.MobileDevices_data[i].id, {
type: 'channel',
common: {
name: this.MobileDevices_data[i].name,
},
native: {},
});
for ( const y in this.MobileDevices_data[i]){
this.log.debug('Mobiel Device' + y + ' with value : ' + JSON.stringify(this.MobileDevices_data[i][y]));
switch (y){
case ('name'):
this.create_state(HomeId + '.Mobile_Devices.' + this.MobileDevices_data[i].id + '.' + y, y, this.MobileDevices_data[i][y]);
break;
case ('id'):
this.create_state(HomeId + '.Mobile_Devices.' + this.MobileDevices_data[i].id + '.' + y, y, this.MobileDevices_data[i][y]);
break;
case ('settings'):
this.create_state(HomeId + '.Mobile_Devices.' + this.MobileDevices_data[i].id + '.geoTrackingEnabled', 'geoTrackingEnabled', this.MobileDevices_data[i][y].geoTrackingEnabled);
break;
case ('deviceMetadata'):
this.create_state(HomeId + '.Mobile_Devices.' + this.MobileDevices_data[i].id + '.locale', 'locale', this.MobileDevices_data[i][y].locale);
this.create_state(HomeId + '.Mobile_Devices.' + this.MobileDevices_data[i].id + '.model', 'model', this.MobileDevices_data[i][y].model);
this.create_state(HomeId + '.Mobile_Devices.' + this.MobileDevices_data[i].id + '.osVersion', 'osVersion', this.MobileDevices_data[i][y].osVersion);
this.create_state(HomeId + '.Mobile_Devices.' + this.MobileDevices_data[i].id + '.platform', 'platform', this.MobileDevices_data[i][y].platform);
break;
case ('location'):
if (this.MobileDevices_data[i][y].stale === undefined || this.MobileDevices_data[i][y].stale === null) {
return;
} else {
this.create_state(HomeId + '.Mobile_Devices.' + this.MobileDevices_data[i].id + '.stale', 'stale', this.MobileDevices_data[i][y].stale);
}
this.create_state(HomeId + '.Mobile_Devices.' + this.MobileDevices_data[i].id + '.atHome', 'atHome', this.MobileDevices_data[i][y].atHome);
this.create_state(HomeId + '.Mobile_Devices.' + this.MobileDevices_data[i].id + '.distance', 'distance', this.MobileDevices_data[i][y].relativeDistanceFromHomeFence);
break;
default:
this.log.error('Send this info to developer !!! { Unhandable information found in DoMobile_Devices : ' + JSON.stringify(y) + ' with value : ' + JSON.stringify(this.MobileDevices_data[i][y]));
}
}
await this.DoMobileDeviceSettings(HomeId,this.MobileDevices_data[i].id);
}
}
async DoMobileDeviceSettings(HomeId,DeviceId){
const MobileDeviceSettings_data = await this.getMobileDeviceSettings(HomeId,DeviceId);
this.log.debug('MobileDeviceSettings_Data Result : ' + JSON.stringify(MobileDeviceSettings_data));
this.DoWriteJsonRespons(HomeId,'Stage_07_MobileDevicesSettings_' + DeviceId, MobileDeviceSettings_data);
// device setting channel for Each Home
await this.setObjectNotExistsAsync(HomeId + '.Mobile_Devices.' + DeviceId + '.Device_Setting', {
type: 'channel',
common: {
name: 'Mobile devices settings',
},
native: {},
});
for (const i in MobileDeviceSettings_data) {
switch (i){
case ('geoTrackingEnabled'):
this.create_state(HomeId + '.Mobile_Devices.' + DeviceId + '.Device_Setting.' + i, i, MobileDeviceSettings_data[i]);
break;
case ('onDemandLogRetrievalEnabled'):
this.create_state(HomeId + '.Mobile_Devices.' + DeviceId + '.Device_Setting.' + i, i, MobileDeviceSettings_data[i]);
break;
case ('pushNotifications'):
await this.setObjectNotExistsAsync(HomeId + '.Mobile_Devices.' + DeviceId + '.Device_Setting.' + i, {
type: 'channel',
common: {
name: i,
},
native: {},
});
for (const y in MobileDeviceSettings_data[i]){
this.create_state(HomeId + '.Mobile_Devices.' + DeviceId + '.Device_Setting.' + i + '.' + y, y, MobileDeviceSettings_data[i][y]);
}
break;
default:
this.log.error('Send this info to developer !!! { Unhandable information found in DoMobileDeviceSettings : ' + JSON.stringify(i) + ' with value : ' + JSON.stringify(MobileDeviceSettings_data[i]));
}
}
}
async DoZones(HomeId){
this.Zones_data = await this.getZones(HomeId);
this.log.debug('Zones_data Result : ' + JSON.stringify(this.Zones_data));
this.DoWriteJsonRespons(HomeId,'Stage_08_ZonesData', this.Zones_data);
await this.setObjectNotExistsAsync(HomeId + '.Rooms', {
type: 'channel',
common: {
name: 'Rooms',
},
native: {},
});
for (const i in this.Zones_data ) {
await this.setObjectNotExistsAsync(HomeId + '.Rooms.' + this.Zones_data [i].id, {
type: 'channel',
common: {
name: this.Zones_data [i].name,
},
native: {},
});
await this.setObjectNotExistsAsync(HomeId + '.Rooms.' + this.Zones_data [i].id + '.info', {
type: 'channel',
common: {
name: 'info',
},
native: {},
});
for (const y in this.Zones_data [i]){
const state_root = HomeId + '.Rooms.' + this.Zones_data [i].id + '.info.' + y;
switch (y){
case ('id'):
// ignore id, no added value in state
// this.create_state(state_root, y, this.Zones_data [i][y]);
break;
case ('name'):
// ignore name, no added value in state
// this.create_state(state_root, y, this.Zones_data [i][y]);
break;
case ('dateCreated'):
await this.create_state(state_root, y, this.Zones_data [i][y]);
break;
case ('dazzleEnabled'):
await this.create_state(state_root, y, this.Zones_data [i][y]);
break;
case ('dazzleMode'):
await this.setObjectNotExistsAsync(HomeId + '.Rooms.' + this.Zones_data [i].id + '.' + y, {
type: 'channel',
common: {
name: y,
},
native: {},
});
for (const x in this.Zones_data [i][y]){
this.create_state(HomeId + '.Rooms.' + this.Zones_data [i].id + '.' + y +'.' + x, y, this.Zones_data [i][y][x]);
}
break;
case ('devices'):
await this.DoReadDevices(HomeId + '.Rooms.' + this.Zones_data [i].id + '.' + y,this.Zones_data [i][y]);
break;
case ('deviceTypes'):
// await this.setObjectNotExistsAsync(state_root, {
// type: 'channel',
// common: {
// name: y,
// },
// native: {},
// });
break;
case ('openWindowDetection'):
await this.setObjectNotExistsAsync(HomeId + '.Rooms.' + this.Zones_data [i].id + '.' + y, {
type: 'channel',
common: {
name: y,
},
native: {},
});
for (const x in this.Zones_data [i][y]){
// this.log.info(x + ' | ' + y)
this.create_state(HomeId + '.Rooms.' + this.Zones_data [i].id + '.' + y + '.' + x, x, this.Zones_data [i][y][x]);
}
break;
case ('reportAvailable'):
this.create_state(state_root, y, this.Zones_data [i][y]);
break;
case ('supportsDazzle'):
this.create_state(state_root, y, this.Zones_data [i][y]);
break;
case ('type'):
this.create_state(state_root, y, this.Zones_data [i][y]);
break;
default:
this.log.error('Send this info to developer !!! { Unhandable information found in DoZones : ' + JSON.stringify(y) + ' with value : ' + JSON.stringify(this.Zones_data [i][y]));
}
}
const basic_tree = HomeId + '.Rooms.' + this.Zones_data [i].id;
try {
await this.DoZoneStates(HomeId, this.Zones_data [i].id, basic_tree);
} catch (error) {
this.log.error('Issue getting ZoneStates ' + error);
}
try {
// Unclear purpose, ignore for now
await this.DoZoneCapabilities(HomeId, this.Zones_data [i].id);
} catch (error) {
this.log.error('Issue getting ZoneCapabilities ' + error);
}
try {
await this.DoZoneOverlay(HomeId, this.Zones_data [i].id); // only 404 error
} catch (error) {
// no info
// this.log.error(error);
}