Ensure config entry platforms are excluded from reload (#42367)
parent
331d5ba7ef
commit
35d2badb24
|
@ -79,6 +79,10 @@ class EntityPlatform:
|
||||||
self.platform_name, []
|
self.platform_name, []
|
||||||
).append(self)
|
).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
|
@callback
|
||||||
def _get_parallel_updates_semaphore(
|
def _get_parallel_updates_semaphore(
|
||||||
self, entity_has_async_update: bool
|
self, entity_has_async_update: bool
|
||||||
|
|
|
@ -80,7 +80,9 @@ async def _resetup_platform(
|
||||||
|
|
||||||
# If its an entity platform, we use the entity_platform
|
# If its an entity platform, we use the entity_platform
|
||||||
# async_reset method
|
# 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:
|
if platform:
|
||||||
await _async_reconfig_platform(platform, root_config[integration_platform])
|
await _async_reconfig_platform(platform, root_config[integration_platform])
|
||||||
return
|
return
|
||||||
|
@ -137,11 +139,13 @@ async def async_integration_yaml_config(
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_get_platform(
|
def async_get_platform_without_config_entry(
|
||||||
hass: HomeAssistantType, integration_name: str, integration_platform_name: str
|
hass: HomeAssistantType, integration_name: str, integration_platform_name: str
|
||||||
) -> Optional[EntityPlatform]:
|
) -> 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):
|
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:
|
if integration_platform.domain == integration_platform_name:
|
||||||
platform: EntityPlatform = integration_platform
|
platform: EntityPlatform = integration_platform
|
||||||
return platform
|
return platform
|
||||||
|
|
|
@ -7,8 +7,9 @@ import pytest
|
||||||
from homeassistant import config
|
from homeassistant import config
|
||||||
from homeassistant.const import SERVICE_RELOAD
|
from homeassistant.const import SERVICE_RELOAD
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
|
from homeassistant.helpers.entity_platform import async_get_platforms
|
||||||
from homeassistant.helpers.reload import (
|
from homeassistant.helpers.reload import (
|
||||||
async_get_platform,
|
async_get_platform_without_config_entry,
|
||||||
async_integration_yaml_config,
|
async_integration_yaml_config,
|
||||||
async_reload_integration_platforms,
|
async_reload_integration_platforms,
|
||||||
async_setup_reload_service,
|
async_setup_reload_service,
|
||||||
|
@ -52,7 +53,7 @@ async def test_reload_platform(hass):
|
||||||
assert f"{DOMAIN}.{PLATFORM}" in hass.config.components
|
assert f"{DOMAIN}.{PLATFORM}" in hass.config.components
|
||||||
assert len(setup_called) == 1
|
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.platform_name == PLATFORM
|
||||||
assert platform.domain == DOMAIN
|
assert platform.domain == DOMAIN
|
||||||
|
|
||||||
|
@ -66,6 +67,11 @@ async def test_reload_platform(hass):
|
||||||
|
|
||||||
assert len(setup_called) == 2
|
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):
|
async def test_setup_reload_service(hass):
|
||||||
"""Test setting up a reload service."""
|
"""Test setting up a reload service."""
|
||||||
|
|
Loading…
Reference in New Issue