Enhance automation integration to use new features in script helper (#37479)

This commit is contained in:
Phil Bruckner 2020-07-05 09:25:15 -05:00 committed by GitHub
parent c3b5bf7437
commit f7c4900d5c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 161 additions and 74 deletions

View file

@ -9,10 +9,13 @@ import voluptuous as vol
from homeassistant.const import (
ATTR_ENTITY_ID,
ATTR_NAME,
CONF_ALIAS,
CONF_DEVICE_ID,
CONF_ENTITY_ID,
CONF_ID,
CONF_MODE,
CONF_PLATFORM,
CONF_QUEUE_SIZE,
CONF_ZONE,
EVENT_HOMEASSISTANT_STARTED,
SERVICE_RELOAD,
@ -23,11 +26,12 @@ from homeassistant.const import (
)
from homeassistant.core import Context, CoreState, HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import condition, extract_domain_configs, script
from homeassistant.helpers import condition, extract_domain_configs
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import ToggleEntity
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.script import SCRIPT_BASE_SCHEMA, Script, validate_queue_size
from homeassistant.helpers.service import async_register_admin_service
from homeassistant.helpers.typing import TemplateVarsType
from homeassistant.loader import bind_hass
@ -41,7 +45,6 @@ ENTITY_ID_FORMAT = DOMAIN + ".{}"
GROUP_NAME_ALL_AUTOMATIONS = "all automations"
CONF_ALIAS = "alias"
CONF_DESCRIPTION = "description"
CONF_HIDE_ENTITY = "hide_entity"
@ -96,7 +99,7 @@ _CONDITION_SCHEMA = vol.All(cv.ensure_list, [cv.CONDITION_SCHEMA])
PLATFORM_SCHEMA = vol.All(
cv.deprecated(CONF_HIDE_ENTITY, invalidation_version="0.110"),
vol.Schema(
SCRIPT_BASE_SCHEMA.extend(
{
# str on purpose
CONF_ID: str,
@ -109,6 +112,7 @@ PLATFORM_SCHEMA = vol.All(
vol.Required(CONF_ACTION): cv.SCRIPT_SCHEMA,
}
),
validate_queue_size,
)
@ -389,7 +393,7 @@ class AutomationEntity(ToggleEntity, RestoreEntity):
try:
await self.action_script.async_run(variables, trigger_context)
except Exception: # pylint: disable=broad-except
pass
_LOGGER.exception("While executing automation %s", self.entity_id)
async def async_will_remove_from_hass(self):
"""Remove listeners when removing automation from Home Assistant."""
@ -498,8 +502,13 @@ async def _async_process_config(hass, config, component):
initial_state = config_block.get(CONF_INITIAL_STATE)
action_script = script.Script(
hass, config_block.get(CONF_ACTION, {}), name, logger=_LOGGER
action_script = Script(
hass,
config_block[CONF_ACTION],
name,
script_mode=config_block[CONF_MODE],
queue_size=config_block.get(CONF_QUEUE_SIZE, 0),
logger=_LOGGER,
)
if CONF_CONDITION in config_block: