Skip to content

Commit

Permalink
feat: set charge limits (usa kia) (#169)
Browse files Browse the repository at this point in the history
* feat: set charge limits (usa kia)

* fix: remove excess comments
  • Loading branch information
dahlb authored Nov 26, 2021
1 parent e916d58 commit 9b8041b
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ You can install this either manually copying files or using HACS. Configuration
- force_update: this will make a call to your vehicle to get its latest data, do not overuse this!
- start_climate / stop_climate: I am not able to test this as I own an PHEV but looking for volunteers to help on this
- start_charge / stop_charge: You can control your charging using these services
- set_charge_limits: You can control your charging capacity limits using this services

I have posted an example screenshot from my own car.

Expand Down
19 changes: 19 additions & 0 deletions custom_components/kia_uvo/KiaUvoAPIUSA.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,22 @@ def stop_charge(self, token: Token):
token=token, url=url
)
self.last_action_xid = response.headers["Xid"]

def set_charge_limits(self, token: Token, ac_limit: int, dc_limit: int):
url = self.API_URL + "evc/sts"
body = {
"targetSOClist": [
{
"plugType": 0,
"targetSOClevel": dc_limit,
},
{
"plugType": 1,
"targetSOClevel": ac_limit,
},
]
}
response = self.post_request_with_logging_and_active_session(
token=token, url=url, json_body=body
)
self.last_action_xid = response.headers["Xid"]
3 changes: 3 additions & 0 deletions custom_components/kia_uvo/KiaUvoApiImpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ def start_charge(self, token: Token):
def stop_charge(self, token: Token):
pass

def set_charge_limits(self, token: Token, ac_limit: int, dc_limit: int):
pass

def get_timezone_by_region(self) -> tzinfo:
if REGIONS[self.region] == REGION_CANADA:
return dt_util.UTC
Expand Down
10 changes: 10 additions & 0 deletions custom_components/kia_uvo/Vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,16 @@ async def stop_charge(self):
await self.hass.async_add_executor_job(self.kia_uvo_api.stop_charge, self.token)
await self.force_update_loop_start()

async def set_charge_limits(self, ac_limit: int, dc_limit: int):
if ac_limit is None:
ac_limit = 90
if dc_limit is None:
dc_limit = 90
await self.hass.async_add_executor_job(
self.kia_uvo_api.set_charge_limits, self.token, ac_limit, dc_limit
)
await self.force_update_loop_start()

def login(self):
self.token = self.kia_uvo_api.login()

Expand Down
9 changes: 9 additions & 0 deletions custom_components/kia_uvo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,21 @@ async def async_handle_stop_charge(call):
vehicle: Vehicle = hass.data[DOMAIN][DATA_VEHICLE_INSTANCE]
await vehicle.stop_charge()

async def async_handle_set_charge_limits(call):
ac_limit = call.data.get("ac_limit")
dc_limit = call.data.get("dc_limit")
vehicle: Vehicle = hass.data[DOMAIN][DATA_VEHICLE_INSTANCE]
await vehicle.set_charge_limits(ac_limit, dc_limit)

hass.services.async_register(DOMAIN, "force_update", async_handle_force_update)
hass.services.async_register(DOMAIN, "update", async_handle_update)
hass.services.async_register(DOMAIN, "start_climate", async_handle_start_climate)
hass.services.async_register(DOMAIN, "stop_climate", async_handle_stop_climate)
hass.services.async_register(DOMAIN, "start_charge", async_handle_start_charge)
hass.services.async_register(DOMAIN, "stop_charge", async_handle_stop_charge)
hass.services.async_register(
DOMAIN, "set_charge_limits", async_handle_set_charge_limits
)

return True

Expand Down
27 changes: 27 additions & 0 deletions custom_components/kia_uvo/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,30 @@ lock:
description: Lock the vehicle
unlock:
description: Unlock the vehicle
set_charge_limits:
description: sets ac and dc charge capacity limits
fields:
dc_limit:
name: DC Charge limit
description: max charge capacity using DC charger
required: false
example: 50
default: 90
selector:
number:
min: 50
max: 100
step: 10
unit_of_measurement: '%'
ac_limit:
name: AC Charge limit
description: max charge capacity using AC charger
required: false
example: 50
default: 90
selector:
number:
min: 50
max: 100
step: 10
unit_of_measurement: '%'

0 comments on commit 9b8041b

Please sign in to comment.