From 35d2badb2478cd52a062f430579173950bdd1edc Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 25 Oct 2020 17:53:31 -0500 Subject: [PATCH] Ensure config entry platforms are excluded from reload (#42367) --- homeassistant/helpers/entity_platform.py | 4 ++++ homeassistant/helpers/reload.py | 10 +++++++--- tests/helpers/test_reload.py | 10 ++++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/homeassistant/helpers/entity_platform.py b/homeassistant/helpers/entity_platform.py index 2792debff53..693c01b982f 100644 --- a/homeassistant/helpers/entity_platform.py +++ b/homeassistant/helpers/entity_platform.py @@ -79,6 +79,10 @@ class EntityPlatform: self.platform_name, [] ).append(self) + def __repr__(self): + """Represent an EntityPlatform.""" + return f"" + @callback def _get_parallel_updates_semaphore( self, entity_has_async_update: bool diff --git a/homeassistant/helpers/reload.py b/homeassistant/helpers/reload.py index 1c11afdb46b..e596027b7e1 100644 --- a/homeassistant/helpers/reload.py +++ b/homeassistant/helpers/reload.py @@ -80,7 +80,9 @@ async def _resetup_platform( # If its an entity platform, we use the entity_platform # async_reset method - platform = async_get_platform(hass, integration_name, integration_platform) + platform = async_get_platform_without_config_entry( + hass, integration_name, integration_platform + ) if platform: await _async_reconfig_platform(platform, root_config[integration_platform]) return @@ -137,11 +139,13 @@ async def async_integration_yaml_config( @callback -def async_get_platform( +def async_get_platform_without_config_entry( hass: HomeAssistantType, integration_name: str, integration_platform_name: str ) -> Optional[EntityPlatform]: - """Find an existing platform.""" + """Find an existing platform that is not a config entry.""" for integration_platform in async_get_platforms(hass, integration_name): + if integration_platform.config_entry is not None: + continue if integration_platform.domain == integration_platform_name: platform: EntityPlatform = integration_platform return platform diff --git a/tests/helpers/test_reload.py b/tests/helpers/test_reload.py index 25844151533..3ed8d17b3f4 100644 --- a/tests/helpers/test_reload.py +++ b/tests/helpers/test_reload.py @@ -7,8 +7,9 @@ import pytest from homeassistant import config from homeassistant.const import SERVICE_RELOAD from homeassistant.helpers.entity_component import EntityComponent +from homeassistant.helpers.entity_platform import async_get_platforms from homeassistant.helpers.reload import ( - async_get_platform, + async_get_platform_without_config_entry, async_integration_yaml_config, async_reload_integration_platforms, async_setup_reload_service, @@ -52,7 +53,7 @@ async def test_reload_platform(hass): assert f"{DOMAIN}.{PLATFORM}" in hass.config.components assert len(setup_called) == 1 - platform = async_get_platform(hass, PLATFORM, DOMAIN) + platform = async_get_platform_without_config_entry(hass, PLATFORM, DOMAIN) assert platform.platform_name == PLATFORM assert platform.domain == DOMAIN @@ -66,6 +67,11 @@ async def test_reload_platform(hass): assert len(setup_called) == 2 + existing_platforms = async_get_platforms(hass, PLATFORM) + for existing_platform in existing_platforms: + existing_platform.config_entry = "abc" + assert not async_get_platform_without_config_entry(hass, PLATFORM, DOMAIN) + async def test_setup_reload_service(hass): """Test setting up a reload service."""