Skip to content

Commit

Permalink
feat: add soc sensors (#154)
Browse files Browse the repository at this point in the history
* feat: add soc (charge limits) sensors

* fix: adjusted for typos

* fix: prevent usa kia reporting bogus soc range values
  • Loading branch information
dahlb authored Nov 26, 2021
1 parent 69e5266 commit e916d58
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
2 changes: 2 additions & 0 deletions custom_components/kia_uvo/KiaUvoAPIUSA.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ def __init__(
self.last_action_tracked = True
self.last_action_xid = None
self.last_action_completed = False
self.supports_soc_range = False

# Randomly generate a plausible device id on startup
self.device_id = (
"".join(
Expand Down
1 change: 1 addition & 0 deletions custom_components/kia_uvo/KiaUvoApiImpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(
self.region = region
self.brand = brand
self.last_action_tracked = False
self.supports_soc_range = True

def login(self) -> Token:
pass
Expand Down
47 changes: 46 additions & 1 deletion custom_components/kia_uvo/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,48 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
None,
)
)
INSTRUMENTS.append(
(
"targetSOCACCapacity",
"Target Capacity of Charge AC",
"vehicleStatus.evStatus.targetSOC.1.targetSOClevel",
PERCENTAGE,
"mdi:car-electric",
None,
)
)
INSTRUMENTS.append(
(
"targetSOCDCCapacity",
"Target Capacity of Charge DC",
"vehicleStatus.evStatus.targetSOC.0.targetSOClevel",
PERCENTAGE,
"mdi:car-electric",
None,
)
)

if vehicle.kia_uvo_api.supports_soc_range:
INSTRUMENTS.append(
(
"targetSOCACRange",
"Target Range of Charge AC",
"vehicleStatus.evStatus.targetSOC.1.dte.rangeByFuel.totalAvailableRange.value",
DYNAMIC_DISTANCE_UNIT,
"mdi:ev-station",
None,
)
)
INSTRUMENTS.append(
(
"targetSOCDCRange",
"Target Range of Charge DC",
"vehicleStatus.evStatus.targetSOC.0.dte.rangeByFuel.totalAvailableRange.value",
DYNAMIC_DISTANCE_UNIT,
"mdi:ev-station",
None,
)
)

if vehicle.engine_type is VEHICLE_ENGINE_TYPE.PHEV:
INSTRUMENTS.append(
Expand Down Expand Up @@ -181,7 +223,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
DEVICE_CLASS_BATTERY,
)
)

INSTRUMENTS.append(
(
"temperatureSetpoint",
Expand Down Expand Up @@ -256,6 +297,10 @@ def __init__(

@property
def state(self):
if self._id.startswith("targetSOC"):
self.vehicle.get_child_value("vehicleStatus.evStatus.targetSOC").sort(
key=lambda x: x["plugType"]
)
if self._id == "lastUpdated":
return dt_util.as_local(self.vehicle.last_updated).isoformat()

Expand Down

0 comments on commit e916d58

Please sign in to comment.