Fix non threadsafe call xiaomi_aqara (#93405)

This commit is contained in:
J. Nick Koston 2023-05-23 11:56:27 -05:00 committed by GitHub
parent fdf40fd1e5
commit 761943e1e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@
import asyncio import asyncio
from datetime import timedelta from datetime import timedelta
import logging import logging
from typing import Any
import voluptuous as vol import voluptuous as vol
from xiaomi_gateway import AsyncXiaomiGatewayMulticast, XiaomiGateway from xiaomi_gateway import AsyncXiaomiGatewayMulticast, XiaomiGateway
@ -351,9 +352,13 @@ class XiaomiDevice(Entity):
return True return True
return False return False
def push_data(self, data: dict[str, Any], raw_data: dict[Any, Any]) -> None:
"""Push from Hub running in another thread."""
self.hass.loop.call_soon(self.async_push_data, data, raw_data)
@callback @callback
def push_data(self, data, raw_data): def async_push_data(self, data: dict[str, Any], raw_data: dict[Any, Any]) -> None:
"""Push from Hub.""" """Push from Hub handled in the event loop."""
_LOGGER.debug("PUSH >> %s: %s", self, data) _LOGGER.debug("PUSH >> %s: %s", self, data)
was_unavailable = self._async_track_unavailable() was_unavailable = self._async_track_unavailable()
is_data = self.parse_data(data, raw_data) is_data = self.parse_data(data, raw_data)