示例#1
0
    CONF_FOR,
    CONF_PLATFORM,
    CONF_TYPE,
)
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, STATE_CLEANING, STATE_DOCKED

TRIGGER_TYPES = {"cleaning", "docked"}

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 Vacuum 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
示例#2
0
"""Offer device oriented automation."""
import voluptuous as vol

from openpeerpower.components.device_automation import (
    TRIGGER_BASE_SCHEMA,
    async_get_device_automation_platform,
)
from openpeerpower.const import CONF_DOMAIN

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

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


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

    return platform.TRIGGER_SCHEMA(config)


async def async_attach_trigger(opp, config, action, automation_info):
    """Listen for trigger."""
    platform = await async_get_device_automation_platform(
        opp, config[CONF_DOMAIN], "trigger")
    return await platform.async_attach_trigger(opp, config, action,
                                               automation_info)
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_automation.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):
示例#4
0
    CONF_PLATFORM,
    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),
    }
)


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

        # Add triggers for each entity that belongs to this integration
示例#5
0
    "button4",
    "button5",
    "button6",
    "button7",
    "button8",
    "button9",
    "button10",
}
TRIGGER_SUBTYPES = {"single_press", "double_press", "long_press"}

CONF_IID = "iid"
CONF_SUBTYPE = "subtype"

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

HK_TO_OP_INPUT_EVENT_VALUES = {
    InputEventValues.SINGLE_PRESS: "single_press",
    InputEventValues.DOUBLE_PRESS: "double_press",
    InputEventValues.LONG_PRESS: "long_press",
}


class TriggerSource:
    """Represents a stateless source of event data from HomeKit."""
    def __init__(self, connection, aid, triggers):
        """Initialize a set of triggers for a device."""
        self._opp = connection.opp
示例#6
0
DEFAULT_ENCODING = "utf-8"
DEVICE = "device"

MQTT_TRIGGER_BASE = {
    # Trigger when MQTT message is received
    CONF_PLATFORM: DEVICE,
    CONF_DOMAIN: DOMAIN,
}

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

TRIGGER_DISCOVERY_SCHEMA = mqtt.MQTT_BASE_PLATFORM_SCHEMA.extend(
    {
        vol.Required(CONF_AUTOMATION_TYPE): str,
        vol.Required(CONF_DEVICE): MQTT_ENTITY_DEVICE_INFO_SCHEMA,
        vol.Optional(CONF_PAYLOAD, default=None): vol.Any(None, cv.string),
        vol.Required(CONF_SUBTYPE): cv.string,
        vol.Required(CONF_TOPIC): cv.string,
        vol.Required(CONF_TYPE): cv.string,
示例#7
0

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_CO,
                    CONF_CO2,
                    CONF_CURRENT,
                    CONF_ENERGY,
                    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),
)
示例#8
0
    GIRA_JUNG_SWITCH_MODEL: GIRA_JUNG_SWITCH_MODEL,
    GIRA_SWITCH_MODEL: GIRA_JUNG_SWITCH_MODEL,
    JUNG_SWITCH_MODEL: GIRA_JUNG_SWITCH_MODEL,
    LIGHTIFIY_FOUR_BUTTON_REMOTE_MODEL: LIGHTIFIY_FOUR_BUTTON_REMOTE,
    LIGHTIFIY_FOUR_BUTTON_REMOTE_4X_MODEL: LIGHTIFIY_FOUR_BUTTON_REMOTE,
    LIGHTIFIY_FOUR_BUTTON_REMOTE_4X_EU_MODEL: LIGHTIFIY_FOUR_BUTTON_REMOTE,
    BUSCH_JAEGER_REMOTE_1_MODEL: BUSCH_JAEGER_REMOTE,
    BUSCH_JAEGER_REMOTE_2_MODEL: BUSCH_JAEGER_REMOTE,
    TRUST_ZYCT_202_MODEL: TRUST_ZYCT_202,
    TRUST_ZYCT_202_ZLL_MODEL: TRUST_ZYCT_202,
    UBISYS_POWER_SWITCH_S2_MODEL: UBISYS_POWER_SWITCH_S2,
    UBISYS_CONTROL_UNIT_C4_MODEL: UBISYS_CONTROL_UNIT_C4,
}

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


def _get_deconz_event_from_device_id(opp, device_id):
    """Resolve deconz event from device id."""
    for gateway in opp.data.get(DOMAIN, {}).values():

        for deconz_event in gateway.events:

            if device_id == deconz_event.device_id:
                return deconz_event

    return None

示例#9
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,
})
示例#10
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
示例#11
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,
示例#12
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]:
示例#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_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])