1
0
mirror of https://github.com/home-assistant/core.git synced 2026-06-08 16:37:30 +01:00
Files
core/homeassistant/components/text/trigger.py
T
Erik Montnemery 8dd35cb129 Add entity triggers and conditions (#156852)
Co-authored-by: Abílio Costa <abmantis@users.noreply.github.com>
Co-authored-by: Artur Pragacz <49985303+arturpragacz@users.noreply.github.com>
Co-authored-by: abmantis <amfcalt@gmail.com>
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
Co-authored-by: Franck Nijhof <git@frenck.dev>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2025-11-25 17:52:20 +01:00

37 lines
1.0 KiB
Python

"""Provides triggers for texts."""
from homeassistant.const import STATE_UNAVAILABLE, STATE_UNKNOWN
from homeassistant.core import HomeAssistant, State
from homeassistant.helpers.trigger import (
ENTITY_STATE_TRIGGER_SCHEMA,
EntityTriggerBase,
Trigger,
)
from .const import DOMAIN
class TextChangedTrigger(EntityTriggerBase):
"""Trigger for text entity when its content changes."""
_domain = DOMAIN
_schema = ENTITY_STATE_TRIGGER_SCHEMA
def is_from_state(self, from_state: State, to_state: State) -> bool:
"""Check if the state matches the origin state."""
return from_state.state != to_state.state
def is_to_state(self, state: State) -> bool:
"""Check if the state matches the target state."""
return state.state not in (STATE_UNAVAILABLE, STATE_UNKNOWN)
TRIGGERS: dict[str, type[Trigger]] = {
"changed": TextChangedTrigger,
}
async def async_get_triggers(hass: HomeAssistant) -> dict[str, type[Trigger]]:
"""Return the triggers for texts."""
return TRIGGERS