Ejemplo n.º 1
0
TRIGGER_SCHEMA = vol.All(
    DEVICE_TRIGGER_BASE_SCHEMA.extend({
        vol.Required(CONF_ENTITY_ID):
        cv.entity_id,
        vol.Required(CONF_TYPE):
        vol.In([
            CONF_BATTERY_LEVEL,
            CONF_CO,
            CONF_CO2,
            CONF_CURRENT,
            CONF_ENERGY,
            CONF_GAS,
            CONF_HUMIDITY,
            CONF_ILLUMINANCE,
            CONF_POWER,
            CONF_POWER_FACTOR,
            CONF_PRESSURE,
            CONF_SIGNAL_STRENGTH,
            CONF_TEMPERATURE,
            CONF_VOLTAGE,
            CONF_VALUE,
        ]),
        vol.Optional(CONF_BELOW):
        vol.Any(vol.Coerce(float)),
        vol.Optional(CONF_ABOVE):
        vol.Any(vol.Coerce(float)),
        vol.Optional(CONF_FOR):
        cv.positive_time_period_dict,
    }),
    cv.has_at_least_one_key(CONF_BELOW, CONF_ABOVE),
)
Ejemplo n.º 2
0
    CONF_TYPE,
    CONF_ZONE,
)
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
from homeassistant.helpers import config_validation as cv, entity_registry
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
from homeassistant.helpers.typing import ConfigType

from .const import DOMAIN

TRIGGER_TYPES: Final[set[str]] = {"enters", "leaves"}

TRIGGER_SCHEMA: Final = DEVICE_TRIGGER_BASE_SCHEMA.extend({
    vol.Required(CONF_ENTITY_ID):
    cv.entity_id,
    vol.Required(CONF_TYPE):
    vol.In(TRIGGER_TYPES),
    vol.Required(CONF_ZONE):
    cv.entity_domain(DOMAIN_ZONE),
})


async def async_get_triggers(hass: HomeAssistant,
                             device_id: str) -> list[dict[str, str]]:
    """List device triggers for Device Tracker devices."""
    registry = entity_registry.async_get(hass)
    triggers = []

    # Get all the integrations entities for this device
    for entry in entity_registry.async_entries_for_device(registry, device_id):
        if entry.domain != DOMAIN:
            continue
Ejemplo n.º 3
0
    DOMAIN,
    SUPPORT_CLOSE,
    SUPPORT_OPEN,
    SUPPORT_SET_POSITION,
    SUPPORT_SET_TILT_POSITION,
)

POSITION_TRIGGER_TYPES = {"position", "tilt_position"}
STATE_TRIGGER_TYPES = {"opened", "closed", "opening", "closing"}

POSITION_TRIGGER_SCHEMA = vol.All(
    DEVICE_TRIGGER_BASE_SCHEMA.extend({
        vol.Required(CONF_ENTITY_ID):
        cv.entity_id,
        vol.Required(CONF_TYPE):
        vol.In(POSITION_TRIGGER_TYPES),
        vol.Optional(CONF_ABOVE):
        vol.All(vol.Coerce(int), vol.Range(min=0, max=100)),
        vol.Optional(CONF_BELOW):
        vol.All(vol.Coerce(int), vol.Range(min=0, max=100)),
    }),
    cv.has_at_least_one_key(CONF_BELOW, CONF_ABOVE),
)

STATE_TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend({
    vol.Required(CONF_ENTITY_ID):
    cv.entity_id,
    vol.Required(CONF_TYPE):
    vol.In(STATE_TRIGGER_TYPES),
    vol.Optional(CONF_FOR):
    cv.positive_time_period_dict,
})
Ejemplo n.º 4
0
    CONF_PLATFORM,
    CONF_TYPE,
)
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
from homeassistant.helpers.typing import ConfigType

from .const import DOMAIN, NANOLEAF_EVENT, TOUCH_GESTURE_TRIGGER_MAP, TOUCH_MODELS

TRIGGER_TYPES = TOUCH_GESTURE_TRIGGER_MAP.values()

TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend({
    vol.Required(CONF_DOMAIN):
    DOMAIN,
    vol.Required(CONF_DEVICE_ID):
    str,
    vol.Required(CONF_TYPE):
    vol.In(TRIGGER_TYPES),
})


async def async_get_triggers(hass: HomeAssistant,
                             device_id: str) -> list[dict[str, str]]:
    """List device triggers for Nanoleaf devices."""
    device_registry = dr.async_get(hass)
    device_entry = device_registry.async_get(device_id)
    if device_entry is None:
        raise DeviceNotFound(f"Device ID {device_id} is not valid")
    if device_entry.model not in TOUCH_MODELS:
        return []
    return [{
from .const import DOMAIN, TASMOTA_EVENT
from .discovery import TASMOTA_DISCOVERY_ENTITY_UPDATED, clear_discovery_hash

_LOGGER = logging.getLogger(__name__)

CONF_DISCOVERY_ID = "discovery_id"
CONF_SUBTYPE = "subtype"
DEVICE = "device"

TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend({
    vol.Required(CONF_PLATFORM):
    DEVICE,
    vol.Required(CONF_DOMAIN):
    DOMAIN,
    vol.Required(CONF_DEVICE_ID):
    str,
    vol.Required(CONF_DISCOVERY_ID):
    str,
    vol.Required(CONF_TYPE):
    cv.string,
    vol.Required(CONF_SUBTYPE):
    cv.string,
})

DEVICE_TRIGGERS = "tasmota_device_triggers"


@attr.s(slots=True)
class TriggerInstance:
    """Attached trigger settings."""

    action: AutomationActionType = attr.ib()
Ejemplo n.º 6
0
    CONF_TYPE,
    STATE_OFF,
    STATE_ON,
)
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
from homeassistant.helpers import config_validation as cv, entity_registry
from homeassistant.helpers.typing import ConfigType

from . import DOMAIN

# TODO specify your supported trigger types.
TRIGGER_TYPES = {"turned_on", "turned_off"}

TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend({
    vol.Required(CONF_ENTITY_ID):
    cv.entity_id,
    vol.Required(CONF_TYPE):
    vol.In(TRIGGER_TYPES),
})


async def async_get_triggers(hass: HomeAssistant,
                             device_id: str) -> list[dict[str, Any]]:
    """List device triggers for NEW_NAME devices."""
    registry = await entity_registry.async_get_registry(hass)
    triggers = []

    # TODO Read this comment and remove it.
    # This example shows how to iterate over the entities of this device
    # that match this integration. If your triggers instead rely on
    # events fired by devices without entities, do something like:
    # zha_device = await _async_get_zha_device(hass, device_id)
Ejemplo n.º 7
0
def _reverse_dict(forward_dict: dict) -> dict:
    """Reverse a dictionary."""
    return {v: k for k, v in forward_dict.items()}


LUTRON_MODEL_TO_TYPE = {
    "RRST-W2B-XX": "SunnataKeypad_2Button",
    "RRST-W3RL-XX": "SunnataKeypad_3ButtonRaiseLower",
    "RRST-W4B-XX": "SunnataKeypad_4Button",
}

SUPPORTED_INPUTS_EVENTS_TYPES = [ACTION_PRESS, ACTION_RELEASE]

LUTRON_BUTTON_TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend({
    vol.Required(CONF_TYPE):
    vol.In(SUPPORTED_INPUTS_EVENTS_TYPES),
})

PICO_2_BUTTON_BUTTON_TYPES_TO_LIP = {
    "on": 2,
    "off": 4,
}
PICO_2_BUTTON_BUTTON_TYPES_TO_LEAP = {
    "on": 0,
    "off": 2,
}
PICO_2_BUTTON_TRIGGER_SCHEMA = LUTRON_BUTTON_TRIGGER_SCHEMA.extend({
    vol.Required(CONF_SUBTYPE):
    vol.In(PICO_2_BUTTON_BUTTON_TYPES_TO_LIP),
})
Ejemplo n.º 8
0
import voluptuous as vol
from homeassistant.components.device_automation import \
    DEVICE_TRIGGER_BASE_SCHEMA
from homeassistant.components.homeassistant.triggers import \
    state as state_trigger
from homeassistant.const import *
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.device_registry import DeviceEntry

from . import DOMAIN
from .core import converters
from .core.converters.base import BUTTON

TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend(
    {
        vol.Required(CONF_TYPE): cv.string,
        vol.Required('action'): cv.string
    }
)


async def async_attach_trigger(hass, config, action, automation_info):
    entity_registry = await hass.helpers.entity_registry.async_get_registry()

    device_id = config[CONF_DEVICE_ID]
    entry = next((
        entry for entry in entity_registry.entities.values() if
        entry.device_id == device_id and entry.unique_id.endswith('action')
    ), None)

    if not entry:
        return None
Ejemplo n.º 9
0
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_validation as cv, entity_registry
from homeassistant.helpers.entity import get_capability
from homeassistant.helpers.typing import ConfigType

from .const import ATTR_OPTIONS, DOMAIN

TRIGGER_TYPES = {"current_option_changed"}

TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend({
    vol.Required(CONF_ENTITY_ID):
    cv.entity_id,
    vol.Required(CONF_TYPE):
    vol.In(TRIGGER_TYPES),
    vol.Optional(CONF_TO):
    vol.Any(vol.Coerce(str)),
    vol.Optional(CONF_FROM):
    vol.Any(vol.Coerce(str)),
    vol.Optional(CONF_FOR):
    cv.positive_time_period_dict,
})


async def async_get_triggers(hass: HomeAssistant,
                             device_id: str) -> list[dict[str, Any]]:
    """List device triggers for Select devices."""
    registry = await entity_registry.async_get_registry(hass)
    return [{
        CONF_PLATFORM: "device",
        CONF_DEVICE_ID: device_id,
        CONF_DOMAIN: DOMAIN,
Ejemplo n.º 10
0
"""Offer device oriented automation."""
import voluptuous as vol

from homeassistant.components.device_automation import (
    DEVICE_TRIGGER_BASE_SCHEMA,
    async_get_device_automation_platform,
)
from homeassistant.const import CONF_DOMAIN

from .exceptions import InvalidDeviceAutomationConfig

# mypy: allow-untyped-defs, no-check-untyped-defs

TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend({}, extra=vol.ALLOW_EXTRA)


async def async_validate_trigger_config(hass, config):
    """Validate config."""
    platform = await async_get_device_automation_platform(
        hass, config[CONF_DOMAIN], "trigger"
    )
    if not hasattr(platform, "async_validate_trigger_config"):
        return platform.TRIGGER_SCHEMA(config)

    try:
        return await getattr(platform, "async_validate_trigger_config")(hass, config)
    except InvalidDeviceAutomationConfig as err:
        raise vol.Invalid(str(err) or "Invalid trigger configuration") from err


async def async_attach_trigger(hass, config, action, automation_info):
Ejemplo n.º 11
0
)
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
from homeassistant.helpers import config_validation as cv, entity_registry
from homeassistant.helpers.typing import ConfigType

from . import DOMAIN

# mypy: disallow-any-generics

TARGET_TRIGGER_SCHEMA = vol.All(
    DEVICE_TRIGGER_BASE_SCHEMA.extend({
        vol.Required(CONF_ENTITY_ID):
        cv.entity_id,
        vol.Required(CONF_TYPE):
        "target_humidity_changed",
        vol.Optional(CONF_BELOW):
        vol.Any(vol.Coerce(int)),
        vol.Optional(CONF_ABOVE):
        vol.Any(vol.Coerce(int)),
        vol.Optional(CONF_FOR):
        cv.positive_time_period_dict,
    }),
    cv.has_at_least_one_key(CONF_BELOW, CONF_ABOVE),
)

TOGGLE_TRIGGER_SCHEMA = toggle_entity.TRIGGER_SCHEMA.extend(
    {vol.Required(CONF_DOMAIN): DOMAIN})

TRIGGER_SCHEMA = vol.Any(TARGET_TRIGGER_SCHEMA, TOGGLE_TRIGGER_SCHEMA)


async def async_get_triggers(hass: HomeAssistant,
Ejemplo n.º 12
0
from ..const import ATTR_HUE_EVENT, CONF_SUBTYPE, DOMAIN

if TYPE_CHECKING:
    from aiohue.v2 import HueBridgeV2

    from homeassistant.components.automation import (
        AutomationActionType,
        AutomationTriggerInfo,
    )

    from ..bridge import HueBridge

TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend(
    {
        vol.Required(CONF_TYPE): str,
        vol.Required(CONF_SUBTYPE): int,
        vol.Optional(CONF_UNIQUE_ID): str,
    }
)


async def async_validate_trigger_config(
    bridge: "HueBridge",
    device_entry: DeviceEntry,
    config: ConfigType,
):
    """Validate config."""
    config = TRIGGER_SCHEMA(config)
    return config

Ejemplo n.º 13
0
from .const import (
    ATTR_CHANNEL,
    ATTR_CLICK_TYPE,
    CONF_SUBTYPE,
    DOMAIN,
    EVENT_SHELLY_CLICK,
    INPUTS_EVENTS_SUBTYPES,
    SHBTN_INPUTS_EVENTS_TYPES,
    SHBTN_MODELS,
    SUPPORTED_INPUTS_EVENTS_TYPES,
)
from .utils import get_input_triggers

TRIGGER_SCHEMA: Final = DEVICE_TRIGGER_BASE_SCHEMA.extend({
    vol.Required(CONF_TYPE):
    vol.In(SUPPORTED_INPUTS_EVENTS_TYPES),
    vol.Required(CONF_SUBTYPE):
    vol.In(INPUTS_EVENTS_SUBTYPES),
})


async def async_validate_trigger_config(
        hass: HomeAssistant, config: dict[str, Any]) -> dict[str, Any]:
    """Validate config."""
    config = TRIGGER_SCHEMA(config)

    # if device is available verify parameters against device capabilities
    wrapper = get_device_wrapper(hass, config[CONF_DEVICE_ID])
    if not wrapper or not wrapper.device.initialized:
        return config

    trigger = (config[CONF_TYPE], config[CONF_SUBTYPE])
Ejemplo n.º 14
0
 DEVICE_TRIGGER_BASE_SCHEMA.extend({
     vol.Required(CONF_ENTITY_ID):
     cv.entity_id,
     vol.Required(CONF_TYPE):
     vol.In([
         CONF_BATTERY_LEVEL,
         CONF_CO,
         CONF_CO2,
         CONF_CURRENT,
         CONF_ENERGY,
         CONF_GAS,
         CONF_HUMIDITY,
         CONF_ILLUMINANCE,
         CONF_NITROGEN_DIOXIDE,
         CONF_NITROGEN_MONOXIDE,
         CONF_NITROUS_OXIDE,
         CONF_OZONE,
         CONF_PM1,
         CONF_PM10,
         CONF_PM25,
         CONF_POWER,
         CONF_POWER_FACTOR,
         CONF_PRESSURE,
         CONF_SIGNAL_STRENGTH,
         CONF_SULPHUR_DIOXIDE,
         CONF_TEMPERATURE,
         CONF_VOLATILE_ORGANIC_COMPOUNDS,
         CONF_VOLTAGE,
         CONF_VALUE,
     ]),
     vol.Optional(CONF_BELOW):
     vol.Any(vol.Coerce(float)),
     vol.Optional(CONF_ABOVE):
     vol.Any(vol.Coerce(float)),
     vol.Optional(CONF_FOR):
     cv.positive_time_period_dict,
 }),
Ejemplo n.º 15
0
"""Triggers for WeMo devices."""
from pywemo.subscribe import EVENT_TYPE_LONG_PRESS
import voluptuous as vol

from homeassistant.components.device_automation import DEVICE_TRIGGER_BASE_SCHEMA
from homeassistant.components.homeassistant.triggers import event as event_trigger
from homeassistant.const import CONF_DEVICE_ID, CONF_DOMAIN, CONF_PLATFORM, CONF_TYPE

from .const import DOMAIN as WEMO_DOMAIN, WEMO_SUBSCRIPTION_EVENT
from .wemo_device import async_get_coordinator

TRIGGER_TYPES = {EVENT_TYPE_LONG_PRESS}

TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend({
    vol.Required(CONF_TYPE):
    vol.In(TRIGGER_TYPES),
})


async def async_get_triggers(hass, device_id):
    """Return a list of triggers."""

    wemo_trigger = {
        # Required fields of TRIGGER_BASE_SCHEMA
        CONF_PLATFORM: "device",
        CONF_DOMAIN: WEMO_DOMAIN,
        CONF_DEVICE_ID: device_id,
    }

    coordinator = async_get_coordinator(hass, device_id)
    triggers = []
Ejemplo n.º 16
0
NOTIFICATION_NOTIFICATION = "event.notification.notification"
BASIC_VALUE_NOTIFICATION = "event.value_notification.basic"
CENTRAL_SCENE_VALUE_NOTIFICATION = "event.value_notification.central_scene"
SCENE_ACTIVATION_VALUE_NOTIFICATION = "event.value_notification.scene_activation"
CONFIG_PARAMETER_VALUE_UPDATED = f"{VALUE_UPDATED_PLATFORM_TYPE}.config_parameter"
VALUE_VALUE_UPDATED = f"{VALUE_UPDATED_PLATFORM_TYPE}.value"
NODE_STATUS = "state.node_status"

NOTIFICATION_EVENT_CC_MAPPINGS = (
    (ENTRY_CONTROL_NOTIFICATION, CommandClass.ENTRY_CONTROL),
    (NOTIFICATION_NOTIFICATION, CommandClass.NOTIFICATION),
)

# Event based trigger schemas
BASE_EVENT_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend({
    vol.Required(ATTR_COMMAND_CLASS):
    vol.In([cc.value for cc in CommandClass]),
})

NOTIFICATION_NOTIFICATION_SCHEMA = BASE_EVENT_SCHEMA.extend({
    vol.Required(CONF_TYPE):
    NOTIFICATION_NOTIFICATION,
    vol.Optional(f"{ATTR_TYPE}."):
    vol.Coerce(int),
    vol.Optional(ATTR_LABEL):
    cv.string,
    vol.Optional(ATTR_EVENT):
    vol.Coerce(int),
    vol.Optional(ATTR_EVENT_LABEL):
    cv.string,
})
Ejemplo n.º 17
0
    "deep_sleep",
    "light_sleep",
    "awake",
    "not_awake",
    "apnea_alarm",
    "antisnoring",
    "sound_event_snore",
    "sound_event_talk",
    "sound_event_cough",
    "sound_event_baby",
    "sound_event_laugh"
]

TRIGGER_SCHEMA = HA_TRIGGER_BASE_SCHEMA.extend(
    {
        vol.Required(CONF_TYPE): vol.In(TRIGGERS),
    }
)


async def async_get_triggers(hass, device_id):
    """Return a list of triggers."""
    device_registry = await hass.helpers.device_registry.async_get_registry()
    device = device_registry.async_get(device_id)

    triggers = []

    for t in TRIGGERS:
        triggers.append({
            # Required fields of TRIGGER_BASE_SCHEMA
            CONF_PLATFORM: "device",
Ejemplo n.º 18
0
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
from homeassistant.helpers import config_validation as cv, entity_registry
from homeassistant.helpers.typing import ConfigType

from . import DOMAIN, const

TRIGGER_TYPES = {
    "current_temperature_changed",
    "current_humidity_changed",
    "hvac_mode_changed",
}

HVAC_MODE_TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend(
    {
        vol.Required(CONF_ENTITY_ID): cv.entity_id,
        vol.Required(CONF_TYPE): "hvac_mode_changed",
        vol.Required(state_trigger.CONF_TO): vol.In(const.HVAC_MODES),
    }
)

CURRENT_TRIGGER_SCHEMA = vol.All(
    DEVICE_TRIGGER_BASE_SCHEMA.extend(
        {
            vol.Required(CONF_ENTITY_ID): cv.entity_id,
            vol.Required(CONF_TYPE): vol.In(
                ["current_temperature_changed", "current_humidity_changed"]
            ),
            vol.Optional(CONF_BELOW): vol.Any(vol.Coerce(float)),
            vol.Optional(CONF_ABOVE): vol.Any(vol.Coerce(float)),
            vol.Optional(CONF_FOR): cv.positive_time_period_dict,
        }
Ejemplo n.º 19
0
    STATE_PLAYING,
)
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
from homeassistant.helpers import config_validation as cv, entity_registry
from homeassistant.helpers.typing import ConfigType

from .const import DOMAIN

TRIGGER_TYPES = {
    "turned_on", "turned_off", "buffering", "idle", "paused", "playing"
}

MEDIA_PLAYER_TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend({
    vol.Required(CONF_ENTITY_ID):
    cv.entity_id,
    vol.Required(CONF_TYPE):
    vol.In(TRIGGER_TYPES),
    vol.Optional(CONF_FOR):
    cv.positive_time_period_dict,
})

TRIGGER_SCHEMA = vol.All(
    vol.Any(
        MEDIA_PLAYER_TRIGGER_SCHEMA,
        entity.TRIGGER_SCHEMA,
    ),
    vol.Schema({vol.Required(CONF_DOMAIN): DOMAIN}, extra=vol.ALLOW_EXTRA),
)


async def async_get_triggers(hass: HomeAssistant,
                             device_id: str) -> list[dict[str, Any]]:
Ejemplo n.º 20
0
# Trigger types
ENTRY_CONTROL_NOTIFICATION = "event.notification.entry_control"
NOTIFICATION_NOTIFICATION = "event.notification.notification"
BASIC_VALUE_NOTIFICATION = "event.value_notification.basic"
CENTRAL_SCENE_VALUE_NOTIFICATION = "event.value_notification.central_scene"
SCENE_ACTIVATION_VALUE_NOTIFICATION = "event.value_notification.scene_activation"
NODE_STATUS = "state.node_status"

NOTIFICATION_EVENT_CC_MAPPINGS = (
    (ENTRY_CONTROL_NOTIFICATION, CommandClass.ENTRY_CONTROL),
    (NOTIFICATION_NOTIFICATION, CommandClass.NOTIFICATION),
)

# Event based trigger schemas
BASE_EVENT_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend({
    vol.Required(ATTR_COMMAND_CLASS):
    vol.In([cc.value for cc in CommandClass]),
})

NOTIFICATION_NOTIFICATION_SCHEMA = BASE_EVENT_SCHEMA.extend({
    vol.Required(CONF_TYPE):
    NOTIFICATION_NOTIFICATION,
    vol.Optional(f"{ATTR_TYPE}."):
    vol.Coerce(int),
    vol.Optional(ATTR_LABEL):
    cv.string,
    vol.Optional(ATTR_EVENT):
    vol.Coerce(int),
    vol.Optional(ATTR_EVENT_LABEL):
    cv.string,
})
from homeassistant.components.device_automation.exceptions import (
    InvalidDeviceAutomationConfig, )
from homeassistant.components.homeassistant.triggers import event as event_trigger
from homeassistant.const import CONF_DEVICE_ID, CONF_DOMAIN, CONF_PLATFORM, CONF_TYPE

from . import DOMAIN
from .core.helpers import async_get_zha_device

CONF_SUBTYPE = "subtype"
DEVICE = "device"
DEVICE_IEEE = "device_ieee"
ZHA_EVENT = "zha_event"

TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend({
    vol.Required(CONF_TYPE):
    str,
    vol.Required(CONF_SUBTYPE):
    str
})


async def async_validate_trigger_config(hass, config):
    """Validate config."""
    config = TRIGGER_SCHEMA(config)

    if "zha" in hass.config.components:
        trigger = (config[CONF_TYPE], config[CONF_SUBTYPE])
        try:
            zha_device = await async_get_zha_device(hass,
                                                    config[CONF_DEVICE_ID])
        except (KeyError, AttributeError) as err:
            raise InvalidDeviceAutomationConfig from err
Ejemplo n.º 22
0
from homeassistant.components.automation import AutomationActionType
from homeassistant.components.device_automation import DEVICE_TRIGGER_BASE_SCHEMA
from homeassistant.components.homeassistant.triggers import state as state_trigger
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN

from .utils import async_get_device_entries
from .const import DOMAIN

NEW_VOD = "new_vod"

TRIGGER_TYPES = {NEW_VOD}

TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend(
    {
        vol.Required(CONF_TYPE): vol.In(TRIGGER_TYPES),
        vol.Optional(CONF_ENTITY_ID): cv.entity_domain(SENSOR_DOMAIN),
    }
)

_LOGGER = logging.getLogger(__name__)


async def async_get_triggers(hass: HomeAssistant, device_id: str):
    """ List of device triggers """

    (device, device_entries) = await async_get_device_entries(hass, device_id)

    triggers = []

    if not device or not device_entries or len(device_entries) < 1:
        return triggers