refactor: Extract preset management into PresetManager#1950
Draft
cl445 wants to merge 2 commits intoKartoffelToby:developfrom
Draft
refactor: Extract preset management into PresetManager#1950cl445 wants to merge 2 commits intoKartoffelToby:developfrom
cl445 wants to merge 2 commits intoKartoffelToby:developfrom
Conversation
Replace 5 loose preset attributes (_preset_mode, _preset_temperature, _enabled_presets, _preset_temperatures, _original_preset_temperatures) with a single PresetManager dataclass that encapsulates mode tracking, temperature storage, and save/restore logic. - New PresetManager with activate/deactivate/update_temperature/get_temperature API - Simplify async_set_preset_mode from ~100 to ~35 lines - Update number.py to use PresetManager API instead of direct dict access - Add 22 unit tests for PresetManager - mypy --strict clean, no typing workarounds
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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
climate.pyinto a newPresetManagerdataclass inutils/preset_manager.pyasync_set_preset_modefrom ~100 lines to ~35 lines by delegating save/restore/clamping logic toPresetManager.activate()number.py(BetterThermostatPresetNumber) to usepreset_mgr.update_temperature()/get_temperature()instead of direct dict accessDetails
New file:
utils/preset_manager.py(~100 lines)PresetManagerdataclass withmode,temperatures,enabled_presets,saved_temperatureactivate(preset, current_temp, min_temp, max_temp)→ handles save/restore/clamping, returns new target tempdeactivate()→ returns to PRESET_NONE, returns saved tempupdate_temperature()/get_temperature()→ API for Number entitiesavailable_modesproperty →[PRESET_NONE] + enabled_presets--strictclean, noAny/cast/type: ignoreworkaroundsRemoved from
climate.py:self._preset_mode→self.preset_mgr.modeself._preset_temperature→self.preset_mgr.saved_temperatureself._preset_temperatures→self.preset_mgr.temperaturesself._enabled_presets→self.preset_mgr.enabled_presetsself._original_preset_temperatures(dead code, never read)Test plan
tests/unit/test_preset_manager.pycovering activate, deactivate, clamping, saved_temperature lifecycle, instance isolationmypy --strictclean forpreset_manager.py