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: add soc sensors #154

Merged
merged 6 commits into from
Nov 26, 2021
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
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