Skip to content

Commit 3fefc8a

Browse files
committed
feat: add action buttons for charge port, hazard, valet, and windows
- 9 new buttons: open/close charge port, hazard lights, hazard+horn, start/stop valet mode, open/close/vent all windows - Conditional creation for charge port and window buttons - Add window convenience methods to coordinator
1 parent 67bc037 commit 3fefc8a

4 files changed

Lines changed: 173 additions & 0 deletions

File tree

custom_components/kia_uvo/button.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,60 @@ class HyundaiKiaButtonDescription(ButtonEntityDescription):
3232
icon="mdi:refresh",
3333
press_action="async_force_refresh_vehicle",
3434
),
35+
HyundaiKiaButtonDescription(
36+
key="open_charge_port",
37+
translation_key="open_charge_port",
38+
icon="mdi:ev-plug-charging",
39+
press_action="async_open_charge_port",
40+
),
41+
HyundaiKiaButtonDescription(
42+
key="close_charge_port",
43+
translation_key="close_charge_port",
44+
icon="mdi:ev-plug",
45+
press_action="async_close_charge_port",
46+
),
47+
HyundaiKiaButtonDescription(
48+
key="start_hazard_lights",
49+
translation_key="start_hazard_lights",
50+
icon="mdi:hazard-lights",
51+
press_action="async_start_hazard_lights",
52+
),
53+
HyundaiKiaButtonDescription(
54+
key="start_hazard_lights_and_horn",
55+
translation_key="start_hazard_lights_and_horn",
56+
icon="mdi:car-emergency",
57+
press_action="async_start_hazard_lights_and_horn",
58+
),
59+
HyundaiKiaButtonDescription(
60+
key="start_valet_mode",
61+
translation_key="start_valet_mode",
62+
icon="mdi:key-variant",
63+
press_action="async_start_valet_mode",
64+
),
65+
HyundaiKiaButtonDescription(
66+
key="stop_valet_mode",
67+
translation_key="stop_valet_mode",
68+
icon="mdi:key",
69+
press_action="async_stop_valet_mode",
70+
),
71+
HyundaiKiaButtonDescription(
72+
key="open_all_windows",
73+
translation_key="open_all_windows",
74+
icon="mdi:window-maximize",
75+
press_action="async_open_all_windows",
76+
),
77+
HyundaiKiaButtonDescription(
78+
key="close_all_windows",
79+
translation_key="close_all_windows",
80+
icon="mdi:window-minimize",
81+
press_action="async_close_all_windows",
82+
),
83+
HyundaiKiaButtonDescription(
84+
key="vent_all_windows",
85+
translation_key="vent_all_windows",
86+
icon="mdi:window-open-variant",
87+
press_action="async_vent_all_windows",
88+
),
3589
)
3690

3791

@@ -45,6 +99,16 @@ async def async_setup_entry(
4599
for vehicle_id in coordinator.vehicle_manager.vehicles.keys():
46100
vehicle: Vehicle = coordinator.vehicle_manager.vehicles[vehicle_id]
47101
for description in BUTTON_DESCRIPTIONS:
102+
if description.key in ("open_charge_port", "close_charge_port"):
103+
if getattr(vehicle, "ev_charge_port_door_is_open", None) is None:
104+
continue
105+
if description.key in (
106+
"open_all_windows",
107+
"close_all_windows",
108+
"vent_all_windows",
109+
):
110+
if getattr(vehicle, "front_left_window_is_open", None) is None:
111+
continue
48112
entities.append(HyundaiKiaConnectButton(coordinator, description, vehicle))
49113

50114
async_add_entities(entities)

custom_components/kia_uvo/coordinator.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,61 @@ async def async_set_windows(
469469
self.async_await_action_and_refresh(vehicle_id, action_id)
470470
)
471471

472+
async def async_open_all_windows(self, vehicle_id: str):
473+
from hyundai_kia_connect_api.const import WINDOW_STATE
474+
475+
options = WindowRequestOptions(
476+
front_left=WINDOW_STATE.OPEN,
477+
front_right=WINDOW_STATE.OPEN,
478+
back_left=WINDOW_STATE.OPEN,
479+
back_right=WINDOW_STATE.OPEN,
480+
)
481+
await self._async_send_action(
482+
vehicle_id,
483+
lambda: self.vehicle_manager.set_windows_state(vehicle_id, options),
484+
"open all windows",
485+
)
486+
487+
async def async_close_all_windows(self, vehicle_id: str):
488+
from hyundai_kia_connect_api.const import WINDOW_STATE
489+
490+
options = WindowRequestOptions(
491+
front_left=WINDOW_STATE.CLOSED,
492+
front_right=WINDOW_STATE.CLOSED,
493+
back_left=WINDOW_STATE.CLOSED,
494+
back_right=WINDOW_STATE.CLOSED,
495+
)
496+
await self._async_send_action(
497+
vehicle_id,
498+
lambda: self.vehicle_manager.set_windows_state(vehicle_id, options),
499+
"close all windows",
500+
)
501+
502+
async def async_vent_all_windows(self, vehicle_id: str):
503+
from hyundai_kia_connect_api.const import WINDOW_STATE
504+
505+
options = WindowRequestOptions(
506+
front_left=WINDOW_STATE.VENTILATION,
507+
front_right=WINDOW_STATE.VENTILATION,
508+
back_left=WINDOW_STATE.VENTILATION,
509+
back_right=WINDOW_STATE.VENTILATION,
510+
)
511+
await self._async_send_action(
512+
vehicle_id,
513+
lambda: self.vehicle_manager.set_windows_state(vehicle_id, options),
514+
"vent all windows",
515+
)
516+
517+
async def _async_send_action(self, vehicle_id: str, action_fn, action_name: str):
518+
await self.async_check_and_refresh_token()
519+
try:
520+
action_id = await self.hass.async_add_executor_job(action_fn)
521+
except Exception as err:
522+
raise HomeAssistantError(f"Failed to {action_name}: {err}") from err
523+
self.hass.async_create_task(
524+
self.async_await_action_and_refresh(vehicle_id, action_id)
525+
)
526+
472527
async def _async_save_token(self):
473528
"""Persist the latest token into the config entry."""
474529
new_token = self.vehicle_manager.token.to_dict()

custom_components/kia_uvo/strings.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,33 @@
381381
"button": {
382382
"force_refresh": {
383383
"name": "Force Refresh"
384+
},
385+
"open_charge_port": {
386+
"name": "Open Charge Port"
387+
},
388+
"close_charge_port": {
389+
"name": "Close Charge Port"
390+
},
391+
"start_hazard_lights": {
392+
"name": "Start Hazard Lights"
393+
},
394+
"start_hazard_lights_and_horn": {
395+
"name": "Start Hazard Lights and Horn"
396+
},
397+
"start_valet_mode": {
398+
"name": "Start Valet Mode"
399+
},
400+
"stop_valet_mode": {
401+
"name": "Stop Valet Mode"
402+
},
403+
"open_all_windows": {
404+
"name": "Open All Windows"
405+
},
406+
"close_all_windows": {
407+
"name": "Close All Windows"
408+
},
409+
"vent_all_windows": {
410+
"name": "Vent All Windows"
384411
}
385412
},
386413
"cover": {

custom_components/kia_uvo/translations/en.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,33 @@
687687
"button": {
688688
"force_refresh": {
689689
"name": "Force Refresh"
690+
},
691+
"open_charge_port": {
692+
"name": "Open Charge Port"
693+
},
694+
"close_charge_port": {
695+
"name": "Close Charge Port"
696+
},
697+
"start_hazard_lights": {
698+
"name": "Start Hazard Lights"
699+
},
700+
"start_hazard_lights_and_horn": {
701+
"name": "Start Hazard Lights and Horn"
702+
},
703+
"start_valet_mode": {
704+
"name": "Start Valet Mode"
705+
},
706+
"stop_valet_mode": {
707+
"name": "Stop Valet Mode"
708+
},
709+
"open_all_windows": {
710+
"name": "Open All Windows"
711+
},
712+
"close_all_windows": {
713+
"name": "Close All Windows"
714+
},
715+
"vent_all_windows": {
716+
"name": "Vent All Windows"
690717
}
691718
},
692719
"cover": {

0 commit comments

Comments
 (0)