diff --git a/homeassistant/components/vicare/coordinator.py b/homeassistant/components/vicare/coordinator.py index b168af30275902..e052681717ff4e 100644 --- a/homeassistant/components/vicare/coordinator.py +++ b/homeassistant/components/vicare/coordinator.py @@ -46,7 +46,7 @@ def __init__( 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 @@ def _refresh(self) -> 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 4738f31f0ed544..3123693289a07e 100644 --- a/tests/components/vicare/conftest.py +++ b/tests/components/vicare/conftest.py @@ -41,15 +41,15 @@ def __init__(self, fixtures: list[Fixture]) -> None: """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 @@ def __init__(self, fixtures: list[Fixture]) -> None: # 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 @@ def as_vicare_data(self) -> ViCareData: 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."""