Skip to content

Clarify and de-duplicate the event system (#102)#109

Merged
eman merged 1 commit into
mainfrom
pr-102-events-docs
Jul 6, 2026
Merged

Clarify and de-duplicate the event system (#102)#109
eman merged 1 commit into
mainfrom
pr-102-events-docs

Conversation

@eman

@eman eman commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary

Issue #102's premise is partly inaccurate: events.py and mqtt_events.py are not two competing event mechanisms. EventEmitter (events.py) is the sole delivery mechanism; mqtt_events.py only supplies the event-name registry (MqttClientEvents) and the typed dataclass payloads carried by each event. They are complementary. This PR documents that relationship and removes the one genuine duplication.

Changes

  • De-duplicate event names: internal emit call sites in mqtt/state_tracker.py, mqtt/client.py and mqtt/subscriptions.py previously hardcoded raw event-name strings ("temperature_changed", "connection_resumed", etc.) that were also defined as MqttClientEvents constants. They now reference the constants, so each event name is defined in exactly one place.
  • Documentation: clarified the mechanism-vs-vocabulary relationship in the events.py and mqtt_events.py module docstrings and in docs/reference/python_api/events.rst.
  • Tests: new tests/test_mqtt_events.py covers the registry (get_all_events, get_event_value) and verifies that subscribing with a MqttClientEvents constant delivers the matching typed payload through the emitter.

No mechanism was removed; there is no behavior change. Per the discussion, a full rewrite/merge was not warranted because the two modules were never duplicate mechanisms.

Validation

  • scripts/lint.py (ruff + pyright): passed
  • mypy src/nwp500: no issues in 50 files
  • pytest: 621 passed

Note: this PR is stacked on #101 (base branch pr-101-awscrt-wrap) and should merge after it.

Closes #102


Recreated because #107 was auto-closed when its stacked base branch (pr-101-awscrt-wrap) was deleted after PR #105 merged. Retargeted to main.

events.py (EventEmitter) is the sole delivery mechanism; mqtt_events.py
provides the MqttClientEvents name registry and typed dataclass payloads it
carries. Internal emit call sites in state_tracker.py, client.py and
subscriptions.py now reference the MqttClientEvents constants instead of
duplicating raw event-name strings, so each event name is defined once.
Update module docstrings and the event-system reference docs to document the
relationship, and add tests covering typed-payload delivery through the
emitter.
@eman
eman force-pushed the pr-102-events-docs branch from 90cbc79 to 59169f5 Compare July 6, 2026 17:28
@eman
eman merged commit 14b0878 into main Jul 6, 2026
7 checks passed
@eman
eman deleted the pr-102-events-docs branch July 6, 2026 17:30
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.

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

1 participant