From 11a7b6aa7fc3f5e321b29c249b03fbaab01ee5f6 Mon Sep 17 00:00:00 2001 From: mampfes Date: Sat, 28 Oct 2023 14:52:40 +0200 Subject: [PATCH] fix errorneous warning if market end datetime is earlier than earliest_start --- custom_components/epex_spot/extreme_price_interval.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/custom_components/epex_spot/extreme_price_interval.py b/custom_components/epex_spot/extreme_price_interval.py index 3e8b122..897ba8f 100644 --- a/custom_components/epex_spot/extreme_price_interval.py +++ b/custom_components/epex_spot/extreme_price_interval.py @@ -139,10 +139,19 @@ def get_start_times( latest_end += timedelta(days=1) if latest_end > latest_market_datetime: + if latest_market_datetime <= earliest_start: + # no data available, return immediately to avoid exception + _LOGGER.debug( + f"no data available yet: earliest_start={earliest_start}, latest_end={latest_end}" # noqa: E501 + ) + return [] + latest_end = latest_market_datetime if latest_end <= earliest_start: - raise ValueError("latest_end is earlier or equal than earliest_start") + raise ValueError( + f"latest_end {latest_end} is earlier or equal to earliest_start {earliest_start}" # noqa: E501 + ) _LOGGER.debug( f"extreme price service call: earliest_start={earliest_start}, latest_end={latest_end}" # noqa: E501