Raise ConfigEntryNotReady when unable to connect during setup of AVM Fritz!Smarthome (#97985)
This commit is contained in:
parent
e0d6210bd0
commit
533a8beac2
6 changed files with 32 additions and 8 deletions
|
@ -5,6 +5,7 @@ from abc import ABC, abstractmethod
|
|||
|
||||
from pyfritzhome import Fritzhome, FritzhomeDevice, LoginError
|
||||
from pyfritzhome.devicetypes.fritzhomeentitybase import FritzhomeEntityBase
|
||||
from requests.exceptions import ConnectionError as RequestConnectionError
|
||||
|
||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
|
@ -16,7 +17,7 @@ from homeassistant.const import (
|
|||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import Event, HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity import EntityDescription
|
||||
from homeassistant.helpers.entity_registry import RegistryEntry, async_migrate_entries
|
||||
|
@ -36,6 +37,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
|
||||
try:
|
||||
await hass.async_add_executor_job(fritz.login)
|
||||
except RequestConnectionError as err:
|
||||
raise ConfigEntryNotReady from err
|
||||
except LoginError as err:
|
||||
raise ConfigEntryAuthFailed from err
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ from datetime import timedelta
|
|||
|
||||
from pyfritzhome import Fritzhome, FritzhomeDevice, LoginError
|
||||
from pyfritzhome.devicetypes import FritzhomeTemplate
|
||||
import requests
|
||||
from requests.exceptions import ConnectionError as RequestConnectionError, HTTPError
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
@ -51,9 +51,9 @@ class FritzboxDataUpdateCoordinator(DataUpdateCoordinator[FritzboxCoordinatorDat
|
|||
self.fritz.update_devices()
|
||||
if self.has_templates:
|
||||
self.fritz.update_templates()
|
||||
except requests.exceptions.ConnectionError as ex:
|
||||
except RequestConnectionError as ex:
|
||||
raise UpdateFailed from ex
|
||||
except requests.exceptions.HTTPError:
|
||||
except HTTPError:
|
||||
# If the device rebooted, login again
|
||||
try:
|
||||
self.fritz.login()
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
"integration_type": "hub",
|
||||
"iot_class": "local_polling",
|
||||
"loggers": ["pyfritzhome"],
|
||||
"requirements": ["pyfritzhome==0.6.8"],
|
||||
"requirements": ["pyfritzhome==0.6.9"],
|
||||
"ssdp": [
|
||||
{
|
||||
"st": "urn:schemas-upnp-org:device:fritzbox:1"
|
||||
|
|
|
@ -1701,7 +1701,7 @@ pyforked-daapd==0.1.14
|
|||
pyfreedompro==1.1.0
|
||||
|
||||
# homeassistant.components.fritzbox
|
||||
pyfritzhome==0.6.8
|
||||
pyfritzhome==0.6.9
|
||||
|
||||
# homeassistant.components.ifttt
|
||||
pyfttt==0.3
|
||||
|
|
|
@ -1256,7 +1256,7 @@ pyforked-daapd==0.1.14
|
|||
pyfreedompro==1.1.0
|
||||
|
||||
# homeassistant.components.fritzbox
|
||||
pyfritzhome==0.6.8
|
||||
pyfritzhome==0.6.9
|
||||
|
||||
# homeassistant.components.ifttt
|
||||
pyfttt==0.3
|
||||
|
|
|
@ -205,7 +205,7 @@ async def test_coordinator_update_when_unreachable(
|
|||
unique_id="any",
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
fritz().get_devices.side_effect = [ConnectionError(), ""]
|
||||
fritz().update_devices.side_effect = [ConnectionError(), ""]
|
||||
|
||||
assert not await hass.config_entries.async_setup(entry.entry_id)
|
||||
assert entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
@ -258,6 +258,27 @@ async def test_raise_config_entry_not_ready_when_offline(hass: HomeAssistant) ->
|
|||
unique_id="any",
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
with patch(
|
||||
"homeassistant.components.fritzbox.Fritzhome.login",
|
||||
side_effect=ConnectionError(),
|
||||
) as mock_login:
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
mock_login.assert_called_once()
|
||||
|
||||
entries = hass.config_entries.async_entries()
|
||||
config_entry = entries[0]
|
||||
assert config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
||||
|
||||
async def test_raise_config_entry_error_when_login_fail(hass: HomeAssistant) -> None:
|
||||
"""Config entry state is SETUP_ERROR when login to fritzbox fail."""
|
||||
entry = MockConfigEntry(
|
||||
domain=FB_DOMAIN,
|
||||
data={CONF_HOST: "any", **MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0]},
|
||||
unique_id="any",
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
with patch(
|
||||
"homeassistant.components.fritzbox.Fritzhome.login",
|
||||
side_effect=LoginError("user"),
|
||||
|
|
Loading…
Add table
Reference in a new issue