mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Add/remove devices on push in Husqvarna Automower (#142550)
Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
parent
8aa30b0ccb
commit
e9789e0b3e
@ -61,6 +61,15 @@ class AutomowerDataUpdateCoordinator(DataUpdateCoordinator[MowerDictionary]):
|
|||||||
self._zones_last_update: dict[str, set[str]] = {}
|
self._zones_last_update: dict[str, set[str]] = {}
|
||||||
self._areas_last_update: dict[str, set[int]] = {}
|
self._areas_last_update: dict[str, set[int]] = {}
|
||||||
|
|
||||||
|
def _async_add_remove_devices_and_entities(self, data: MowerDictionary) -> None:
|
||||||
|
"""Add/remove devices and dynamic entities, when amount of devices changed."""
|
||||||
|
self._async_add_remove_devices(data)
|
||||||
|
for mower_id in data:
|
||||||
|
if data[mower_id].capabilities.stay_out_zones:
|
||||||
|
self._async_add_remove_stay_out_zones(data)
|
||||||
|
if data[mower_id].capabilities.work_areas:
|
||||||
|
self._async_add_remove_work_areas(data)
|
||||||
|
|
||||||
async def _async_update_data(self) -> MowerDictionary:
|
async def _async_update_data(self) -> MowerDictionary:
|
||||||
"""Subscribe for websocket and poll data from the API."""
|
"""Subscribe for websocket and poll data from the API."""
|
||||||
if not self.ws_connected:
|
if not self.ws_connected:
|
||||||
@ -73,20 +82,14 @@ class AutomowerDataUpdateCoordinator(DataUpdateCoordinator[MowerDictionary]):
|
|||||||
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
|
||||||
|
self._async_add_remove_devices_and_entities(data)
|
||||||
self._async_add_remove_devices(data)
|
|
||||||
for mower_id in data:
|
|
||||||
if data[mower_id].capabilities.stay_out_zones:
|
|
||||||
self._async_add_remove_stay_out_zones(data)
|
|
||||||
for mower_id in data:
|
|
||||||
if data[mower_id].capabilities.work_areas:
|
|
||||||
self._async_add_remove_work_areas(data)
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def callback(self, ws_data: MowerDictionary) -> None:
|
def callback(self, ws_data: MowerDictionary) -> None:
|
||||||
"""Process websocket callbacks and write them to the DataUpdateCoordinator."""
|
"""Process websocket callbacks and write them to the DataUpdateCoordinator."""
|
||||||
self.async_set_updated_data(ws_data)
|
self.async_set_updated_data(ws_data)
|
||||||
|
self._async_add_remove_devices_and_entities(ws_data)
|
||||||
|
|
||||||
async def client_listen(
|
async def client_listen(
|
||||||
self,
|
self,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user