mirror of
https://github.com/home-assistant/core.git
synced 2026-09-02 02:35:09 -05:00
Ignore location FORBIDDEN response for the Volvo integration (#169713)
This commit is contained in:
committed by
Paulus Schoutsen
parent
179d370c2a
commit
28742822cb
@@ -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
|
||||
|
||||
@@ -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."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user