diff --git a/src/batcontrol/forecastsolar/baseclass.py b/src/batcontrol/forecastsolar/baseclass.py index dfdb2c9..5035fb2 100644 --- a/src/batcontrol/forecastsolar/baseclass.py +++ b/src/batcontrol/forecastsolar/baseclass.py @@ -151,15 +151,15 @@ def get_forecast(self) -> dict[int, float]: # Validate minimum forecast length if self.target_resolution == 60: - min_intervals = 18 # 18 hours + min_intervals = 12 # 12 hours else: # 15 minutes - min_intervals = 72 # 18 hours * 4 = 72 intervals + min_intervals = 48 # 12 hours * 4 = 48 intervals - max_interval = max(current_aligned_forecast.keys()) if current_aligned_forecast else 0 - if max_interval < min_intervals: - logger.error('Less than 18 hours of forecast data. Got %d intervals, need %d.', - max_interval, min_intervals) - raise RuntimeError('Less than 18 hours of forecast data.') + num_intervals = len(current_aligned_forecast) + if num_intervals < min_intervals: + logger.error('Less than 12 hours of forecast data. Got %d intervals, need %d.', + num_intervals, min_intervals) + raise RuntimeError('Less than 12 hours of forecast data.') return current_aligned_forecast diff --git a/tests/batcontrol/forecastsolar/test_baseclass.py b/tests/batcontrol/forecastsolar/test_baseclass.py index 4264cc7..d778f59 100644 --- a/tests/batcontrol/forecastsolar/test_baseclass.py +++ b/tests/batcontrol/forecastsolar/test_baseclass.py @@ -341,7 +341,7 @@ def mock_forecast(): mock_forecast_func=mock_forecast ) - with pytest.raises(RuntimeError, match="Less than 18 hours"): + with pytest.raises(RuntimeError, match="Less than 12 hours"): instance.get_forecast() def test_base_class_not_implemented_errors(self, single_installation, timezone): diff --git a/tests/batcontrol/forecastsolar/test_baseclass_alignment.py b/tests/batcontrol/forecastsolar/test_baseclass_alignment.py index 779fdf3..40617b9 100644 --- a/tests/batcontrol/forecastsolar/test_baseclass_alignment.py +++ b/tests/batcontrol/forecastsolar/test_baseclass_alignment.py @@ -317,7 +317,7 @@ def test_minimum_forecast_validation_hourly(self, pvinstallations, timezone): mock_datetime.timezone = datetime.timezone with patch.object(provider, 'refresh_data'): - with pytest.raises(RuntimeError, match="Less than 18 hours"): + with pytest.raises(RuntimeError, match="Less than 12 hours"): provider.get_forecast() def test_minimum_forecast_validation_15min(self, pvinstallations, timezone): @@ -327,8 +327,8 @@ def test_minimum_forecast_validation_15min(self, pvinstallations, timezone): target_resolution=15, native_resolution=15 ) - # Set insufficient data (less than 72 intervals = 18 hours) - data_15min = {i: 250 for i in range(50)} + # Set insufficient data (less than 48 intervals = 12 hours) + data_15min = {i: 250 for i in range(40)} provider.set_mock_data(data_15min) mock_time = datetime.datetime(2024, 1, 1, 10, 0, 0, tzinfo=timezone) @@ -338,7 +338,7 @@ def test_minimum_forecast_validation_15min(self, pvinstallations, timezone): mock_datetime.timezone = datetime.timezone with patch.object(provider, 'refresh_data'): - with pytest.raises(RuntimeError, match="Less than 18 hours"): + with pytest.raises(RuntimeError, match="Less than 12 hours"): provider.get_forecast() @@ -394,8 +394,8 @@ def test_scenario_1020_with_15min(self, pvinstallations, timezone): assert 0 in result assert result[0] > 0 # Should have some solar production - # Result should have many intervals (at least 72 for 18 hours) - assert len(result) >= 72 + # Result should have many intervals (at least 48 for 12 hours) + assert len(result) >= 48 def test_scenario_matching_doc_example(self, pvinstallations, timezone): """