Skip to content

Consolidate error message constants into ErrorMsg class#1432

Merged
liudger merged 1 commit intomainfrom
refactor/consolidate-error-messages
Apr 10, 2026
Merged

Consolidate error message constants into ErrorMsg class#1432
liudger merged 1 commit intomainfrom
refactor/consolidate-error-messages

Conversation

@liudger
Copy link
Copy Markdown
Owner

@liudger liudger commented Apr 10, 2026

This pull request refactors how error messages are managed and referenced throughout the bsblan codebase. Instead of using individual string constants for each error message, all error messages are now encapsulated in a new ErrorMsg class. All code that previously referenced the old constants has been updated to use the new class attributes, improving maintainability and consistency.

Key changes include:

Error Message Refactoring:

  • Introduced a new ErrorMsg class in constants.py to centralize all error message strings, replacing the previous pattern of individual error message constants.
  • Updated all references in bsblan.py to use ErrorMsg.<ATTRIBUTE> instead of the old error message constants, ensuring consistent error handling throughout the codebase. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24]

Test Updates:

  • Modified tests to reference the new ErrorMsg class attributes instead of the old error message constants, ensuring tests remain valid and up to date. [1] [2] [3]

This refactor improves code clarity and makes it easier to manage and update error messages in the future.

Replace 19 individual *_ERROR_MSG / *_MSG constants with an ErrorMsg
class in constants.py, reducing import clutter across bsblan.py and
14 test files.
@liudger liudger added the refactor Improvement of existing code, not introducing new features. label Apr 10, 2026
Copilot AI review requested due to automatic review settings April 10, 2026 19:09
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.89%. Comparing base (4d129f5) to head (f4555c3).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1432   +/-   ##
=======================================
  Coverage   99.89%   99.89%           
=======================================
  Files           6        6           
  Lines         986      987    +1     
  Branches      139      139           
=======================================
+ Hits          985      986    +1     
  Partials        1        1           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud
Copy link
Copy Markdown

@liudger liudger merged commit fc9bb94 into main Apr 10, 2026
17 checks passed
@liudger liudger deleted the refactor/consolidate-error-messages branch April 10, 2026 19:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors error-message handling in the bsblan async client by consolidating scattered error message string constants into a single ErrorMsg namespace and updating call sites accordingly, aiming to improve consistency and maintainability.

Changes:

  • Introduces ErrorMsg in src/bsblan/constants.py and migrates existing error message strings into class attributes.
  • Updates src/bsblan/bsblan.py to raise errors using ErrorMsg.<NAME> instead of *_ERROR_MSG constants.
  • Updates multiple tests to reference ErrorMsg so assertions continue to validate the correct error messages.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/bsblan/constants.py Replaces module-level error message constants with the new ErrorMsg class.
src/bsblan/bsblan.py Updates all internal error raising to use ErrorMsg attributes.
tests/test_version_errors.py Updates version-related error assertions to use ErrorMsg.
tests/test_thermostat.py Updates multi-parameter error assertion to use ErrorMsg.
tests/test_temperature_validation.py Updates temperature-range error assertion to use ErrorMsg.
tests/test_set_hotwater.py Updates hot water validation error assertions to use ErrorMsg.
tests/test_initialization.py Updates API-version error assertion to use ErrorMsg.
tests/test_include_parameter.py Updates include-list validation assertions to use ErrorMsg.
tests/test_dhw_time_switch.py Updates multi-parameter error assertion to use ErrorMsg.
tests/test_configuration.py Updates _validate_single_parameter error assertions to use ErrorMsg.
tests/test_circuit.py Updates multi-parameter error assertion to use ErrorMsg.
tests/test_bsblan_edge_cases.py Updates API-data-not-initialized error assertion to use ErrorMsg.
tests/test_api_validation.py Updates validator/data-not-initialized error assertions to use ErrorMsg.
tests/test_api_initialization.py Updates API-version error assertion to use ErrorMsg.

Comment on lines 465 to +476
# Error Messages
NO_STATE_ERROR_MSG: Final[str] = "No state provided."
NO_SCHEDULE_ERROR_MSG: Final[str] = "No schedule provided."
VERSION_ERROR_MSG: Final[str] = "Version not supported"
FIRMWARE_VERSION_ERROR_MSG: Final[str] = "Firmware version not available"
TEMPERATURE_RANGE_ERROR_MSG: Final[str] = "Temperature range not initialized"
API_VERSION_ERROR_MSG: Final[str] = "API version not set"
MULTI_PARAMETER_ERROR_MSG: Final[str] = "Only one parameter can be set at a time"
SESSION_NOT_INITIALIZED_ERROR_MSG: Final[str] = "Session not initialized"
API_DATA_NOT_INITIALIZED_ERROR_MSG: Final[str] = "API data not initialized"
API_VALIDATOR_NOT_INITIALIZED_ERROR_MSG: Final[str] = "API validator not initialized"
SECTION_NOT_FOUND_ERROR_MSG: Final[str] = "Section '{}' not found in API data"
INVALID_CIRCUIT_ERROR_MSG: Final[str] = "Invalid circuit number: {}. Must be 1 or 2."
INVALID_RESPONSE_ERROR_MSG: Final[str] = (
"Invalid response format from BSB-LAN device: {}"
)
EMPTY_SECTION_PARAMS_ERROR_MSG: Final[str] = (
"No valid parameters found for section '{}'. "
"The device may not support this circuit or section."
)
class ErrorMsg:
"""Error message constants for BSBLAN."""

NO_STATE = "No state provided."
NO_SCHEDULE = "No schedule provided."
VERSION = "Version not supported"
FIRMWARE_VERSION = "Firmware version not available"
TEMPERATURE_RANGE = "Temperature range not initialized"
API_VERSION = "API version not set"
MULTI_PARAMETER = "Only one parameter can be set at a time"
SESSION_NOT_INITIALIZED = "Session not initialized"
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacing the module-level *_ERROR_MSG constants with ErrorMsg is a breaking API change for any downstream code importing those names from bsblan.constants. Consider keeping backward-compatible aliases (e.g., NO_STATE_ERROR_MSG = ErrorMsg.NO_STATE, etc.) and deprecating them over at least one release cycle to avoid unexpected runtime ImportErrors.

Copilot uses AI. Check for mistakes.
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

refactor Improvement of existing code, not introducing new features.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants