@@ -350,12 +350,12 @@ async def energy_update(self) -> EnergyStatistics | None: # noqa: PLR0911 PLR09
350350
351351 # Always request last energy log records at initial startup
352352 if not self ._last_energy_log_requested :
353- self ._last_energy_log_requested = await self .energy_log_update (
353+ self ._last_energy_log_requested , _ = await self .energy_log_update (
354354 self ._current_log_address
355355 )
356356
357357 if self ._energy_counters .log_rollover :
358- # Try updating node_info
358+ # Try updating node_info to collect the updated energy log address
359359 if await self .node_info_update () is None :
360360 _LOGGER .debug (
361361 "async_energy_update | %s | Log rollover | node_info_update failed" ,
@@ -364,7 +364,8 @@ async def energy_update(self) -> EnergyStatistics | None: # noqa: PLR0911 PLR09
364364 return None
365365
366366 # Try collecting energy-stats for _current_log_address
367- if not await self .energy_log_update (self ._current_log_address ):
367+ result , _ = await self .energy_log_update (self ._current_log_address )
368+ if not result :
368369 _LOGGER .debug (
369370 "async_energy_update | %s | Log rollover | energy_log_update failed" ,
370371 self ._mac_in_str ,
@@ -377,7 +378,8 @@ async def energy_update(self) -> EnergyStatistics | None: # noqa: PLR0911 PLR09
377378 _prev_log_address , _ = calc_log_address (
378379 self ._current_log_address , 1 , - 4
379380 )
380- if not await self .energy_log_update (_prev_log_address ):
381+ result , _ = await self .energy_log_update (_prev_log_address )
382+ if not result :
381383 _LOGGER .debug (
382384 "async_energy_update | %s | Log rollover | energy_log_update %s failed" ,
383385 self ._mac_in_str ,
@@ -397,7 +399,8 @@ async def energy_update(self) -> EnergyStatistics | None: # noqa: PLR0911 PLR09
397399 return self ._energy_counters .energy_statistics
398400
399401 if len (missing_addresses ) == 1 :
400- if await self .energy_log_update (missing_addresses [0 ]):
402+ result , _ = await self .energy_log_update (missing_addresses [0 ])
403+ if result :
401404 await self .power_update ()
402405 _LOGGER .debug (
403406 "async_energy_update for %s | single energy log is missing | %s" ,
@@ -447,7 +450,8 @@ async def _get_initial_energy_logs(self) -> None:
447450 log_address = self ._current_log_address
448451 prev_address_timestamp : datetime | None = None
449452 while total_addresses > 0 :
450- if not await self .energy_log_update (log_address ):
453+ result , empty_log = await self .energy_log_update (log_address )
454+ if result and empty_log :
451455 # Handle case with None-data in all address slots
452456 _LOGGER .debug (
453457 "Energy None-data collected from log address %s, stopping collection" ,
@@ -526,10 +530,12 @@ async def get_missing_energy_logs(self) -> None:
526530 if self ._cache_enabled :
527531 await self ._energy_log_records_save_to_cache ()
528532
529- async def energy_log_update (self , address : int | None ) -> bool :
533+ async def energy_log_update (self , address : int | None ) -> tuple [ bool , bool ] :
530534 """Request energy log statistics from node. Returns true if successful."""
535+ empty_log = False
536+ result = False
531537 if address is None :
532- return False
538+ return result , empty_log
533539
534540 _LOGGER .debug (
535541 "Request of energy log at address %s for node %s" ,
@@ -543,7 +549,7 @@ async def energy_log_update(self, address: int | None) -> bool:
543549 str (address ),
544550 self ._mac_in_str ,
545551 )
546- return False
552+ return result , empty_log
547553
548554 _LOGGER .debug ("EnergyLogs data from %s, address=%s" , self ._mac_in_str , address )
549555 await self ._available_update_state (True , response .timestamp )
@@ -560,6 +566,7 @@ async def energy_log_update(self, address: int | None) -> bool:
560566 )
561567 if log_timestamp is None or log_pulses is None :
562568 self ._energy_counters .add_empty_log (response .log_address , _slot )
569+ empty_log = True
563570 elif await self ._energy_log_record_update_state (
564571 response .log_address ,
565572 _slot ,
@@ -579,15 +586,15 @@ async def energy_log_update(self, address: int | None) -> bool:
579586 )
580587 last_energy_timestamp_collected = True
581588
589+ result = True
582590 self ._energy_counters .update ()
583591 if energy_record_update :
584592 _LOGGER .debug (
585593 "Saving energy record update to cache for %s" , self ._mac_in_str
586594 )
587595 await self .save_cache ()
588- return True
589596
590- return False
597+ return result , empty_log
591598
592599 async def _energy_log_records_load_from_cache (self ) -> bool :
593600 """Load energy_log_record from cache."""
0 commit comments