Skip to content

Slim mqtt/client.py toward a thin facade (#99)#110

Merged
eman merged 1 commit into
mainfrom
pr-99-slim-client
Jul 6, 2026
Merged

Slim mqtt/client.py toward a thin facade (#99)#110
eman merged 1 commit into
mainfrom
pr-99-slim-client

Conversation

@eman

@eman eman commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary

Slims NavienMqttClient toward a thin façade by extracting cohesive, low-risk method groups into focused helper modules, while keeping the public API and behavior identical.

Changes

  • New src/nwp500/mqtt/_control_commands.pyDeviceControlCommandsMixin: the ~40 device-control convenience methods (set_power, set_dhw_temperature, configure_tou_schedule, firmware/wifi/recirculation commands, etc.) that forward to MqttDeviceController.
  • New src/nwp500/mqtt/_device_subscriptions.pyDeviceSubscriptionsMixin: the typed subscribe_*/unsubscribe_* device-subscription proxies (plus the _delegate_subscription helper) that forward to MqttSubscriptionManager.
  • NavienMqttClient now inherits both mixins; the public API surface is unchanged (verified by test_public_api and the full suite).
  • mqtt/client.py: 1572 → 1196 lines (−376). What remains is __init__, connection-lifecycle orchestration (connect/reconnect/recover), periodic-request management, ensure_device_info_cached, and state properties.

Scope note

The connection-lifecycle orchestration (connect, _active_reconnect, _deep_reconnect, recover_connection, clean-session handling) was intentionally left in client.py. It mutates ~15 pieces of client state and the reconnection/reliability tests patch nwp500.mqtt.client.MqttConnection directly, so extracting it is a larger, higher-risk change better suited to a dedicated follow-up. This PR takes the safe, behavior-preserving decomposition.

Validation

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

Note: stacked on #101#102 (base branch pr-102-events-docs); merge after those.

Closes #99


Recreated because #108 was auto-closed when its stacked base branch (pr-102-events-docs) was deleted after PR #107/#109 merged. Retargeted to main.

Extract the ~40 device control command proxies and the typed subscribe_*/
unsubscribe_* device-subscription proxies from NavienMqttClient into two
focused mixins (DeviceControlCommandsMixin in _control_commands.py and
DeviceSubscriptionsMixin in _device_subscriptions.py). NavienMqttClient now
inherits both, keeping its public API unchanged while client.py shrinks from
~1572 to ~1196 lines and reads as connection orchestration plus a public
facade. No behavior change.
@eman
eman force-pushed the pr-99-slim-client branch from 50665c5 to 6014e44 Compare July 6, 2026 17:34
@eman
eman merged commit 02ea312 into main Jul 6, 2026
7 checks passed
@eman
eman deleted the pr-99-slim-client branch July 6, 2026 17:35
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.

Slim mqtt/client.py (~1500 lines) into a thin façade over helper modules

1 participant