Skip to content

Commit

Permalink
forecast: fix parse_interval_value offset calculation
Browse files Browse the repository at this point in the history
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
  • Loading branch information
Noltari committed Feb 23, 2024
1 parent 979333f commit db30100
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions aemet_opendata/forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,15 +596,20 @@ def parse_interval_value(
) -> Any:
"""Parse Town hourly forecast interval value from data."""
period_offset = None

for value in values:
if key not in value:
continue
period = value[AEMET_ATTR_PERIOD]
period_start = int(period[0:API_PERIOD_SPLIT])
if period_offset is None or period_start < period_offset:
period_offset = period_start
period_end = int(period[API_PERIOD_SPLIT : API_PERIOD_SPLIT * 2])
if period_end < period_start:
if period_offset is None or period_end < period_offset:
period_offset = period_end

if period_offset is None:
period_offset = 0

for value in values:
if key not in value:
continue
Expand All @@ -619,6 +624,7 @@ def parse_interval_value(
hour = hour + API_PERIOD_24H
if period_start <= hour < period_end:
return None if not value[key] else value[key]

return None

def parse_value(self, values: Any, hour: int, key: str = AEMET_ATTR_VALUE) -> Any:
Expand Down

0 comments on commit db30100

Please sign in to comment.