Fix Husqvarna Automower coordinator listener list mutating (#148926)

This commit is contained in:
Abílio Costa 2025-07-17 07:52:59 +01:00 committed by GitHub
parent 6dc2340c5a
commit e32e06d7a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import asyncio
from collections.abc import Callable
from datetime import timedelta
import logging
from typing import override
from aioautomower.exceptions import (
ApiError,
@ -60,7 +61,12 @@ class AutomowerDataUpdateCoordinator(DataUpdateCoordinator[MowerDictionary]):
self._devices_last_update: set[str] = set()
self._zones_last_update: dict[str, set[str]] = {}
self._areas_last_update: dict[str, set[int]] = {}
self.async_add_listener(self._on_data_update)
@override
@callback
def async_update_listeners(self) -> None:
self._on_data_update()
super().async_update_listeners()
async def _async_update_data(self) -> MowerDictionary:
"""Subscribe for websocket and poll data from the API."""

View File

@ -462,7 +462,13 @@ async def test_add_and_remove_work_area(
poll_values[TEST_MOWER_ID].work_area_names.remove("Front lawn")
del poll_values[TEST_MOWER_ID].work_area_dict[123456]
del poll_values[TEST_MOWER_ID].work_areas[123456]
del poll_values[TEST_MOWER_ID].calendar.tasks[:2]
poll_values[TEST_MOWER_ID].calendar.tasks = [
task
for task in poll_values[TEST_MOWER_ID].calendar.tasks
if task.work_area_id not in [1, 123456]
]
poll_values[TEST_MOWER_ID].mower.work_area_id = 654321
mock_automower_client.get_status.return_value = poll_values
freezer.tick(SCAN_INTERVAL)