feat: add HA-compatible device and state class mappings#1346
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1346 +/- ##
=======================================
Coverage 99.88% 99.88%
=======================================
Files 6 6
Lines 892 906 +14
Branches 124 126 +2
=======================================
+ Hits 891 905 +14
Partials 1 1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves Home Assistant integration support by introducing unit-to-HA sensor class mappings and exposing HA-oriented helper properties on EntityInfo to auto-suggest device/state classes.
Changes:
- Added
UNIT_DEVICE_CLASS_MAPandUNIT_STATE_CLASS_MAPinconstants.pyand re-exported them from the package. - Extended
EntityInfowithdata_type_name/data_type_familyfields andsuggested_device_class/suggested_state_classproperties. - Added a dedicated test module validating HA mapping behavior and JSON backward compatibility.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/bsblan/constants.py |
Adds HA unit→device/state class mapping dictionaries. |
src/bsblan/models.py |
Extends EntityInfo with new fields and HA suggestion properties using the mappings. |
src/bsblan/__init__.py |
Re-exports the new mapping constants as part of the public API. |
tests/test_entity_info_ha.py |
Adds test coverage for the new HA suggestion properties and new EntityInfo fields. |
…ric types in EntityInfo
… non-numeric types
|
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.



This pull request introduces improvements to Home Assistant (HA) integration by adding mappings from BSB-LAN units to HA sensor device classes and state classes, and exposes these mappings throughout the codebase. It also enhances the
EntityInfomodel with new attributes and helper properties to make entity configuration in HA more automatic and reliable.Home Assistant Integration Enhancements:
UNIT_DEVICE_CLASS_MAPandUNIT_STATE_CLASS_MAPdictionaries tobsblan.constants.pyfor mapping BSB-LAN units to HA sensor device and state classes. These mappings cover temperature, energy, power, pressure, voltage, current, frequency, volume flow rate, duration, and percentage units.bsblan/__init__.pyto import and exposeUNIT_DEVICE_CLASS_MAPandUNIT_STATE_CLASS_MAPas part of the package API. [1] [2]bsblan/models.pyto import the new unit mapping constants for use in model definitions.Entity Model Improvements:
EntityInfodataclass with new fields:data_type_nameanddata_type_family, allowing for more granular description of entity data types. [1] [2]suggested_device_classandsuggested_state_classproperties toEntityInfo, which use the unit mappings to automatically suggest HA sensor device class and state class for each entity. These properties facilitate easier and more accurate integration with Home Assistant.