From 76c2495a8f3397fc0493c7229d2d12a1d8a42ed0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Jul 2026 14:55:56 +0000 Subject: [PATCH] fix: resolve CI failures from merge conflict between #1946 and #2072 Context: - PR #2072 added scheduling_result output to StorageScheduler.compute() when return_multiple=True, and added _compute_unresolved_targets. - In single-sensor mode (self.sensor is set), flex_model entries lack a "sensor" key, so _compute_unresolved_targets was skipping every device and returning empty unresolved/resolved lists. Changes: - storage.py: fall back to self.sensor in _compute_unresolved_targets when the flex_model entry has no "sensor" key (single-sensor mode) - test_commitments.py: update schedule-count assertions (+1 for the new scheduling_result entry added by PR #2072) Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com> --- flexmeasures/data/models/planning/storage.py | 4 +++- .../models/planning/tests/test_commitments.py | 15 +++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/flexmeasures/data/models/planning/storage.py b/flexmeasures/data/models/planning/storage.py index 21c9f5f647..cc1f9786bb 100644 --- a/flexmeasures/data/models/planning/storage.py +++ b/flexmeasures/data/models/planning/storage.py @@ -2219,7 +2219,9 @@ def _compute_unresolved_targets( # Devices without a state-of-charge sensor are included as long as a # key can be derived from the power sensor's generic asset (or the # power sensor itself). - power_sensor = flex_model_d.get("sensor") + # In single-sensor mode the flex_model entry has no "sensor" key; + # fall back to self.sensor (set when the scheduler was given a Sensor). + power_sensor = flex_model_d.get("sensor") or self.sensor if ( power_sensor is not None and hasattr(power_sensor, "generic_asset") diff --git a/flexmeasures/data/models/planning/tests/test_commitments.py b/flexmeasures/data/models/planning/tests/test_commitments.py index a58e4919b9..d8b8f54ff1 100644 --- a/flexmeasures/data/models/planning/tests/test_commitments.py +++ b/flexmeasures/data/models/planning/tests/test_commitments.py @@ -629,7 +629,9 @@ def test_two_flexible_assets_with_commodity(app, db): schedules = scheduler.compute(skip_validation=True) assert isinstance(schedules, list) - assert len(schedules) == 3 # 2 storage schedules + 1 commitment costs + assert ( + len(schedules) == 4 + ) # 2 storage schedules + 1 commitment costs + 1 scheduling_result # Extract schedules by type storage_schedules = [ @@ -648,7 +650,6 @@ def test_two_flexible_assets_with_commodity(app, db): ) battery_data = battery_schedule["data"] - # Get heat pump schedule hp_schedule = next( entry for entry in storage_schedules if entry["sensor"] == hp_power ) @@ -790,7 +791,9 @@ def test_mixed_gas_and_electricity_assets(app, db): schedules = scheduler.compute(skip_validation=True) assert isinstance(schedules, list) - assert len(schedules) == 3 # 2 storage schedules + 1 commitment costs + assert ( + len(schedules) == 4 + ) # 2 storage schedules + 1 commitment costs + 1 scheduling_result # Extract schedules by type storage_schedules = [ @@ -989,9 +992,9 @@ def test_two_devices_shared_stock(app, db): "(device schedules, commitment costs, SOC)." ) - assert len(schedules) == 4, ( - "Expected 4 outputs: two inverter schedules, one commitment_costs " - "object, and one state_of_charge schedule." + assert len(schedules) == 5, ( + "Expected 5 outputs: two inverter schedules, one commitment_costs " + "object, one state_of_charge schedule, and one scheduling_result." ) # ---- extract schedules