1- from typing import Any
1+ from pickle import INT
2+ from typing import Any , Literal
23import aiohttp
34import time
45
@@ -17,14 +18,13 @@ class TeslaFleetOAuth(TeslaFleetApi):
1718 def __init__ (
1819 self ,
1920 session : aiohttp .ClientSession ,
21+ region : Literal ["na" , "eu" , "cn" ],
2022 client_id : str ,
2123 client_secret : str | None = None ,
2224 redirect_uri : str | None = None ,
2325 access_token : str | None = None ,
2426 refresh_token : str | None = None ,
2527 expires : int = 0 ,
26- region : str | None = None ,
27- server : str | None = None ,
2828 ):
2929 self .client_id = client_id
3030 self ._client_secret = client_secret
@@ -37,14 +37,18 @@ def __init__(
3737 session ,
3838 access_token = "" ,
3939 region = region ,
40- server = server ,
4140 )
4241
4342 def get_login_url (self , scopes : list [Scope ], state : str = "login" ) -> str :
4443 """Get the login URL."""
4544 if self .redirect_uri is None :
4645 raise ValueError ("Redirect URI is missing" )
47- return f"https://auth.tesla.com/oauth2/v3/authorize?response_type=code&client_id={ self .client_id } &redirect_uri={ self .redirect_uri } &scope={ '+' .join (scopes )} &state={ state } "
46+ if self .region == "cn" :
47+ domain = "auth.tesla.cn"
48+ else :
49+ domain = "auth.tesla.com"
50+
51+ return f"https://{ domain } /oauth2/v3/authorize?response_type=code&client_id={ self .client_id } &redirect_uri={ self .redirect_uri } &scope={ '+' .join (scopes )} &state={ state } "
4852
4953 async def get_refresh_token (self , code : str ) -> None :
5054 """Get the refresh token."""
@@ -56,7 +60,6 @@ async def get_refresh_token(self, code: str) -> None:
5660 raise ValueError ("Redirect URI is missing" )
5761
5862 if self .server is None :
59- self .region = code .split ("_" )[0 ].lower ()
6063 self .server = SERVERS .get (self .region )
6164
6265 async with self .session .post (
0 commit comments