Skip to content

Commit

Permalink
fix(EU): SPA2 control token for charge port (#506)
Browse files Browse the repository at this point in the history
Co-authored-by: cdnninja <cdnninja@users.noreply.github.com>
  • Loading branch information
cdnninja and cdnninja committed Apr 23, 2024
1 parent e81af87 commit 209e098
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion hyundai_kia_connect_api/KiaUvoApiEU.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import datetime as dt
import logging
import uuid
import math
from time import sleep
from urllib.parse import parse_qs, urlparse

Expand Down Expand Up @@ -817,7 +818,7 @@ def charge_port_action(
payload = {"action": action.value}
_LOGGER.debug(f"{DOMAIN} - Charge Port Action Request: {payload}")
response = requests.post(
url, json=payload, headers=self._get_authenticated_headers(token)
url, json=payload, headers=self._get_control_headers(token)
).json()
_LOGGER.debug(f"{DOMAIN} - Charge Port Action Response: {response}")
_check_response_for_errors(response)
Expand Down Expand Up @@ -1380,6 +1381,27 @@ def _get_refresh_token(self, stamp, authorization_code):
refresh_token = token_type + " " + response["access_token"]
return token_type, refresh_token

def _get_control_token(self, token: Token) -> Token:
url = self.USER_API_URL + "pin?token="
headers = {
"Authorization": token.access_token,
"Content-type": "application/json",
"Host": self.BASE_URL,
"Accept-Encoding": "gzip",
"User-Agent": USER_AGENT_OK_HTTP,
}

data = {"deviceId": token.device_id, "pin": token.pin}
_LOGGER.debug(f"{DOMAIN} - Get Control Token Data: {data}")
response = requests.put(url, json=data, headers=headers)
response = response.json()
_LOGGER.debug(f"{DOMAIN} - Get Control Token Response {response}")
control_token = "Bearer " + response["controlToken"]
control_token_expire_at = math.floor(
dt.datetime.now().timestamp() + response["expiresTime"]
)
return control_token, control_token_expire_at

def check_action_status(
self,
token: Token,
Expand Down

0 comments on commit 209e098

Please sign in to comment.