@@ -25,11 +25,32 @@ def __init__(self, config: dict[str, Any] | None = None):
2525 self .password = (self .config or {}).get ("password" , "" )
2626 self .apikey = (self .config or {}).get ("apikey" , "" )
2727
28- self .client = RideWithGPS (apikey = self .apikey , cache = True )
28+ self ._client : RideWithGPS | None = None
29+ self ._userid = None
30+ self ._user_info = None
31+
32+ def _ensure_authenticated (self ):
33+ """Authenticate lazily — only when a live API call is actually needed."""
34+ if self ._client is None :
35+ self ._client = RideWithGPS (apikey = self .apikey , cache = True )
36+ user_info = self ._client .authenticate (self .username , self .password )
37+ self ._userid = getattr (user_info , "id" , None )
38+ self ._user_info = user_info
2939
30- user_info = self .client .authenticate (self .username , self .password )
31- self .userid = getattr (user_info , "id" , None )
32- self .user_info = user_info
40+ @property
41+ def client (self ) -> RideWithGPS :
42+ self ._ensure_authenticated ()
43+ return self ._client # type: ignore[return-value]
44+
45+ @property
46+ def userid (self ):
47+ self ._ensure_authenticated ()
48+ return self ._userid
49+
50+ @property
51+ def user_info (self ):
52+ self ._ensure_authenticated ()
53+ return self ._user_info
3354
3455 @property
3556 def provider_name (self ) -> str :
0 commit comments