Skip to content

Commit

Permalink
fix: KiaUVOApiCA check_action_status (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjantoine committed Jun 19, 2024
1 parent a54fb43 commit be9b0d7
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion hyundai_kia_connect_api/KiaUvoApiCA.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# pylint:disable=unused-argument,missing-timeout,logging-fstring-interpolation,bare-except,invalid-name,missing-function-docstring

import time
import datetime as dt
import json
import logging
Expand Down Expand Up @@ -637,6 +638,10 @@ def check_action_status(
synchronous: bool = False,
timeout: int = 0,
) -> OrderStatus:
if timeout < 0:
return OrderStatus.TIMEOUT
start_time = dt.datetime.now()

url = self.API_URL + "rmtsts"
headers = self.API_HEADERS
headers["accessToken"] = token.access_token
Expand All @@ -649,10 +654,27 @@ def check_action_status(
last_action_completed = (
response["result"]["transaction"]["apiStatusCode"] != "null"
)

if last_action_completed:
action_status = response["result"]["transaction"]["apiStatusCode"]
_LOGGER.debug(f"{DOMAIN} - Last action_status: {action_status}")
return last_action_completed

if response["responseHeader"]["responseCode"] == 1:
return OrderStatus.FAILED
elif response["result"]["transaction"]["apiResult"] == "C":
return OrderStatus.SUCCESS
elif response["result"]["transaction"]["apiResult"] == "P":
if not synchronous:
return OrderStatus.PENDING
else:
timedelta = dt.datetime.now() - start_time
time_left = timeout - timedelta.seconds - 10
time.sleep(10)
return self.check_action_status(
token, vehicle, action_id, synchronous, time_left
)

return OrderStatus.FAILED

def start_charge(self, token: Token, vehicle: Vehicle) -> str:
url = self.API_URL + "evc/rcstrt"
Expand Down

0 comments on commit be9b0d7

Please sign in to comment.