Skip to content

Commit 039155e

Browse files
ArnoutDbouwew
authored andcommitted
Only query logs for today on initialisation.. becomes a small set ... back to gather instead of loop
1 parent cc67a2a commit 039155e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

plugwise_usb/nodes/circle.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
from __future__ import annotations
44

5-
from asyncio import Task, create_task
5+
from asyncio import Task, create_task, gather
66
from collections.abc import Awaitable, Callable
77
from dataclasses import replace
8+
from math import floor
89
from datetime import UTC, datetime
910
from functools import wraps
1011
import logging
@@ -446,7 +447,8 @@ async def get_missing_energy_logs(self) -> None:
446447
"Start with initial energy request for the last 10 log addresses for node %s.",
447448
self._mac_in_str,
448449
)
449-
total_addresses = 11
450+
451+
total_addresses = int(floor(datetime.now(tz=UTC).hour / 4) + 1)
450452
log_address = self._current_log_address
451453
while total_addresses > 0:
452454
await self.energy_log_update(log_address)
@@ -474,8 +476,7 @@ async def get_missing_energy_logs(self) -> None:
474476
create_task(self.energy_log_update(address))
475477
for address in missing_addresses
476478
]
477-
for task in tasks:
478-
await task
479+
await gather(*tasks, return_exceptions=True)
479480

480481
if self._cache_enabled:
481482
await self._energy_log_records_save_to_cache()

0 commit comments

Comments
 (0)