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