Simplify parsing of script and automation config (#80465)

This commit is contained in:
Erik Montnemery 2022-10-17 11:42:17 +02:00 committed by GitHub
parent b6a59b282f
commit 627bd82766
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 62 deletions

View File

@ -53,7 +53,7 @@ from homeassistant.exceptions import (
ServiceNotFound,
TemplateError,
)
from homeassistant.helpers import condition, extract_domain_configs
from homeassistant.helpers import condition
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import ToggleEntity
from homeassistant.helpers.entity_component import EntityComponent
@ -670,7 +670,6 @@ class AutomationEntityConfig:
"""Container for prepared automation entity configuration."""
config_block: ConfigType
config_key: str
list_no: int
raw_blueprint_inputs: ConfigType | None
raw_config: ConfigType | None
@ -683,8 +682,7 @@ async def _prepare_automation_config(
"""Parse configuration and prepare automation entity configuration."""
automation_configs: list[AutomationEntityConfig] = []
for config_key in extract_domain_configs(config, DOMAIN):
conf: list[ConfigType | blueprint.BlueprintInputs] = config[config_key]
conf: list[ConfigType | blueprint.BlueprintInputs] = config[DOMAIN]
for list_no, config_block in enumerate(conf):
raw_blueprint_inputs = None
@ -712,7 +710,7 @@ async def _prepare_automation_config(
automation_configs.append(
AutomationEntityConfig(
config_block, config_key, list_no, raw_blueprint_inputs, raw_config
config_block, list_no, raw_blueprint_inputs, raw_config
)
)
@ -722,9 +720,8 @@ async def _prepare_automation_config(
def _automation_name(automation_config: AutomationEntityConfig) -> str:
"""Return the configured name of an automation."""
config_block = automation_config.config_block
config_key = automation_config.config_key
list_no = automation_config.list_no
return config_block.get(CONF_ALIAS) or f"{config_key} {list_no}"
return config_block.get(CONF_ALIAS) or f"{DOMAIN} {list_no}"
async def _create_automation_entities(
@ -855,7 +852,6 @@ async def _async_process_config(
if idx not in config_matches
]
entities = await _create_automation_entities(hass, updated_automation_configs)
if entities:
await component.async_add_entities(entities)
return

View File

@ -29,7 +29,7 @@ from homeassistant.const import (
STATE_ON,
)
from homeassistant.core import HomeAssistant, ServiceCall, callback
from homeassistant.helpers import entity_registry as er, extract_domain_configs
from homeassistant.helpers import entity_registry as er
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.config_validation import make_entity_service_schema
from homeassistant.helpers.entity import ToggleEntity
@ -238,8 +238,7 @@ async def _async_process_config(hass, config, component) -> None:
"""
entities = []
for config_key in extract_domain_configs(config, DOMAIN):
conf: dict[str, dict[str, Any] | BlueprintInputs] = config[config_key]
conf: dict[str, dict[str, Any] | BlueprintInputs] = config[DOMAIN]
for key, config_block in conf.items():
raw_blueprint_inputs = None