Exemple #1
0
async def async_attach_trigger(
    hass: HomeAssistant,
    config: ConfigType,
    action: AutomationActionType,
    automation_info: dict,
) -> CALLBACK_TYPE:
    """Attach a trigger."""
    device = get_button_device_by_dr_id(hass, 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.TRIGGER_SCHEMA(
        {
            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(
        hass, event_config, action, automation_info, platform_type="device"
    )
Exemple #2
0
async def async_attach_trigger(
    bridge: "HueBridge",
    device_entry: DeviceEntry,
    config: ConfigType,
    action: TriggerActionType,
    trigger_info: TriggerInfo,
) -> CALLBACK_TYPE:
    """Listen for state changes based on configuration."""
    hass = bridge.hass

    hue_event = _get_hue_event_from_device_id(hass, device_entry.id)
    if hue_event is None:
        raise InvalidDeviceAutomationConfig

    trigger_key: tuple[str, str] = (config[CONF_TYPE], config[CONF_SUBTYPE])

    assert device_entry.model
    trigger = REMOTES[device_entry.model][trigger_key]

    event_config = {
        event_trigger.CONF_PLATFORM: "event",
        event_trigger.CONF_EVENT_TYPE: ATTR_HUE_EVENT,
        event_trigger.CONF_EVENT_DATA: {
            CONF_UNIQUE_ID: hue_event.unique_id,
            **trigger
        },
    }

    event_config = event_trigger.TRIGGER_SCHEMA(event_config)
    return await event_trigger.async_attach_trigger(hass,
                                                    event_config,
                                                    action,
                                                    trigger_info,
                                                    platform_type="device")
Exemple #3
0
async def async_attach_trigger(
    hass: HomeAssistant,
    config: ConfigType,
    action: AutomationActionType,
    automation_info: AutomationTriggerInfo,
) -> CALLBACK_TYPE:
    """Attach a trigger."""
    config = TRIGGER_SCHEMA(config)

    event_data = {ATTR_DEVICE_ID: config[CONF_DEVICE_ID]}

    if config[CONF_TYPE] == CONF_TYPE_COMMAND:
        event_data["values"] = {"Command": config[CONF_SUBTYPE]}
    elif config[CONF_TYPE] == CONF_TYPE_STATUS:
        event_data["values"] = {"Status": config[CONF_SUBTYPE]}

    event_config = event_trigger.TRIGGER_SCHEMA({
        event_trigger.CONF_PLATFORM:
        "event",
        event_trigger.CONF_EVENT_TYPE:
        EVENT_RFXTRX_EVENT,
        event_trigger.CONF_EVENT_DATA:
        event_data,
    })

    return await event_trigger.async_attach_trigger(hass,
                                                    event_config,
                                                    action,
                                                    automation_info,
                                                    platform_type="device")
async def async_attach_trigger(hass, 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(hass, 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(hass,
                                                    event_config,
                                                    action,
                                                    automation_info,
                                                    platform_type="device")
Exemple #5
0
async def async_attach_trigger(
    hass: HomeAssistant,
    config: ConfigType,
    action: TriggerActionType,
    trigger_info: TriggerInfo,
) -> CALLBACK_TYPE:
    """Attach a trigger."""
    event_data = {
        CONF_DEVICE_ID: config[CONF_DEVICE_ID],
        **{
            key: config[key]
            for key in ("code", "level", "key", "action") if key in config
        },
    }

    event_config = event.TRIGGER_SCHEMA({
        event.CONF_PLATFORM: "event",
        event.CONF_EVENT_TYPE: f"lcn_{config[CONF_TYPE]}",
        event.CONF_EVENT_DATA: event_data,
    })

    return await event.async_attach_trigger(hass,
                                            event_config,
                                            action,
                                            trigger_info,
                                            platform_type="device")
Exemple #6
0
async def async_attach_trigger(
    hass: HomeAssistant,
    config: ConfigType,
    action: TriggerActionType,
    trigger_info: TriggerInfo,
) -> CALLBACK_TYPE:
    """Listen for state changes based on configuration."""
    trigger_key: tuple[str, str] = (config[CONF_TYPE], config[CONF_SUBTYPE])
    try:
        zha_device = async_get_zha_device(hass, config[CONF_DEVICE_ID])
    except (KeyError, AttributeError) as err:
        raise HomeAssistantError(
            f"Unable to get zha device {config[CONF_DEVICE_ID]}") from err

    if trigger_key not in zha_device.device_automation_triggers:
        raise HomeAssistantError(f"Unable to find trigger {trigger_key}")

    trigger = zha_device.device_automation_triggers[trigger_key]

    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(hass,
                                                    event_config,
                                                    action,
                                                    trigger_info,
                                                    platform_type="device")
Exemple #7
0
async def async_attach_trigger(bridge, device_entry, config, action,
                               automation_info):
    """Listen for state changes based on configuration."""
    hass = bridge.hass

    hue_event = _get_hue_event_from_device_id(hass, device_entry.id)
    if hue_event is None:
        raise InvalidDeviceAutomationConfig

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

    trigger = REMOTES[device_entry.model][trigger]

    event_config = {
        event_trigger.CONF_PLATFORM: "event",
        event_trigger.CONF_EVENT_TYPE: ATTR_HUE_EVENT,
        event_trigger.CONF_EVENT_DATA: {
            CONF_UNIQUE_ID: hue_event.unique_id,
            **trigger
        },
    }

    event_config = event_trigger.TRIGGER_SCHEMA(event_config)
    return await event_trigger.async_attach_trigger(hass,
                                                    event_config,
                                                    action,
                                                    automation_info,
                                                    platform_type="device")
async def async_attach_trigger(
    hass: HomeAssistant,
    config: ConfigType,
    action: AutomationActionType,
    automation_info: dict,
) -> CALLBACK_TYPE:
    """Attach a trigger."""

    event_config = None

    config = TRIGGER_SCHEMA(config)
    event_config = event_trigger.TRIGGER_SCHEMA({
        event_trigger.CONF_PLATFORM: CONF_EVENT,
        event_trigger.CONF_EVENT_TYPE: EVENT_BOSCH_SHC,
        event_trigger.CONF_EVENT_DATA: {
            ATTR_DEVICE_ID: config[CONF_DEVICE_ID],
            ATTR_EVENT_TYPE: config[CONF_TYPE],
            ATTR_EVENT_SUBTYPE: config[CONF_SUBTYPE],
        },
    })

    return await event_trigger.async_attach_trigger(hass,
                                                    event_config,
                                                    action,
                                                    automation_info,
                                                    platform_type="device")
async def async_attach_trigger(hass, config, action, automation_info):
    """Listen for state changes based on configuration."""
    device_registry = await hass.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(hass, device.id)
    if deconz_event is None:
        raise InvalidDeviceAutomationConfig

    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(
        hass, event_config, action, automation_info, platform_type="device"
    )
async def async_attach_trigger(
    hass: HomeAssistant,
    config: ConfigType,
    action: AutomationActionType,
    automation_info: dict,
) -> CALLBACK_TYPE:
    """Attach a trigger."""
    device_registry = await hass.helpers.device_registry.async_get_registry()
    device = device_registry.async_get(config[CONF_DEVICE_ID])

    if not device:
        return lambda: None

    if device.model not in DEVICES:
        return lambda: None

    event_config = {
        event_trigger.CONF_PLATFORM: "event",
        event_trigger.CONF_EVENT_TYPE: NETATMO_EVENT,
        event_trigger.CONF_EVENT_DATA: {
            "type": config[CONF_TYPE],
            ATTR_DEVICE_ID: config[ATTR_DEVICE_ID],
        },
    }

    if config[CONF_TYPE] in SUBTYPES:
        event_config.update(
            {event_trigger.CONF_EVENT_DATA: {"data": {"mode": config[CONF_SUBTYPE]}}}
        )

    event_config = event_trigger.TRIGGER_SCHEMA(event_config)
    return await event_trigger.async_attach_trigger(
        hass, event_config, action, automation_info, platform_type="device"
    )
Exemple #11
0
async def async_attach_trigger(
    hass: HomeAssistant,
    config: ConfigType,
    action: AutomationActionType,
    automation_info: AutomationTriggerInfo,
) -> CALLBACK_TYPE:
    """Attach a trigger."""
    device_registry = dr.async_get(hass)
    device = device_registry.async_get(config[CONF_DEVICE_ID])
    device_type = _device_model_to_type(device.model)
    _, serial = list(device.identifiers)[0]
    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: 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(hass,
                                                    event_config,
                                                    action,
                                                    automation_info,
                                                    platform_type="device")
Exemple #12
0
async def async_attach_trigger(
    hass: HomeAssistant,
    config: ConfigType,
    action: AutomationActionType,
    automation_info: dict,
) -> CALLBACK_TYPE:
    """Attach a trigger."""
    trigger_type = config[CONF_TYPE]
    trigger_platform = trigger_type.split(".")[0]

    event_data = {CONF_DEVICE_ID: config[CONF_DEVICE_ID]}
    event_config = {
        event.CONF_PLATFORM: "event",
        event.CONF_EVENT_DATA: event_data,
    }

    if ATTR_COMMAND_CLASS in config:
        event_data[ATTR_COMMAND_CLASS] = config[ATTR_COMMAND_CLASS]

    # Take input data from automation trigger UI and add it to the trigger we are
    # attaching to
    if trigger_platform == "event":
        if trigger_type == ENTRY_CONTROL_NOTIFICATION:
            event_config[event.CONF_EVENT_TYPE] = ZWAVE_JS_NOTIFICATION_EVENT
            copy_available_params(config, event_data,
                                  [ATTR_EVENT_TYPE, ATTR_DATA_TYPE])
        elif trigger_type == NOTIFICATION_NOTIFICATION:
            event_config[event.CONF_EVENT_TYPE] = ZWAVE_JS_NOTIFICATION_EVENT
            copy_available_params(config, event_data,
                                  [ATTR_LABEL, ATTR_EVENT_LABEL, ATTR_EVENT])
            if (val := config.get(f"{ATTR_TYPE}.")) not in ("", None):
                event_data[ATTR_TYPE] = val
        elif trigger_type in (
                BASIC_VALUE_NOTIFICATION,
                CENTRAL_SCENE_VALUE_NOTIFICATION,
                SCENE_ACTIVATION_VALUE_NOTIFICATION,
        ):
            event_config[
                event.CONF_EVENT_TYPE] = ZWAVE_JS_VALUE_NOTIFICATION_EVENT
            copy_available_params(
                config, event_data,
                [ATTR_PROPERTY, ATTR_PROPERTY_KEY, ATTR_ENDPOINT])
            if ATTR_VALUE in config:
                event_data[ATTR_VALUE_RAW] = config[ATTR_VALUE]
        else:
            raise HomeAssistantError(f"Unhandled trigger type {trigger_type}")

        event_config = event.TRIGGER_SCHEMA(event_config)
        return await event.async_attach_trigger(hass,
                                                event_config,
                                                action,
                                                automation_info,
                                                platform_type="device")
Exemple #13
0
async def async_attach_trigger(hass, config, action, automation_info):
    """Attach a trigger."""
    event_config = event_trigger.TRIGGER_SCHEMA({
        event_trigger.CONF_PLATFORM: "event",
        event_trigger.CONF_EVENT_TYPE: WEMO_SUBSCRIPTION_EVENT,
        event_trigger.CONF_EVENT_DATA: {
            CONF_DEVICE_ID: config[CONF_DEVICE_ID],
            CONF_TYPE: config[CONF_TYPE],
        },
    })
    return await event_trigger.async_attach_trigger(hass,
                                                    event_config,
                                                    action,
                                                    automation_info,
                                                    platform_type="device")
async def async_attach_trigger(hass: HomeAssistant, config, action, automation_info):
    """ Attach a trigger. """
    config = TRIGGER_SCHEMA(config)
    _LOGGER.debug("Got subscription to trigger: %s", config)
    event_config = event_trigger.TRIGGER_SCHEMA({
        event_trigger.CONF_PLATFORM: "event",
        event_trigger.CONF_EVENT_TYPE: DOMAIN + "_event",
        event_trigger.CONF_EVENT_DATA: {
            CONF_DEVICE_ID: config[CONF_DEVICE_ID],
            CONF_TYPE: config[CONF_TYPE],
        }
    })

    return await event_trigger.async_attach_trigger(
        hass, event_config, action, automation_info, platform_type="device"
    )
Exemple #15
0
async def async_attach_trigger(
    hass: HomeAssistant,
    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(
        hass, event_config, action, automation_info, platform_type="device"
    )
async def async_attach_trigger(
    hass: HomeAssistant,
    config: ConfigType,
    action: AutomationActionType,
    automation_info: AutomationTriggerInfo,
) -> CALLBACK_TYPE:
    """Attach a trigger."""
    event_config = event_trigger.TRIGGER_SCHEMA(
        {
            event_trigger.CONF_PLATFORM: "event",
            event_trigger.CONF_EVENT_TYPE: NEST_EVENT,
            event_trigger.CONF_EVENT_DATA: {
                CONF_DEVICE_ID: config[CONF_DEVICE_ID],
                CONF_TYPE: config[CONF_TYPE],
            },
        }
    )
    return await event_trigger.async_attach_trigger(
        hass, event_config, action, automation_info, platform_type="device"
    )
async def async_attach_trigger(
    hass: HomeAssistant,
    config: ConfigType,
    action: AutomationActionType,
    automation_info: AutomationTriggerInfo,
) -> Callable[[], None]:
    """Attach a trigger."""
    result = get_hubitat_device(hass, config[CONF_DEVICE_ID])

    hubitat_device = result[0]
    hub = result[1]

    if hubitat_device is None or hub is None:
        _LOGGER.warning(
            "Could not find Hubitat device for ID %s", config[CONF_DEVICE_ID]
        )
        raise InvalidDeviceAutomationConfig

    # Event data should match up to the data a hubitat_event event would
    # contain
    event_data = {
        ATTR_DEVICE_ID: hubitat_device.id,
        ATTR_HUB: hub.id,
        ATTR_ATTRIBUTE: config[CONF_TYPE],
    }
    if CONF_SUBTYPE in config:
        event_data[ATTR_VALUE] = config[CONF_SUBTYPE]

    trigger = event.TRIGGER_SCHEMA(
        {
            event.CONF_PLATFORM: "event",
            event.CONF_EVENT_TYPE: CONF_HUBITAT_EVENT,
            event.CONF_EVENT_DATA: event_data,
        }
    )

    _LOGGER.debug("Attaching trigger %s", trigger)

    return await event.async_attach_trigger(
        hass, trigger, action, automation_info, platform_type="device"
    )
Exemple #18
0
async def async_attach_trigger(hass, config, action, automation_info):
    """Listen for tag_scanned events based on configuration."""
    tag_id = config.get(TAG_ID)
    device_id = config.get(DEVICE_ID)
    event_data = {TAG_ID: tag_id}

    if device_id:
        event_data[DEVICE_ID] = device_id

    event_config = {
        event_trigger.CONF_PLATFORM: "event",
        event_trigger.CONF_EVENT_TYPE: EVENT_TAG_SCANNED,
        event_trigger.CONF_EVENT_DATA: event_data,
    }
    event_config = event_trigger.TRIGGER_SCHEMA(event_config)

    return await event_trigger.async_attach_trigger(hass,
                                                    event_config,
                                                    action,
                                                    automation_info,
                                                    platform_type=DOMAIN)
Exemple #19
0
async def async_attach_trigger(
    bridge: "HueBridge",
    device_entry: DeviceEntry,
    config: ConfigType,
    action: "AutomationActionType",
    automation_info: "AutomationTriggerInfo",
) -> CALLBACK_TYPE:
    """Listen for state changes based on configuration."""
    hass = bridge.hass
    event_config = event_trigger.TRIGGER_SCHEMA(
        {
            event_trigger.CONF_PLATFORM: "event",
            event_trigger.CONF_EVENT_TYPE: ATTR_HUE_EVENT,
            event_trigger.CONF_EVENT_DATA: {
                CONF_DEVICE_ID: config[CONF_DEVICE_ID],
                CONF_TYPE: config[CONF_TYPE],
                CONF_SUBTYPE: config[CONF_SUBTYPE],
            },
        }
    )
    return await event_trigger.async_attach_trigger(
        hass, event_config, action, automation_info, platform_type="device"
    )
Exemple #20
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.hass,
            event_config,
            self.action,
            self.automation_info,
            platform_type="device",
        )
Exemple #21
0
        )
    device_type = _device_model_to_type(device.model)
    _, serial = list(device.identifiers)[0]
    schema = DEVICE_TYPE_SCHEMA_MAP[device_type]
    valid_buttons = DEVICE_TYPE_SUBTYPE_MAP_TO_LEAP[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: serial,
            ATTR_LEAP_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(hass,
                                                    event_config,
                                                    action,
                                                    trigger_info,
                                                    platform_type="device")


def get_button_device_by_dr_id(hass: HomeAssistant, device_id: str):
    """Get a lutron device for the given device id."""
    if DOMAIN not in hass.data:
        return None

    for entry_id in hass.data[DOMAIN]:
        data: LutronCasetaData = hass.data[DOMAIN][entry_id]
        if device := data.button_devices.get(device_id):