@@ -510,28 +510,27 @@ async def get_missing_energy_logs(self) -> None:
510510
511511 async def energy_log_update (self , address : int | None ) -> bool :
512512 """Request energy log statistics from node. Returns true if successful."""
513- result = False
513+ any_record_stored = False
514514 if address is None :
515- return result
515+ return False
516516
517517 _LOGGER .debug (
518518 "Requesting EnergyLogs from node %s address %s" ,
519- str ( address ),
520- self . name ,
519+ self . _mac_in_str
520+ address ,
521521 )
522522 request = CircleEnergyLogsRequest (self ._send , self ._mac_in_bytes , address )
523523 if (response := await request .send ()) is None :
524524 _LOGGER .debug (
525525 "Retrieving EnergyLogs data from node %s failed" ,
526526 self ._mac_in_str ,
527527 )
528- return result
528+ return False
529529
530530 _LOGGER .debug (
531- "EnergyLogs data from node %s, address=%s" , self ._mac_in_str , address
531+ "EnergyLogs from node %s, address=%s: " , self ._mac_in_str , address
532532 )
533533 await self ._available_update_state (True , response .timestamp )
534- energy_record_update = False
535534
536535 # Forward historical energy log information to energy counters
537536 # Each response message contains 4 log counters (slots) of the
@@ -557,7 +556,7 @@ async def energy_log_update(self, address: int | None) -> bool:
557556 log_pulses ,
558557 import_only = True ,
559558 ):
560- energy_record_update = True
559+ any_record_stored = True
561560 if not last_energy_timestamp_collected :
562561 # Collect the timestamp of the most recent response
563562 self ._last_collected_energy_timestamp = log_timestamp .replace (
@@ -569,25 +568,26 @@ async def energy_log_update(self, address: int | None) -> bool:
569568 )
570569 last_energy_timestamp_collected = True
571570
572- result = True
573571 self ._energy_counters .update ()
574- if energy_record_update :
572+ if any_record_stored :
575573 _LOGGER .debug (
576574 "Saving energy record update to cache for %s" , self ._mac_in_str
577575 )
578576 await self .save_cache ()
579577
580- return result
578+ return any_record_stored
581579
582- def _check_timestamp_is_recent (self , address , slot , timestamp ) -> bool :
580+ def _check_timestamp_is_recent (
581+ self , address : int , slot : int , timestamp : datetime
582+ ) -> bool :
583583 """Check if the timestamp of the received log-record is recent.
584584
585585 A timestamp from within the last 24 hours is considered recent.
586586 """
587- if (
588- ( datetime .now (tz = UTC ) - timestamp .replace (tzinfo = UTC )). total_seconds ( )
589- // 3600
590- ) > DAY_IN_HOURS :
587+ age_seconds = (
588+ datetime .now (tz = UTC ) - timestamp .replace (tzinfo = UTC )
589+ ). total_seconds ()
590+ if age_seconds > DAY_IN_HOURS * 3600 :
591591 _LOGGER .warning (
592592 "EnergyLog from Node %s | address %s | slot %s | timestamp %s is outdated, ignoring..." ,
593593 self ._mac_in_str ,
0 commit comments