Skip to content

Commit

Permalink
Merge pull request #304 from custom-components/fixup-dst
Browse files Browse the repository at this point in the history
fix for dst
  • Loading branch information
Hellowlol authored Mar 26, 2023
2 parents 57be772 + 37817ca commit 2b4ed5c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 9 additions & 2 deletions custom_components/nordpool/aio_price.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,15 @@ def join_result_for_correct_time(results, dt):

for val in values:
local = val["start"].astimezone(zone)
local_end = val["end"].astimezone(zone)
if start_of_day <= local and local <= end_of_day:
fin["areas"][key]["values"].append(val)
if local == local_end:
_LOGGER.info(
"Hour has the same start and end, most likly due to dst change %s exluded this hour",
val,
)
else:
fin["areas"][key]["values"].append(val)

# _LOGGER.debug("Combines result: %s", fin)

Expand Down Expand Up @@ -202,7 +209,7 @@ async def fetch(self, data_type, end_date=None, areas=None):

# compare utc offset
if self.timeezone == tz.gettz("Europe/Stockholm"):
data = await self._fetch_json(data_type, end_date, areas)
data = await self._fetch_json(data_type, end_date)
return self._parse_json(data, areas)
else:
yesterday = datetime.now() - timedelta(days=1)
Expand Down
7 changes: 5 additions & 2 deletions custom_components/nordpool/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ def join_result_for_correct_time(results):

for val in values:
local = val["start"].astimezone(zone)
local_end = val["end"].astimezone(zone)
if start_of_day <= local and local <= end_of_day:

#
if n == 1:
# this is yesterday
Expand Down Expand Up @@ -169,13 +171,14 @@ def manual_check(region, currency, vat):
today = spot.hourly(end_date=dt_today)
tomorrow = spot.hourly(end_date=dt_today + timedelta(days=1))
#print(today)
print(pprint(today.get("areas")))
return
#print(pprint(today.get("areas")))
#return

results = [yesterday, today, tomorrow]

data = join_result_for_correct_time(results)
values = []
return
for key, value in data["areas"].items():
values = []
if key == region or region is None:
Expand Down

0 comments on commit 2b4ed5c

Please sign in to comment.