Do not attempt to unload non loaded config entries (#51356)

This commit is contained in:
Erik Montnemery 2021-06-02 10:00:24 +02:00 committed by GitHub
parent d51fc5814a
commit 1d9d9021de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 19 additions and 0 deletions

View file

@ -392,6 +392,9 @@ class ConfigEntry:
self.reason = None
return True
if self.state == ConfigEntryState.NOT_LOADED:
return True
if integration is None:
try:
integration = await loader.async_get_integration(hass, self.domain)

View file

@ -12,6 +12,7 @@ from homeassistant.components.binary_sensor import (
)
from homeassistant.components.smartthings import binary_sensor
from homeassistant.components.smartthings.const import DOMAIN, SIGNAL_SMARTTHINGS_UPDATE
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import ATTR_FRIENDLY_NAME, STATE_UNAVAILABLE
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.dispatcher import async_dispatcher_send
@ -91,6 +92,7 @@ async def test_unload_config_entry(hass, device_factory):
"Motion Sensor 1", [Capability.motion_sensor], {Attribute.motion: "inactive"}
)
config_entry = await setup_platform(hass, BINARY_SENSOR_DOMAIN, devices=[device])
config_entry.state = ConfigEntryState.LOADED
# Act
await hass.config_entries.async_forward_entry_unload(config_entry, "binary_sensor")
# Assert

View file

@ -19,6 +19,7 @@ from homeassistant.components.cover import (
STATE_OPENING,
)
from homeassistant.components.smartthings.const import DOMAIN, SIGNAL_SMARTTHINGS_UPDATE
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import ATTR_BATTERY_LEVEL, ATTR_ENTITY_ID, STATE_UNAVAILABLE
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.dispatcher import async_dispatcher_send
@ -191,6 +192,7 @@ async def test_unload_config_entry(hass, device_factory):
"Garage", [Capability.garage_door_control], {Attribute.door: "open"}
)
config_entry = await setup_platform(hass, COVER_DOMAIN, devices=[device])
config_entry.state = ConfigEntryState.LOADED
# Act
await hass.config_entries.async_forward_entry_unload(config_entry, COVER_DOMAIN)
# Assert

View file

@ -17,6 +17,7 @@ from homeassistant.components.fan import (
SUPPORT_SET_SPEED,
)
from homeassistant.components.smartthings.const import DOMAIN, SIGNAL_SMARTTHINGS_UPDATE
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import (
ATTR_ENTITY_ID,
ATTR_SUPPORTED_FEATURES,
@ -186,6 +187,7 @@ async def test_unload_config_entry(hass, device_factory):
status={Attribute.switch: "off", Attribute.fan_speed: 0},
)
config_entry = await setup_platform(hass, FAN_DOMAIN, devices=[device])
config_entry.state = ConfigEntryState.LOADED
# Act
await hass.config_entries.async_forward_entry_unload(config_entry, "fan")
# Assert

View file

@ -19,6 +19,7 @@ from homeassistant.components.light import (
SUPPORT_TRANSITION,
)
from homeassistant.components.smartthings.const import DOMAIN, SIGNAL_SMARTTHINGS_UPDATE
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import (
ATTR_ENTITY_ID,
ATTR_SUPPORTED_FEATURES,
@ -306,6 +307,7 @@ async def test_unload_config_entry(hass, device_factory):
},
)
config_entry = await setup_platform(hass, LIGHT_DOMAIN, devices=[device])
config_entry.state = ConfigEntryState.LOADED
# Act
await hass.config_entries.async_forward_entry_unload(config_entry, "light")
# Assert

View file

@ -9,6 +9,7 @@ from pysmartthings.device import Status
from homeassistant.components.lock import DOMAIN as LOCK_DOMAIN
from homeassistant.components.smartthings.const import DOMAIN, SIGNAL_SMARTTHINGS_UPDATE
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import STATE_UNAVAILABLE
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.dispatcher import async_dispatcher_send
@ -103,6 +104,7 @@ async def test_unload_config_entry(hass, device_factory):
# Arrange
device = device_factory("Lock_1", [Capability.lock], {Attribute.lock: "locked"})
config_entry = await setup_platform(hass, LOCK_DOMAIN, devices=[device])
config_entry.state = ConfigEntryState.LOADED
# Act
await hass.config_entries.async_forward_entry_unload(config_entry, "lock")
# Assert

View file

@ -5,6 +5,7 @@ The only mocking required is of the underlying SmartThings API object so
real HTTP calls are not initiated during testing.
"""
from homeassistant.components.scene import DOMAIN as SCENE_DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_ON, STATE_UNAVAILABLE
from homeassistant.helpers import entity_registry as er
@ -44,6 +45,7 @@ async def test_unload_config_entry(hass, scene):
"""Test the scene is removed when the config entry is unloaded."""
# Arrange
config_entry = await setup_platform(hass, SCENE_DOMAIN, scenes=[scene])
config_entry.state = ConfigEntryState.LOADED
# Act
await hass.config_entries.async_forward_entry_unload(config_entry, SCENE_DOMAIN)
# Assert

View file

@ -9,6 +9,7 @@ from pysmartthings import ATTRIBUTES, CAPABILITIES, Attribute, Capability
from homeassistant.components.sensor import DEVICE_CLASSES, DOMAIN as SENSOR_DOMAIN
from homeassistant.components.smartthings import sensor
from homeassistant.components.smartthings.const import DOMAIN, SIGNAL_SMARTTHINGS_UPDATE
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import (
ATTR_FRIENDLY_NAME,
ATTR_UNIT_OF_MEASUREMENT,
@ -116,6 +117,7 @@ async def test_unload_config_entry(hass, device_factory):
# Arrange
device = device_factory("Sensor 1", [Capability.battery], {Attribute.battery: 100})
config_entry = await setup_platform(hass, SENSOR_DOMAIN, devices=[device])
config_entry.state = ConfigEntryState.LOADED
# Act
await hass.config_entries.async_forward_entry_unload(config_entry, "sensor")
# Assert

View file

@ -12,6 +12,7 @@ from homeassistant.components.switch import (
ATTR_TODAY_ENERGY_KWH,
DOMAIN as SWITCH_DOMAIN,
)
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import STATE_UNAVAILABLE
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.dispatcher import async_dispatcher_send
@ -95,6 +96,7 @@ async def test_unload_config_entry(hass, device_factory):
# Arrange
device = device_factory("Switch 1", [Capability.switch], {Attribute.switch: "on"})
config_entry = await setup_platform(hass, SWITCH_DOMAIN, devices=[device])
config_entry.state = ConfigEntryState.LOADED
# Act
await hass.config_entries.async_forward_entry_unload(config_entry, "switch")
# Assert