feat: add EventBus.remove() to unsubscribe handlers
Ā
HA
1mo ago+160+160+012345678901234567890123456789-14-14-01234567890123456789
What
Add a public EventBus.remove(event_pattern, handler) method so callers can unsubscribe a handler registered with EventBus.on(). Returns True if the handler was found and removed, False otherwise.
Also extract the event-key resolution from on() into _get_event_key() and reuse it in on() and remove(), and refactor expect() cleanup to use remove().
Why
There is no way to unsubscribe after EventBus.on() ā the only cleanup path is expect()'s internal self.handlers[...].remove(...). Closes #5.
How tested
- Added
tests/test_remove_handler.py(4 cases: by class, by string name, scoped removal, wildcard*). - Core suite: 63 passed.
š¤ Generated with Claude Code
Summary by cubic
Adds EventBus.remove() to unsubscribe a handler registered with EventBus.on(). Returns True if the handler was found and removed, False otherwise. Closes #5.
Changes
- Extracts event-key resolution into
_get_event_key()and reuses it inon(),remove(), andexpect()cleanup. - Adds overloads mirroring
on()so typed handlers remain valid when removed, and drops the event key from the registry once its last handler is gone. - Adds tests covering removal by class, string name, scoped handlers, and
*wildcard.