Event
event
event domain implementation (read-only, stateless triggers).
Home Assistant's event domain (added in 2023.8) represents stateless
trigger entities such as button presses, doorbell rings, and remote
control actions. The entity's state is an ISO-8601 timestamp of the
most recent event, while event_type (the kind of event that just
fired) and event_types (all possible event types) live in the
attributes.
This module exposes those values as typed properties and provides a
single intent-driven listener decorator, Event.on_event, that can be
used either bare (@button.on_event) or with a filter
(@button.on_event(event_type="double_press")).
SPEC
module-attribute
SPEC: DomainSpec[Event] = register_domain(DomainSpec(name='event', entity_cls=Event))
The DomainSpec registered with the shared DomainRegistry.
Event
Bases: Entity
A read-only Home Assistant event entity.
Event entities represent discrete, stateless triggers (e.g. a
button press). Each fire updates the entity's state to the new
event timestamp and populates the event_type attribute with the
kind of event that occurred.
Listener callbacks registered via on_event receive a single
positional argument: the event_type string of the event that
just fired (e.g. "single_press").
Source code in src/haclient/domains/event.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
event_type
property
event_type: str | None
Type of the most recent event (e.g. "single_press").
Returns:
| Type | Description |
|---|---|
str or None
|
The event type from the entity's attributes, or |
event_types
property
event_types: list[str] | None
All event types this entity is capable of firing.
Returns:
| Type | Description |
|---|---|
list of str or None
|
The declared event-type catalogue, or |
device_class
property
device_class: str | None
Device class (e.g. "button", "doorbell").
on_event
on_event(func: Callable[[str], Any]) -> Callable[[str], Any]
on_event(*, event_type: str) -> Callable[[Callable[[str], Any]], Callable[[str], Any]]
on_event(func: Callable[[str], Any] | None = None, *, event_type: str | None = None) -> Any
Register a listener for events fired by this entity.
May be used either as a bare decorator to receive every event,
or as a parameterised decorator to filter by event_type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
callable
|
Sync or async callable receiving a single positional
argument: the event-type string that just fired. Supplied
implicitly when used as |
None
|
event_type
|
(str or None, keyword - only)
|
Restrict the listener to a specific event-type. When
|
None
|
Returns:
| Type | Description |
|---|---|
callable
|
When called as a bare decorator, returns func. When called
with |
Examples:
Listen to every event::
@button.on_event
async def any_press(event_type):
...
Filter to a specific event type::
@button.on_event(event_type="double_press")
async def double(event_type):
...
Source code in src/haclient/domains/event.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
remove_event_listener
remove_event_listener(func: Callable[[str], Any]) -> None
Remove a previously registered event listener.
Searches all registered buckets (catch-all and per-event-type) and removes the first match. Unknown callables are silently ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
callable
|
The exact callable previously registered via |
required |
Source code in src/haclient/domains/event.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |