mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Use _async_setup
in tedee coordinator (#126812)
This commit is contained in:
parent
c5b4892596
commit
8999e9f116
@ -36,6 +36,7 @@ class TedeeApiCoordinator(DataUpdateCoordinator[dict[int, TedeeLock]]):
|
|||||||
"""Class to handle fetching data from the tedee API centrally."""
|
"""Class to handle fetching data from the tedee API centrally."""
|
||||||
|
|
||||||
config_entry: ConfigEntry
|
config_entry: ConfigEntry
|
||||||
|
bridge: TedeeBridge
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant) -> None:
|
def __init__(self, hass: HomeAssistant) -> None:
|
||||||
"""Initialize coordinator."""
|
"""Initialize coordinator."""
|
||||||
@ -46,7 +47,6 @@ class TedeeApiCoordinator(DataUpdateCoordinator[dict[int, TedeeLock]]):
|
|||||||
update_interval=SCAN_INTERVAL,
|
update_interval=SCAN_INTERVAL,
|
||||||
)
|
)
|
||||||
|
|
||||||
self._bridge: TedeeBridge | None = None
|
|
||||||
self.tedee_client = TedeeClient(
|
self.tedee_client = TedeeClient(
|
||||||
local_token=self.config_entry.data[CONF_LOCAL_ACCESS_TOKEN],
|
local_token=self.config_entry.data[CONF_LOCAL_ACCESS_TOKEN],
|
||||||
local_ip=self.config_entry.data[CONF_HOST],
|
local_ip=self.config_entry.data[CONF_HOST],
|
||||||
@ -58,22 +58,18 @@ class TedeeApiCoordinator(DataUpdateCoordinator[dict[int, TedeeLock]]):
|
|||||||
self.new_lock_callbacks: list[Callable[[int], None]] = []
|
self.new_lock_callbacks: list[Callable[[int], None]] = []
|
||||||
self.tedee_webhook_id: int | None = None
|
self.tedee_webhook_id: int | None = None
|
||||||
|
|
||||||
@property
|
async def _async_setup(self) -> None:
|
||||||
def bridge(self) -> TedeeBridge:
|
"""Set up the coordinator."""
|
||||||
"""Return bridge."""
|
|
||||||
assert self._bridge
|
|
||||||
return self._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:
|
async def _async_get_bridge() -> None:
|
||||||
self._bridge = await self.tedee_client.get_local_bridge()
|
self.bridge = await self.tedee_client.get_local_bridge()
|
||||||
|
|
||||||
_LOGGER.debug("Update coordinator: Getting bridge from API")
|
_LOGGER.debug("Update coordinator: Getting bridge from API")
|
||||||
await self._async_update(_async_get_bridge)
|
await self._async_update(_async_get_bridge)
|
||||||
|
|
||||||
|
async def _async_update_data(self) -> dict[int, TedeeLock]:
|
||||||
|
"""Fetch data from API endpoint."""
|
||||||
|
|
||||||
_LOGGER.debug("Update coordinator: Getting locks from API")
|
_LOGGER.debug("Update coordinator: Getting locks from API")
|
||||||
# once every hours get all lock details, otherwise use the sync endpoint
|
# once every hours get all lock details, otherwise use the sync endpoint
|
||||||
if self._next_get_locks <= time.time():
|
if self._next_get_locks <= time.time():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user