mirror of
https://github.com/home-assistant/core.git
synced 2025-08-30 09:51:37 +02:00
Use _async_setup in Huqvarna Automower (#151325)
This commit is contained in:
@@ -55,7 +55,6 @@ class AutomowerDataUpdateCoordinator(DataUpdateCoordinator[MowerDictionary]):
|
|||||||
update_interval=SCAN_INTERVAL,
|
update_interval=SCAN_INTERVAL,
|
||||||
)
|
)
|
||||||
self.api = api
|
self.api = api
|
||||||
self.ws_connected: bool = False
|
|
||||||
self.reconnect_time = DEFAULT_RECONNECT_TIME
|
self.reconnect_time = DEFAULT_RECONNECT_TIME
|
||||||
self.new_devices_callbacks: list[Callable[[set[str]], None]] = []
|
self.new_devices_callbacks: list[Callable[[set[str]], None]] = []
|
||||||
self.new_zones_callbacks: list[Callable[[str, set[str]], None]] = []
|
self.new_zones_callbacks: list[Callable[[str, set[str]], None]] = []
|
||||||
@@ -71,12 +70,10 @@ class AutomowerDataUpdateCoordinator(DataUpdateCoordinator[MowerDictionary]):
|
|||||||
self._on_data_update()
|
self._on_data_update()
|
||||||
super().async_update_listeners()
|
super().async_update_listeners()
|
||||||
|
|
||||||
async def _async_update_data(self) -> MowerDictionary:
|
async def _async_setup(self) -> None:
|
||||||
"""Subscribe for websocket and poll data from the API."""
|
"""Initialize websocket connection and callbacks."""
|
||||||
if not self.ws_connected:
|
|
||||||
await self.api.connect()
|
await self.api.connect()
|
||||||
self.api.register_data_callback(self.handle_websocket_updates)
|
self.api.register_data_callback(self.handle_websocket_updates)
|
||||||
self.ws_connected = True
|
|
||||||
|
|
||||||
def start_watchdog() -> None:
|
def start_watchdog() -> None:
|
||||||
if self._watchdog_task is not None and not self._watchdog_task.done():
|
if self._watchdog_task is not None and not self._watchdog_task.done():
|
||||||
@@ -89,13 +86,15 @@ class AutomowerDataUpdateCoordinator(DataUpdateCoordinator[MowerDictionary]):
|
|||||||
)
|
)
|
||||||
|
|
||||||
self.api.register_ws_ready_callback(start_watchdog)
|
self.api.register_ws_ready_callback(start_watchdog)
|
||||||
|
|
||||||
|
async def _async_update_data(self) -> MowerDictionary:
|
||||||
|
"""Poll data from the API."""
|
||||||
try:
|
try:
|
||||||
data = await self.api.get_status()
|
return await self.api.get_status()
|
||||||
except ApiError as err:
|
except ApiError as err:
|
||||||
raise UpdateFailed(err) from err
|
raise UpdateFailed(err) from err
|
||||||
except AuthError as err:
|
except AuthError as err:
|
||||||
raise ConfigEntryAuthFailed(err) from err
|
raise ConfigEntryAuthFailed(err) from err
|
||||||
return data
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _on_data_update(self) -> None:
|
def _on_data_update(self) -> None:
|
||||||
|
Reference in New Issue
Block a user