Catch exception (fixes #3699) (#3727)

This commit is contained in:
Fabian Affolter
2016-10-07 17:30:59 -07:00
committed by Paulus Schoutsen
parent 2d4df42a65
commit b09b13f552
+7 -4
View File
@@ -25,7 +25,7 @@ ATTR_QUERIES_TODAY = 'queries_today'
DEFAULT_HOST = 'localhost'
DEFAULT_METHOD = 'GET'
DEFAULT_NAME = 'Pi-hole'
DEFAULT_NAME = 'Pi-Hole'
DEFAULT_SSL = False
DEFAULT_VERIFY_SSL = True
@@ -59,7 +59,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
rest.update()
if rest.data is None:
_LOGGER.error('Unable to fetch REST data')
_LOGGER.error("Unable to fetch data from Pi-Hole")
return False
add_devices([PiHoleSensor(hass, rest, name)])
@@ -99,5 +99,8 @@ class PiHoleSensor(Entity):
def update(self):
"""Get the latest data from REST API and updates the state."""
self.rest.update()
self._state = json.loads(self.rest.data)
try:
self.rest.update()
self._state = json.loads(self.rest.data)
except TypeError:
_LOGGER.error("Unable to fetch data from Pi-Hole")