Add exception handling for Netatmo climate (#24311)

* Add exception handling

* Make pylint happy
This commit is contained in:
cgtobi 2019-06-06 09:30:16 +02:00 committed by Daniel Høyer Iversen
parent 6cc1bf37cc
commit 9ca5bdda7f

View File

@ -344,8 +344,8 @@ class ThermostatData:
"""Return all module available on the API as a list.""" """Return all module available on the API as a list."""
if not self.setup(): if not self.setup():
return [] return []
for key in self.homestatus.rooms: for room in self.homestatus.rooms:
self.room_ids.append(key) self.room_ids.append(room)
return self.room_ids return self.room_ids
def setup(self): def setup(self):
@ -365,6 +365,7 @@ class ThermostatData:
def update(self): def update(self):
"""Call the NetAtmo API to update the data.""" """Call the NetAtmo API to update the data."""
import pyatmo import pyatmo
try: try:
self.homestatus = pyatmo.HomeStatus(self.auth, home=self.home) self.homestatus = pyatmo.HomeStatus(self.auth, home=self.home)
except TypeError: except TypeError:
@ -372,40 +373,52 @@ class ThermostatData:
return return
_LOGGER.debug("Following is the debugging output for homestatus:") _LOGGER.debug("Following is the debugging output for homestatus:")
_LOGGER.debug(self.homestatus.rawData) _LOGGER.debug(self.homestatus.rawData)
for key in self.homestatus.rooms: for room in self.homestatus.rooms:
roomstatus = {} try:
homestatus_room = self.homestatus.rooms[key] roomstatus = {}
homedata_room = self.homedata.rooms[self.home][key] homestatus_room = self.homestatus.rooms[room]
roomstatus['roomID'] = homestatus_room['id'] homedata_room = self.homedata.rooms[self.home][room]
roomstatus['roomname'] = homedata_room['name'] roomstatus["roomID"] = homestatus_room["id"]
roomstatus['target_temperature'] = \ roomstatus["roomname"] = homedata_room["name"]
homestatus_room['therm_setpoint_temperature'] roomstatus["target_temperature"] = homestatus_room[
roomstatus['setpoint_mode'] = \ "therm_setpoint_temperature"
homestatus_room['therm_setpoint_mode'] ]
roomstatus['current_temperature'] = \ roomstatus["setpoint_mode"] = homestatus_room[
homestatus_room['therm_measured_temperature'] "therm_setpoint_mode"
roomstatus['module_type'] = \ ]
self.homestatus.thermostatType(self.home, key) roomstatus["current_temperature"] = homestatus_room[
roomstatus['module_id'] = None "therm_measured_temperature"
roomstatus['heating_status'] = None ]
roomstatus['heating_power_request'] = None roomstatus["module_type"] = self.homestatus.thermostatType(
for module_id in homedata_room['module_ids']: self.home, room
if self.homedata.modules[self.home][module_id]['type'] == \ )
NA_THERM or roomstatus['module_id'] is None: roomstatus["module_id"] = None
roomstatus['module_id'] = module_id roomstatus["heating_status"] = None
if roomstatus['module_type'] == NA_THERM: roomstatus["heating_power_request"] = None
self.boilerstatus = self.homestatus.boilerStatus( for module_id in homedata_room["module_ids"]:
rid=roomstatus['module_id']) if (self.homedata.modules[self.home][module_id]["type"]
roomstatus['heating_status'] = self.boilerstatus == NA_THERM
elif roomstatus['module_type'] == NA_VALVE: or roomstatus["module_id"] is None):
roomstatus['heating_power_request'] = \ roomstatus["module_id"] = module_id
homestatus_room['heating_power_request'] if roomstatus["module_type"] == NA_THERM:
roomstatus['heating_status'] = \ self.boilerstatus = self.homestatus.boilerStatus(
roomstatus['heating_power_request'] > 0 rid=roomstatus["module_id"]
if self.boilerstatus is not None: )
roomstatus['heating_status'] = \ roomstatus["heating_status"] = self.boilerstatus
self.boilerstatus and roomstatus['heating_status'] elif roomstatus["module_type"] == NA_VALVE:
self.room_status[key] = roomstatus roomstatus["heating_power_request"] = homestatus_room[
"heating_power_request"
]
roomstatus["heating_status"] = (
roomstatus["heating_power_request"] > 0
)
if self.boilerstatus is not None:
roomstatus["heating_status"] = (
self.boilerstatus and roomstatus["heating_status"]
)
self.room_status[room] = roomstatus
except KeyError as err:
_LOGGER.error("Update of room %s failed. Error: %s", room, err)
self.away_temperature = self.homestatus.getAwaytemp(self.home) self.away_temperature = self.homestatus.getAwaytemp(self.home)
self.hg_temperature = self.homestatus.getHgtemp(self.home) self.hg_temperature = self.homestatus.getHgtemp(self.home)
self.setpoint_duration = self.homedata.setpoint_duration[self.home] self.setpoint_duration = self.homedata.setpoint_duration[self.home]