improved error handling (#3725)

This commit is contained in:
Erik Eriksson 2016-10-08 02:25:51 +02:00 committed by Paulus Schoutsen
parent fccc7e69d0
commit 2d4df42a65

View File

@ -62,23 +62,25 @@ def setup(hass, config):
def request_switches(): def request_switches():
"""Make request to online service.""" """Make request to online service."""
_LOGGER.debug("Updating switches from Telldus Live") _LOGGER.debug("Updating switches from Telldus Live")
switches = NETWORK.request('devices/list')['device'] switches = NETWORK.request('devices/list')
# Filter out any group of switches. # Filter out any group of switches.
switches = {switch["id"]: switch for switch in switches if switches and 'device' in switches:
return {switch["id"]: switch for switch in switches['device']
if switch["type"] == "device"} if switch["type"] == "device"}
return switches return None
@Throttle(MIN_TIME_BETWEEN_SENSOR_UPDATES) @Throttle(MIN_TIME_BETWEEN_SENSOR_UPDATES)
def request_sensors(): def request_sensors():
"""Make request to online service.""" """Make request to online service."""
_LOGGER.debug("Updating sensors from Telldus Live") _LOGGER.debug("Updating sensors from Telldus Live")
units = NETWORK.request('sensors/list')['sensor'] units = NETWORK.request('sensors/list')
# One unit can contain many sensors. # One unit can contain many sensors.
sensors = {unit['id']+sensor['name']: dict(unit, data=sensor) if units and 'sensor' in units:
for unit in units return {unit['id']+sensor['name']: dict(unit, data=sensor)
for sensor in unit['data']} for unit in units['sensor']
return sensors for sensor in unit['data']}
return None
class TelldusLiveData(object): class TelldusLiveData(object):
@ -155,8 +157,9 @@ class TelldusLiveData(object):
response = self._client.request(what, params) response = self._client.request(what, params)
_LOGGER.debug("got response %s", response) _LOGGER.debug("got response %s", response)
return response return response
except (ConnectionError, TimeoutError): except (ConnectionError, TimeoutError, OSError) as error:
_LOGGER.error("failed to make request to Tellduslive servers") _LOGGER.error("failed to make request to Tellduslive servers: %s",
error)
return None return None
def update_devices(self, local_devices, remote_devices, component_name): def update_devices(self, local_devices, remote_devices, component_name):