Skip to content

Commit b98572a

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

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

plugwise_usb/nodes/circle.py

Lines changed: 11 additions & 2 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
@@ -443,7 +444,8 @@ async def get_missing_energy_logs(self) -> None:
443444
"Start with initial energy request for the last 10 log addresses for node %s.",
444445
self._mac_in_str,
445446
)
446-
total_addresses = 11
447+
448+
total_addresses = int(floor(datetime.now(tz=UTC).hour / 4) + 1)
447449
log_address = self._current_log_address
448450
while total_addresses > 0:
449451
await self.energy_log_update(log_address)
@@ -470,6 +472,13 @@ async def get_missing_energy_logs(self) -> None:
470472
for task in tasks:
471473
await task
472474

475+
missing_addresses = sorted(missing_addresses, reverse=True)
476+
tasks = [
477+
create_task(self.energy_log_update(address))
478+
for address in missing_addresses
479+
]
480+
await gather(*tasks, return_exceptions=True)
481+
473482
if self._cache_enabled:
474483
await self._energy_log_records_save_to_cache()
475484

0 commit comments

Comments
 (0)