From 30febd8b675ad5c316e8b5fc610a72449ff2539d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CWouterK=E2=80=9D?= Date: Sun, 31 May 2026 15:10:17 +0200 Subject: [PATCH] fix(services): preserve service call data through coordinator data fetch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In `_handle_find_block` and `_handle_find_hours`, the local `data` variable holding the resolved service call data was rebound to the coordinator data dict returned by `get_entry_and_data()`. As a result, the subsequent calls to `validate_search_params(data)`, `apply_must_finish_by(data, ...)` and `resolve_search_range(...)` read search-range parameters from coordinator data instead of from the service call, silently ignoring: - must_finish_by - search_scope - search_start, search_end - search_start_time, search_end_time - search_start_day_offset, search_end_day_offset - search_start_offset_minutes, search_end_offset_minutes - include_current_interval The functions fell back to the default range ("now → end of tomorrow") for every call that depended on these parameters. Rename the third return value of `get_entry_and_data()` to `coordinator_data` so the service call `data` survives, restoring deadline and search-scope semantics. `find_cheapest_schedule.py` already uses `data_dict` for the same purpose and was not affected. Verified locally against v0.31.0: a call with `must_finish_by: 2026-06-01T20:00:00+02:00` now correctly produces `search_end: 2026-06-01T20:00:00+02:00` (was end-of-tomorrow before). --- .../tibber_prices/services/find_cheapest_block.py | 7 +++++-- .../tibber_prices/services/find_cheapest_hours.py | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/custom_components/tibber_prices/services/find_cheapest_block.py b/custom_components/tibber_prices/services/find_cheapest_block.py index fc33470..9995202 100644 --- a/custom_components/tibber_prices/services/find_cheapest_block.py +++ b/custom_components/tibber_prices/services/find_cheapest_block.py @@ -267,8 +267,11 @@ async def _handle_find_block( # Round up to nearest quarter-hour interval duration_minutes = math.ceil(duration_minutes_requested / INTERVAL_MINUTES) * INTERVAL_MINUTES - entry, coordinator, data = get_entry_and_data(hass, entry_id) - rating_lookup = build_rating_lookup(data) + # Note: rebind to coordinator_data — `data` (the resolved service call + # data) is still needed below for validate_search_params() and + # apply_must_finish_by(), which read search-range parameters from it. + entry, coordinator, coordinator_data = get_entry_and_data(hass, entry_id) + rating_lookup = build_rating_lookup(coordinator_data) home_id = entry.data.get("home_id") if not home_id: diff --git a/custom_components/tibber_prices/services/find_cheapest_hours.py b/custom_components/tibber_prices/services/find_cheapest_hours.py index b585a35..7c888ad 100644 --- a/custom_components/tibber_prices/services/find_cheapest_hours.py +++ b/custom_components/tibber_prices/services/find_cheapest_hours.py @@ -329,8 +329,11 @@ async def _handle_find_hours( total_minutes = math.ceil(total_minutes_requested / INTERVAL_MINUTES) * INTERVAL_MINUTES min_segment_minutes = math.ceil(min_segment_minutes_requested / INTERVAL_MINUTES) * INTERVAL_MINUTES - entry, coordinator, data = get_entry_and_data(hass, entry_id) - rating_lookup = build_rating_lookup(data) + # Note: rebind to coordinator_data — `data` (the resolved service call + # data) is still needed below for validate_search_params() and + # apply_must_finish_by(), which read search-range parameters from it. + entry, coordinator, coordinator_data = get_entry_and_data(hass, entry_id) + rating_lookup = build_rating_lookup(coordinator_data) home_id = entry.data.get("home_id") if not home_id: