hyundai-kia-connect-api 3.33.0__py2.py3-none-any.whl → 3.33.1__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.
@@ -1,6 +1,8 @@
1
1
  """ApiImplType1.py"""
2
2
 
3
3
  import datetime as dt
4
+ import requests
5
+ import logging
4
6
  from typing import Optional
5
7
 
6
8
  from .ApiImpl import (
@@ -15,14 +17,70 @@ from .utils import (
15
17
  )
16
18
 
17
19
  from .const import (
20
+ DOMAIN,
18
21
  DISTANCE_UNITS,
19
22
  ENGINE_TYPES,
20
23
  SEAT_STATUS,
21
24
  TEMPERATURE_UNITS,
22
25
  )
23
26
 
27
+ from .exceptions import (
28
+ APIError,
29
+ DuplicateRequestError,
30
+ RequestTimeoutError,
31
+ ServiceTemporaryUnavailable,
32
+ NoDataFound,
33
+ InvalidAPIResponseError,
34
+ RateLimitingError,
35
+ DeviceIDError,
36
+ )
37
+
24
38
  USER_AGENT_OK_HTTP: str = "okhttp/3.12.0"
25
39
 
40
+ _LOGGER = logging.getLogger(__name__)
41
+
42
+
43
+ def _check_response_for_errors(response: dict) -> None:
44
+ """
45
+ Checks for errors in the API response.
46
+ If an error is found, an exception is raised.
47
+ retCode known values:
48
+ - S: success
49
+ - F: failure
50
+ resCode / resMsg known values:
51
+ - 0000: no error
52
+ - 4002: "Invalid request body - invalid deviceId",
53
+ relogin will resolve but a bandaid.
54
+ - 4004: "Duplicate request"
55
+ - 4081: "Request timeout"
56
+ - 5031: "Unavailable remote control - Service Temporary Unavailable"
57
+ - 5091: "Exceeds number of requests"
58
+ - 5921: "No Data Found v2 - No Data Found v2"
59
+ - 9999: "Undefined Error - Response timeout"
60
+ :param response: the API's JSON response
61
+ """
62
+
63
+ error_code_mapping = {
64
+ "4002": DeviceIDError,
65
+ "4004": DuplicateRequestError,
66
+ "4081": RequestTimeoutError,
67
+ "5031": ServiceTemporaryUnavailable,
68
+ "5091": RateLimitingError,
69
+ "5921": NoDataFound,
70
+ "9999": RequestTimeoutError,
71
+ }
72
+
73
+ if not any(x in response for x in ["retCode", "resCode", "resMsg"]):
74
+ _LOGGER.error(f"Unknown API response format: {response}")
75
+ raise InvalidAPIResponseError()
76
+
77
+ if response["retCode"] == "F":
78
+ if response["resCode"] in error_code_mapping:
79
+ raise error_code_mapping[response["resCode"]](response["resMsg"])
80
+ raise APIError(
81
+ f"Server returned: '{response['resCode']}' '{response['resMsg']}'"
82
+ )
83
+
26
84
 
27
85
  class ApiImplType1(ApiImpl):
28
86
  """ApiImplType1"""
@@ -319,3 +377,68 @@ class ApiImplType1(ApiImpl):
319
377
  )
320
378
 
321
379
  vehicle.data = state
