mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Fix Tado doing async wrong (#13078)
* Fix Tado doing async wrong * Remove last coroutine decorator
This commit is contained in:
parent
d0f089975d
commit
56b3cb0583
@ -68,22 +68,18 @@ class TadoDeviceScanner(DeviceScanner):
|
|||||||
self.websession = async_create_clientsession(
|
self.websession = async_create_clientsession(
|
||||||
hass, cookie_jar=aiohttp.CookieJar(unsafe=True, loop=hass.loop))
|
hass, cookie_jar=aiohttp.CookieJar(unsafe=True, loop=hass.loop))
|
||||||
|
|
||||||
self.success_init = self._update_info()
|
self.success_init = asyncio.run_coroutine_threadsafe(
|
||||||
|
self._async_update_info(), hass.loop
|
||||||
|
).result()
|
||||||
|
|
||||||
_LOGGER.info("Scanner initialized")
|
_LOGGER.info("Scanner initialized")
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def async_scan_devices(self):
|
||||||
def async_scan_devices(self):
|
|
||||||
"""Scan for devices and return a list containing found device ids."""
|
"""Scan for devices and return a list containing found device ids."""
|
||||||
info = self._update_info()
|
await self._async_update_info()
|
||||||
|
|
||||||
# Don't yield if we got None
|
|
||||||
if info is not None:
|
|
||||||
yield from info
|
|
||||||
|
|
||||||
return [device.mac for device in self.last_results]
|
return [device.mac for device in self.last_results]
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def async_get_device_name(self, device):
|
||||||
def async_get_device_name(self, device):
|
|
||||||
"""Return the name of the given device or None if we don't know."""
|
"""Return the name of the given device or None if we don't know."""
|
||||||
filter_named = [result.name for result in self.last_results
|
filter_named = [result.name for result in self.last_results
|
||||||
if result.mac == device]
|
if result.mac == device]
|
||||||
@ -93,7 +89,7 @@ class TadoDeviceScanner(DeviceScanner):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_SCANS)
|
@Throttle(MIN_TIME_BETWEEN_SCANS)
|
||||||
def _update_info(self):
|
async def _async_update_info(self):
|
||||||
"""
|
"""
|
||||||
Query Tado for device marked as at home.
|
Query Tado for device marked as at home.
|
||||||
|
|
||||||
@ -111,14 +107,14 @@ class TadoDeviceScanner(DeviceScanner):
|
|||||||
home_id=self.home_id, username=self.username,
|
home_id=self.home_id, username=self.username,
|
||||||
password=self.password)
|
password=self.password)
|
||||||
|
|
||||||
response = yield from self.websession.get(url)
|
response = await self.websession.get(url)
|
||||||
|
|
||||||
if response.status != 200:
|
if response.status != 200:
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"Error %d on %s.", response.status, self.tadoapiurl)
|
"Error %d on %s.", response.status, self.tadoapiurl)
|
||||||
return
|
return False
|
||||||
|
|
||||||
tado_json = yield from response.json()
|
tado_json = await response.json()
|
||||||
|
|
||||||
except (asyncio.TimeoutError, aiohttp.ClientError):
|
except (asyncio.TimeoutError, aiohttp.ClientError):
|
||||||
_LOGGER.error("Cannot load Tado data")
|
_LOGGER.error("Cannot load Tado data")
|
||||||
@ -139,7 +135,7 @@ class TadoDeviceScanner(DeviceScanner):
|
|||||||
|
|
||||||
self.last_results = last_results
|
self.last_results = last_results
|
||||||
|
|
||||||
_LOGGER.info(
|
_LOGGER.debug(
|
||||||
"Tado presence query successful, %d device(s) at home",
|
"Tado presence query successful, %d device(s) at home",
|
||||||
len(self.last_results)
|
len(self.last_results)
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user