diff --git a/homeassistant/components/fritzbox/coordinator.py b/homeassistant/components/fritzbox/coordinator.py index 69ab0b4c274..a94a7483e18 100644 --- a/homeassistant/components/fritzbox/coordinator.py +++ b/homeassistant/components/fritzbox/coordinator.py @@ -8,8 +8,8 @@ import requests from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant -from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady -from homeassistant.helpers.update_coordinator import DataUpdateCoordinator +from homeassistant.exceptions import ConfigEntryAuthFailed +from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from .const import CONF_CONNECTIONS, DOMAIN, LOGGER @@ -34,19 +34,19 @@ class FritzboxDataUpdateCoordinator(DataUpdateCoordinator): def _update_fritz_devices(self) -> dict[str, FritzhomeDevice]: """Update all fritzbox device data.""" try: - devices = self.fritz.get_devices() + self.fritz.update_devices() except requests.exceptions.ConnectionError as ex: - raise ConfigEntryNotReady from ex + raise UpdateFailed from ex except requests.exceptions.HTTPError: # If the device rebooted, login again try: self.fritz.login() except LoginError as ex: raise ConfigEntryAuthFailed from ex - devices = self.fritz.get_devices() + self.fritz.update_devices() + devices = self.fritz.get_devices() data = {} - self.fritz.update_devices() for device in devices: # assume device as unavailable, see #55799 if ( diff --git a/tests/components/fritzbox/test_climate.py b/tests/components/fritzbox/test_climate.py index 92143662c0a..993c1009432 100644 --- a/tests/components/fritzbox/test_climate.py +++ b/tests/components/fritzbox/test_climate.py @@ -222,15 +222,15 @@ async def test_update_error(hass: HomeAssistant, fritz: Mock): hass, MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0], ENTITY_ID, device, fritz ) - assert fritz().update_devices.call_count == 1 - assert fritz().login.call_count == 1 + assert fritz().update_devices.call_count == 2 + assert fritz().login.call_count == 2 next_update = dt_util.utcnow() + timedelta(seconds=200) async_fire_time_changed(hass, next_update) await hass.async_block_till_done() - assert fritz().update_devices.call_count == 2 - assert fritz().login.call_count == 2 + assert fritz().update_devices.call_count == 4 + assert fritz().login.call_count == 4 async def test_set_temperature_temperature(hass: HomeAssistant, fritz: Mock): diff --git a/tests/components/fritzbox/test_init.py b/tests/components/fritzbox/test_init.py index e0dfcdd2663..f69d7256e23 100644 --- a/tests/components/fritzbox/test_init.py +++ b/tests/components/fritzbox/test_init.py @@ -163,10 +163,11 @@ async def test_coordinator_update_after_reboot(hass: HomeAssistant, fritz: Mock) unique_id="any", ) entry.add_to_hass(hass) - fritz().get_devices.side_effect = [HTTPError(), ""] + fritz().update_devices.side_effect = [HTTPError(), ""] assert await hass.config_entries.async_setup(entry.entry_id) - assert fritz().get_devices.call_count == 2 + assert fritz().update_devices.call_count == 2 + assert fritz().get_devices.call_count == 1 assert fritz().login.call_count == 2 @@ -180,11 +181,12 @@ async def test_coordinator_update_after_password_change( unique_id="any", ) entry.add_to_hass(hass) - fritz().get_devices.side_effect = HTTPError() + fritz().update_devices.side_effect = HTTPError() fritz().login.side_effect = ["", LoginError("some_user")] assert not await hass.config_entries.async_setup(entry.entry_id) - assert fritz().get_devices.call_count == 1 + assert fritz().update_devices.call_count == 1 + assert fritz().get_devices.call_count == 0 assert fritz().login.call_count == 2 diff --git a/tests/components/fritzbox/test_light.py b/tests/components/fritzbox/test_light.py index 24077306647..b63d19da7e0 100644 --- a/tests/components/fritzbox/test_light.py +++ b/tests/components/fritzbox/test_light.py @@ -174,12 +174,12 @@ async def test_update_error(hass: HomeAssistant, fritz: Mock): assert not await setup_config_entry( hass, MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0], ENTITY_ID, device, fritz ) - assert fritz().update_devices.call_count == 1 - assert fritz().login.call_count == 1 + assert fritz().update_devices.call_count == 2 + assert fritz().login.call_count == 2 next_update = dt_util.utcnow() + timedelta(seconds=200) async_fire_time_changed(hass, next_update) await hass.async_block_till_done() - assert fritz().update_devices.call_count == 2 - assert fritz().login.call_count == 2 + assert fritz().update_devices.call_count == 4 + assert fritz().login.call_count == 4 diff --git a/tests/components/fritzbox/test_sensor.py b/tests/components/fritzbox/test_sensor.py index 21262636635..dfb480459da 100644 --- a/tests/components/fritzbox/test_sensor.py +++ b/tests/components/fritzbox/test_sensor.py @@ -78,12 +78,12 @@ async def test_update_error(hass: HomeAssistant, fritz: Mock): assert not await setup_config_entry( hass, MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0], ENTITY_ID, device, fritz ) - assert fritz().update_devices.call_count == 1 - assert fritz().login.call_count == 1 + assert fritz().update_devices.call_count == 2 + assert fritz().login.call_count == 2 next_update = dt_util.utcnow() + timedelta(seconds=200) async_fire_time_changed(hass, next_update) await hass.async_block_till_done() - assert fritz().update_devices.call_count == 2 - assert fritz().login.call_count == 2 + assert fritz().update_devices.call_count == 4 + assert fritz().login.call_count == 4 diff --git a/tests/components/fritzbox/test_switch.py b/tests/components/fritzbox/test_switch.py index de49a5cd89e..a3135dd61f3 100644 --- a/tests/components/fritzbox/test_switch.py +++ b/tests/components/fritzbox/test_switch.py @@ -123,15 +123,15 @@ async def test_update_error(hass: HomeAssistant, fritz: Mock): assert not await setup_config_entry( hass, MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0], ENTITY_ID, device, fritz ) - assert fritz().update_devices.call_count == 1 - assert fritz().login.call_count == 1 + assert fritz().update_devices.call_count == 2 + assert fritz().login.call_count == 2 next_update = dt_util.utcnow() + timedelta(seconds=200) async_fire_time_changed(hass, next_update) await hass.async_block_till_done() - assert fritz().update_devices.call_count == 2 - assert fritz().login.call_count == 2 + assert fritz().update_devices.call_count == 4 + assert fritz().login.call_count == 4 async def test_assume_device_unavailable(hass: HomeAssistant, fritz: Mock):