From 771afe7c0f50ebaa58417b82b38896df429c44cf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 13 Nov 2025 22:36:36 +0000 Subject: [PATCH 1/2] Initial plan From 62eacfb30b5efed18088d072d84a7d78ca823ef7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 13 Nov 2025 22:40:55 +0000 Subject: [PATCH 2/2] refactor: convert flexibility_pct to ratio once at function entry Co-authored-by: jpawlowski <75446+jpawlowski@users.noreply.github.com> --- .../tibber_prices/period_utils/outlier_filtering.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/custom_components/tibber_prices/period_utils/outlier_filtering.py b/custom_components/tibber_prices/period_utils/outlier_filtering.py index 7192156..12981f2 100644 --- a/custom_components/tibber_prices/period_utils/outlier_filtering.py +++ b/custom_components/tibber_prices/period_utils/outlier_filtering.py @@ -181,6 +181,9 @@ def filter_price_outliers( flexibility_pct, ) + # Convert percentage to ratio once for all comparisons (e.g., 15.0 → 0.15) + flexibility_ratio = flexibility_pct / 100 + result = [] smoothed_count = 0 @@ -225,7 +228,7 @@ def filter_price_outliers( context_diff_pct = abs(avg_after - avg_before) / avg_before if avg_before > 0 else 0 - if context_diff_pct > (flexibility_pct / 100): + if context_diff_pct > flexibility_ratio: result.append(current) _LOGGER.debug( "%sInterval %s: Context unstable (%.1f%% change) - not a spike",