Fix non-thread-safe operation in harmony (#116070)
Fix unsafe thread operation in harmony
2417771664
This commit is contained in:
parent
e3016b131a
commit
f2336a5a3a
2 changed files with 10 additions and 5 deletions
|
@ -6,6 +6,7 @@ from collections.abc import Callable
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.event import async_call_later
|
from homeassistant.helpers.event import async_call_later
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ class HarmonyEntity(Entity):
|
||||||
_LOGGER.debug("%s: connected to the HUB", self._data.name)
|
_LOGGER.debug("%s: connected to the HUB", self._data.name)
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
self._clear_disconnection_delay()
|
self._async_clear_disconnection_delay()
|
||||||
|
|
||||||
async def async_got_disconnected(self, _: str | None = None) -> None:
|
async def async_got_disconnected(self, _: str | None = None) -> None:
|
||||||
"""Notification that we're disconnected from the HUB."""
|
"""Notification that we're disconnected from the HUB."""
|
||||||
|
@ -46,15 +47,19 @@ class HarmonyEntity(Entity):
|
||||||
# We're going to wait for 10 seconds before announcing we're
|
# We're going to wait for 10 seconds before announcing we're
|
||||||
# unavailable, this to allow a reconnection to happen.
|
# unavailable, this to allow a reconnection to happen.
|
||||||
self._unsub_mark_disconnected = async_call_later(
|
self._unsub_mark_disconnected = async_call_later(
|
||||||
self.hass, TIME_MARK_DISCONNECTED, self._mark_disconnected_if_unavailable
|
self.hass,
|
||||||
|
TIME_MARK_DISCONNECTED,
|
||||||
|
self._async_mark_disconnected_if_unavailable,
|
||||||
)
|
)
|
||||||
|
|
||||||
def _clear_disconnection_delay(self) -> None:
|
@callback
|
||||||
|
def _async_clear_disconnection_delay(self) -> None:
|
||||||
if self._unsub_mark_disconnected:
|
if self._unsub_mark_disconnected:
|
||||||
self._unsub_mark_disconnected()
|
self._unsub_mark_disconnected()
|
||||||
self._unsub_mark_disconnected = None
|
self._unsub_mark_disconnected = None
|
||||||
|
|
||||||
def _mark_disconnected_if_unavailable(self, _: datetime) -> None:
|
@callback
|
||||||
|
def _async_mark_disconnected_if_unavailable(self, _: datetime) -> None:
|
||||||
self._unsub_mark_disconnected = None
|
self._unsub_mark_disconnected = None
|
||||||
if not self.available:
|
if not self.available:
|
||||||
# Still disconnected. Let the state engine know.
|
# Still disconnected. Let the state engine know.
|
||||||
|
|
|
@ -138,7 +138,7 @@ class HarmonyRemote(HarmonyEntity, RemoteEntity, RestoreEntity):
|
||||||
|
|
||||||
_LOGGER.debug("%s: Harmony Hub added", self._data.name)
|
_LOGGER.debug("%s: Harmony Hub added", self._data.name)
|
||||||
|
|
||||||
self.async_on_remove(self._clear_disconnection_delay)
|
self.async_on_remove(self._async_clear_disconnection_delay)
|
||||||
self._setup_callbacks()
|
self._setup_callbacks()
|
||||||
|
|
||||||
self.async_on_remove(
|
self.async_on_remove(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue