Move async_deinitialize to google_assistant AbstractConfig (#109736)

pull/109757/head
Erik Montnemery 2024-02-05 19:53:22 +01:00 committed by GitHub
parent 3294506190
commit 9d42455955
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 10 deletions

View File

@ -23,7 +23,6 @@ from homeassistant.components.homeassistant.exposed_entities import (
from homeassistant.components.sensor import SensorDeviceClass
from homeassistant.const import CLOUD_NEVER_EXPOSED_ENTITIES
from homeassistant.core import (
CALLBACK_TYPE,
CoreState,
Event,
HomeAssistant,
@ -145,7 +144,6 @@ class CloudGoogleConfig(AbstractConfig):
self._prefs = prefs
self._cloud = cloud
self._sync_entities_lock = asyncio.Lock()
self._on_deinitialize: list[CALLBACK_TYPE] = []
@property
def enabled(self) -> bool:
@ -283,13 +281,6 @@ class CloudGoogleConfig(AbstractConfig):
)
)
@callback
def async_deinitialize(self) -> None:
"""Remove listeners."""
_LOGGER.debug("async_deinitialize")
while self._on_deinitialize:
self._on_deinitialize.pop()()
def should_expose(self, state: State) -> bool:
"""If a state object should be exposed."""
return self._should_expose_entity_id(state.entity_id)

View File

@ -105,6 +105,7 @@ class AbstractConfig(ABC):
self._local_last_active: datetime | None = None
self._local_sdk_version_warn = False
self.is_supported_cache: dict[str, tuple[int | None, bool]] = {}
self._on_deinitialize: list[CALLBACK_TYPE] = []
async def async_initialize(self) -> None:
"""Perform async initialization of config."""
@ -118,7 +119,14 @@ class AbstractConfig(ABC):
"""Sync entities to Google."""
await self.async_sync_entities_all()
start.async_at_start(self.hass, sync_google)
self._on_deinitialize.append(start.async_at_start(self.hass, sync_google))
@callback
def async_deinitialize(self) -> None:
"""Remove listeners."""
_LOGGER.debug("async_deinitialize")
while self._on_deinitialize:
self._on_deinitialize.pop()()
@property
def enabled(self):