mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 14:57:09 +00:00
Perform re-login after Fritzbox has rebooted (#64709)
This commit is contained in:
parent
2a00c096db
commit
6874b49a39
@ -8,8 +8,8 @@ import requests
|
|||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
from .const import CONF_CONNECTIONS, DOMAIN, LOGGER
|
from .const import CONF_CONNECTIONS, DOMAIN, LOGGER
|
||||||
|
|
||||||
@ -34,19 +34,19 @@ class FritzboxDataUpdateCoordinator(DataUpdateCoordinator):
|
|||||||
def _update_fritz_devices(self) -> dict[str, FritzhomeDevice]:
|
def _update_fritz_devices(self) -> dict[str, FritzhomeDevice]:
|
||||||
"""Update all fritzbox device data."""
|
"""Update all fritzbox device data."""
|
||||||
try:
|
try:
|
||||||
devices = self.fritz.get_devices()
|
self.fritz.update_devices()
|
||||||
except requests.exceptions.ConnectionError as ex:
|
except requests.exceptions.ConnectionError as ex:
|
||||||
raise ConfigEntryNotReady from ex
|
raise UpdateFailed from ex
|
||||||
except requests.exceptions.HTTPError:
|
except requests.exceptions.HTTPError:
|
||||||
# If the device rebooted, login again
|
# If the device rebooted, login again
|
||||||
try:
|
try:
|
||||||
self.fritz.login()
|
self.fritz.login()
|
||||||
except LoginError as ex:
|
except LoginError as ex:
|
||||||
raise ConfigEntryAuthFailed from ex
|
raise ConfigEntryAuthFailed from ex
|
||||||
devices = self.fritz.get_devices()
|
|
||||||
|
|
||||||
data = {}
|
|
||||||
self.fritz.update_devices()
|
self.fritz.update_devices()
|
||||||
|
|
||||||
|
devices = self.fritz.get_devices()
|
||||||
|
data = {}
|
||||||
for device in devices:
|
for device in devices:
|
||||||
# assume device as unavailable, see #55799
|
# assume device as unavailable, see #55799
|
||||||
if (
|
if (
|
||||||
|
@ -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
|
hass, MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0], ENTITY_ID, device, fritz
|
||||||
)
|
)
|
||||||
|
|
||||||
assert fritz().update_devices.call_count == 1
|
assert fritz().update_devices.call_count == 2
|
||||||
assert fritz().login.call_count == 1
|
assert fritz().login.call_count == 2
|
||||||
|
|
||||||
next_update = dt_util.utcnow() + timedelta(seconds=200)
|
next_update = dt_util.utcnow() + timedelta(seconds=200)
|
||||||
async_fire_time_changed(hass, next_update)
|
async_fire_time_changed(hass, next_update)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert fritz().update_devices.call_count == 2
|
assert fritz().update_devices.call_count == 4
|
||||||
assert fritz().login.call_count == 2
|
assert fritz().login.call_count == 4
|
||||||
|
|
||||||
|
|
||||||
async def test_set_temperature_temperature(hass: HomeAssistant, fritz: Mock):
|
async def test_set_temperature_temperature(hass: HomeAssistant, fritz: Mock):
|
||||||
|
@ -163,10 +163,11 @@ async def test_coordinator_update_after_reboot(hass: HomeAssistant, fritz: Mock)
|
|||||||
unique_id="any",
|
unique_id="any",
|
||||||
)
|
)
|
||||||
entry.add_to_hass(hass)
|
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 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
|
assert fritz().login.call_count == 2
|
||||||
|
|
||||||
|
|
||||||
@ -180,11 +181,12 @@ async def test_coordinator_update_after_password_change(
|
|||||||
unique_id="any",
|
unique_id="any",
|
||||||
)
|
)
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
fritz().get_devices.side_effect = HTTPError()
|
fritz().update_devices.side_effect = HTTPError()
|
||||||
fritz().login.side_effect = ["", LoginError("some_user")]
|
fritz().login.side_effect = ["", LoginError("some_user")]
|
||||||
|
|
||||||
assert not await hass.config_entries.async_setup(entry.entry_id)
|
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
|
assert fritz().login.call_count == 2
|
||||||
|
|
||||||
|
|
||||||
|
@ -174,12 +174,12 @@ async def test_update_error(hass: HomeAssistant, fritz: Mock):
|
|||||||
assert not await setup_config_entry(
|
assert not await setup_config_entry(
|
||||||
hass, MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0], ENTITY_ID, device, fritz
|
hass, MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0], ENTITY_ID, device, fritz
|
||||||
)
|
)
|
||||||
assert fritz().update_devices.call_count == 1
|
assert fritz().update_devices.call_count == 2
|
||||||
assert fritz().login.call_count == 1
|
assert fritz().login.call_count == 2
|
||||||
|
|
||||||
next_update = dt_util.utcnow() + timedelta(seconds=200)
|
next_update = dt_util.utcnow() + timedelta(seconds=200)
|
||||||
async_fire_time_changed(hass, next_update)
|
async_fire_time_changed(hass, next_update)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert fritz().update_devices.call_count == 2
|
assert fritz().update_devices.call_count == 4
|
||||||
assert fritz().login.call_count == 2
|
assert fritz().login.call_count == 4
|
||||||
|
@ -78,12 +78,12 @@ async def test_update_error(hass: HomeAssistant, fritz: Mock):
|
|||||||
assert not await setup_config_entry(
|
assert not await setup_config_entry(
|
||||||
hass, MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0], ENTITY_ID, device, fritz
|
hass, MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0], ENTITY_ID, device, fritz
|
||||||
)
|
)
|
||||||
assert fritz().update_devices.call_count == 1
|
assert fritz().update_devices.call_count == 2
|
||||||
assert fritz().login.call_count == 1
|
assert fritz().login.call_count == 2
|
||||||
|
|
||||||
next_update = dt_util.utcnow() + timedelta(seconds=200)
|
next_update = dt_util.utcnow() + timedelta(seconds=200)
|
||||||
async_fire_time_changed(hass, next_update)
|
async_fire_time_changed(hass, next_update)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert fritz().update_devices.call_count == 2
|
assert fritz().update_devices.call_count == 4
|
||||||
assert fritz().login.call_count == 2
|
assert fritz().login.call_count == 4
|
||||||
|
@ -123,15 +123,15 @@ async def test_update_error(hass: HomeAssistant, fritz: Mock):
|
|||||||
assert not await setup_config_entry(
|
assert not await setup_config_entry(
|
||||||
hass, MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0], ENTITY_ID, device, fritz
|
hass, MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0], ENTITY_ID, device, fritz
|
||||||
)
|
)
|
||||||
assert fritz().update_devices.call_count == 1
|
assert fritz().update_devices.call_count == 2
|
||||||
assert fritz().login.call_count == 1
|
assert fritz().login.call_count == 2
|
||||||
|
|
||||||
next_update = dt_util.utcnow() + timedelta(seconds=200)
|
next_update = dt_util.utcnow() + timedelta(seconds=200)
|
||||||
async_fire_time_changed(hass, next_update)
|
async_fire_time_changed(hass, next_update)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert fritz().update_devices.call_count == 2
|
assert fritz().update_devices.call_count == 4
|
||||||
assert fritz().login.call_count == 2
|
assert fritz().login.call_count == 4
|
||||||
|
|
||||||
|
|
||||||
async def test_assume_device_unavailable(hass: HomeAssistant, fritz: Mock):
|
async def test_assume_device_unavailable(hass: HomeAssistant, fritz: Mock):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user