Catch request exceptions and log a warning

This commit is contained in:
pavoni 2015-10-28 10:57:10 +00:00
parent b3b2f2e326
commit 16a3511c0a

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
"""
import logging
from requests import get
from requests import get, RequestException
from homeassistant.helpers.entity import Entity
@ -80,6 +80,7 @@ class EfergySensor(Entity):
def update(self):
""" Gets the Efergy monitor data from the web service. """
try:
if self.type == 'instant_readings':
url_string = _RESOURCE + 'getInstant?token=' + self.app_token
response = get(url_string)
@ -96,3 +97,5 @@ class EfergySensor(Entity):
self._state = response.json()['sum']
else:
self._state = 'Unknown'
except RequestException:
_LOGGER.warning('Could not update status for %s', self.name)