hyundai-kia-connect-api 3.32.3__py2.py3-none-any.whl → 3.32.5__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -89,6 +89,11 @@ class ApiImpl:
89
89
  """Get cached vehicle data and update Vehicle instance with it"""
90
90
  pass
91
91
 
92
+ def test_token(self, token: Token) -> bool:
93
+ """Test if token is valid
94
+ Use any dummy request to test if token is still valid"""
95
+ return True
96
+
92
97
  def check_action_status(
93
98
  self,
94
99
  token: Token,
@@ -22,7 +22,6 @@ from .const import (
22
22
  DISTANCE_UNITS,
23
23
  DOMAIN,
24
24
  ENGINE_TYPES,
25
- LOGIN_TOKEN_LIFETIME,
26
25
  OrderStatus,
27
26
  SEAT_STATUS,
28
27
  TEMPERATURE_UNITS,
@@ -37,9 +36,6 @@ from .utils import (
37
36
  parse_datetime,
38
37
  )
39
38
 
40
-
41
- CIPHERS = "ALL:@SECLEVEL=0"
42
-
43
39
  _LOGGER = logging.getLogger(__name__)
44
40
 
45
41
 
@@ -64,17 +60,19 @@ class KiaUvoApiCA(ApiImpl):
64
60
  self.old_vehicle_status = {}
65
61
  self.API_URL: str = "https://" + self.BASE_URL + "/tods/api/"
66
62
  self.API_HEADERS = {
67
- "content-type": "application/json;charset=UTF-8",
63
+ "content-type": "application/json",
68
64
  "accept": "application/json, text/plain, */*",
69
65
  "accept-encoding": "gzip, deflate, br",
70
66
  "accept-language": "en-US,en;q=0.9",
71
- "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36", # noqa
67
+ "user-agent": "MyHyundai/2.0.25 (iPhone; iOS 18.3.1; Scale/3.00)", # noqa
72
68
  "host": self.BASE_URL,
69
+ "client_id": "HATAHSPACA0232141ED9722C67715A0B",
70
+ "client_secret": "CLISCR01AHSPA",
73
71
  "origin": "https://" + self.BASE_URL,
74
72
  "referer": "https://" + self.BASE_URL + "/login",
75
- "from": "CWP",
73
+ "from": "SPA",
76
74
  "language": "0",
77
- "offset": "0",
75
+ "offset": "-5",
78
76
  "sec-fetch-dest": "empty",
79
77
  "sec-fetch-mode": "cors",
80
78
  "sec-fetch-site": "same-origin",
@@ -115,17 +113,19 @@ class KiaUvoApiCA(ApiImpl):
115
113
  url = self.API_URL + "v2/login"
116
114
  data = {"loginId": username, "password": password}
117
115
  headers = self.API_HEADERS
116
+ headers.pop("accessToken", None)
118
117
  response = self.sessions.post(url, json=data, headers=headers)
119
118
  _LOGGER.debug(f"{DOMAIN} - Sign In Response {response.text}")
120
119
  response = response.json()
121
120
  self._check_response_for_errors(response)
122
121
  response = response["result"]["token"]
122
+ token_expire_in = int(response["expireIn"]) - 60
123
123
  access_token = response["accessToken"]
124
124
  refresh_token = response["refreshToken"]
125
125
  _LOGGER.debug(f"{DOMAIN} - Access Token Value {access_token}")
126
126
  _LOGGER.debug(f"{DOMAIN} - Refresh Token Value {refresh_token}")
127
127
 
128
- valid_until = dt.datetime.now(pytz.utc) + LOGIN_TOKEN_LIFETIME
128
+ valid_until = dt.datetime.now(pytz.utc) + dt.timedelta(seconds=token_expire_in)
129
129
 
130
130
  return Token(
131
131
  username=username,
@@ -135,6 +135,24 @@ class KiaUvoApiCA(ApiImpl):
135
135
  valid_until=valid_until,
136
136
  )
137
137
 
138
+ def test_token(self, token: Token) -> bool:
139
+ # Use "get number of notifications" as a dummy request to test the token
140
+ # Use this api because it's likely checked more frequently than other APIs, less
141
+ # chance to get banned. And it's short and simple.
142
+ url = self.API_URL + "ntcmsgcnt"
143
+ headers = self.API_HEADERS
144
+ headers["accessToken"] = token.access_token
145
+ response = self.sessions.post(url, headers=headers)
146
+ _LOGGER.debug(f"{DOMAIN} - Test Token Response {response.text}")
147
+ response = response.json()
148
+ token_errors = ["7403", "7602"]
149
+ if (
150
+ response["responseHeader"]["responseCode"] == 1
151
+ and response["error"]["errorCode"] in token_errors
152
+ ):
153
+ return False
154
+ return True
155
+
138
156
  def get_vehicles(self, token: Token) -> list[Vehicle]:
139
157
  url = self.API_URL + "vhcllst"
140
158
  headers = self.API_HEADERS
@@ -134,7 +134,10 @@ class VehicleManager:
134
134
  def check_and_refresh_token(self) -> bool:
135
135
  if self.token is None:
136
136
  self.initialize()
137
- if self.token.valid_until <= dt.datetime.now(pytz.utc):
137
+ if (
138
+ self.token.valid_until <= dt.datetime.now(pytz.utc)
139
+ or self.api.test_token(self.token) is False
140
+ ):
138
141
  _LOGGER.debug(f"{DOMAIN} - Refresh token expired")
139
142
  self.token: Token = self.api.login(self.username, self.password)
140
143
  self.token.pin = self.pin
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: hyundai_kia_connect_api
3
- Version: 3.32.3
3
+ Version: 3.32.5
4
4
  Summary: Python Boilerplate contains all the boilerplate you need to create a Python package.
5
5
  Home-page: https://github.com/Hyundai-Kia-Connect/hyundai_kia_connect_api
6
6
  Author: Fuat Akgun
@@ -1,23 +1,23 @@
1
- hyundai_kia_connect_api/ApiImpl.py,sha256=eCEQEz6L-7EN2eKnrYiHrYC0pPV-ngGFcayF0tFdPxA,7569
1
+ hyundai_kia_connect_api/ApiImpl.py,sha256=mZO8AT-MBMBFspB7sZ2MkK_uxbbJ59J3rM_uJmU4-fE,7737
2
2
  hyundai_kia_connect_api/ApiImplType1.py,sha256=PnKwpbCoYGOXBWzBLIlDSrC6daIYeW9qlfW7TM4HCU0,12184
3
3
  hyundai_kia_connect_api/HyundaiBlueLinkApiUSA.py,sha256=Tx-L4ZWiPhq-uHcjWSUzjLEsfunV6nzyzqQpjPTYuIo,36831
4
4
  hyundai_kia_connect_api/KiaUvoApiAU.py,sha256=tslh0gzvPBwYJmcWlf9B0l7PyYZdy2e7GqpRkl8_Svk,48471
5
- hyundai_kia_connect_api/KiaUvoApiCA.py,sha256=uANAbsqG-ywLxIWLPPzcsougiRL8hho9gzg2kxErgT8,30874
5
+ hyundai_kia_connect_api/KiaUvoApiCA.py,sha256=IOiInYhUID1Vg15ChooBr7p8x1bwAUIGyZw7QqxmD80,31767
6
6
  hyundai_kia_connect_api/KiaUvoApiCN.py,sha256=cwIPZ0dU6HolKdooUQeQKlLAic6YU8dQmNs0VQDBgpQ,47035
7
7
  hyundai_kia_connect_api/KiaUvoApiEU.py,sha256=TxgO2dfLjKSKfSkRMoTL_fbmzRFRPb8oJ9IDztD50Ug,71300
8
8
  hyundai_kia_connect_api/KiaUvoApiUSA.py,sha256=G2sGtv88sBZuAz8qKYq_3_JNXIkxEjOBAzwM6R8GUi0,30548
9
9
  hyundai_kia_connect_api/Token.py,sha256=ZsPvXh1ID7FUTGHAqhZUZyrKT7xVbOtIn6FRJn4Ygf0,370
10
10
  hyundai_kia_connect_api/Vehicle.py,sha256=raCMzJsLuJnVHlFJ16VKdKat55L0uivbbcZRDCGWTxI,18793
11
- hyundai_kia_connect_api/VehicleManager.py,sha256=I0HDOsbXDen-26vyD7YR-RUgdaofOZrv_H_PPPuWjHg,11087
11
+ hyundai_kia_connect_api/VehicleManager.py,sha256=SfGuCT0foCJqUNNLXs_9lRR5XGQ7xd-fodTIs3JEl0o,11167
12
12
  hyundai_kia_connect_api/__init__.py,sha256=IkyVeIMbcFJZgLaiiNnUVA1Ferxvrm1bXHKVg01cxvc,319
13
13
  hyundai_kia_connect_api/bluelink.py,sha256=sBU7hlElie21GU4Ma-i4a5vdztGc2jtmlVBbbgUqmTE,19720
14
14
  hyundai_kia_connect_api/const.py,sha256=scBlhrMims0W6_pESVVdQz2uUxczg2cf2qDQ7avbhVo,2174
15
15
  hyundai_kia_connect_api/exceptions.py,sha256=m7gyDnvA5OVAK4EXSP_ZwE0s0uV8HsGUV0tiYwqofK0,1343
16
16
  hyundai_kia_connect_api/utils.py,sha256=J0aXUX-nKIoS3XbelatNh-DZlHRU2_DYz_Mg_ZUKQJU,1957
17
- hyundai_kia_connect_api-3.32.3.dist-info/AUTHORS.rst,sha256=T77OE1hrQF6YyDE6NbdMKyL66inHt7dnjHAzblwuk2A,155
18
- hyundai_kia_connect_api-3.32.3.dist-info/LICENSE,sha256=49hmc755oyMwKdZ-2epiorjStRB0PfcZR1w5_NXZPgs,1068
19
- hyundai_kia_connect_api-3.32.3.dist-info/METADATA,sha256=E1v9297ptlZ8mATwHUzP88PdwPQZ3OHXGMxT2t7E1jk,6872
20
- hyundai_kia_connect_api-3.32.3.dist-info/WHEEL,sha256=9Hm2OB-j1QcCUq9Jguht7ayGIIZBRTdOXD1qg9cCgPM,109
21
- hyundai_kia_connect_api-3.32.3.dist-info/entry_points.txt,sha256=XfrroRdyC_9q9VXjEZe5SdRPhkQyCCE4S7ZK6XSKelA,67
22
- hyundai_kia_connect_api-3.32.3.dist-info/top_level.txt,sha256=otZ7J_fN-s3EW4jD-kAearIo2OIzhQLR8DNEHIaFfds,24
23
- hyundai_kia_connect_api-3.32.3.dist-info/RECORD,,
17
+ hyundai_kia_connect_api-3.32.5.dist-info/AUTHORS.rst,sha256=T77OE1hrQF6YyDE6NbdMKyL66inHt7dnjHAzblwuk2A,155
18
+ hyundai_kia_connect_api-3.32.5.dist-info/LICENSE,sha256=49hmc755oyMwKdZ-2epiorjStRB0PfcZR1w5_NXZPgs,1068
19
+ hyundai_kia_connect_api-3.32.5.dist-info/METADATA,sha256=sOCl_6n3H20DpGwXK7OCuEtfH6MTMVYo3DF2lHCUYqo,6872
20
+ hyundai_kia_connect_api-3.32.5.dist-info/WHEEL,sha256=9Hm2OB-j1QcCUq9Jguht7ayGIIZBRTdOXD1qg9cCgPM,109
21
+ hyundai_kia_connect_api-3.32.5.dist-info/entry_points.txt,sha256=XfrroRdyC_9q9VXjEZe5SdRPhkQyCCE4S7ZK6XSKelA,67
22
+ hyundai_kia_connect_api-3.32.5.dist-info/top_level.txt,sha256=otZ7J_fN-s3EW4jD-kAearIo2OIzhQLR8DNEHIaFfds,24
23
+ hyundai_kia_connect_api-3.32.5.dist-info/RECORD,,