Automatic cleanup of entity and device registry in AVM FRITZ!SmartHome (#114601)
This commit is contained in:
parent
0ea1564248
commit
354c20a57b
4 changed files with 165 additions and 75 deletions
|
@ -6,7 +6,7 @@ from unittest.mock import Mock, call, patch
|
|||
|
||||
from pyfritzhome import LoginError
|
||||
import pytest
|
||||
from requests.exceptions import ConnectionError, HTTPError
|
||||
from requests.exceptions import ConnectionError as RequestConnectionError
|
||||
|
||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
||||
from homeassistant.components.fritzbox.const import DOMAIN as FB_DOMAIN
|
||||
|
@ -80,6 +80,7 @@ async def test_update_unique_id(
|
|||
new_unique_id: str,
|
||||
) -> None:
|
||||
"""Test unique_id update of integration."""
|
||||
fritz().get_devices.return_value = [FritzDeviceSwitchMock()]
|
||||
entry = MockConfigEntry(
|
||||
domain=FB_DOMAIN,
|
||||
data=MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0],
|
||||
|
@ -138,6 +139,7 @@ async def test_update_unique_id_no_change(
|
|||
unique_id: str,
|
||||
) -> None:
|
||||
"""Test unique_id is not updated of integration."""
|
||||
fritz().get_devices.return_value = [FritzDeviceSwitchMock()]
|
||||
entry = MockConfigEntry(
|
||||
domain=FB_DOMAIN,
|
||||
data=MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0],
|
||||
|
@ -158,62 +160,6 @@ async def test_update_unique_id_no_change(
|
|||
assert entity_migrated.unique_id == unique_id
|
||||
|
||||
|
||||
async def test_coordinator_update_after_reboot(
|
||||
hass: HomeAssistant, fritz: Mock
|
||||
) -> None:
|
||||
"""Test coordinator after reboot."""
|
||||
entry = MockConfigEntry(
|
||||
domain=FB_DOMAIN,
|
||||
data=MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0],
|
||||
unique_id="any",
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
fritz().update_devices.side_effect = [HTTPError(), ""]
|
||||
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
assert fritz().update_devices.call_count == 2
|
||||
assert fritz().update_templates.call_count == 1
|
||||
assert fritz().get_devices.call_count == 1
|
||||
assert fritz().get_templates.call_count == 1
|
||||
assert fritz().login.call_count == 2
|
||||
|
||||
|
||||
async def test_coordinator_update_after_password_change(
|
||||
hass: HomeAssistant, fritz: Mock
|
||||
) -> None:
|
||||
"""Test coordinator after password change."""
|
||||
entry = MockConfigEntry(
|
||||
domain=FB_DOMAIN,
|
||||
data=MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0],
|
||||
unique_id="any",
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
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().update_devices.call_count == 1
|
||||
assert fritz().get_devices.call_count == 0
|
||||
assert fritz().get_templates.call_count == 0
|
||||
assert fritz().login.call_count == 2
|
||||
|
||||
|
||||
async def test_coordinator_update_when_unreachable(
|
||||
hass: HomeAssistant, fritz: Mock
|
||||
) -> None:
|
||||
"""Test coordinator after reboot."""
|
||||
entry = MockConfigEntry(
|
||||
domain=FB_DOMAIN,
|
||||
data=MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0],
|
||||
unique_id="any",
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
fritz().update_devices.side_effect = [ConnectionError(), ""]
|
||||
|
||||
assert not await hass.config_entries.async_setup(entry.entry_id)
|
||||
assert entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
||||
|
||||
async def test_unload_remove(hass: HomeAssistant, fritz: Mock) -> None:
|
||||
"""Test unload and remove of integration."""
|
||||
fritz().get_devices.return_value = [FritzDeviceSwitchMock()]
|
||||
|
@ -325,7 +271,7 @@ async def test_raise_config_entry_not_ready_when_offline(hass: HomeAssistant) ->
|
|||
entry.add_to_hass(hass)
|
||||
with patch(
|
||||
"homeassistant.components.fritzbox.Fritzhome.login",
|
||||
side_effect=ConnectionError(),
|
||||
side_effect=RequestConnectionError(),
|
||||
) as mock_login:
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue