Skip to content

Commit

Permalink
feat(EU): support valet mode (#672)
Browse files Browse the repository at this point in the history
  • Loading branch information
asychow authored Nov 11, 2024
1 parent 5ff7396 commit d7634b6
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
22 changes: 20 additions & 2 deletions hyundai_kia_connect_api/ApiImpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@
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,
VEHICLE_LOCK_ACTION,
)
from .utils import get_child_value

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -128,7 +135,9 @@ def update_geocoded_location(
get_child_value(response, "address"),
)

def lock_action(self, token: Token, vehicle: Vehicle, action: str) -> str:
def lock_action(
self, token: Token, vehicle: Vehicle, action: VEHICLE_LOCK_ACTION
) -> str:
"""Lock or unlocks a vehicle. Returns the tracking ID"""
pass

Expand Down Expand Up @@ -220,3 +229,12 @@ def start_hazard_lights(self, token: Token, vehicle: Vehicle) -> str:
def start_hazard_lights_and_horn(self, token: Token, vehicle: Vehicle) -> str:
"""Turns on the hazard lights and horn for 30 seconds"""
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
16 changes: 16 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 @@ -1435,6 +1436,21 @@ 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())
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
15 changes: 13 additions & 2 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 @@ -257,11 +258,21 @@ def enable_vehicle(self, vehicle_id: str) -> None:

def schedule_charging_and_climate(
self, vehicle_id: str, options: ScheduleChargingClimateRequestOptions
) -> None:
self.api.schedule_charging_and_climate(
) -> str:
return self.api.schedule_charging_and_climate(
self.token, self.get_vehicle(vehicle_id), options
)

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

def stop_valet_mode(self, vehicle_id: str) -> str:
return 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 d7634b6

Please sign in to comment.