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 authored and GitHub committed 2019-09-24 14:57:05 -07:00
1 parent b52cfd3409
commit 6fdff9ffab
48 files changed
+2014 -1771

No files matched your search

@@ -0,0 +1,30 @@
"""Provides device actions for lights."""
from typing import List
import voluptuous as vol
from homeassistant.core import HomeAssistant, Context
from homeassistant.components.device_automation import toggle_entity
from homeassistant.const import CONF_DOMAIN
from homeassistant.helpers.typing import TemplateVarsType, ConfigType
from . import DOMAIN
ACTION_SCHEMA = toggle_entity.ACTION_SCHEMA.extend({vol.Required(CONF_DOMAIN): DOMAIN})
async def async_call_action_from_config(
hass: HomeAssistant,
config: ConfigType,
variables: TemplateVarsType,
context: Context,
) -> None:
"""Change state based on configuration."""
config = ACTION_SCHEMA(config)
await toggle_entity.async_call_action_from_config(
hass, config, variables, context, DOMAIN
)
async def async_get_actions(hass: HomeAssistant, device_id: str) -> List[dict]:
"""List device actions."""
return await toggle_entity.async_get_actions(hass, device_id, DOMAIN)
@@ -1,56 +0,0 @@
"""Provides device automations for lights."""
import voluptuous as vol
from homeassistant.components.device_automation import toggle_entity
from homeassistant.const import CONF_DOMAIN
from . import DOMAIN
# mypy: allow-untyped-defs, no-check-untyped-defs
ACTION_SCHEMA = toggle_entity.ACTION_SCHEMA.extend({vol.Required(CONF_DOMAIN): DOMAIN})
CONDITION_SCHEMA = toggle_entity.CONDITION_SCHEMA.extend(
{vol.Required(CONF_DOMAIN): DOMAIN}
)
TRIGGER_SCHEMA = toggle_entity.TRIGGER_SCHEMA.extend(
{vol.Required(CONF_DOMAIN): DOMAIN}
)
async def async_call_action_from_config(hass, config, variables, context):
"""Change state based on configuration."""
config = ACTION_SCHEMA(config)
await toggle_entity.async_call_action_from_config(
hass, config, variables, context, DOMAIN
)
def async_condition_from_config(config, config_validation):
"""Evaluate state based on configuration."""
config = CONDITION_SCHEMA(config)
return toggle_entity.async_condition_from_config(config, config_validation)
async def async_trigger(hass, config, action, automation_info):
"""Listen for state changes based on configuration."""
config = TRIGGER_SCHEMA(config)
return await toggle_entity.async_attach_trigger(
hass, config, action, automation_info
)
async def async_get_actions(hass, device_id):
"""List device actions."""
return await toggle_entity.async_get_actions(hass, device_id, DOMAIN)
async def async_get_conditions(hass, device_id):
"""List device conditions."""
return await toggle_entity.async_get_conditions(hass, device_id, DOMAIN)
async def async_get_triggers(hass, device_id):
"""List device triggers."""
return await toggle_entity.async_get_triggers(hass, device_id, DOMAIN)
@@ -0,0 +1,28 @@
"""Provides device conditions for lights."""
from typing import List
import voluptuous as vol
from homeassistant.core import HomeAssistant
from homeassistant.components.device_automation import toggle_entity
from homeassistant.const import CONF_DOMAIN
from homeassistant.helpers.typing import ConfigType
from homeassistant.helpers.condition import ConditionCheckerType
from . import DOMAIN
CONDITION_SCHEMA = toggle_entity.CONDITION_SCHEMA.extend(
{vol.Required(CONF_DOMAIN): DOMAIN}
)
def async_condition_from_config(
config: ConfigType, config_validation: bool
) -> ConditionCheckerType:
"""Evaluate state based on configuration."""
config = CONDITION_SCHEMA(config)
return toggle_entity.async_condition_from_config(config, config_validation)
async def async_get_conditions(hass: HomeAssistant, device_id: str) -> List[dict]:
"""List device conditions."""
return await toggle_entity.async_get_conditions(hass, device_id, DOMAIN)
@@ -0,0 +1,33 @@
"""Provides device trigger for lights."""
from typing import List
import voluptuous as vol
from homeassistant.core import HomeAssistant, CALLBACK_TYPE
from homeassistant.components.automation import AutomationActionType
from homeassistant.components.device_automation import toggle_entity
from homeassistant.const import CONF_DOMAIN
from homeassistant.helpers.typing import ConfigType
from . import DOMAIN
TRIGGER_SCHEMA = toggle_entity.TRIGGER_SCHEMA.extend(
{vol.Required(CONF_DOMAIN): DOMAIN}
)
async def async_attach_trigger(
hass: HomeAssistant,
config: ConfigType,
action: AutomationActionType,
automation_info: dict,
) -> CALLBACK_TYPE:
"""Listen for state changes based on configuration."""
config = TRIGGER_SCHEMA(config)
return await toggle_entity.async_attach_trigger(
hass, config, action, automation_info
)
async def async_get_triggers(hass: HomeAssistant, device_id: str) -> List[dict]:
"""List device triggers."""
return await toggle_entity.async_get_triggers(hass, device_id, DOMAIN)