mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Simplify parsing of script and automation config (#80465)
This commit is contained in:
parent
b6a59b282f
commit
627bd82766
@ -53,7 +53,7 @@ from homeassistant.exceptions import (
|
|||||||
ServiceNotFound,
|
ServiceNotFound,
|
||||||
TemplateError,
|
TemplateError,
|
||||||
)
|
)
|
||||||
from homeassistant.helpers import condition, extract_domain_configs
|
from homeassistant.helpers import condition
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity import ToggleEntity
|
from homeassistant.helpers.entity import ToggleEntity
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
@ -670,7 +670,6 @@ class AutomationEntityConfig:
|
|||||||
"""Container for prepared automation entity configuration."""
|
"""Container for prepared automation entity configuration."""
|
||||||
|
|
||||||
config_block: ConfigType
|
config_block: ConfigType
|
||||||
config_key: str
|
|
||||||
list_no: int
|
list_no: int
|
||||||
raw_blueprint_inputs: ConfigType | None
|
raw_blueprint_inputs: ConfigType | None
|
||||||
raw_config: ConfigType | None
|
raw_config: ConfigType | None
|
||||||
@ -683,8 +682,7 @@ async def _prepare_automation_config(
|
|||||||
"""Parse configuration and prepare automation entity configuration."""
|
"""Parse configuration and prepare automation entity configuration."""
|
||||||
automation_configs: list[AutomationEntityConfig] = []
|
automation_configs: list[AutomationEntityConfig] = []
|
||||||
|
|
||||||
for config_key in extract_domain_configs(config, DOMAIN):
|
conf: list[ConfigType | blueprint.BlueprintInputs] = config[DOMAIN]
|
||||||
conf: list[ConfigType | blueprint.BlueprintInputs] = config[config_key]
|
|
||||||
|
|
||||||
for list_no, config_block in enumerate(conf):
|
for list_no, config_block in enumerate(conf):
|
||||||
raw_blueprint_inputs = None
|
raw_blueprint_inputs = None
|
||||||
@ -712,7 +710,7 @@ async def _prepare_automation_config(
|
|||||||
|
|
||||||
automation_configs.append(
|
automation_configs.append(
|
||||||
AutomationEntityConfig(
|
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:
|
def _automation_name(automation_config: AutomationEntityConfig) -> str:
|
||||||
"""Return the configured name of an automation."""
|
"""Return the configured name of an automation."""
|
||||||
config_block = automation_config.config_block
|
config_block = automation_config.config_block
|
||||||
config_key = automation_config.config_key
|
|
||||||
list_no = automation_config.list_no
|
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(
|
async def _create_automation_entities(
|
||||||
@ -855,7 +852,6 @@ async def _async_process_config(
|
|||||||
if idx not in config_matches
|
if idx not in config_matches
|
||||||
]
|
]
|
||||||
entities = await _create_automation_entities(hass, updated_automation_configs)
|
entities = await _create_automation_entities(hass, updated_automation_configs)
|
||||||
if entities:
|
|
||||||
await component.async_add_entities(entities)
|
await component.async_add_entities(entities)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -29,7 +29,7 @@ from homeassistant.const import (
|
|||||||
STATE_ON,
|
STATE_ON,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
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
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.config_validation import make_entity_service_schema
|
from homeassistant.helpers.config_validation import make_entity_service_schema
|
||||||
from homeassistant.helpers.entity import ToggleEntity
|
from homeassistant.helpers.entity import ToggleEntity
|
||||||
@ -238,8 +238,7 @@ async def _async_process_config(hass, config, component) -> None:
|
|||||||
"""
|
"""
|
||||||
entities = []
|
entities = []
|
||||||
|
|
||||||
for config_key in extract_domain_configs(config, DOMAIN):
|
conf: dict[str, dict[str, Any] | BlueprintInputs] = config[DOMAIN]
|
||||||
conf: dict[str, dict[str, Any] | BlueprintInputs] = config[config_key]
|
|
||||||
|
|
||||||
for key, config_block in conf.items():
|
for key, config_block in conf.items():
|
||||||
raw_blueprint_inputs = None
|
raw_blueprint_inputs = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user