Skip to content

feat: add HA-compatible device and state class mappings#1346

Merged
liudger merged 7 commits intomainfrom
add-entity-info-ha
Feb 11, 2026
Merged

feat: add HA-compatible device and state class mappings#1346
liudger merged 7 commits intomainfrom
add-entity-info-ha

Conversation

@liudger
Copy link
Owner

@liudger liudger commented Feb 11, 2026

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 EntityInfo model with new attributes and helper properties to make entity configuration in HA more automatic and reliable.

Home Assistant Integration Enhancements:

  • Added UNIT_DEVICE_CLASS_MAP and UNIT_STATE_CLASS_MAP dictionaries to bsblan.constants.py for 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.
  • Updated bsblan/__init__.py to import and expose UNIT_DEVICE_CLASS_MAP and UNIT_STATE_CLASS_MAP as part of the package API. [1] [2]
  • Modified bsblan/models.py to import the new unit mapping constants for use in model definitions.

Entity Model Improvements:

  • Extended the EntityInfo dataclass with new fields: data_type_name and data_type_family, allowing for more granular description of entity data types. [1] [2]
  • Added suggested_device_class and suggested_state_class properties to EntityInfo, 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.

Copilot AI review requested due to automatic review settings February 11, 2026 10:08
@liudger liudger added enhancement Enhancement of the code, not introducing new features. new-feature New features or options. labels Feb 11, 2026
@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.88%. Comparing base (0121fe7) to head (3c530fc).
⚠️ Report is 7 commits behind head on main.

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.
📢 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.

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 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_MAP and UNIT_STATE_CLASS_MAP in constants.py and re-exported them from the package.
  • Extended EntityInfo with data_type_name / data_type_family fields and suggested_device_class / suggested_state_class properties.
  • 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.

@liudger liudger linked an issue Feb 11, 2026 that may be closed by this pull request
@sonarqubecloud
Copy link

@liudger liudger merged commit 1a5804c into main Feb 11, 2026
19 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Feb 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement Enhancement of the code, not introducing new features. new-feature New features or options.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Report total enegy consumption

1 participant