From 93ece01c9f0b82e3d8d3b53cf2f4481e6f95e3b6 Mon Sep 17 00:00:00 2001 From: Rene Lange Date: Wed, 27 Nov 2024 17:42:03 +0100 Subject: [PATCH] fixed some sync/async problems --- custom_components/homeassistantedupage/__init__.py | 4 +--- .../homeassistantedupage/homeassistant_edupage.py | 6 ++++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/custom_components/homeassistantedupage/__init__.py b/custom_components/homeassistantedupage/__init__.py index deffcb9..3e55f51 100644 --- a/custom_components/homeassistantedupage/__init__.py +++ b/custom_components/homeassistantedupage/__init__.py @@ -32,9 +32,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: coordinator = None try: - await hass.async_add_executor_job( - edupage.login, username, password, subdomain - ) + await edupage.login(username, password, subdomain) _LOGGER.debug("INIT login_success") except BadCredentialsException as e: diff --git a/custom_components/homeassistantedupage/homeassistant_edupage.py b/custom_components/homeassistantedupage/homeassistant_edupage.py index fae947d..e8d9b2d 100644 --- a/custom_components/homeassistantedupage/homeassistant_edupage.py +++ b/custom_components/homeassistantedupage/homeassistant_edupage.py @@ -18,12 +18,14 @@ async def login(self, username: str, password: str, subdomain: str): try: result = True login = Login(self.api) - await asyncio.to_thread( + await self.hass.async_add_executor_job( login.reload_data, subdomain, self.sessionid, username ) if not self.api.is_logged_in: #TODO: how to handle 2FA at this point?! - result = await asyncio.to_thread(self.api.login, username, password, subdomain) + result = await self.hass.async_add_executor_job( + self.api.login, username, password, subdomain + ) _LOGGER.debug(f"EDUPAGE Login successful, result: {result}") return result except BadCredentialsException as e: