Refactor parameter constants into configuration classes#1433
Conversation
…rParams, and Validation classes
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1433 +/- ##
=======================================
Coverage 99.89% 99.89%
=======================================
Files 6 6
Lines 987 990 +3
Branches 139 139
=======================================
+ Hits 986 989 +3
Partials 1 1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR refactors bsblan.constants by grouping previously module-level constants into focused configuration classes (CircuitConfig, Validation, HotWaterParams) and updates the client and tests to reference these class attributes, improving organization and encapsulation across the library.
Changes:
- Introduced
CircuitConfig,Validation, andHotWaterParamsclasses to organize circuit, validation, and hot water constant groups. - Updated
BSBLANclient logic to use the new class-based constants (circuits, HVAC mode validation, hot water parameter grouping, DHW time program mappings). - Updated constants-related tests to reference the new
HotWaterParamsgroups.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/bsblan/constants.py |
Replaces several module-level constant groupings with CircuitConfig, Validation, and HotWaterParams classes. |
src/bsblan/bsblan.py |
Updates constant imports/usages to the new class attributes for circuit probing, validation, and hot water operations. |
tests/test_constants.py |
Updates tests to validate hot water group completeness/overlap/counts via HotWaterParams. |
|
|
||
| # Marker value returned by BSB-LAN for parameters on inactive circuits | ||
| INACTIVE_CIRCUIT_MARKER: Final[str] = "---" | ||
| VALID: Final[set[int]] = {1, 2} |
There was a problem hiding this comment.
CircuitConfig.VALID hard-codes {1, 2} while the module also defines MIN_CIRCUIT/MAX_CIRCUIT (now unused). This duplicates the source of truth and can drift if circuit support changes; consider either removing MIN_CIRCUIT/MAX_CIRCUIT or deriving CircuitConfig.VALID from them (and/or using them consistently in validation/error messages).
| VALID: Final[set[int]] = {1, 2} | |
| VALID: Final[set[int]] = set(range(MIN_CIRCUIT, MAX_CIRCUIT + 1)) |
| @@ -1548,7 +1536,9 @@ async def set_hot_water_schedule(self, schedule: DHWSchedule) -> None: | |||
| # Invert DHW_TIME_PROGRAM_PARAMS to get day_name -> param_id mapping | |||
There was a problem hiding this comment.
The comment still references DHW_TIME_PROGRAM_PARAMS, but the code now uses HotWaterParams.TIME_PROGRAMS. Updating this avoids misleading future maintenance (especially since this method is part of the public schedule-setting API).
| # Invert DHW_TIME_PROGRAM_PARAMS to get day_name -> param_id mapping | |
| # Invert HotWaterParams.TIME_PROGRAMS to get day_name -> param_id mapping |



This pull request refactors how constants are organized and accessed in the
bsblancodebase. The main improvement is the grouping of related constants into dedicated classes (CircuitConfig,Validation, andHotWaterParams) instead of using module-level variables. This change improves code clarity, maintainability, and encapsulation, and all usages throughout the codebase and tests have been updated accordingly.Refactoring and Encapsulation of Constants:
CircuitConfigclass inconstants.pyto encapsulate all circuit-related constants, such as valid circuit numbers, section mappings, thermostat parameters, probe/status parameters, and inactive marker. All references to these constants inbsblan.pywere updated to use the new class attributes. [1] [2] [3] [4] [5] [6] [7] [8] [9]Validationclass inconstants.pyto group validation-related constants such as valid HVAC modes and valid year ranges. All usages inbsblan.pynow reference these via the class. [1] [2] [3]HotWaterParamsclass inconstants.pyfor all hot water parameter groups and mappings (essential, config, schedule, settable, and time programs). All usages inbsblan.pyandtest_constants.pywere updated to use this class. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16]Test Updates:
test_constants.pyto use the newHotWaterParamsclass attributes instead of the old module-level constants. [1] [2] [3] [4] [5]These changes are purely organizational and do not alter any functional logic, but they make the codebase more modular and easier to maintain.