[sensor] Fix delta filter percentage mode regression#14302
[sensor] Fix delta filter percentage mode regression#14302swoboda1337 merged 1 commit intoesphome:devfrom
Conversation
The _get_delta() helper introduced in esphome#12605 converts percentage strings like "5%" to float but doesn't divide by 100. This means delta: 5% actually requires a 500% change instead of 5%, effectively filtering out all values after the first one. Fixes esphome#14301 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
👋 Hi there! This PR modifies 1 file(s) with codeowners. @esphome/core - As codeowner(s) of the affected files, your review would be appreciated! 🙏 Note: Automatic review request may have failed, but you're still welcome to review. |
|
To use the changes from this PR as an external component, add the following to your ESPHome configuration YAML file: external_components:
- source: github://pr#14302
components: [sensor]
refresh: 1h(Added by the PR bot) |
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical regression introduced in PR #12605 where percentage-based delta filters (e.g., delta: 5%) were incorrectly converted to their linear coefficients. The bug caused the filter to require a 500% change instead of 5%, effectively filtering out all values after the first one. The fix adds the missing division by 100 when converting percentage strings to decimal coefficients.
Changes:
- Fixed
_get_delta()helper inesphome/components/sensor/__init__.pyto divide percentage values by 100 - Added integration test for percentage mode delta filter to prevent future regressions
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| esphome/components/sensor/init.py | Fixed percentage conversion in _get_delta() by adding division by 100 |
| tests/integration/test_sensor_filters_delta.py | Added Test 5 for percentage mode delta filter with proper assertions |
| tests/integration/fixtures/sensor_filters_delta.yaml | Added source sensor 5, filter_percentage sensor, test script, and button for percentage mode testing |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #14302 +/- ##
==========================================
- Coverage 74.28% 74.25% -0.03%
==========================================
Files 55 55
Lines 11595 11595
Branches 1583 1583
==========================================
- Hits 8613 8610 -3
- Misses 2578 2580 +2
- Partials 404 405 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Memory Impact AnalysisComponents:
This analysis runs automatically when components change. Memory usage is measured from a representative test configuration. |
|
Thanks |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
What does this implement/fix?
Fixes a regression introduced in #12605 where the
_get_delta()helper does not divide percentage values by 100 when converting to the linear coefficient used byDeltaFilter.The old code used
cv.percentage()which correctly converts"5%"→0.05. The new code replaced this with manual string parsing (float(value[:-1])) but forgot the division, so"5%"→5.0. This meansdelta: 5%actually requires a 500% change instead of 5%, effectively filtering out all values after the first one.The fix: divide by 100 in
_get_delta():An integration test for percentage mode is added to catch this regression.
Types of changes
Related issue or feature (if applicable):
Pull request in esphome-docs with documentation (if applicable):
Test Environment
Example entry for
config.yaml:Checklist:
tests/folder).If user exposed functionality or configuration variables are added/changed: