mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 02:07:54 +00:00
Adjust cleanup of removed integration myq (#138931)
This commit is contained in:
parent
affec21a6a
commit
d9a18c2994
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry, ConfigEntryState
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import issue_registry as ir
|
from homeassistant.helpers import issue_registry as ir
|
||||||
|
|
||||||
@ -29,11 +29,13 @@ async def async_setup_entry(hass: HomeAssistant, _: ConfigEntry) -> bool:
|
|||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""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
|
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 MyQ Connected Services integration."""
|
"""Tests for the MyQ Connected Services integration."""
|
||||||
|
|
||||||
from homeassistant.components.myq import DOMAIN
|
from homeassistant.components.myq import DOMAIN
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import (
|
||||||
|
SOURCE_IGNORE,
|
||||||
|
ConfigEntryDisabler,
|
||||||
|
ConfigEntryState,
|
||||||
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import issue_registry as ir
|
from homeassistant.helpers import issue_registry as ir
|
||||||
|
|
||||||
@ -33,6 +37,28 @@ async def test_myq_repair_issue(
|
|||||||
assert config_entry_2.state is ConfigEntryState.LOADED
|
assert config_entry_2.state is ConfigEntryState.LOADED
|
||||||
assert issue_registry.async_get_issue(DOMAIN, DOMAIN)
|
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
|
# Remove the first one
|
||||||
await hass.config_entries.async_remove(config_entry_1.entry_id)
|
await hass.config_entries.async_remove(config_entry_1.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -48,3 +74,6 @@ async def test_myq_repair_issue(
|
|||||||
assert config_entry_1.state is ConfigEntryState.NOT_LOADED
|
assert config_entry_1.state is ConfigEntryState.NOT_LOADED
|
||||||
assert config_entry_2.state is ConfigEntryState.NOT_LOADED
|
assert config_entry_2.state is ConfigEntryState.NOT_LOADED
|
||||||
assert issue_registry.async_get_issue(DOMAIN, DOMAIN) is None
|
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…
x
Reference in New Issue
Block a user