1 """Samsung TV device turn on trigger."""
3 from __future__
import annotations
5 import voluptuous
as vol
24 from ..const
import DOMAIN
25 from ..helpers
import (
26 async_get_device_entry_by_device_id,
27 async_get_device_id_from_entity_id,
31 PLATFORM_TYPE = f
"{DOMAIN}.{__name__.rsplit('.', maxsplit=1)[-1]}"
33 TRIGGER_TYPE_TURN_ON =
"turn_on"
35 TRIGGER_SCHEMA = vol.All(
36 cv.TRIGGER_BASE_SCHEMA.extend(
38 vol.Required(CONF_PLATFORM): PLATFORM_TYPE,
39 vol.Optional(ATTR_DEVICE_ID): vol.All(cv.ensure_list, [cv.string]),
40 vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
43 cv.has_at_least_one_key(ATTR_ENTITY_ID, ATTR_DEVICE_ID),
48 """Return data for a turn on trigger."""
51 CONF_PLATFORM:
"device",
52 CONF_DEVICE_ID: device_id,
54 CONF_TYPE: PLATFORM_TYPE,
61 action: TriggerActionType,
62 trigger_info: TriggerInfo,
64 platform_type: str = PLATFORM_TYPE,
65 ) -> CALLBACK_TYPE |
None:
66 """Attach a trigger."""
68 if ATTR_DEVICE_ID
in config:
69 device_ids.update(config.get(ATTR_DEVICE_ID, []))
71 if ATTR_ENTITY_ID
in config:
75 for entity_id
in config.get(ATTR_ENTITY_ID, [])
79 trigger_data = trigger_info[
"trigger_data"]
83 for device_id
in device_ids:
85 device_name = device.name_by_user
or device.name
89 CONF_PLATFORM: platform_type,
90 ATTR_DEVICE_ID: device_id,
91 "description": f
"Samsung turn on trigger for {device_name}",
97 PluggableAction.async_attach_trigger(
98 hass, turn_on_trigger, action, {
"trigger": variables}
104 """Remove state listeners async."""
DeviceEntry async_get_device_entry_by_device_id(HomeAssistant hass, str device_id)
str async_get_device_id_from_entity_id(HomeAssistant hass, str entity_id)
CALLBACK_TYPE|None async_attach_trigger(HomeAssistant hass, ConfigType config, TriggerActionType action, TriggerInfo trigger_info, *str platform_type=PLATFORM_TYPE)
dict[str, str] async_get_turn_on_trigger(str device_id)
None async_remove(HomeAssistant hass, str intent_type)