mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Ensure a deleted integration can be removed (#36130)
* Ensure a deleted intergration can be removed * Update homeassistant/config_entries.py Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
parent
ba120d4220
commit
d2a92ce4f3
@ -268,7 +268,15 @@ class ConfigEntry:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
if integration is None:
|
if integration is None:
|
||||||
|
try:
|
||||||
integration = await loader.async_get_integration(hass, self.domain)
|
integration = await loader.async_get_integration(hass, self.domain)
|
||||||
|
except loader.IntegrationNotFound:
|
||||||
|
# The integration was likely a custom_component
|
||||||
|
# that was uninstalled, or an integration
|
||||||
|
# that has been renamed without removing the config
|
||||||
|
# entry.
|
||||||
|
self.state = ENTRY_STATE_NOT_LOADED
|
||||||
|
return True
|
||||||
|
|
||||||
component = integration.get_component()
|
component = integration.get_component()
|
||||||
|
|
||||||
@ -316,7 +324,15 @@ class ConfigEntry:
|
|||||||
if self.source == SOURCE_IGNORE:
|
if self.source == SOURCE_IGNORE:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
integration = await loader.async_get_integration(hass, self.domain)
|
integration = await loader.async_get_integration(hass, self.domain)
|
||||||
|
except loader.IntegrationNotFound:
|
||||||
|
# The integration was likely a custom_component
|
||||||
|
# that was uninstalled, or an integration
|
||||||
|
# that has been renamed without removing the config
|
||||||
|
# entry.
|
||||||
|
return
|
||||||
|
|
||||||
component = integration.get_component()
|
component = integration.get_component()
|
||||||
if not hasattr(component, "async_remove_entry"):
|
if not hasattr(component, "async_remove_entry"):
|
||||||
return
|
return
|
||||||
|
@ -365,6 +365,28 @@ async def test_remove_entry_if_not_loaded(hass, manager):
|
|||||||
assert len(mock_unload_entry.mock_calls) == 0
|
assert len(mock_unload_entry.mock_calls) == 0
|
||||||
|
|
||||||
|
|
||||||
|
async def test_remove_entry_if_integration_deleted(hass, manager):
|
||||||
|
"""Test that we can remove an entry when the integration is deleted."""
|
||||||
|
mock_unload_entry = AsyncMock(return_value=True)
|
||||||
|
|
||||||
|
MockConfigEntry(domain="test", entry_id="test1").add_to_manager(manager)
|
||||||
|
MockConfigEntry(domain="comp", entry_id="test2").add_to_manager(manager)
|
||||||
|
MockConfigEntry(domain="test", entry_id="test3").add_to_manager(manager)
|
||||||
|
|
||||||
|
assert [item.entry_id for item in manager.async_entries()] == [
|
||||||
|
"test1",
|
||||||
|
"test2",
|
||||||
|
"test3",
|
||||||
|
]
|
||||||
|
|
||||||
|
result = await manager.async_remove("test2")
|
||||||
|
|
||||||
|
assert result == {"require_restart": False}
|
||||||
|
assert [item.entry_id for item in manager.async_entries()] == ["test1", "test3"]
|
||||||
|
|
||||||
|
assert len(mock_unload_entry.mock_calls) == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_add_entry_calls_setup_entry(hass, manager):
|
async def test_add_entry_calls_setup_entry(hass, manager):
|
||||||
"""Test we call setup_config_entry."""
|
"""Test we call setup_config_entry."""
|
||||||
mock_setup_entry = AsyncMock(return_value=True)
|
mock_setup_entry = AsyncMock(return_value=True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user