|
| 1 | +import copy |
1 | 2 | import pathlib |
2 | 3 | import unittest |
3 | 4 |
|
@@ -80,3 +81,44 @@ async def test_perform_optimization_with_config_defaults_json_runs(self): |
80 | 81 | emhass_conf, |
81 | 82 | ) |
82 | 83 | self._build_and_run(retrieve_hass_conf, optim_conf, plant_conf) |
| 84 | + |
| 85 | + def _run_hybrid_status(self, ac_output_max): |
| 86 | + """Run a hybrid-inverter optimization with PV present; return optim_status.""" |
| 87 | + plant_conf = copy.deepcopy(self.plant_conf) |
| 88 | + plant_conf["inverter_is_hybrid"] = True |
| 89 | + plant_conf["inverter_ac_output_max"] = ac_output_max |
| 90 | + plant_conf["inverter_ac_input_max"] = ac_output_max |
| 91 | + n = 48 |
| 92 | + freq = self.retrieve_hass_conf["optimization_time_step"] |
| 93 | + tz = self.retrieve_hass_conf["time_zone"] |
| 94 | + idx = pd.date_range("2024-01-01", periods=n, freq=freq, tz=tz) |
| 95 | + p_pv = np.full(n, 3000.0) |
| 96 | + p_load = np.full(n, 1000.0) |
| 97 | + ulc = np.full(n, 0.2) |
| 98 | + upp = np.full(n, 0.1) |
| 99 | + df = pd.DataFrame({_VAR_LOAD_COST: ulc, _VAR_PROD_PRICE: upp}, index=idx) |
| 100 | + opt = Optimization( |
| 101 | + self.retrieve_hass_conf, |
| 102 | + self.optim_conf, |
| 103 | + plant_conf, |
| 104 | + _VAR_LOAD_COST, |
| 105 | + _VAR_PROD_PRICE, |
| 106 | + "profit", |
| 107 | + emhass_conf, |
| 108 | + logger, |
| 109 | + ) |
| 110 | + res = opt.perform_optimization(df, p_pv, p_load, ulc, upp) |
| 111 | + return res["optim_status"].iloc[0] |
| 112 | + |
| 113 | + def test_hybrid_inverter_feasible_on_default_ac_output_max(self): |
| 114 | + """Regression for #875: the default inverter_ac_output_max must let a hybrid |
| 115 | + inverter solve. It regressed to 0 in the #830 config alignment, which caps |
| 116 | + hybrid AC output at 0 W, so any PV has nowhere to go and the solve is infeasible. |
| 117 | + """ |
| 118 | + status = self._run_hybrid_status(self.plant_conf["inverter_ac_output_max"]) |
| 119 | + self.assertIn("Optimal", status) |
| 120 | + |
| 121 | + def test_hybrid_inverter_infeasible_when_ac_output_max_zero(self): |
| 122 | + """Locks the failure mode: ac_output_max=0 caps hybrid AC output at 0 W.""" |
| 123 | + status = self._run_hybrid_status(0) |
| 124 | + self.assertNotIn("Optimal", status) |
0 commit comments