Adjust cleanup of removed integration linear_garage_door (#138929)
parent
e53617a788
commit
94869f3210
|
@ -2,7 +2,7 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigEntryState
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import issue_registry as ir
|
||||
|
@ -43,14 +43,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: 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)
|
||||
|
||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
|
||||
return unload_ok
|
||||
|
||||
|
||||
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))
|
||||
|
|
|
@ -6,7 +6,12 @@ from linear_garage_door import InvalidLoginError
|
|||
import pytest
|
||||
|
||||
from homeassistant.components.linear_garage_door.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.config_entries import (
|
||||
SOURCE_IGNORE,
|
||||
ConfigEntryDisabler,
|
||||
ConfigEntryState,
|
||||
)
|
||||
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import issue_registry as ir
|
||||
|
||||
|
@ -58,18 +63,73 @@ async def test_setup_failure(
|
|||
async def test_repair_issue(
|
||||
hass: HomeAssistant,
|
||||
mock_linear: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
) -> None:
|
||||
"""Test reauth trigger setup."""
|
||||
|
||||
await setup_integration(hass, mock_config_entry, [])
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
"""Test the Linear Garage Door configuration entry loading/unloading handles the repair."""
|
||||
config_entry_1 = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
entry_id="acefdd4b3a4a0911067d1cf51414201e",
|
||||
title="test-site-name",
|
||||
data={
|
||||
CONF_EMAIL: "test-email",
|
||||
CONF_PASSWORD: "test-password",
|
||||
"site_id": "test-site-id",
|
||||
"device_id": "test-uuid",
|
||||
},
|
||||
)
|
||||
await setup_integration(hass, config_entry_1, [])
|
||||
assert config_entry_1.state is ConfigEntryState.LOADED
|
||||
|
||||
# Add a second one
|
||||
config_entry_2 = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
entry_id="acefdd4b3a4a0911067d1cf51414201f",
|
||||
title="test-site-name",
|
||||
data={
|
||||
CONF_EMAIL: "test-email",
|
||||
CONF_PASSWORD: "test-password",
|
||||
"site_id": "test-site-id",
|
||||
"device_id": "test-uuid",
|
||||
},
|
||||
)
|
||||
await setup_integration(hass, config_entry_2, [])
|
||||
assert config_entry_2.state is ConfigEntryState.LOADED
|
||||
assert issue_registry.async_get_issue(DOMAIN, DOMAIN)
|
||||
|
||||
await hass.config_entries.async_remove(mock_config_entry.entry_id)
|
||||
# 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 mock_config_entry.state is ConfigEntryState.NOT_LOADED
|
||||
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()
|
||||
assert config_entry_1.state is ConfigEntryState.NOT_LOADED
|
||||
assert config_entry_2.state is ConfigEntryState.LOADED
|
||||
assert issue_registry.async_get_issue(DOMAIN, DOMAIN)
|
||||
# Remove the second one
|
||||
await hass.config_entries.async_remove(config_entry_2.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
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