@@ -666,27 +666,43 @@ async def set_relay_lock(self, state: bool) -> bool:
666666 return state
667667
668668 async def _relay_load_from_cache (self ) -> bool :
669- """Load relay state and lock from cache."""
669+ """Load relay state from cache."""
670670 if (cached_relay_data := self ._get_cache (CACHE_RELAY )) is not None :
671- cached_relay_lock = self ._get_cache (CACHE_RELAY_LOCK )
672- _LOGGER .debug ("Restore relay state and lock cache for node %s" , self ._mac_in_str )
673- relay_state = relay_lock = False
671+ _LOGGER .debug (
672+ "Restore relay state from cache for node %s: relay: %s" ,
673+ self ._mac_in_str ,
674+ cached_relay_data ,
675+ )
676+ relay_state = False
674677 if cached_relay_data == "True" :
675678 relay_state = True
676- if cached_relay_lock == "True" :
677- relay_lock = True
679+
678680 await self ._relay_update_state (relay_state )
679- await self ._relay_update_lock (relay_lock )
680- return True
681+ result = True
681682
682683 _LOGGER .debug (
683684 "Failed to restore relay state from cache for node %s, try to request node info..." ,
684685 self ._mac_in_str ,
685686 )
686687 if await self .node_info_update () is None :
687- return False
688+ result = False
688689
689- return True
690+ if (cached_relay_lock := self ._get_cache (CACHE_RELAY_LOCK )) is not None :
691+ _LOGGER .debug (
692+ "Restore relay_lock state from cache for node %s: relay_lock: %s" ,
693+ self ._mac_in_str ,
694+ cached_relay_lock ,
695+ )
696+ relay_lock = False
697+ if cached_relay_lock == "True" :
698+ relay_lock = True
699+
700+ await self ._relay_update_lock (relay_lock )
701+
702+ # Set to initial state False when not present in cache
703+ await self ._relay_update_lock (False )
704+
705+ return result
690706
691707 async def _relay_update_state (
692708 self , state : bool , timestamp : datetime | None = None
@@ -960,7 +976,7 @@ async def update_node_details(
960976 hardware : str | None ,
961977 node_type : NodeType | None ,
962978 timestamp : datetime | None ,
963- relay_lock : bool | None ,
979+ relay_lock : bool | None ,
964980 relay_state : bool | None ,
965981 logaddress_pointer : int | None ,
966982 ) -> bool :
0 commit comments