예제 #1
0
async def async_attach_trigger(opp, config, action, automation_info):
    """Listen for state changes based on configuration."""
    device_registry = await opp.helpers.device_registry.async_get_registry()
    device = device_registry.async_get(config[CONF_DEVICE_ID])

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

    trigger = REMOTES[device.model][trigger]

    deconz_event = _get_deconz_event_from_device_id(opp, device.id)
    if deconz_event is None:
        raise InvalidDeviceAutomationConfig(
            f'No deconz_event tied to device "{device.name}" found')

    event_id = deconz_event.serial

    event_config = {
        event_trigger.CONF_PLATFORM: "event",
        event_trigger.CONF_EVENT_TYPE: CONF_DECONZ_EVENT,
        event_trigger.CONF_EVENT_DATA: {
            CONF_UNIQUE_ID: event_id,
            **trigger
        },
    }

    event_config = event_trigger.TRIGGER_SCHEMA(event_config)
    return await event_trigger.async_attach_trigger(opp,
                                                    event_config,
                                                    action,
                                                    automation_info,
                                                    platform_type="device")
예제 #2
0
async def async_attach_trigger(
    opp: OpenPeerPower,
    config: ConfigType,
    action: AutomationActionType,
    automation_info: dict,
) -> CALLBACK_TYPE:
    """Attach a trigger."""
    device = get_button_device_by_dr_id(opp, config[CONF_DEVICE_ID])
    schema = DEVICE_TYPE_SCHEMA_MAP.get(device["type"])
    valid_buttons = DEVICE_TYPE_SUBTYPE_MAP.get(device["type"])
    config = schema(config)
    event_config = {
        event_trigger.CONF_PLATFORM: CONF_EVENT,
        event_trigger.CONF_EVENT_TYPE: LUTRON_CASETA_BUTTON_EVENT,
        event_trigger.CONF_EVENT_DATA: {
            ATTR_SERIAL: device["serial"],
            ATTR_BUTTON_NUMBER: valid_buttons[config[CONF_SUBTYPE]],
            ATTR_ACTION: config[CONF_TYPE],
        },
    }
    event_config = event_trigger.TRIGGER_SCHEMA(event_config)
    return await event_trigger.async_attach_trigger(opp,
                                                    event_config,
                                                    action,
                                                    automation_info,
                                                    platform_type="device")
예제 #3
0
async def async_attach_trigger(opp, config, action, automation_info):
    """Listen for state changes based on configuration."""
    trigger = (config[CONF_TYPE], config[CONF_SUBTYPE])
    try:
        zha_device = await async_get_zha_device(opp, config[CONF_DEVICE_ID])
    except (KeyError, AttributeError):
        return None

    if trigger not in zha_device.device_automation_triggers:
        return None

    trigger = zha_device.device_automation_triggers[trigger]

    event_config = {
        event_trigger.CONF_PLATFORM: "event",
        event_trigger.CONF_EVENT_TYPE: ZHA_EVENT,
        event_trigger.CONF_EVENT_DATA: {
            DEVICE_IEEE: str(zha_device.ieee),
            **trigger
        },
    }

    event_config = event_trigger.TRIGGER_SCHEMA(event_config)
    return await event_trigger.async_attach_trigger(opp,
                                                    event_config,
                                                    action,
                                                    automation_info,
                                                    platform_type="device")
예제 #4
0
async def async_attach_trigger(
    opp: OpenPeerPower,
    config: ConfigType,
    action: AutomationActionType,
    automation_info: dict,
) -> CALLBACK_TYPE:
    """Attach a trigger."""
    event_config = {
        event_trigger.CONF_PLATFORM: CONF_EVENT,
        event_trigger.CONF_EVENT_TYPE: EVENT_SHELLY_CLICK,
        event_trigger.CONF_EVENT_DATA: {
            ATTR_DEVICE_ID: config[CONF_DEVICE_ID],
            ATTR_CHANNEL: INPUTS_EVENTS_SUBTYPES[config[CONF_SUBTYPE]],
            ATTR_CLICK_TYPE: config[CONF_TYPE],
        },
    }
    event_config = event_trigger.TRIGGER_SCHEMA(event_config)
    return await event_trigger.async_attach_trigger(opp,
                                                    event_config,
                                                    action,
                                                    automation_info,
                                                    platform_type="device")
예제 #5
0
    async def async_attach_trigger(self):
        """Attach event trigger."""
        event_config = {
            event_trigger.CONF_PLATFORM: "event",
            event_trigger.CONF_EVENT_TYPE: TASMOTA_EVENT,
            event_trigger.CONF_EVENT_DATA: {
                "mac": self.trigger.tasmota_trigger.cfg.mac,
                "source": self.trigger.tasmota_trigger.cfg.subtype,
                "event": self.trigger.tasmota_trigger.cfg.event,
            },
        }

        event_config = event_trigger.TRIGGER_SCHEMA(event_config)
        if self.remove:
            self.remove()
        # Note: No lock needed, event_trigger.async_attach_trigger is an synchronous function
        self.remove = await event_trigger.async_attach_trigger(
            self.trigger.opp,
            event_config,
            self.action,
            self.automation_info,
            platform_type="device",
        )