Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
HGlab01 committed Oct 7, 2024
1 parent 3968e3d commit 906291d
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@ class Tado extends utils.Adapter {
this.on('ready', this.onReady.bind(this));
this.on('stateChange', this.onStateChange.bind(this));
this.on('unload', this.onUnload.bind(this));
jsonExplorer.init(this, state_attr);
this.accessToken = null;
this.getMe_data = null;
this.Home_data = null;
this.lastupdate = 0;
this.apiCallinExecution = false;
jsonExplorer.init(this, state_attr);
this.intervall_time = 60 * 1000;
this.roomCapabilities = {};
this.oldStatesVal = [];
this.isTadoX = false;
}

/**
Expand Down Expand Up @@ -837,7 +838,8 @@ class Tado extends utils.Adapter {
step = 'DoMobileDevices';
await this.DoMobileDevices(homeID);
step = 'DoZones';
await this.DoZones(homeID);
if (this.isTadoX) await this.DoRoomsTadoX(homeID);
else await this.DoZones(homeID);
step = 'DoWeather';
await this.DoWeather(homeID);
step = 'DoHomeState';
Expand Down Expand Up @@ -943,6 +945,9 @@ class Tado extends utils.Adapter {
this.Home_data = await this.getHome(HomeId);
}
this.log.debug('Home_data Result: ' + JSON.stringify(this.Home_data));
if (this.Home_data.generation == 'LINE_X') this.isTadoX = true;
else this.isTadoX = false;
this.log.info('TadoX is ' + this.isTadoX);
this.Home_data.masterswitch = '';
this.DoWriteJsonRespons(HomeId, 'Stage_02_HomeData', this.Home_data);
jsonExplorer.traverseJson(this.Home_data, `${HomeId}.Home`, true, true, 0);
Expand Down Expand Up @@ -981,14 +986,24 @@ class Tado extends utils.Adapter {
jsonExplorer.traverseJson(this.MobileDevices_data, `${HomeId}.Mobile_Devices`, true, true, 0);
}

async DoRooms(HomeId) {
let rooms = await this.getRooms(HomeId);
this.log.info(JSON.stringify(rooms));
jsonExplorer.traverseJson(rooms, `${HomeId}.Rooms1`, true, true, 0);
async DoRoomsTadoX(homeId) {
let rooms = await this.getRoomsTadoX(homeId);
let roomsAndDevices = await this.getRoomsAndDevicesTadoX(homeId);
//this.log.info(JSON.stringify(rooms));
this.log.info(JSON.stringify(roomsAndDevices));
jsonExplorer.traverseJson(rooms, `${homeId}.Rooms`, true, true, 0);

for (const i in roomsAndDevices.rooms) {
let roomId = roomsAndDevices.rooms[i].roomId;
this.log.info('RoomID is ' + roomId);
let roomState = await this.getRoomStateTadoX(homeId, roomId);
this.log.info(JSON.stringify(roomState));
jsonExplorer.traverseJson(roomsAndDevices.rooms[i].devices, `${homeId}.Rooms.${roomsAndDevices.rooms[i].roomId}.devices`, true, true, 1);
jsonExplorer.traverseJson(roomState, `${homeId}.Rooms.${roomId}`, true, true, 0);
}
}

async DoZones(HomeId) {
this.DoRooms(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);
Expand Down Expand Up @@ -1042,7 +1057,7 @@ class Tado extends utils.Adapter {
if (this.roomCapabilities[zoneId]) capabilities_data = this.roomCapabilities[zoneId];
else capabilities_data = await this.getCapabilities(homeId, zoneId);
this.roomCapabilities[zoneId] = capabilities_data;
this.log.debug(`Capabilities_data result for room '${zoneId}' is ${JSON.stringify(capabilities_data)}`);
this.log.info(`Capabilities_data result for room '${zoneId}' is ${JSON.stringify(capabilities_data)}`);
this.DoWriteJsonRespons(homeId, 'Stage_09_Capabilities_data_' + zoneId, capabilities_data);
jsonExplorer.traverseJson(capabilities_data, homeId + '.Rooms.' + zoneId + '.capabilities', true, true, 2);
}
Expand Down Expand Up @@ -1391,10 +1406,6 @@ class Tado extends utils.Adapter {
return this.apiCall(`/api/v2/homes/${home_id}/zones`);
}

getRooms(home_id) {
return this.apiCall(`https://hops.tado.com/homes/${home_id}/rooms`);
}

getZoneState(home_id, zone_id) {
return this.apiCall(`/api/v2/homes/${home_id}/zones/${zone_id}/state`);
}
Expand All @@ -1418,6 +1429,18 @@ class Tado extends utils.Adapter {
getHomeState(home_id) {
return this.apiCall(`/api/v2/homes/${home_id}/state`);
}

getRoomsTadoX(home_id) {
return this.apiCall(`https://hops.tado.com/homes/${home_id}/rooms`);
}

getRoomStateTadoX(home_id, zone_id) {
return this.apiCall(`https://hops.tado.com/homes/${home_id}/rooms/${zone_id}`);
}

getRoomsAndDevicesTadoX(home_id) {
return this.apiCall(`https://hops.tado.com/homes/${home_id}/roomsAndDevices`);
}
}

function toBoolean(valueToBoolean) {
Expand Down

0 comments on commit 906291d

Please sign in to comment.