Reorg device automation (#26880)

* async_trigger -> async_attach_trigger

* Reorg device automations

* Update docstrings

* Fix types

* Fix extending schemas
This commit is contained in:
Paulus Schoutsen 2019-09-24 14:57:05 -07:00 committed by GitHub
parent b52cfd3409
commit 6fdff9ffab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
48 changed files with 2014 additions and 1771 deletions

View file

@ -3,7 +3,7 @@ import asyncio
from functools import partial
import importlib
import logging
from typing import Any
from typing import Any, Awaitable, Callable
import voluptuous as vol
@ -23,7 +23,7 @@ from homeassistant.const import (
SERVICE_TURN_ON,
STATE_ON,
)
from homeassistant.core import Context, CoreState
from homeassistant.core import Context, CoreState, HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import condition, extract_domain_configs, script
import homeassistant.helpers.config_validation as cv
@ -31,6 +31,7 @@ from homeassistant.helpers.config_validation import ENTITY_SERVICE_SCHEMA
from homeassistant.helpers.entity import ToggleEntity
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.typing import TemplateVarsType
from homeassistant.loader import bind_hass
from homeassistant.util.dt import parse_datetime, utcnow
@ -67,6 +68,8 @@ SERVICE_TRIGGER = "trigger"
_LOGGER = logging.getLogger(__name__)
AutomationActionType = Callable[[HomeAssistant, TemplateVarsType], Awaitable[None]]
def _platform_validator(config):
"""Validate it is a valid platform."""
@ -474,7 +477,7 @@ async def _async_process_trigger(hass, config, trigger_configs, name, action):
platform = importlib.import_module(".{}".format(conf[CONF_PLATFORM]), __name__)
try:
remove = await platform.async_trigger(hass, conf, action, info)
remove = await platform.async_attach_trigger(hass, conf, action, info)
except InvalidDeviceAutomationConfig:
remove = False