Merge pull request #562 from pavoni/efergy_error_handling

Log request exceptions in Efergy sensor
This commit is contained in:
Paulus Schoutsen 2015-10-28 12:41:42 -07:00
commit 776616bcac

View File

@ -8,7 +8,7 @@ For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.efergy.html https://home-assistant.io/components/sensor.efergy.html
""" """
import logging import logging
from requests import get from requests import get, RequestException
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
@ -80,6 +80,7 @@ class EfergySensor(Entity):
def update(self): def update(self):
""" Gets the Efergy monitor data from the web service. """ """ Gets the Efergy monitor data from the web service. """
try:
if self.type == 'instant_readings': if self.type == 'instant_readings':
url_string = _RESOURCE + 'getInstant?token=' + self.app_token url_string = _RESOURCE + 'getInstant?token=' + self.app_token
response = get(url_string) response = get(url_string)
@ -96,3 +97,5 @@ class EfergySensor(Entity):
self._state = response.json()['sum'] self._state = response.json()['sum']
else: else:
self._state = 'Unknown' self._state = 'Unknown'
except RequestException:
_LOGGER.warning('Could not update status for %s', self.name)