Skip to content

Comments

Add energy to sensor#1361

Merged
liudger merged 4 commits intomainfrom
add-energy-to-sensor
Feb 23, 2026
Merged

Add energy to sensor#1361
liudger merged 4 commits intomainfrom
add-energy-to-sensor

Conversation

@liudger
Copy link
Owner

@liudger liudger commented Feb 23, 2026

This pull request adds support for parsing and handling BSB-LAN parameters whose values are strings containing both a number and a unit (e.g., "7968 kWh"). The code now automatically extracts the numeric value and unit for known units when the unit field is empty, improving the accuracy and usability of sensor data. It also introduces a new example script for fetching parameters and updates tests to cover the new parsing logic.

Enhanced parameter parsing and model updates:

  • The convert_raw_value method in EntityInfo now detects string values with embedded units (like "7968 kWh") when the unit field is empty. It extracts the numeric value and sets the correct unit for known units, ensuring downstream code receives structured data.
  • The Sensor model adds a new total_energy field (EntityInfo[int] | None), and parameter 3113 (total_energy) is now mapped in BASE_SENSOR_PARAMS. [1] [2]

Testing improvements:

  • New tests verify that string values with embedded units are parsed correctly, including cases for integers, floats, unknown units, and existing unit fields.
  • The sensor test now checks that total_energy is correctly parsed and available when present in the response.
  • Test fixture updated to include a sample "3113" parameter with a value like "7968 kWh".

Developer tooling:

  • Added a new example script fetch_param.py for fetching one or more BSB-LAN parameters and printing the raw API response, to help with debugging and development.

Internal code quality:

  • Minor import cleanup to support new parsing logic (imported re for regex matching).

Copilot AI review requested due to automatic review settings February 23, 2026 10:34
@liudger liudger added the enhancement Enhancement of the code, not introducing new features. label Feb 23, 2026
@codecov
Copy link

codecov bot commented Feb 23, 2026

Codecov Report

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

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1361   +/-   ##
=======================================
  Coverage   99.88%   99.88%           
=======================================
  Files           6        6           
  Lines         898      907    +9     
  Branches      126      128    +2     
=======================================
+ Hits          897      906    +9     
  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 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 enhances python-bsblan’s parameter parsing so that BSB-LAN values returned as STRING but containing an embedded unit (e.g., "7968 kWh") are normalized into structured EntityInfo data (numeric value + populated unit). It also exposes a new sensor field for total energy and adds an example utility script for debugging raw parameter responses.

Changes:

  • Extend EntityInfo.convert_raw_value to extract numeric values + known units from STRING values when the unit field is empty.
  • Add sensor parameter mapping + model field for total_energy (parameter 3113).
  • Add/extend tests and fixtures to cover embedded-unit parsing and sensor energy handling; introduce a new fetch_param.py example script.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/bsblan/models.py Adds embedded-unit parsing logic in EntityInfo and introduces Sensor.total_energy.
src/bsblan/constants.py Maps parameter 3113 to the new total_energy sensor attribute.
tests/test_entity_info.py Adds unit-parsing tests for integer/float cases and non-parsing scenarios.
tests/test_sensor.py Extends sensor test assertions to validate total_energy when present.
tests/fixtures/sensor.json Adds fixture data for parameter 3113 with value "7968 kWh".
examples/fetch_param.py New example script to fetch arbitrary parameter IDs and print the raw API response.

@liudger liudger merged commit cb1e38a into main Feb 23, 2026
19 checks passed
@liudger liudger deleted the add-energy-to-sensor branch February 23, 2026 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Enhancement of the code, not introducing new features.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant