feat(domains): add Event domain (#36)#68
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #36.
Issue validity
Valid feature request. Home Assistant's
eventdomain (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 parseevent_typefrom attributes manually — inconsistent with every other domain in the library.Fix
New
Evententity insrc/haclient/domains/event.py:event_type,event_types,device_classparsed from attributes; all returnNonewhen missing (graceful degradation as required by AGENTS.md).on_eventis polymorphic via@overload:@button.on_eventregisters a catch-all listener.@button.on_event(event_type="double_press")registers a filtered listener._handle_state_changedto fire callbacks only when the state timestamp advances and anevent_typeattribute is present. Identical-state replays and transitions tounknown/unavailableare ignored.remove_event_listenermirrors the existingremove_granular_listenershape.domains/__init__.pysoha.event("name")works out of the box.Tests & checks
tests/test_event_domain.pycover: properties, bare decorator, filtered decorator, no-dispatch-on-same-state, no-dispatch-on-unavailable/missing-event-type, listener removal, andTypeErrorwhen bothfuncandevent_typeare passed.domains/event.pyat 100%.ruff check+ruff format --check: clean.mypy src(strict): no issues.