mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Change confusing parameter naming in reload helper (#104257)
This commit is contained in:
parent
f359b33f2e
commit
6f41243410
@ -26,7 +26,7 @@ PLATFORM_RESET_LOCK = "lock_async_reset_platform_{}"
|
|||||||
|
|
||||||
|
|
||||||
async def async_reload_integration_platforms(
|
async def async_reload_integration_platforms(
|
||||||
hass: HomeAssistant, integration_name: str, integration_platforms: Iterable[str]
|
hass: HomeAssistant, integration_domain: str, platform_domains: Iterable[str]
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Reload an integration's platforms.
|
"""Reload an integration's platforms.
|
||||||
|
|
||||||
@ -44,10 +44,8 @@ async def async_reload_integration_platforms(
|
|||||||
return
|
return
|
||||||
|
|
||||||
tasks = [
|
tasks = [
|
||||||
_resetup_platform(
|
_resetup_platform(hass, integration_domain, platform_domain, unprocessed_conf)
|
||||||
hass, integration_name, integration_platform, unprocessed_conf
|
for platform_domain in platform_domains
|
||||||
)
|
|
||||||
for integration_platform in integration_platforms
|
|
||||||
]
|
]
|
||||||
|
|
||||||
await asyncio.gather(*tasks)
|
await asyncio.gather(*tasks)
|
||||||
@ -55,27 +53,27 @@ async def async_reload_integration_platforms(
|
|||||||
|
|
||||||
async def _resetup_platform(
|
async def _resetup_platform(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
integration_name: str,
|
integration_domain: str,
|
||||||
integration_platform: str,
|
platform_domain: str,
|
||||||
unprocessed_conf: ConfigType,
|
unprocessed_config: ConfigType,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Resetup a platform."""
|
"""Resetup a platform."""
|
||||||
integration = await async_get_integration(hass, integration_platform)
|
integration = await async_get_integration(hass, platform_domain)
|
||||||
|
|
||||||
conf = await conf_util.async_process_component_config(
|
conf = await conf_util.async_process_component_config(
|
||||||
hass, unprocessed_conf, integration
|
hass, unprocessed_config, integration
|
||||||
)
|
)
|
||||||
|
|
||||||
if not conf:
|
if not conf:
|
||||||
return
|
return
|
||||||
|
|
||||||
root_config: dict[str, list[ConfigType]] = {integration_platform: []}
|
root_config: dict[str, list[ConfigType]] = {platform_domain: []}
|
||||||
# Extract only the config for template, ignore the rest.
|
# Extract only the config for template, ignore the rest.
|
||||||
for p_type, p_config in config_per_platform(conf, integration_platform):
|
for p_type, p_config in config_per_platform(conf, platform_domain):
|
||||||
if p_type != integration_name:
|
if p_type != integration_domain:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
root_config[integration_platform].append(p_config)
|
root_config[platform_domain].append(p_config)
|
||||||
|
|
||||||
component = integration.get_component()
|
component = integration.get_component()
|
||||||
|
|
||||||
@ -83,47 +81,47 @@ async def _resetup_platform(
|
|||||||
# If the integration has its own way to reset
|
# If the integration has its own way to reset
|
||||||
# use this method.
|
# use this method.
|
||||||
async with hass.data.setdefault(
|
async with hass.data.setdefault(
|
||||||
PLATFORM_RESET_LOCK.format(integration_platform), asyncio.Lock()
|
PLATFORM_RESET_LOCK.format(platform_domain), asyncio.Lock()
|
||||||
):
|
):
|
||||||
await component.async_reset_platform(hass, integration_name)
|
await component.async_reset_platform(hass, integration_domain)
|
||||||
await component.async_setup(hass, root_config)
|
await component.async_setup(hass, root_config)
|
||||||
return
|
return
|
||||||
|
|
||||||
# If it's an entity platform, we use the entity_platform
|
# If it's an entity platform, we use the entity_platform
|
||||||
# async_reset method
|
# async_reset method
|
||||||
platform = async_get_platform_without_config_entry(
|
platform = async_get_platform_without_config_entry(
|
||||||
hass, integration_name, integration_platform
|
hass, integration_domain, platform_domain
|
||||||
)
|
)
|
||||||
if platform:
|
if platform:
|
||||||
await _async_reconfig_platform(platform, root_config[integration_platform])
|
await _async_reconfig_platform(platform, root_config[platform_domain])
|
||||||
return
|
return
|
||||||
|
|
||||||
if not root_config[integration_platform]:
|
if not root_config[platform_domain]:
|
||||||
# No config for this platform
|
# No config for this platform
|
||||||
# and it's not loaded. Nothing to do.
|
# and it's not loaded. Nothing to do.
|
||||||
return
|
return
|
||||||
|
|
||||||
await _async_setup_platform(
|
await _async_setup_platform(
|
||||||
hass, integration_name, integration_platform, root_config[integration_platform]
|
hass, integration_domain, platform_domain, root_config[platform_domain]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def _async_setup_platform(
|
async def _async_setup_platform(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
integration_name: str,
|
integration_domain: str,
|
||||||
integration_platform: str,
|
platform_domain: str,
|
||||||
platform_configs: list[dict[str, Any]],
|
platform_configs: list[dict[str, Any]],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Platform for the first time when new configuration is added."""
|
"""Platform for the first time when new configuration is added."""
|
||||||
if integration_platform not in hass.data:
|
if platform_domain not in hass.data:
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass, integration_platform, {integration_platform: platform_configs}
|
hass, platform_domain, {platform_domain: platform_configs}
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
entity_component: EntityComponent[Entity] = hass.data[integration_platform]
|
entity_component: EntityComponent[Entity] = hass.data[platform_domain]
|
||||||
tasks = [
|
tasks = [
|
||||||
entity_component.async_setup_platform(integration_name, p_config)
|
entity_component.async_setup_platform(integration_domain, p_config)
|
||||||
for p_config in platform_configs
|
for p_config in platform_configs
|
||||||
]
|
]
|
||||||
await asyncio.gather(*tasks)
|
await asyncio.gather(*tasks)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user