diff --git a/homeassistant/components/volvo/coordinator.py b/homeassistant/components/volvo/coordinator.py index db2654da179f..2b70476c6313 100644 --- a/homeassistant/components/volvo/coordinator.py +++ b/homeassistant/components/volvo/coordinator.py @@ -263,9 +263,21 @@ class VolvoSlowIntervalCoordinator(VolvoBaseCoordinator): api.async_get_odometer, ] - location = await api.async_get_location() + # Volvo is returning FORBIDDEN for the location request in case the vehicle + # is in an unsupported region. Since we can't know where the vehicle is + # located, we silently ignore the failure. If (re-)authentication is needed, + # other requests will fail as well and trigger the re-auth flow. + location = None + try: + location = await api.async_get_location() + except VolvoAuthException as ex: + _LOGGER.debug( + "%s - Location not supported for this vehicle. %s", + self.config_entry.entry_id, + ex.message, + ) - if location.get("location") is not None: + if location and location.get("location") is not None: api_calls.append(api.async_get_location) return api_calls diff --git a/tests/components/volvo/test_coordinator.py b/tests/components/volvo/test_coordinator.py index 8d1a8f0a725a..822e4fa3d225 100644 --- a/tests/components/volvo/test_coordinator.py +++ b/tests/components/volvo/test_coordinator.py @@ -130,6 +130,33 @@ async def test_update_coordinator_all_error( assert state.state == STATE_UNAVAILABLE +@pytest.mark.freeze_time("2025-05-31T10:00:00+00:00") +async def test_coordinator_location_auth_exception( + hass: HomeAssistant, + freezer: FrozenDateTimeFactory, + setup_integration: Callable[[], Awaitable[bool]], + mock_api: VolvoCarsApi, +) -> None: + """Test coordinator setup when location returns VolvoAuthException.""" + configure_mock( + mock_api.async_get_location, side_effect=VolvoAuthException(403, "Forbidden") + ) + assert await setup_integration() + + # Verify no reauthentication flow is started + flows = hass.config_entries.flow.async_progress_by_handler(DOMAIN) + assert not flows + + # Verify integration loads without location entity + device_tracker_states = hass.states.async_all(domain_filter="device_tracker") + assert len(device_tracker_states) == 0 + + # Verify other entities still work + sensor_id = "sensor.volvo_xc40_odometer" + state = hass.states.get(sensor_id) + assert state.state == "30000" + + def _mock_api_failure(mock_api: VolvoCarsApi) -> AsyncMock: """Mock the Volvo API so that it raises an exception for all calls."""