Do not block event loop on updates
This commit is contained in:
committed by
rospogrigio
parent
e673340229
commit
7a9deea830
@@ -94,13 +94,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||||||
|
|
||||||
device = TuyaDevice(entry.data)
|
device = TuyaDevice(entry.data)
|
||||||
|
|
||||||
def update_state(now):
|
async def update_state(now):
|
||||||
"""Read device status and update platforms."""
|
"""Read device status and update platforms."""
|
||||||
status = None
|
status = None
|
||||||
try:
|
try:
|
||||||
status = device.status()
|
status = await hass.async_add_executor_job(device.status)
|
||||||
except Exception:
|
except Exception:
|
||||||
_LOGGER.exception("update failed")
|
_LOGGER.debug("update failed")
|
||||||
|
|
||||||
signal = f"localtuya_{entry.data[CONF_DEVICE_ID]}"
|
signal = f"localtuya_{entry.data[CONF_DEVICE_ID]}"
|
||||||
async_dispatcher_send(hass, signal, status)
|
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())
|
hass.async_create_task(setup_entities())
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user