From 2937c80da5b7f7ad139b22fe3350eec2a1525f3a Mon Sep 17 00:00:00 2001 From: Christian Lackas Date: Thu, 27 Aug 2026 12:46:56 +0200 Subject: [PATCH] Fix ViCare setup by passing the accessor to fetch_all_features (#180315) --- .../components/vicare/coordinator.py | 4 ++-- tests/components/vicare/conftest.py | 23 ++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/vicare/coordinator.py b/homeassistant/components/vicare/coordinator.py index b168af302759..e052681717ff 100644 --- a/homeassistant/components/vicare/coordinator.py +++ b/homeassistant/components/vicare/coordinator.py @@ -46,7 +46,7 @@ class ViCareCoordinator(DataUpdateCoordinator[None]): hass, _LOGGER, config_entry=config_entry, - name=f"{DOMAIN}_{device.service.accessor.id}", + name=f"{DOMAIN}_{device.accessor.serial}_{device.accessor.device_id}", update_interval=timedelta(seconds=DEFAULT_CACHE_DURATION * device_count), ) self._device = device @@ -60,7 +60,7 @@ class ViCareCoordinator(DataUpdateCoordinator[None]): """Force a fresh fetch from the Viessmann API.""" try: self._device.service.clear_cache() - self._device.service.fetch_all_features() + self._device.service.fetch_all_features(self._device.accessor) except PyViCareInvalidCredentialsError as err: raise ConfigEntryAuthFailed from err except ( diff --git a/tests/components/vicare/conftest.py b/tests/components/vicare/conftest.py index 4738f31f0ed5..3123693289a0 100644 --- a/tests/components/vicare/conftest.py +++ b/tests/components/vicare/conftest.py @@ -41,15 +41,15 @@ class MockPyViCare: """Init a single device from json dump.""" self.devices = [] for idx, fixture in enumerate(fixtures): - service = MockViCareService( + accessor = ViCareDeviceAccessor( f"installation{idx}", fixture.gateway_id or f"gateway{idx}", f"deviceId{idx}", - fixture, ) + service = MockViCareService(fixture) self.devices.append( PyViCareDeviceConfig( - service.accessor, + accessor, service, "Vitovalor" if fixture.data_file.endswith("VitoValor.json") @@ -61,16 +61,18 @@ class MockPyViCare: # Simulate a device with an unsupported deviceType that PyViCare's # `devices` filter would drop but should still appear in `all_devices` # (used by diagnostics). - unsupported_service = MockViCareService( + unsupported_accessor = ViCareDeviceAccessor( "installation_unsupported", "gateway_unsupported", "deviceId_unsupported", - Fixture(set(), "vicare/dummy-device-no-serial.json"), + ) + unsupported_service = MockViCareService( + Fixture(set(), "vicare/dummy-device-no-serial.json") ) self.all_devices = [ *self.devices, PyViCareDeviceConfig( - unsupported_service.accessor, + unsupported_accessor, unsupported_service, "unsupported_model", "Online", @@ -92,16 +94,15 @@ class MockPyViCare: class MockViCareService: """PyVicareService mock using a json dump.""" - def __init__( - self, installation_id: str, gateway_id: str, device_id: str, fixture: Fixture - ) -> None: + def __init__(self, fixture: Fixture) -> None: """Initialize the mock from a json dump.""" self._test_data = load_json_object_fixture(fixture.data_file) - self.fetch_all_features = Mock(return_value=self._test_data) + # Mirror the real signature: fetch_all_features() requires an accessor, + # and no real service carries one. + self.fetch_all_features = Mock(side_effect=lambda accessor: self._test_data) self.setProperty = Mock() self.clear_cache = Mock() self.roles = fixture.roles - self.accessor = ViCareDeviceAccessor(installation_id, gateway_id, device_id) def hasRoles(self, requested_roles: list[str]) -> bool: """Return true if requested roles are assigned."""