Skip to content

Commit

Permalink
Raise exception if data is not available when update is called
Browse files Browse the repository at this point in the history
This happens if the first auction is unsuccessful.

Implemented by verifying that the data is valid (in
join_result_for_correct_time()) and raising an exception if it isn't.

This partially fixes issue custom-components#326.
  • Loading branch information
Arto Jantunen committed Jul 28, 2023
1 parent a0c575c commit 56379f3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions custom_components/nordpool/aio_price.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
"PL ": "PL",
}

INVALID_VALUES = frozenset((None, float("inf")))


class InvalidValueException(ValueError):
pass


def join_result_for_correct_time(results, dt):
"""Parse a list of responses from the api
Expand Down Expand Up @@ -135,6 +141,8 @@ def join_result_for_correct_time(results, dt):
local = val["start"].astimezone(zone)
local_end = val["end"].astimezone(zone)
if start_of_day <= local and local <= end_of_day:
if val['value'] in INVALID_VALUES:
raise InvalidValueException()
if local == local_end:
_LOGGER.info(
"Hour has the same start and end, most likly due to dst change %s exluded this hour",
Expand Down

0 comments on commit 56379f3

Please sign in to comment.