Skip to content

Conversation

@liudger
Copy link
Owner

@liudger liudger commented Jan 3, 2026

This pull request refactors how HVAC action status codes are handled and mapped to simplified categories. Instead of using multiple sets of status codes and manual mappings, the code now uses new enums (HeatingCircuitStatus and HVACActionCategory) and a helper function to provide a more maintainable and extensible approach. This change improves clarity and allows for easier future updates to status code handling.

Refactoring and API improvements:

  • Introduced HeatingCircuitStatus and HVACActionCategory enums in src/bsblan/constants.py, replacing individual status code sets for HVAC actions. These enums provide descriptive names for vendor-specific status codes and their corresponding action categories.
  • Added the get_hvac_action_category helper function to map raw status codes to their action category, simplifying lookups and fallback handling.

Codebase cleanup and usage updates:

  • Removed legacy status code sets (BSBLAN_HVAC_ACTION_*) and updated all imports and exports in src/bsblan/__init__.py and related files to use the new enums and helper function. [1] [2] [3] [4]
  • Refactored examples/control.py to use the new enum-based approach for mapping and displaying HVAC actions, including updating the logic in get_hvac_action_name and print_state to leverage the new helpers and provide both category and specific status name. [1] [2] [3] [4]
  • Updated test imports in tests/test_constants.py to use the new enums and helper function, removing references to the old status code sets.

Copilot AI review requested due to automatic review settings January 3, 2026 18:17
@liudger liudger added the refactor Improvement of existing code, not introducing new features. label Jan 3, 2026
@codecov
Copy link

codecov bot commented Jan 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.60%. Comparing base (96d6f56) to head (81ca0cb).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1298      +/-   ##
==========================================
+ Coverage   99.55%   99.60%   +0.05%     
==========================================
  Files           6        6              
  Lines         678      767      +89     
  Branches       82       83       +1     
==========================================
+ Hits          675      764      +89     
  Partials        3        3              

☔ 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

sonarqubecloud bot commented Jan 3, 2026

@liudger liudger merged commit 38183a9 into main Jan 3, 2026
26 checks passed
Copy link
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 pull request refactors the HVAC action status code handling system from a set-based approach to an enum-based architecture. The changes introduce strongly-typed enums for heating circuit status codes and action categories, replacing manual set memberships and lookups with a more maintainable and self-documenting solution.

Key changes:

  • Introduced HeatingCircuitStatus IntEnum with 70 vendor-specific status codes and HVACActionCategory enum for 8 simplified action states
  • Added get_hvac_action_category() helper function that maps raw status codes to action categories with fallback to IDLE
  • Removed 7 legacy BSBLAN_HVAC_ACTION_* constants (sets) and updated all imports, exports, and usages throughout the codebase

Reviewed changes

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

File Description
src/bsblan/constants.py Replaced status code sets with HeatingCircuitStatus and HVACActionCategory enums; added get_hvac_action_category() helper function and internal _STATUS_TO_CATEGORY mapping dictionary
src/bsblan/__init__.py Updated package exports to remove old BSBLAN_HVAC_ACTION_* constants and export new enums and helper function
examples/control.py Refactored get_hvac_action_name() to use enum-based lookup; enhanced print_state() to display both status name and category using new enums
tests/test_constants.py Replaced set-based tests with comprehensive enum tests covering category values, status mappings, value conversions, and package exports

Comment on lines 118 to 119
except (ValueError, TypeError):
hvac_action_mapped = "unknown"
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

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

In the exception handler, the status_name variable is not being set when an error occurs. This could lead to status_name being undefined if the code in the try block fails before line 117. Consider setting status_name = "unknown" alongside hvac_action_mapped = "unknown" in the exception handler to ensure both variables are properly initialized in all code paths.

Copilot uses AI. Check for mistakes.
@liudger liudger deleted the refactor-hvac0action branch January 3, 2026 18:29
@github-actions github-actions bot locked and limited conversation to collaborators Jan 5, 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