From 7a9deea83070dec463a63c3b666a38bc183be4ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20St=C3=A5hl?= Date: Mon, 28 Sep 2020 22:28:15 +0200 Subject: [PATCH] Do not block event loop on updates --- custom_components/localtuya/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/custom_components/localtuya/__init__.py b/custom_components/localtuya/__init__.py index 16fb9de..459aa59 100644 --- a/custom_components/localtuya/__init__.py +++ b/custom_components/localtuya/__init__.py @@ -94,13 +94,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): device = TuyaDevice(entry.data) - def update_state(now): + async def update_state(now): """Read device status and update platforms.""" status = None try: - status = device.status() + status = await hass.async_add_executor_job(device.status) except Exception: - _LOGGER.exception("update failed") + _LOGGER.debug("update failed") signal = f"localtuya_{entry.data[CONF_DEVICE_ID]}" async_dispatcher_send(hass, signal, status) @@ -125,7 +125,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): ] ) - update_state(datetime.now()) + await update_state(datetime.now()) hass.async_create_task(setup_entities())