Merge pull request #1280 from molobrakos/tellduslive

added assumed_state property + improved error handling
This commit is contained in:
Paulus Schoutsen committed 2016-02-16 13:51:14 -08:00
commit 79dbd14568
2 files changed
+20 -20

No files matched your search

@@ -40,6 +40,11 @@ class TelldusLiveSwitch(ToggleEntity):
""" Tells Home Assistant to poll this entity. """
return True
@property
def assumed_state(self):
"""Return True if unable to access real state of entity."""
return True
@property
def name(self):
""" Returns the name of the switch if any. """
+15 -20
View File
@@ -86,10 +86,8 @@ class TelldusLiveData(object):
def validate_session(self):
""" Make a dummy request to see if the session is valid """
try:
return 'email' in self.request("user/profile")
except RuntimeError:
return False
response = self.request("user/profile")
return response and 'email' in response
def discover(self):
""" Update states, will trigger discover """
@@ -143,10 +141,13 @@ class TelldusLiveData(object):
# re-use sessions, instead it opens a new session for each request
# this needs to be fixed
response = self._client.request(what, params)
_LOGGER.debug("got response %s", response)
return response
try:
response = self._client.request(what, params)
_LOGGER.debug("got response %s", response)
return response
except (ConnectionError, TimeoutError):
_LOGGER.error("failed to make request to Tellduslive servers")
return None
def update_devices(self,
local_devices,
@@ -172,21 +173,15 @@ class TelldusLiveData(object):
def update_sensors(self):
""" update local list of sensors """
try:
self._sensors = self.update_devices(self._sensors,
request_sensors(),
"sensor")
except OSError:
_LOGGER.warning("could not update sensors")
self._sensors = self.update_devices(self._sensors,
request_sensors(),
"sensor")
def update_switches(self):
""" update local list of switches """
try:
self._switches = self.update_devices(self._switches,
request_switches(),
"switch")
except OSError:
_LOGGER.warning("could not update switches")
self._switches = self.update_devices(self._switches,
request_switches(),
"switch")
def _check_request(self, what, **params):
""" Make request, check result if successful """