From 002e903c5689c3980206c081fb67957735f70445 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Wed, 5 Jun 2019 20:50:05 -0700 Subject: [PATCH] Initiate websession inside event loop --- homeassistant/components/tado/device_tracker.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/tado/device_tracker.py b/homeassistant/components/tado/device_tracker.py index 3bb62f328b9e29..31b424b9cd4676 100644 --- a/homeassistant/components/tado/device_tracker.py +++ b/homeassistant/components/tado/device_tracker.py @@ -42,6 +42,7 @@ class TadoDeviceScanner(DeviceScanner): def __init__(self, hass, config): """Initialize the scanner.""" + self.hass = hass self.last_results = [] self.username = config[CONF_USERNAME] @@ -60,8 +61,7 @@ def __init__(self, hass, config): # The API URL always needs a username and password self.tadoapiurl += '?username={username}&password={password}' - self.websession = async_create_clientsession( - hass, cookie_jar=aiohttp.CookieJar(unsafe=True)) + self.websession = None self.success_init = asyncio.run_coroutine_threadsafe( self._async_update_info(), hass.loop @@ -92,6 +92,10 @@ async def _async_update_info(self): """ _LOGGER.debug("Requesting Tado") + if self.websession is None: + self.websession = async_create_clientsession( + self.hass, cookie_jar=aiohttp.CookieJar(unsafe=True)) + last_results = [] try: