Catch thethingsnetwork TypeError (#23667)

* Catch TypeError (fixes #23097)

* Re-add return values

* Update homeassistant/components/thethingsnetwork/sensor.py

Co-Authored-By: fabaff <mail@fabian-affolter.ch>
pull/23712/head
Fabian Affolter 2019-05-06 09:47:46 +02:00 committed by GitHub
parent cf03e42773
commit b331b081f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 11 deletions

View File

@ -45,7 +45,7 @@ async def async_setup_platform(
success = await ttn_data_storage.async_update()
if not success:
return False
return
devices = []
for value, unit_of_measurement in values.items():
@ -78,8 +78,9 @@ class TtnDataSensor(Entity):
if self._ttn_data_storage.data is not None:
try:
return round(self._state[self._value], 1)
except KeyError:
pass
except (KeyError, TypeError):
return None
return None
@property
def unit_of_measurement(self):
@ -124,32 +125,32 @@ class TtnDataStorage:
try:
session = async_get_clientsession(self._hass)
with async_timeout.timeout(DEFAULT_TIMEOUT, loop=self._hass.loop):
req = await session.get(self._url, headers=self._headers)
response = await session.get(self._url, headers=self._headers)
except (asyncio.TimeoutError, aiohttp.ClientError):
_LOGGER.error("Error while accessing: %s", self._url)
return False
return None
status = req.status
status = response.status
if status == 204:
_LOGGER.error("The device is not available: %s", self._device_id)
return False
return None
if status == 401:
_LOGGER.error(
"Not authorized for Application ID: %s", self._app_id)
return False
return None
if status == 404:
_LOGGER.error("Application ID is not available: %s", self._app_id)
return False
return None
data = await req.json()
data = await response.json()
self.data = data[-1]
for value in self._values.items():
if value[0] not in self.data.keys():
_LOGGER.warning("Value not available: %s", value[0])
return req
return response