Work around bad content-type in Hook api response (#7267)

This commit is contained in:
Klaas Hoekema 2017-04-24 02:58:17 -04:00 committed by Paulus Schoutsen
parent 0e662c4007
commit 64da8cd47d

View file

@ -47,7 +47,9 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
data={
'username': username,
'password': password})
data = yield from response.json()
# The Hook API returns JSON but calls it 'text/html'. Setting
# content_type=None disables aiohttp's content-type validation.
data = yield from response.json(content_type=None)
except (asyncio.TimeoutError, aiohttp.ClientError) as error:
_LOGGER.error("Failed authentication API call: %s", error)
return False
@ -63,7 +65,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
response = yield from websession.get(
'{}{}'.format(HOOK_ENDPOINT, 'device'),
params={"token": token})
data = yield from response.json()
data = yield from response.json(content_type=None)
except (asyncio.TimeoutError, aiohttp.ClientError) as error:
_LOGGER.error("Failed getting devices: %s", error)
return False
@ -110,7 +112,7 @@ class HookSmartHome(SwitchDevice):
with async_timeout.timeout(TIMEOUT, loop=self.hass.loop):
response = yield from websession.get(
url, params={"token": self._token})
data = yield from response.json()
data = yield from response.json(content_type=None)
except (asyncio.TimeoutError, aiohttp.ClientError) as error:
_LOGGER.error("Failed setting state: %s", error)