Use _async_setup in tedee coordinator (#126812)

This commit is contained in:
Josef Zweck 2024-09-27 19:10:52 +02:00 committed by GitHub
parent c5b4892596
commit 8999e9f116
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -36,6 +36,7 @@ class TedeeApiCoordinator(DataUpdateCoordinator[dict[int, TedeeLock]]):
"""Class to handle fetching data from the tedee API centrally."""
config_entry: ConfigEntry
bridge: TedeeBridge
def __init__(self, hass: HomeAssistant) -> None:
"""Initialize coordinator."""
@ -46,7 +47,6 @@ class TedeeApiCoordinator(DataUpdateCoordinator[dict[int, TedeeLock]]):
update_interval=SCAN_INTERVAL,
)
self._bridge: TedeeBridge | None = None
self.tedee_client = TedeeClient(
local_token=self.config_entry.data[CONF_LOCAL_ACCESS_TOKEN],
local_ip=self.config_entry.data[CONF_HOST],
@ -58,21 +58,17 @@ class TedeeApiCoordinator(DataUpdateCoordinator[dict[int, TedeeLock]]):
self.new_lock_callbacks: list[Callable[[int], None]] = []
self.tedee_webhook_id: int | None = None
@property
def bridge(self) -> TedeeBridge:
"""Return bridge."""
assert self._bridge
return self._bridge
async def _async_setup(self) -> None:
"""Set up the coordinator."""
async def _async_get_bridge() -> None:
self.bridge = await self.tedee_client.get_local_bridge()
_LOGGER.debug("Update coordinator: Getting bridge from API")
await self._async_update(_async_get_bridge)
async def _async_update_data(self) -> dict[int, TedeeLock]:
"""Fetch data from API endpoint."""
if self._bridge is None:
async def _async_get_bridge() -> None:
self._bridge = await self.tedee_client.get_local_bridge()
_LOGGER.debug("Update coordinator: Getting bridge from API")
await self._async_update(_async_get_bridge)
_LOGGER.debug("Update coordinator: Getting locks from API")
# once every hours get all lock details, otherwise use the sync endpoint