File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 22
33from __future__ import annotations
44
5- from asyncio import Task , create_task
5+ from asyncio import Task , create_task , gather
66from collections .abc import Awaitable , Callable
77from dataclasses import replace
8+ from math import floor
89from datetime import UTC , datetime
910from functools import wraps
1011import 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
You can’t perform that action at this time.
0 commit comments