Adjust cleanup of removed integration aladdin_connect (#138917)
parent
c7169a4ed7
commit
d24a14442f
|
@ -2,7 +2,7 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigEntryState
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import issue_registry as ir
|
||||
|
||||
|
@ -28,11 +28,13 @@ async def async_setup_entry(hass: HomeAssistant, _: ConfigEntry) -> bool:
|
|||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
if all(
|
||||
config_entry.state is ConfigEntryState.NOT_LOADED
|
||||
for config_entry in hass.config_entries.async_entries(DOMAIN)
|
||||
if config_entry.entry_id != entry.entry_id
|
||||
):
|
||||
ir.async_delete_issue(hass, DOMAIN, DOMAIN)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||
"""Remove a config entry."""
|
||||
if not hass.config_entries.async_loaded_entries(DOMAIN):
|
||||
ir.async_delete_issue(hass, DOMAIN, DOMAIN)
|
||||
# Remove any remaining disabled or ignored entries
|
||||
for _entry in hass.config_entries.async_entries(DOMAIN):
|
||||
hass.async_create_task(hass.config_entries.async_remove(_entry.entry_id))
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
"""Tests for the Aladdin Connect integration."""
|
||||
|
||||
from homeassistant.components.aladdin_connect import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.config_entries import (
|
||||
SOURCE_IGNORE,
|
||||
ConfigEntryDisabler,
|
||||
ConfigEntryState,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import issue_registry as ir
|
||||
|
||||
|
@ -33,6 +37,28 @@ async def test_aladdin_connect_repair_issue(
|
|||
assert config_entry_2.state is ConfigEntryState.LOADED
|
||||
assert issue_registry.async_get_issue(DOMAIN, DOMAIN)
|
||||
|
||||
# Add an ignored entry
|
||||
config_entry_3 = MockConfigEntry(
|
||||
source=SOURCE_IGNORE,
|
||||
domain=DOMAIN,
|
||||
)
|
||||
config_entry_3.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(config_entry_3.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entry_3.state is ConfigEntryState.NOT_LOADED
|
||||
|
||||
# Add a disabled entry
|
||||
config_entry_4 = MockConfigEntry(
|
||||
disabled_by=ConfigEntryDisabler.USER,
|
||||
domain=DOMAIN,
|
||||
)
|
||||
config_entry_4.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(config_entry_4.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entry_4.state is ConfigEntryState.NOT_LOADED
|
||||
|
||||
# Remove the first one
|
||||
await hass.config_entries.async_remove(config_entry_1.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
@ -48,3 +74,6 @@ async def test_aladdin_connect_repair_issue(
|
|||
assert config_entry_1.state is ConfigEntryState.NOT_LOADED
|
||||
assert config_entry_2.state is ConfigEntryState.NOT_LOADED
|
||||
assert issue_registry.async_get_issue(DOMAIN, DOMAIN) is None
|
||||
|
||||
# Check the ignored and disabled entries are removed
|
||||
assert not hass.config_entries.async_entries(DOMAIN)
|
||||
|
|
Loading…
Reference in New Issue