Ensure config entry platforms are excluded from reload (#42367)

pull/42516/head
J. Nick Koston 2020-10-25 17:53:31 -05:00 committed by Paulus Schoutsen
parent 331d5ba7ef
commit 35d2badb24
3 changed files with 19 additions and 5 deletions

View File

@ -79,6 +79,10 @@ class EntityPlatform:
self.platform_name, []
).append(self)
def __repr__(self):
"""Represent an EntityPlatform."""
return f"<EntityPlatform domain={self.domain} platform_name={self.platform_name} config_entry={self.config_entry}>"
@callback
def _get_parallel_updates_semaphore(
self, entity_has_async_update: bool

View File

@ -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

View File

@ -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."""