3838 EnergyCalibrationRequest ,
3939 NodeInfoRequest ,
4040)
41- from ..messages .responses import NodeInfoResponse , NodeResponse , NodeResponseType
41+ from ..messages .responses import NodeInfoResponse , NodeResponseType
4242from .helpers import EnergyCalibration , raise_not_loaded
4343from .helpers .counter import EnergyCounters
4444from .helpers .firmware import CIRCLE_FIRMWARE_SUPPORT
@@ -532,7 +532,6 @@ async def energy_log_update(self, address: int | None) -> bool:
532532
533533 async def _energy_log_records_load_from_cache (self ) -> bool :
534534 """Load energy_log_record from cache."""
535- cache_data = self ._get_cache (CACHE_ENERGY_COLLECTION )
536535 if (cache_data := self ._get_cache (CACHE_ENERGY_COLLECTION )) is None :
537536 _LOGGER .warning (
538537 "Failed to restore energy log records from cache for node %s" , self .name
@@ -733,7 +732,6 @@ async def clock_synchronize(self) -> bool:
733732 datetime .now (tz = UTC ),
734733 self ._node_protocols .max ,
735734 )
736- node_response : NodeResponse | None = await set_clock_request .send ()
737735 if (node_response := await set_clock_request .send ()) is None :
738736 _LOGGER .warning (
739737 "Failed to (re)set the internal clock of %s" ,
@@ -849,12 +847,14 @@ async def initialize(self) -> bool:
849847 )
850848 self ._initialized = False
851849 return False
850+
852851 if not self ._calibration and not await self .calibration_update ():
853852 _LOGGER .debug (
854853 "Failed to initialized node %s, no calibration" , self ._mac_in_str
855854 )
856855 self ._initialized = False
857856 return False
857+
858858 if (
859859 self .skip_update (self ._node_info , 30 )
860860 and await self .node_info_update () is None
@@ -869,7 +869,9 @@ async def initialize(self) -> bool:
869869 )
870870 self ._initialized = False
871871 return False
872- return await super ().initialize ()
872+
873+ await super ().initialize ()
874+ return True
873875
874876 async def node_info_update (
875877 self , node_info : NodeInfoResponse | None = None
@@ -1083,15 +1085,14 @@ def _correct_power_pulses(self, pulses: int, offset: int) -> float:
10831085 async def get_state (self , features : tuple [NodeFeature ]) -> dict [NodeFeature , Any ]:
10841086 """Update latest state for given feature."""
10851087 states : dict [NodeFeature , Any ] = {}
1086- if not self ._available :
1087- if not await self .is_online ():
1088- _LOGGER .debug (
1089- "Node %s did not respond, unable to update state" , self ._mac_in_str
1090- )
1091- for feature in features :
1092- states [feature ] = None
1093- states [NodeFeature .AVAILABLE ] = self .available_state
1094- return states
1088+ if not self ._available and not await self .is_online ():
1089+ _LOGGER .debug (
1090+ "Node %s did not respond, unable to update state" , self ._mac_in_str
1091+ )
1092+ for feature in features :
1093+ states [feature ] = None
1094+ states [NodeFeature .AVAILABLE ] = self .available_state
1095+ return states
10951096
10961097 for feature in features :
10971098 if feature not in self ._features :
0 commit comments