mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Merge pull request #562 from pavoni/efergy_error_handling
Log request exceptions in Efergy sensor
This commit is contained in:
commit
776616bcac
@ -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,19 +80,22 @@ 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. """
|
||||||
if self.type == 'instant_readings':
|
try:
|
||||||
url_string = _RESOURCE + 'getInstant?token=' + self.app_token
|
if self.type == 'instant_readings':
|
||||||
response = get(url_string)
|
url_string = _RESOURCE + 'getInstant?token=' + self.app_token
|
||||||
self._state = response.json()['reading'] / 1000
|
response = get(url_string)
|
||||||
elif self.type == 'budget':
|
self._state = response.json()['reading'] / 1000
|
||||||
url_string = _RESOURCE + 'getBudget?token=' + self.app_token
|
elif self.type == 'budget':
|
||||||
response = get(url_string)
|
url_string = _RESOURCE + 'getBudget?token=' + self.app_token
|
||||||
self._state = response.json()['status']
|
response = get(url_string)
|
||||||
elif self.type == 'cost':
|
self._state = response.json()['status']
|
||||||
url_string = _RESOURCE + 'getCost?token=' + self.app_token \
|
elif self.type == 'cost':
|
||||||
+ '&offset=' + self.utc_offset + '&period=' \
|
url_string = _RESOURCE + 'getCost?token=' + self.app_token \
|
||||||
+ self.period
|
+ '&offset=' + self.utc_offset + '&period=' \
|
||||||
response = get(url_string)
|
+ self.period
|
||||||
self._state = response.json()['sum']
|
response = get(url_string)
|
||||||
else:
|
self._state = response.json()['sum']
|
||||||
self._state = 'Unknown'
|
else:
|
||||||
|
self._state = 'Unknown'
|
||||||
|
except RequestException:
|
||||||
|
_LOGGER.warning('Could not update status for %s', self.name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user