Skip to content

Unify the two event systems (events.py string emitter vs typed mqtt_events.py) #102

Description

@eman

Summary

Deferred follow-up from #95 (comprehensive repo evaluation, batch 6: architecture cleanup).

The library currently ships two parallel event mechanisms:

  • src/nwp500/events.py: a generic, string-keyed EventEmitter/EventListener callback system (~422 lines).
  • src/nwp500/mqtt_events.py: typed, frozen dataclass events (e.g. StatusReceivedEvent, FeatureReceivedEvent) (~372 lines).

Having two separate systems for conceptually the same thing ("something happened, notify subscribers") means callers must learn two different subscription APIs, and library maintainers must keep both consistent as new event types are added.

Suggested approach

  • Decide on a single target design: either extend the typed mqtt_events dataclasses to cover all events currently emitted via the string-based EventEmitter, or generalize EventEmitter to support typed payloads while keeping today's ergonomics.
  • Migrate all internal emit/subscribe call sites to the unified system.
  • Since the project has no backward-compatibility requirement, remove the redundant system entirely rather than deprecating it, and document the breaking change with migration guidance in CHANGELOG.rst.

Acceptance criteria

  • A single event system remains; the other is removed.
  • All existing event-driven behavior (device/system updates) continues to work, covered by existing tests.
  • ruff/mypy clean.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions