Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(EU): add services for hazard lights, hazard lights & horn and va… #970

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions custom_components/kia_uvo/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,41 @@ async def async_schedule_charging_and_climate(
self.hass.async_create_task(
self.async_await_action_and_refresh(vehicle_id, action_id)
)

async def async_start_hazard_lights(self, vehicle_id: str):
await self.async_check_and_refresh_token()
action_id = await self.hass.async_add_executor_job(
self.vehicle_manager.start_hazard_lights, vehicle_id
)
self.hass.async_create_task(
self.async_await_action_and_refresh(vehicle_id, action_id)
)

async def async_start_hazard_lights_and_horn(self, vehicle_id: str):
await self.async_check_and_refresh_token()
action_id = await self.hass.async_add_executor_job(
self.vehicle_manager.start_hazard_lights_and_horn,
vehicle_id,
)
self.hass.async_create_task(
self.async_await_action_and_refresh(vehicle_id, action_id)
)

async def async_start_valet_mode(self, vehicle_id: str):
await self.async_check_and_refresh_token()
action_id = await self.hass.async_add_executor_job(
self.vehicle_manager.start_valet_mode, vehicle_id
)
self.hass.async_create_task(
self.async_await_action_and_refresh(vehicle_id, action_id)
)

async def async_stop_valet_mode(self, vehicle_id: str):
await self.async_check_and_refresh_token()
action_id = await self.hass.async_add_executor_job(
self.vehicle_manager.stop_valet_mode,
vehicle_id,
)
self.hass.async_create_task(
self.async_await_action_and_refresh(vehicle_id, action_id)
)
32 changes: 32 additions & 0 deletions custom_components/kia_uvo/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
SERVICE_OPEN_CHARGE_PORT = "open_charge_port"
SERVICE_CLOSE_CHARGE_PORT = "close_charge_port"
SERVICE_SCHEDULE_CHARGING_AND_CLIMATE = "schedule_charging_and_climate"
SERVICE_START_HAZARD_LIGHTS = "start_hazard_lights"
SERVICE_START_HAZARD_LIGHTS_AND_HORN = "start_hazard_lights_and_horn"
SERVICE_START_VALET_MODE = "start_valet_mode"
SERVICE_STOP_VALET_MODE = "stop_valet_mode"

SUPPORTED_SERVICES = (
SERVICE_UPDATE,
Expand All @@ -43,6 +47,10 @@
SERVICE_OPEN_CHARGE_PORT,
SERVICE_CLOSE_CHARGE_PORT,
SERVICE_SCHEDULE_CHARGING_AND_CLIMATE,
SERVICE_START_HAZARD_LIGHTS,
SERVICE_START_HAZARD_LIGHTS_AND_HORN,
SERVICE_START_VALET_MODE,
SERVICE_STOP_VALET_MODE,
)

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -230,6 +238,26 @@ def initialize_departure_option(
vehicle_id, schedule_options
)

async def async_handle_start_hazard_lights(call):
coordinator = _get_coordinator_from_device(hass, call)
vehicle_id = _get_vehicle_id_from_device(hass, call)
await coordinator.async_start_hazard_lights(vehicle_id)

async def async_handle_start_hazard_lights_and_horn(call):
coordinator = _get_coordinator_from_device(hass, call)
vehicle_id = _get_vehicle_id_from_device(hass, call)
await coordinator.async_start_hazard_lights_and_horn(vehicle_id)

async def async_handle_start_valet_mode(call):
coordinator = _get_coordinator_from_device(hass, call)
vehicle_id = _get_vehicle_id_from_device(hass, call)
await coordinator.async_start_valet_mode(vehicle_id)

async def async_handle_stop_valet_mode(call):
coordinator = _get_coordinator_from_device(hass, call)
vehicle_id = _get_vehicle_id_from_device(hass, call)
await coordinator.async_stop_valet_mode(vehicle_id)

services = {
SERVICE_FORCE_UPDATE: async_handle_force_update,
SERVICE_UPDATE: async_handle_update,
Expand All @@ -244,6 +272,10 @@ def initialize_departure_option(
SERVICE_CLOSE_CHARGE_PORT: async_handle_close_charge_port,
SERVICE_SET_CHARGING_CURRENT: async_handle_set_charging_current,
SERVICE_SCHEDULE_CHARGING_AND_CLIMATE: async_handle_schedule_charging_and_climate,
SERVICE_START_HAZARD_LIGHTS: async_handle_start_hazard_lights,
SERVICE_START_HAZARD_LIGHTS_AND_HORN: async_handle_start_hazard_lights_and_horn,
SERVICE_START_VALET_MODE: async_handle_start_valet_mode,
SERVICE_STOP_VALET_MODE: async_handle_stop_valet_mode,
}

for service in SUPPORTED_SERVICES:
Expand Down
28 changes: 28 additions & 0 deletions custom_components/kia_uvo/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,31 @@ schedule_charging_and_climate:
default: false
selector:
boolean:
start_hazard_lights:
fields:
device_id:
required: false
selector:
device:
integration: kia_uvo
start_hazard_lights_and_horn:
fields:
device_id:
required: false
selector:
device:
integration: kia_uvo
start_valet_mode:
fields:
device_id:
required: false
selector:
device:
integration: kia_uvo
stop_valet_mode:
fields:
device_id:
required: false
selector:
device:
integration: kia_uvo
40 changes: 40 additions & 0 deletions custom_components/kia_uvo/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,46 @@
"description": "Front Windshield Defrost prior to departure"
}
}
},
"start_hazard_lights": {
"name": "Turn on the hazard lights",
"description": "Turn on the hazard lights for 30 seconds.",
"fields": {
"device_id": {
"name": "Vehicle",
"description": "Target vehicle"
}
}
},
"start_hazard_lights_and_horn": {
"name": "Turn on the hazard lights and horn",
"description": "Turn on the hazard lights and horn for 30 seconds.",
"fields": {
"device_id": {
"name": "Vehicle",
"description": "Target vehicle"
}
}
},
"start_valet_mode": {
"name": "Start valet mode",
"description": "Activate valet mode. If remote valet mode is activated while driving, the vehicle display screen is deactivated.",
"fields": {
"device_id": {
"name": "Vehicle",
"description": "Target vehicle"
}
}
},
"stop_valet_mode": {
"name": "Stop valet mode",
"description": "Deactivate valet mode.",
"fields": {
"device_id": {
"name": "Vehicle",
"description": "Target vehicle"
}
}
}
}
}
Loading