88from datetime import UTC , datetime
99from functools import wraps
1010import logging
11- from typing import Any , TypeVar , cast
11+ from typing import Any , Final , TypeVar , cast
1212
1313from ..api import (
1414 EnergyStatistics ,
5959CACHE_RELAY_INIT = "relay_init"
6060CACHE_RELAY_LOCK = "relay_lock"
6161
62+ CIRCLE_FEATURES : Final = (
63+ NodeFeature .CIRCLE ,
64+ NodeFeature .RELAY ,
65+ NodeFeature .RELAY_INIT ,
66+ NodeFeature .RELAY_LOCK ,
67+ NodeFeature .ENERGY ,
68+ NodeFeature .POWER ,
69+ )
70+
71+
72+ # Default firmware if not known
73+ DEFAULT_FIRMWARE : Final = datetime (2008 , 8 , 26 , 15 , 46 , tzinfo = UTC )
74+
6275FuncT = TypeVar ("FuncT" , bound = Callable [..., Any ])
6376_LOGGER = logging .getLogger (__name__ )
6477
@@ -884,10 +897,10 @@ async def clock_synchronize(self) -> bool:
884897 return True
885898 return False
886899
887- async def load (self ) -> bool :
900+ async def load (self ) -> None :
888901 """Load and activate Circle node features."""
889902 if self ._loaded :
890- return True
903+ return
891904
892905 if self ._cache_enabled :
893906 _LOGGER .debug ("Loading Circle node %s from cache" , self ._mac_in_str )
@@ -897,34 +910,18 @@ async def load(self) -> bool:
897910 _LOGGER .debug ("Retrieving Info For Circle node %s" , self ._mac_in_str )
898911
899912 # Check if node is online
900- if not self ._available and not await self .is_online ():
901- _LOGGER .debug (
902- "Failed to load Circle node %s because it is not online" ,
903- self ._mac_in_str ,
904- )
905- return False
906-
907- # Get node info
908- if await self .node_info_update () is None :
913+ if (
914+ not self ._available and not await self .is_online ()
915+ ) or await self .node_info_update () is None :
909916 _LOGGER .debug (
910- "Failed to load Circle node %s because it is not responding to information request " ,
917+ "Failed to retrieve NodeInfo for %s, loading defaults " ,
911918 self ._mac_in_str ,
912919 )
913- return False
920+ await self . _load_defaults ()
914921
915- self ._loaded = True
922+ self ._loaded = True
916923
917- self ._setup_protocol (
918- CIRCLE_FIRMWARE_SUPPORT ,
919- (
920- NodeFeature .CIRCLE ,
921- NodeFeature .RELAY ,
922- NodeFeature .RELAY_INIT ,
923- NodeFeature .RELAY_LOCK ,
924- NodeFeature .ENERGY ,
925- NodeFeature .POWER ,
926- ),
927- )
924+ self ._setup_protocol (CIRCLE_FIRMWARE_SUPPORT , CIRCLE_FEATURES )
928925 await self ._loaded_callback (NodeEvent .LOADED , self .mac )
929926 await self .initialize ()
930927 return True
@@ -974,6 +971,15 @@ async def _load_from_cache(self) -> bool:
974971
975972 return result
976973
974+ async def _load_defaults (self ) -> None :
975+ """Load default configuration settings."""
976+ if self ._node_info .model is None :
977+ self ._node_info .model = "Circle"
978+ if self ._node_info .name is None :
979+ self ._node_info .name = f"Circle { self ._node_info .mac [- 5 :]} "
980+ if self ._node_info .firmware is None :
981+ self ._node_info .firmware = DEFAULT_FIRMWARE
982+
977983 @raise_not_loaded
978984 async def initialize (self ) -> bool :
979985 """Initialize node."""
0 commit comments