Skip to content

feat(domains): add Event domain (#36)#68

Merged
Faerkeren merged 1 commit into
mainfrom
feat/event-domain
May 26, 2026
Merged

feat(domains): add Event domain (#36)#68
Faerkeren merged 1 commit into
mainfrom
feat/event-domain

Conversation

@Faerkeren

Copy link
Copy Markdown
Contributor

Closes #36.

Issue validity

Valid feature request. Home Assistant's event domain (added in 2023.8) represents stateless triggers (button presses, doorbells, remote actions). Without a typed domain helper, users have to subscribe to raw state changes and parse event_type from attributes manually — inconsistent with every other domain in the library.

Fix

New Event entity in src/haclient/domains/event.py:

  • State propertiesevent_type, event_types, device_class parsed from attributes; all return None when missing (graceful degradation as required by AGENTS.md).
  • Listener decoratoron_event is polymorphic via @overload:
    • @button.on_event registers a catch-all listener.
    • @button.on_event(event_type="double_press") registers a filtered listener.
  • Dispatch semantics — overrides _handle_state_changed to fire callbacks only when the state timestamp advances and an event_type attribute is present. Identical-state replays and transitions to unknown/unavailable are ignored.
  • Removal APIremove_event_listener mirrors the existing remove_granular_listener shape.
  • Registered in domains/__init__.py so ha.event("name") works out of the box.

Tests & checks

  • 7 new tests in tests/test_event_domain.py cover: properties, bare decorator, filtered decorator, no-dispatch-on-same-state, no-dispatch-on-unavailable/missing-event-type, listener removal, and TypeError when both func and event_type are passed.
  • Full suite: 277 passed.
  • Coverage: 96.94% total; domains/event.py at 100%.
  • ruff check + ruff format --check: clean.
  • mypy src (strict): no issues.

Adds Event domain for Home Assistant's stateless trigger entities
(button presses, doorbell rings, remote actions; HA 2023.8+).

- event_type / event_types / device_class properties read from
  the entity's attributes and degrade to None gracefully.
- on_event listener decorator usable bare (every event) or with
  event_type=... to filter by a specific event type.
- Dispatch fires only when the state timestamp advances, so
  identical-state replays and transitions to unknown/unavailable
  are correctly ignored.
- remove_event_listener mirrors the existing granular-listener
  removal API.
@Faerkeren Faerkeren merged commit bf17b53 into main May 26, 2026
12 checks passed
@Faerkeren Faerkeren deleted the feat/event-domain branch May 26, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add Event domain support

1 participant