Esempio n. 1
0
from openpeerpower.helpers.typing import ConfigType

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 = 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()
    automation_info: dict = attr.ib()
    trigger: Trigger = attr.ib()
Esempio n. 2
0
    CONF_TYPE,
    STATE_OFF,
    STATE_ON,
)
from openpeerpower.core import CALLBACK_TYPE, OpenPeerPower
from openpeerpower.helpers import config_validation as cv, entity_registry
from openpeerpower.helpers.typing import ConfigType

from . import DOMAIN

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

TRIGGER_SCHEMA = 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(opp: OpenPeerPower, device_id: str) -> list[dict]:
    """List device triggers for NEW_NAME devices."""
    registry = await entity_registry.async_get_registry(opp)
    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(opp, device_id)
    # return zha_device.device_triggers
Esempio n. 3
0
from openpeerpower.components.device_automation import TRIGGER_BASE_SCHEMA
from openpeerpower.components.device_automation.exceptions import (
    InvalidDeviceAutomationConfig, )
from openpeerpower.components.openpeerpower.triggers import event as event_trigger
from openpeerpower.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 = TRIGGER_BASE_SCHEMA.extend({
    vol.Required(CONF_TYPE): str,
    vol.Required(CONF_SUBTYPE): str
})


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

    if "zha" in opp.config.components:
        trigger = (config[CONF_TYPE], config[CONF_SUBTYPE])
        try:
            zha_device = await async_get_zha_device(opp,
                                                    config[CONF_DEVICE_ID])
        except (KeyError, AttributeError) as err:
            raise InvalidDeviceAutomationConfig from err
        if (zha_device.device_automation_triggers is None
Esempio n. 4
0
from openpeerpower.core import CALLBACK_TYPE, OpenPeerPower
from openpeerpower.helpers import config_validation as cv, entity_registry
from openpeerpower.helpers.typing import ConfigType

from . import DOMAIN, const

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

HVAC_MODE_TRIGGER_SCHEMA = 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(
    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):
Esempio n. 5
0
    CONF_TYPE,
    STATE_LOCKED,
    STATE_UNLOCKED,
)
from openpeerpower.core import CALLBACK_TYPE, OpenPeerPower
from openpeerpower.helpers import config_validation as cv, entity_registry
from openpeerpower.helpers.typing import ConfigType

from . import DOMAIN

TRIGGER_TYPES = {"locked", "unlocked"}

TRIGGER_SCHEMA = 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,
})


async def async_get_triggers(opp: OpenPeerPower, device_id: str) -> list[dict]:
    """List device triggers for Lock devices."""
    registry = await entity_registry.async_get_registry(opp)
    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
Esempio n. 6
0
    CONF_PLATFORM,
    CONF_TYPE,
    CONF_ZONE,
)
from openpeerpower.core import CALLBACK_TYPE, OpenPeerPower
from openpeerpower.helpers import config_validation as cv, entity_registry
from openpeerpower.helpers.typing import ConfigType

from . import DOMAIN

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

TRIGGER_SCHEMA: Final = 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(opp: OpenPeerPower, device_id: str) -> list[dict]:
    """List device triggers for Device Tracker devices."""
    registry = await entity_registry.async_get_registry(opp)
    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
Esempio n. 7
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(
    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 = 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,
})
    DEVICE_CLASS_NONE: [{CONF_TYPE: CONF_VALUE}],
}


TRIGGER_SCHEMA = vol.All(
    TRIGGER_BASE_SCHEMA.extend(
        {
            vol.Required(CONF_ENTITY_ID): cv.entity_id,
            vol.Required(CONF_TYPE): vol.In(
                [
                    CONF_BATTERY_LEVEL,
                    CONF_HUMIDITY,
                    CONF_ILLUMINANCE,
                    CONF_POWER,
                    CONF_PRESSURE,
                    CONF_SIGNAL_STRENGTH,
                    CONF_TEMPERATURE,
                    CONF_TIMESTAMP,
                    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),
)


async def async_attach_trigger(opp, config, action, automation_info):
Esempio n. 9
0
from .const import (
    ACTION_PRESS,
    ACTION_RELEASE,
    ATTR_ACTION,
    ATTR_BUTTON_NUMBER,
    ATTR_SERIAL,
    BUTTON_DEVICES,
    CONF_SUBTYPE,
    DOMAIN,
    LUTRON_CASETA_BUTTON_EVENT,
)

SUPPORTED_INPUTS_EVENTS_TYPES = [ACTION_PRESS, ACTION_RELEASE]

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

PICO_2_BUTTON_BUTTON_TYPES = {
    "on": 2,
    "off": 4,
}
PICO_2_BUTTON_TRIGGER_SCHEMA = LUTRON_BUTTON_TRIGGER_SCHEMA.extend({
    vol.Required(CONF_SUBTYPE):
    vol.In(PICO_2_BUTTON_BUTTON_TYPES),
})

PICO_2_BUTTON_RAISE_LOWER_BUTTON_TYPES = {
    "on": 2,
    "off": 4,
    "raise": 5,
Esempio n. 10
0
from openpeerpower.components.automation import AutomationActionType
from openpeerpower.components.device_automation import TRIGGER_BASE_SCHEMA
from openpeerpower.const import CONF_DEVICE_ID, CONF_DOMAIN, CONF_PLATFORM, CONF_TYPE
from openpeerpower.core import CALLBACK_TYPE, OpenPeerPower
from openpeerpower.helpers.device_registry import DeviceRegistry, async_get_registry
from openpeerpower.helpers.typing import ConfigType

from . import PhilipsTVDataUpdateCoordinator
from .const import DOMAIN

TRIGGER_TYPE_TURN_ON = "turn_on"

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


async def async_get_triggers(opp: OpenPeerPower, device_id: str) -> list[dict]:
    """List device triggers for device."""
    triggers = []
    triggers.append({
        CONF_PLATFORM: "device",
        CONF_DEVICE_ID: device_id,
        CONF_DOMAIN: DOMAIN,
        CONF_TYPE: TRIGGER_TYPE_TURN_ON,
    })

    return triggers
Esempio n. 11
0
    CONF_TYPE,
    PERCENTAGE,
)
from openpeerpower.core import CALLBACK_TYPE, OpenPeerPower
from openpeerpower.helpers import config_validation as cv, entity_registry
from openpeerpower.helpers.typing import ConfigType

from . import DOMAIN

TARGET_TRIGGER_SCHEMA = vol.All(
    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(opp: OpenPeerPower, device_id: str) -> list[dict]:
Esempio n. 12
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_device_wrapper, get_input_triggers

TRIGGER_SCHEMA = 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(opp, config):
    """Validate config."""
    config = TRIGGER_SCHEMA(config)

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

    trigger = (config[CONF_TYPE], config[CONF_SUBTYPE])