@@ -113,14 +113,16 @@ export class Tado {
113
113
#username?: string ;
114
114
#password?: string ;
115
115
#firstLogin: boolean ;
116
- #isX: boolean ;
116
+ #forceX: boolean ;
117
+ #xLookup: { [ key : number ] : boolean } ;
117
118
118
- constructor ( username ?: string , password ?: string ) {
119
+ constructor ( username ?: string , password ?: string , forceX ?: boolean ) {
119
120
this . #username = username ;
120
121
this . #password = password ;
121
122
this . #httpsAgent = new Agent ( { keepAlive : true } ) ;
123
+ this . #forceX = forceX ?? false ;
122
124
this . #firstLogin = true ;
123
- this . #isX = false ;
125
+ this . #xLookup = { } ;
124
126
}
125
127
126
128
async #login( ) : Promise < void > {
@@ -139,10 +141,9 @@ export class Tado {
139
141
if ( this . #firstLogin) {
140
142
try {
141
143
const me = await this . getMe ( ) ;
142
- if ( me . homes . length > 0 ) {
143
- const home_id = me . homes [ 0 ] . id ;
144
+ for ( const { id : home_id } of me . homes ) {
144
145
const home = await this . getHome ( home_id ) ;
145
- this . #isX = home . generation == "LINE_X" ;
146
+ this . #xLookup [ home_id ] = home . generation == "LINE_X" ;
146
147
}
147
148
} catch ( err ) {
148
149
console . error ( `Could not determine TadoX status: ${ err } ` ) ;
@@ -187,8 +188,8 @@ export class Tado {
187
188
return this . #accessToken;
188
189
}
189
190
190
- get isX ( ) : boolean {
191
- return this . #isX ;
191
+ isHomeX ( home_id : number ) : boolean {
192
+ return this . #forceX || this . #xLookup [ home_id ] || false ;
192
193
}
193
194
194
195
/**
@@ -353,7 +354,7 @@ export class Tado {
353
354
* @returns A promise that resolves to an array of Device objects.
354
355
*/
355
356
getDevices ( home_id : number ) : Promise < Device [ ] > {
356
- if ( this . #isX ) {
357
+ if ( this . isHomeX ( home_id ) ) {
357
358
return this . apiCallX ( `/homes/${ home_id } /roomsAndDevices` ) ;
358
359
} else {
359
360
return this . apiCall ( `/api/v2/homes/${ home_id } /devices` ) ;
@@ -584,7 +585,7 @@ export class Tado {
584
585
* @returns A promise that resolves to an array of Zone objects.
585
586
*/
586
587
getZones ( home_id : number ) : Promise < Zone [ ] > {
587
- if ( this . #isX ) {
588
+ if ( this . isHomeX ( home_id ) ) {
588
589
return this . apiCallX ( `/homes/${ home_id } /rooms` ) ;
589
590
} else {
590
591
return this . apiCall ( `/api/v2/homes/${ home_id } /zones` ) ;
@@ -599,7 +600,7 @@ export class Tado {
599
600
* @returns A promise that resolves to the state of the specified zone.
600
601
*/
601
602
getZoneState ( home_id : number , zone_id : number ) : Promise < ZoneState > {
602
- if ( this . #isX ) {
603
+ if ( this . isHomeX ( home_id ) ) {
603
604
return this . apiCallX ( `/homes/${ home_id } /rooms/${ zone_id } ` ) ;
604
605
} else {
605
606
return this . apiCall ( `/api/v2/homes/${ home_id } /zones/${ zone_id } /state` ) ;
@@ -835,7 +836,7 @@ export class Tado {
835
836
* @deprecated Use {@link clearZoneOverlays} instead.
836
837
*/
837
838
clearZoneOverlay ( home_id : number , zone_id : number ) : Promise < void > {
838
- if ( this . #isX ) {
839
+ if ( this . isHomeX ( home_id ) ) {
839
840
return this . apiCallX ( `/homes/${ home_id } /rooms/${ zone_id } /resumeSchedule` , "post" , { } ) ;
840
841
} else {
841
842
return this . apiCall ( `/api/v2/homes/${ home_id } /zones/${ zone_id } /overlay` , "delete" ) ;
@@ -957,12 +958,8 @@ export class Tado {
957
958
} ;
958
959
}
959
960
960
- if ( this . #isX) {
961
- return this . apiCallX (
962
- `/api/v2/homes/${ home_id } /rooms/${ zone_id } /manualControl` ,
963
- "post" ,
964
- config ,
965
- ) ;
961
+ if ( this . isHomeX ( home_id ) ) {
962
+ return this . apiCallX ( `/homes/${ home_id } /rooms/${ zone_id } /manualControl` , "post" , config ) ;
966
963
} else {
967
964
return this . apiCall ( `/api/v2/homes/${ home_id } /zones/${ zone_id } /overlay` , "put" , config ) ;
968
965
}
@@ -976,7 +973,7 @@ export class Tado {
976
973
* @returns A promise that resolves when the overlays are cleared.
977
974
*/
978
975
async clearZoneOverlays ( home_id : number , zone_ids : number [ ] ) : Promise < void > {
979
- if ( this . #isX ) {
976
+ if ( this . isHomeX ( home_id ) ) {
980
977
for ( const zone_id of zone_ids ) {
981
978
return this . apiCallX ( `/homes/${ home_id } /rooms/${ zone_id } /resumeSchedule` , "post" , { } ) ;
982
979
}
@@ -1122,10 +1119,10 @@ export class Tado {
1122
1119
config . push ( overlay_config ) ;
1123
1120
}
1124
1121
1125
- if ( this . #isX ) {
1122
+ if ( this . isHomeX ( home_id ) ) {
1126
1123
for ( const c of config ) {
1127
1124
return this . apiCallX (
1128
- `/api/v2/ homes/${ home_id } /rooms/${ c . room } /manualControl` ,
1125
+ `/homes/${ home_id } /rooms/${ c . room } /manualControl` ,
1129
1126
"post" ,
1130
1127
c . overlay ,
1131
1128
) ;
0 commit comments