diff --git a/homeassistant/components/subaru/__init__.py b/homeassistant/components/subaru/__init__.py index 8ecf33e8f483..c5e027dc67d6 100644 --- a/homeassistant/components/subaru/__init__.py +++ b/homeassistant/components/subaru/__init__.py @@ -75,7 +75,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: SubaruConfigEntry) -> bo hass, entry, controller=controller, vehicle_info=vehicle_info ) - await coordinator.async_refresh() + await coordinator.async_config_entry_first_refresh() entry.runtime_data = SubaruRuntimeData( controller=controller, diff --git a/tests/components/subaru/test_button.py b/tests/components/subaru/test_button.py index a805bf823bc0..3c6cddd1d51b 100644 --- a/tests/components/subaru/test_button.py +++ b/tests/components/subaru/test_button.py @@ -26,6 +26,7 @@ from .conftest import ( MOCK_API, MOCK_API_FETCH, MOCK_API_GET_DATA, + advance_time_to_next_fetch, setup_subaru_config_entry, ) @@ -302,12 +303,12 @@ async def test_no_buttons_without_remote_start( async def test_button_unavailable_on_fetch_failure( - hass: HomeAssistant, subaru_config_entry: MockConfigEntry + hass: HomeAssistant, ev_entry: MockConfigEntry ) -> None: - """Test button goes unavailable when the coordinator fails to fetch data.""" - await setup_subaru_config_entry( - hass, subaru_config_entry, fetch_effect=SubaruException("403 Error") - ) + """Test button goes unavailable when a fetch fails after setup.""" + with patch(MOCK_API_FETCH, side_effect=SubaruException("403 Error")): + advance_time_to_next_fetch(hass) + await hass.async_block_till_done() state = hass.states.get(VEHICLE_BUTTONS[TEST_VIN_2_EV]["remote_start"]) assert state.state == STATE_UNAVAILABLE diff --git a/tests/components/subaru/test_init.py b/tests/components/subaru/test_init.py index 7d8c7ad64419..e658f5040ec7 100644 --- a/tests/components/subaru/test_init.py +++ b/tests/components/subaru/test_init.py @@ -172,7 +172,7 @@ async def test_update_disabled(hass: HomeAssistant, ev_entry) -> None: async def test_fetch_failed(hass: HomeAssistant, subaru_config_entry) -> None: - """Tests when fetch fails.""" + """Test setup retries when the first fetch fails.""" await setup_subaru_config_entry( hass, subaru_config_entry, @@ -182,8 +182,7 @@ async def test_fetch_failed(hass: HomeAssistant, subaru_config_entry) -> None: fetch_effect=SubaruException("403 Error"), ) - test_entity = hass.states.get(TEST_ENTITY_ID) - assert test_entity.state == "unavailable" + assert subaru_config_entry.state is ConfigEntryState.SETUP_RETRY async def test_unload_entry(hass: HomeAssistant, ev_entry) -> None: diff --git a/tests/components/subaru/test_lock.py b/tests/components/subaru/test_lock.py index 2984f90111c0..aba40b2ac69f 100644 --- a/tests/components/subaru/test_lock.py +++ b/tests/components/subaru/test_lock.py @@ -23,7 +23,7 @@ from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import entity_registry as er -from .conftest import MOCK_API, setup_subaru_config_entry +from .conftest import MOCK_API, MOCK_API_FETCH, advance_time_to_next_fetch from tests.common import MockConfigEntry @@ -98,12 +98,12 @@ async def test_unlock_specific_door_invalid(hass: HomeAssistant, ev_entry) -> No async def test_lock_unavailable_on_fetch_failure( - hass: HomeAssistant, subaru_config_entry: MockConfigEntry + hass: HomeAssistant, ev_entry: MockConfigEntry ) -> None: - """Test lock goes unavailable when the coordinator fails to fetch data.""" - await setup_subaru_config_entry( - hass, subaru_config_entry, fetch_effect=SubaruException("403 Error") - ) + """Test lock goes unavailable when a fetch fails after setup.""" + with patch(MOCK_API_FETCH, side_effect=SubaruException("403 Error")): + advance_time_to_next_fetch(hass) + await hass.async_block_till_done() state = hass.states.get(DEVICE_ID) assert state.state == STATE_UNAVAILABLE