Skip to content

Commit

Permalink
feat(EU): support valet mode
Browse files Browse the repository at this point in the history
  • Loading branch information
asychow committed Nov 10, 2024
1 parent 4e586d8 commit 2dd6b1b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
15 changes: 14 additions & 1 deletion hyundai_kia_connect_api/ApiImpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from requests.exceptions import JSONDecodeError
from .Token import Token
from .Vehicle import Vehicle
from .const import WINDOW_STATE, CHARGE_PORT_ACTION, OrderStatus, DOMAIN
from .const import WINDOW_STATE, CHARGE_PORT_ACTION, OrderStatus, DOMAIN, VALET_MODE_ACTION
from .utils import get_child_value

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -212,3 +212,16 @@ def schedule_charging_and_climate(
Schedule charging and climate control. Returns the tracking ID
"""
pass

def valet_mode_action(
self,
token: Token,
vehicle: Vehicle,
action: VALET_MODE_ACTION
) -> str:
"""
feature only available for some regions.
Activate or Deactivate valet mode. Returns the tracking ID
"""
pass

15 changes: 15 additions & 0 deletions hyundai_kia_connect_api/KiaUvoApiEU.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
SEAT_STATUS,
TEMPERATURE_UNITS,
VEHICLE_LOCK_ACTION,
VALET_MODE_ACTION,
)
from .exceptions import (
AuthenticationError,
Expand Down Expand Up @@ -1405,6 +1406,20 @@ def set_default_departure_options(
token.device_id = self._get_device_id(self._get_stamp())
return response["msgId"]

def valet_mode_action(self, token: Token, vehicle: Vehicle, action: VALET_MODE_ACTION) -> str:
url = self.SPA_API_URL_V2 + "vehicles/" + vehicle.id + "/control/valet"

payload = {"action": action.value}
_LOGGER.debug(f"{DOMAIN} - Valet Mode Action Request: {payload}")
response = requests.post(
url, json=payload, headers=self._get_control_headers(token, vehicle)
).json()
_LOGGER.debug(f"{DOMAIN} - Valet Mode Action Response: {response}")
_check_response_for_errors(response)
token.device_id = self._get_device_id(self._get_stamp())
print(response)
return response["msgId"]

def _get_stamp(self) -> str:
raw_data = f"{self.APP_ID}:{int(dt.datetime.now().timestamp())}".encode()
result = bytes(b1 ^ b2 for b1, b2 in zip(self.CFB, raw_data))
Expand Down
11 changes: 11 additions & 0 deletions hyundai_kia_connect_api/VehicleManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
VEHICLE_LOCK_ACTION,
CHARGE_PORT_ACTION,
OrderStatus,
VALET_MODE_ACTION,
)

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -254,6 +255,16 @@ def schedule_charging_and_climate(
self.token, self.get_vehicle(vehicle_id), options
)

def start_valet_mode(self, vehicle_id: str) -> None:
self.api.valet_mode_action(
self.token, self.get_vehicle(vehicle_id), VALET_MODE_ACTION.ACTIVATE
)

def stop_valet_mode(self, vehicle_id: str) -> None:
self.api.valet_mode_action(
self.token, self.get_vehicle(vehicle_id), VALET_MODE_ACTION.DEACTIVATE
)

@staticmethod
def get_implementation_by_region_brand(
region: int, brand: int, language: str
Expand Down
5 changes: 5 additions & 0 deletions hyundai_kia_connect_api/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,8 @@ class WINDOW_STATE(IntEnum):
CLOSED = 0
OPEN = 1
VENTILATION = 2


class VALET_MODE_ACTION(Enum):
ACTIVATE = "activate"
DEACTIVATE = "deactivate"

0 comments on commit 2dd6b1b

Please sign in to comment.