380
+
381
+ def start_charge(self, token: Token, vehicle: Vehicle) -> str:
382
+ if not vehicle.ccu_ccs2_protocol_support:
383
+ url = self.SPA_API_URL + "vehicles/" + vehicle.id + "/control/charge"
384
+
385
+ payload = {"action": "start", "deviceId": token.device_id}
386
+ headers = self._get_authenticated_headers(
387
+ token, vehicle.ccu_ccs2_protocol_support
388
+ )
389
+
390
+ else:
391
+ url = (
392
+ self.SPA_API_URL_V2 + "vehicles/" + vehicle.id + "/ccs2/control/charge"
393
+ )
394
+
395
+ payload = {"command": "start"}
396
+ headers = self._get_control_headers(token, vehicle)
397
+
398
+ _LOGGER.debug(f"{DOMAIN} - Start Charge Action Request: {payload}")
399
+ response = requests.post(url, json=payload, headers=headers).json()
400
+ _LOGGER.debug(f"{DOMAIN} - Start Charge Action Response: {response}")
401
+ _check_response_for_errors(response)
402
+ token.device_id = self._get_device_id(self._get_stamp())
403
+ return response["msgId"]
404
+
405
+ def stop_charge(self, token: Token, vehicle: Vehicle) -> str:
406
+ if not vehicle.ccu_ccs2_protocol_support:
407
+ url = self.SPA_API_URL + "vehicles/" + vehicle.id + "/control/charge"
408
+
409
+ payload = {"action": "stop", "deviceId": token.device_id}
410
+ headers = self._get_authenticated_headers(
411
+ token, vehicle.ccu_ccs2_protocol_support
412
+ )
413
+
414
+ else:
415
+ url = (
416
+ self.SPA_API_URL_V2 + "vehicles/" + vehicle.id + "/ccs2/control/charge"
417
+ )
418
+
419
+ payload = {"command": "stop"}
420
+ headers = self._get_control_headers(token, vehicle)
421
+
422
+ _LOGGER.debug(f"{DOMAIN} - Stop Charge Action Request: {payload}")
423
+ response = requests.post(url, json=payload, headers=headers).json()
424
+ _LOGGER.debug(f"{DOMAIN} - Stop Charge Action Response: {response}")
425
+ _check_response_for_errors(response)
426
+ token.device_id = self._get_device_id(self._get_stamp())
427
+ return response["msgId"]
428
+
429
+ def set_charging_current(self, token: Token, vehicle: Vehicle, level: int) -> str:
430
+ url = (
431
+ self.SPA_API_URL + "vehicles/" + vehicle.id + "/ccs2/charge/chargingcurrent"
432
+ )
433
+
434
+ body = {"chargingCurrent": level}
435
+ response = requests.post(
436
+ url,
437
+ json=body,
438
+ headers=self._get_authenticated_headers(
439
+ token, vehicle.ccu_ccs2_protocol_support
440
+ ),
441
+ ).json()
442
+ _LOGGER.debug(f"{DOMAIN} - Set Charging Current Response: {response}")
443
+ _check_response_for_errors(response)
444
+ return response["msgId"]
@@ -29,6 +29,7 @@ from .Vehicle import (
29
29
  TripInfo,
30
30
  DayTripCounts,
31
31
  )
