hyundai-kia-connect-api 3.17.6__py2.py3-none-any.whl → 3.32.0__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.
@@ -5,20 +5,20 @@
5
5
  import datetime as dt
6
6
  import math
7
7
  import logging
8
- import re
9
8
  import uuid
9
+ from typing import Optional
10
10
  from time import sleep
11
11
  from urllib.parse import parse_qs, urlparse
12
12
 
13
13
  import pytz
14
14
  import requests
15
- from bs4 import BeautifulSoup
16
15
  from dateutil import tz
17
16
 
18
17
  from .ApiImpl import (
19
- ApiImpl,
20
18
  ClimateRequestOptions,
21
19
  )
20
+ from .ApiImplType1 import ApiImplType1
21
+
22
22
  from .Token import Token
23
23
  from .Vehicle import (
24
24
  Vehicle,
@@ -42,22 +42,28 @@ from .const import (
42
42
  TEMPERATURE_UNITS,
43
43
  VEHICLE_LOCK_ACTION,
44
44
  )
45
- from .exceptions import *
45
+ from .exceptions import (
46
+ AuthenticationError,
47
+ DuplicateRequestError,
48
+ RequestTimeoutError,
49
+ ServiceTemporaryUnavailable,
50
+ NoDataFound,
51
+ InvalidAPIResponseError,
52
+ APIError,
53
+ RateLimitingError,
54
+ )
46
55
  from .utils import (
47
56
  get_child_value,
48
57
  get_index_into_hex_temp,
49
58
  get_hex_temp_into_index,
59
+ parse_datetime,
50
60
  )
51
61
 
52
62
  _LOGGER = logging.getLogger(__name__)
53
63
 
54
64
  USER_AGENT_OK_HTTP: str = "okhttp/3.12.0"
55
- USER_AGENT_MOZILLA: str = (
56
- "Mozilla/5.0 (Linux; Android 4.1.1; Galaxy Nexus Build/JRO03C) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19" # noqa
57
- )
58
- ACCEPT_HEADER_ALL: str = (
59
- "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" # noqa
60
- )
65
+ USER_AGENT_MOZILLA: str = "Mozilla/5.0 (Linux; Android 4.1.1; Galaxy Nexus Build/JRO03C) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19" # noqa
66
+ ACCEPT_HEADER_ALL: str = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" # noqa
61
67
 
62
68
 
63
69
  def _check_response_for_errors(response: dict) -> None:
@@ -98,7 +104,7 @@ def _check_response_for_errors(response: dict) -> None:
98
104
  raise APIError(f"Server returned: '{response['resMsg']}'")
99
105
 
100
106
 
101
- class KiaUvoApiCN(ApiImpl):
107
+ class KiaUvoApiCN(ApiImplType1):
102
108
  data_timezone = tz.gettz("Asia/Shanghai")
103
109
  temperature_range = [x * 0.5 for x in range(28, 60)]
104
110
 
@@ -107,9 +113,7 @@ class KiaUvoApiCN(ApiImpl):
107
113
  self.BASE_DOMAIN: str = "prd.cn-ccapi.kia.com"
108
114
  self.CCSP_SERVICE_ID: str = "9d5df92a-06ae-435f-b459-8304f2efcc67"
109
115
  self.APP_ID: str = "eea8762c-adfc-4ee4-8d7a-6e2452ddf342"
110
- self.BASIC_AUTHORIZATION: str = (
111
- "Basic OWQ1ZGY5MmEtMDZhZS00MzVmLWI0NTktODMwNGYyZWZjYzY3OnRzWGRrVWcwOEF2MlpaelhPZ1d6Snl4VVQ2eWVTbk5OUWtYWFBSZEtXRUFOd2wxcA=="
112
- )
116
+ self.BASIC_AUTHORIZATION: str = "Basic OWQ1ZGY5MmEtMDZhZS00MzVmLWI0NTktODMwNGYyZWZjYzY3OnRzWGRrVWcwOEF2MlpaelhPZ1d6Snl4VVQ2eWVTbk5OUWtYWFBSZEtXRUFOd2wxcA==" # noqa
113
117
  elif BRANDS[brand] == BRAND_HYUNDAI:
114
118
  self.BASE_DOMAIN: str = "prd.cn-ccapi.hyundai.com"
115
119
  self.CCSP_SERVICE_ID: str = "72b3d019-5bc7-443d-a437-08f307cf06e2"
@@ -125,7 +129,9 @@ class KiaUvoApiCN(ApiImpl):
125
129
  self.CLIENT_ID: str = self.CCSP_SERVICE_ID
126
130
  self.GCM_SENDER_ID = 199360397125
127
131
 
128
- def _get_authenticated_headers(self, token: Token) -> dict:
132
+ def _get_authenticated_headers(
133
+ self, token: Token, ccs2_support: Optional[int] = None
134
+ ) -> dict:
129
135
  return {
130
136
  "Authorization": token.access_token,
131
137
  "ccsp-service-id": self.CCSP_SERVICE_ID,
@@ -209,25 +215,6 @@ class KiaUvoApiCN(ApiImpl):
209
215
  result.append(vehicle)
210
216
  return result
211
217
 
212
- def get_last_updated_at(self, value) -> dt.datetime:
213
- _LOGGER.debug(f"{DOMAIN} - last_updated_at - before {value}")
214
- if value is None:
215
- value = dt.datetime(2000, 1, 1, tzinfo=self.data_timezone)
216
- else:
217
- m = re.match(r"(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})", value)
218
- value = dt.datetime(
219
- year=int(m.group(1)),
220
- month=int(m.group(2)),
221
- day=int(m.group(3)),
222
- hour=int(m.group(4)),
223
- minute=int(m.group(5)),
224
- second=int(m.group(6)),
225
- tzinfo=self.data_timezone,
226
- )
227
-
228
- _LOGGER.debug(f"{DOMAIN} - last_updated_at - after {value}")
229
- return value
230
-
231
218
  def _get_time_from_string(self, value, timesection) -> dt.datetime.time:
232
219
  if value is not None:
233
220
  lastTwo = int(value[-2:])
@@ -290,8 +277,8 @@ class KiaUvoApiCN(ApiImpl):
290
277
 
291
278
  def _update_vehicle_properties(self, vehicle: Vehicle, state: dict) -> None:
292
279
  if get_child_value(state, "status.time"):
293
- vehicle.last_updated_at = self.get_last_updated_at(
294
- get_child_value(state, "status.time")
280
+ vehicle.last_updated_at = parse_datetime(
281
+ get_child_value(state, "status.time"), self.data_timezone
295
282
  )
296
283
  else:
297
284
  vehicle.last_updated_at = dt.datetime.now(self.data_timezone)
@@ -485,7 +472,7 @@ class KiaUvoApiCN(ApiImpl):
485
472
  vehicle.ev_charge_limits_dc = [
486
473
  x["targetSOClevel"] for x in target_soc_list if x["plugType"] == 0
487
474
  ][-1]
488
- except:
475
+ except Exception:
489
476
  _LOGGER.debug(f"{DOMAIN} - SOC Levels couldn't be found. May not be an EV.")
490
477
  if (
491
478
  get_child_value(
@@ -641,8 +628,8 @@ class KiaUvoApiCN(ApiImpl):
641
628
  vehicle.location = (
642
629
  get_child_value(state, "vehicleLocation.coord.lat"),
643
630
  get_child_value(state, "vehicleLocation.coord.lon"),
644
- self.get_last_updated_at(
645
- get_child_value(state, "vehicleLocation.time")
631
+ parse_datetime(
632
+ get_child_value(state, "vehicleLocation.time"), self.data_timezone
646
633
  ),
647
634
  )
648
635
  vehicle.data = state
@@ -674,7 +661,7 @@ class KiaUvoApiCN(ApiImpl):
674
661
  _LOGGER.debug(f"{DOMAIN} - _get_location response: {response}")
675
662
  _check_response_for_errors(response)
676
663
  return response["resMsg"]
677
- except:
664
+ except Exception:
678
665
  _LOGGER.debug(f"{DOMAIN} - _get_location failed")
679
666
  return None
680
667
 
@@ -842,7 +829,7 @@ class KiaUvoApiCN(ApiImpl):
842
829
  yyyymm_string,
843
830
  ) -> None:
844
831
  """
845
- Europe feature only.
832
+ feature only available for some regions.
846
833
  Updates the vehicle.month_trip_info for the specified month.
847
834
 
848
835
  Default this information is None:
@@ -886,7 +873,7 @@ class KiaUvoApiCN(ApiImpl):
886
873
  yyyymmdd_string,
887
874
  ) -> None:
888
875
  """
889
- Europe feature only.
876
+ feature only available for some regions.
890
877
  Updates the vehicle.day_trip_info information for the specified day.
891
878
 
892
879
  Default this information is None:
@@ -960,6 +947,7 @@ class KiaUvoApiCN(ApiImpl):
960
947
  battery_care_consumption=day["batteryMgPwrCsp"],
961
948
  regenerated_energy=day["regenPwr"],
962
949
  distance=day["calculativeOdo"],
950
+ distance_unit=vehicle.odometer_unit,
963
951
  )
964
952
  drivingInfo["dailyStats"].append(processedDay)
965
953