Slim mqtt/client.py toward a thin facade (#99)#110
Merged
Conversation
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.
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.
Summary
Slims
NavienMqttClienttoward a thin façade by extracting cohesive, low-risk method groups into focused helper modules, while keeping the public API and behavior identical.Changes
src/nwp500/mqtt/_control_commands.py—DeviceControlCommandsMixin: the ~40 device-control convenience methods (set_power,set_dhw_temperature,configure_tou_schedule, firmware/wifi/recirculation commands, etc.) that forward toMqttDeviceController.src/nwp500/mqtt/_device_subscriptions.py—DeviceSubscriptionsMixin: the typedsubscribe_*/unsubscribe_*device-subscription proxies (plus the_delegate_subscriptionhelper) that forward toMqttSubscriptionManager.NavienMqttClientnow inherits both mixins; the public API surface is unchanged (verified bytest_public_apiand 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 inclient.py. It mutates ~15 pieces of client state and the reconnection/reliability tests patchnwp500.mqtt.client.MqttConnectiondirectly, 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): passedmypy src/nwp500: no issues in 52 filespytest: 621 passedNote: 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.