32
+ from .ApiImplType1 import _check_response_for_errors
32
33
  from .const import (
33
34
  BRAND_HYUNDAI,
34
35
  BRAND_KIA,
@@ -44,13 +45,7 @@ from .const import (
44
45
  )
45
46
  from .exceptions import (
46
47
  AuthenticationError,
47
- DuplicateRequestError,
48
- RequestTimeoutError,
49
- ServiceTemporaryUnavailable,
50
- NoDataFound,
51
- InvalidAPIResponseError,
52
48
  APIError,
53
- RateLimitingError,
54
49
  )
55
50
  from .utils import (
56
51
  get_child_value,
@@ -65,44 +60,6 @@ USER_AGENT_OK_HTTP: str = "okhttp/3.12.0"
65
60
  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
61
 
67
62
 
68
- def _check_response_for_errors(response: dict) -> None:
69
- """
70
- Checks for errors in the API response.
71
- If an error is found, an exception is raised.
72
- retCode known values:
73
- - S: success
74
- - F: failure
75
- resCode / resMsg known values:
76
- - 0000: no error
77
- - 4004: "Duplicate request"
78
- - 4081: "Request timeout"
79
- - 5031: "Unavailable remote control - Service Temporary Unavailable"
80
- - 5091: "Exceeds number of requests"
81
- - 5921: "No Data Found v2 - No Data Found v2"
82
- - 9999: "Undefined Error - Response timeout"
83
- :param response: the API's JSON response
84
- """
85
-
86
- error_code_mapping = {
87
- "4004": DuplicateRequestError,
88
- "4081": RequestTimeoutError,
89
- "5031": ServiceTemporaryUnavailable,
90
- "5091": RateLimitingError,
91
- "5921": NoDataFound,
92
- "9999": RequestTimeoutError,
93
- }
94
-
95
- if not any(x in response for x in ["retCode", "resCode", "resMsg"]):
96
- _LOGGER.error(f"Unknown API response format: {response}")
97
- raise InvalidAPIResponseError()
98
-
99
- if response["retCode"] == "F":
100
- if response["resCode"] in error_code_mapping:
101
- raise error_code_mapping[response["resCode"]](response["resMsg"])
102
- else:
103
- raise APIError(f"Server returned: '{response['resMsg']}'")
104
-
105
-
106
63
  class KiaUvoApiAU(ApiImplType1):
107
64
  data_timezone = tz.gettz("Australia/Sydney")
108
65
  temperature_range = [x * 0.5 for x in range(34, 54)]
@@ -783,30 +740,6 @@ class KiaUvoApiAU(ApiImplType1):
783
740
  _check_response_for_errors(response)
784
741
  return response["msgId"]
785
742
 
786
- def start_charge(self, token: Token, vehicle: Vehicle) -> str:
787
- url = self.SPA_API_URL + "vehicles/" + vehicle.id + "/control/charge"
788
-
789
- payload = {"action": "start", "deviceId": token.device_id}
790
- _LOGGER.debug(f"{DOMAIN} - Start Charge Action Request: {payload}")
791
- response = requests.post(
792
- url, json=payload, headers=self._get_control_headers(token)
793
- ).json()
794
- _LOGGER.debug(f"{DOMAIN} - Start Charge Action Response: {response}")
795
- _check_response_for_errors(response)
796
- return response["msgId"]
797
-
798
- def stop_charge(self, token: Token, vehicle: Vehicle) -> str:
799
- url = self.SPA_API_URL + "vehicles/" + vehicle.id + "/control/charge"
800
-
801
- payload = {"action": "stop", "deviceId": token.device_id}
802
- _LOGGER.debug(f"{DOMAIN} - Stop Charge Action Request {payload}")
803
- response = requests.post(
804
- url, json=payload, headers=self._get_control_headers(token)
805
- ).json()
806
- _LOGGER.debug(f"{DOMAIN} - Stop Charge Action Response: {response}")
807
- _check_response_for_errors(response)
808
- return response["msgId"]
809
-
810
743
  def _get_charge_limits(self, token: Token, vehicle: Vehicle) -> dict:
811
744
  # Not currently used as value is in the general get.
812
745
  # Most likely this forces the car the update it.
@@ -21,6 +21,7 @@ from .ApiImpl import (
21
21
  ScheduleChargingClimateRequestOptions,
22
22
  )
23
23
  from .ApiImplType1 import ApiImplType1
24
+ from .ApiImplType1 import _check_response_for_errors
24
25
 
25
26
  from .Token import Token
26
27
  from .Vehicle import (
@@ -49,14 +50,7 @@ from .const import (
49
50
  )
50
51
  from .exceptions import (
51
52
  AuthenticationError,
52
- DuplicateRequestError,
53
- RequestTimeoutError,
54
- ServiceTemporaryUnavailable,
55
- NoDataFound,
56
- InvalidAPIResponseError,
57
53
  APIError,
58
- RateLimitingError,
59
- DeviceIDError,
60
54
  )
61
55
  from .utils import (
62
56
  get_child_value,
@@ -90,48 +84,6 @@ SUPPORTED_LANGUAGES_LIST = [
90
84
  ]
91
85
 
92
86
 
93
- def _check_response_for_errors(response: dict) -> None:
94
- """
95
- Checks for errors in the API response.
96
- If an error is found, an exception is raised.
97
- retCode known values:
98
- - S: success
99
- - F: failure
100
- resCode / resMsg known values:
101
- - 0000: no error
102
- - 4002: "Invalid request body - invalid deviceId",
103
- relogin will resolve but a bandaid.
104
- - 4004: "Duplicate request"
105
- - 4081: "Request timeout"
106
- - 5031: "Unavailable remote control - Service Temporary Unavailable"
107
- - 5091: "Exceeds number of requests"
108
- - 5921: "No Data Found v2 - No Data Found v2"
109
- - 9999: "Undefined Error - Response timeout"
110
- :param response: the API's JSON response
111
- """
112
-
113
- error_code_mapping = {
114
- "4002": DeviceIDError,
115
- "4004": DuplicateRequestError,
116
- "4081": RequestTimeoutError,
117
- "5031": ServiceTemporaryUnavailable,
118
- "5091": RateLimitingError,
119
- "5921": NoDataFound,
120
- "9999": RequestTimeoutError,
121
- }
122
-
123
- if not any(x in response for x in ["retCode", "resCode", "resMsg"]):
124
- _LOGGER.error(f"Unknown API response format: {response}")
125
- raise InvalidAPIResponseError()
126
-
127
- if response["retCode"] == "F":
128
- if response["resCode"] in error_code_mapping:
129
- raise error_code_mapping[response["resCode"]](response["resMsg"])
130
- raise APIError(
131
- f"Server returned: '{response['resCode']}' '{response['resMsg']}'"
132
- )
133
-
134
-
135
87
  class KiaUvoApiEU(ApiImplType1):
136
88
  data_timezone = tz.gettz("Europe/Berlin")
137
89
  temperature_range = [x * 0.5 for x in range(28, 60)]
@@ -1013,54 +965,6 @@ class KiaUvoApiEU(ApiImplType1):
1013
965
  token.device_id = self._get_device_id(self._get_stamp())
1014
966
  return response["msgId"]
1015
967
 
1016
- def start_charge(self, token: Token, vehicle: Vehicle) -> str:
1017
- if not vehicle.ccu_ccs2_protocol_support:
1018
- url = self.SPA_API_URL + "vehicles/" + vehicle.id + "/control/charge"
1019
-
1020
- payload = {"action": "start", "deviceId": token.device_id}
1021
- headers = self._get_authenticated_headers(
1022
- token, vehicle.ccu_ccs2_protocol_support
1023
- )
1024
-
1025
- else:
1026
- url = (
1027
- self.SPA_API_URL_V2 + "vehicles/" + vehicle.id + "/ccs2/control/charge"
1028
- )
1029
-
1030
- payload = {"command": "start"}
1031
- headers = self._get_control_headers(token, vehicle)
1032
-
1033
- _LOGGER.debug(f"{DOMAIN} - Start Charge Action Request: {payload}")
1034
- response = requests.post(url, json=payload, headers=headers).json()
1035
- _LOGGER.debug(f"{DOMAIN} - Start Charge Action Response: {response}")
1036
- _check_response_for_errors(response)
1037
- token.device_id = self._get_device_id(self._get_stamp())
1038
- return response["msgId"]
1039
-
1040
- def stop_charge(self, token: Token, vehicle: Vehicle) -> str:
1041
- if not vehicle.ccu_ccs2_protocol_support:
1042
- url = self.SPA_API_URL + "vehicles/" + vehicle.id + "/control/charge"
1043
-
1044
- payload = {"action": "stop", "deviceId": token.device_id}
1045
- headers = self._get_authenticated_headers(
1046
- token, vehicle.ccu_ccs2_protocol_support
1047
- )
1048
-
1049
- else:
1050
- url = (
1051
- self.SPA_API_URL_V2 + "vehicles/" + vehicle.id + "/ccs2/control/charge"
1052
- )
1053
-
1054
- payload = {"command": "stop"}
1055
- headers = self._get_control_headers(token, vehicle)
1056
-
1057
- _LOGGER.debug(f"{DOMAIN} - Stop Charge Action Request: {payload}")
1058
- response = requests.post(url, json=payload, headers=headers).json()
1059
- _LOGGER.debug(f"{DOMAIN} - Stop Charge Action Response: {response}")
1060
- _check_response_for_errors(response)
1061
- token.device_id = self._get_device_id(self._get_stamp())
1062
- return response["msgId"]
1063
-
1064
968
  def start_hazard_lights(self, token: Token, vehicle: Vehicle) -> str:
1065
969
  url = self.SPA_API_URL_V2 + "vehicles/" + vehicle.id + "/ccs2/control/light"
1066
970
 
@@ -1330,23 +1234,6 @@ class KiaUvoApiEU(ApiImplType1):
1330
1234
  _check_response_for_errors(response)
1331
1235
  return response["msgId"]
1332
1236
 
1333
- def set_charging_current(self, token: Token, vehicle: Vehicle, level: int) -> str:
1334
- url = (
1335
- self.SPA_API_URL + "vehicles/" + vehicle.id + "/ccs2/charge/chargingcurrent"
1336
- )
1337
-
1338
- body = {"chargingCurrent": level}
1339
- response = requests.post(
1340
- url,
1341
- json=body,
1342
- headers=self._get_authenticated_headers(
1343
- token, vehicle.ccu_ccs2_protocol_support
1344
- ),
1345
- ).json()
1346
- _LOGGER.debug(f"{DOMAIN} - Set Charging Current Response: {response}")
1347
- _check_response_for_errors(response)
1348
- return response["msgId"]
1349
-
1350
1237
  def schedule_charging_and_climate(
1351
1238
  self,
1352
1239
  token: Token,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hyundai_kia_connect_api
3
- Version: 3.33.0
3
+ Version: 3.33.1
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,10 +1,10 @@
1
1
  hyundai_kia_connect_api/ApiImpl.py,sha256=PuK3dID01qTGB6aGtQY4uf1hF-t4d03wUzG_gUFn_1g,8353
2
- hyundai_kia_connect_api/ApiImplType1.py,sha256=PnKwpbCoYGOXBWzBLIlDSrC6daIYeW9qlfW7TM4HCU0,12184
2
+ hyundai_kia_connect_api/ApiImplType1.py,sha256=V2rieKKPhR-92E4_0N6wKFEupab5OgAaKxHxB5OKVi4,16587
3
3
  hyundai_kia_connect_api/HyundaiBlueLinkApiUSA.py,sha256=FGYyrS3dSq8Plfu8DQMwVG1LM3nmRv8Y4vrN7wZ4oVY,36988
4
- hyundai_kia_connect_api/KiaUvoApiAU.py,sha256=tslh0gzvPBwYJmcWlf9B0l7PyYZdy2e7GqpRkl8_Svk,48471
4
+ hyundai_kia_connect_api/KiaUvoApiAU.py,sha256=0QmWLeLa6RL3tKrCLOfemhVDmC8pdsxykdNd_C1DHLg,45945
5
5
  hyundai_kia_connect_api/KiaUvoApiCA.py,sha256=XBya0yHZ2MC3TBVQLSc6N-SzmGt_s3l4nGVyNgmjl9Q,32514
6
6
  hyundai_kia_connect_api/KiaUvoApiCN.py,sha256=cwIPZ0dU6HolKdooUQeQKlLAic6YU8dQmNs0VQDBgpQ,47035
7
- hyundai_kia_connect_api/KiaUvoApiEU.py,sha256=TxgO2dfLjKSKfSkRMoTL_fbmzRFRPb8oJ9IDztD50Ug,71300
7
+ hyundai_kia_connect_api/KiaUvoApiEU.py,sha256=RuPWWsyEYP4xYPH5YTNnC2Vzgkm0tB9PE9Ar2wK2v_M,67075
8
8
  hyundai_kia_connect_api/KiaUvoApiUSA.py,sha256=8DP7iOORHtU98LipcAYEPdtJvubBlUP2-jlDxAhTDhQ,30548
9
9
  hyundai_kia_connect_api/Token.py,sha256=ZsPvXh1ID7FUTGHAqhZUZyrKT7xVbOtIn6FRJn4Ygf0,370
10
10
  hyundai_kia_connect_api/Vehicle.py,sha256=hZT0wU7-mMi85bgqNHMu6CyhQQ5h-Jfmoc1ce2uPhYM,18867
@@ -14,10 +14,10 @@ hyundai_kia_connect_api/bluelink.py,sha256=JiNIHl-Qi8zwqyN6ywKg5CdXOLT74WkvpjVcn
14
14
  hyundai_kia_connect_api/const.py,sha256=dXEh-lpthH8000nUXFoRZpQXkTxVHDAgDe_KqnSZhZw,2280
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.33.0.dist-info/licenses/AUTHORS.rst,sha256=T77OE1hrQF6YyDE6NbdMKyL66inHt7dnjHAzblwuk2A,155
18
- hyundai_kia_connect_api-3.33.0.dist-info/licenses/LICENSE,sha256=49hmc755oyMwKdZ-2epiorjStRB0PfcZR1w5_NXZPgs,1068
19
- hyundai_kia_connect_api-3.33.0.dist-info/METADATA,sha256=XVjyHKnqYRRtOs_DdZDcMRdcNAIqAMmQRp8QmIongwU,7142
20
- hyundai_kia_connect_api-3.33.0.dist-info/WHEEL,sha256=MAQBAzGbXNI3bUmkDsiV_duv8i-gcdnLzw7cfUFwqhU,109
21
- hyundai_kia_connect_api-3.33.0.dist-info/entry_points.txt,sha256=XfrroRdyC_9q9VXjEZe5SdRPhkQyCCE4S7ZK6XSKelA,67
22
- hyundai_kia_connect_api-3.33.0.dist-info/top_level.txt,sha256=otZ7J_fN-s3EW4jD-kAearIo2OIzhQLR8DNEHIaFfds,24
23
- hyundai_kia_connect_api-3.33.0.dist-info/RECORD,,
17
+ hyundai_kia_connect_api-3.33.1.dist-info/licenses/AUTHORS.rst,sha256=T77OE1hrQF6YyDE6NbdMKyL66inHt7dnjHAzblwuk2A,155
18
+ hyundai_kia_connect_api-3.33.1.dist-info/licenses/LICENSE,sha256=49hmc755oyMwKdZ-2epiorjStRB0PfcZR1w5_NXZPgs,1068
19
+ hyundai_kia_connect_api-3.33.1.dist-info/METADATA,sha256=q9Xdkya0cPSkYGagr8hL8l0P07KgHgi3ZLM5R--dpaU,7142
20
+ hyundai_kia_connect_api-3.33.1.dist-info/WHEEL,sha256=MAQBAzGbXNI3bUmkDsiV_duv8i-gcdnLzw7cfUFwqhU,109
21
+ hyundai_kia_connect_api-3.33.1.dist-info/entry_points.txt,sha256=XfrroRdyC_9q9VXjEZe5SdRPhkQyCCE4S7ZK6XSKelA,67
22
+ hyundai_kia_connect_api-3.33.1.dist-info/top_level.txt,sha256=otZ7J_fN-s3EW4jD-kAearIo2OIzhQLR8DNEHIaFfds,24
23
+ hyundai_kia_connect_api-3.33.1.dist-info/RECORD,,