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

added SoC and Time to Charge sensors #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 1 addition & 1 deletion custom_components/kia_uvo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

# TODO List the platforms that you want to support.
# For your initial PR, limit it to 1 platform.
PLATFORMS = ["binary_sensor"]
PLATFORMS = ["binary_sensor","sensor"]

DEFAULT_SCAN_INTERVAL = timedelta(minutes=1)
FORCE_SCAN_INTERVAL = timedelta(minutes=60)
Expand Down
77 changes: 77 additions & 0 deletions custom_components/sensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from . import KiaUvoEntity
from .const import DOMAIN, VEHICLE_DATA, VEHICLE_ACCOUNT

async def async_setup_entry(hass, config_entry, async_add_entities):
vehicle_data = hass.data[DOMAIN][config_entry.entry_id][VEHICLE_ACCOUNT].vehicle_data

async_add_entities([BatterySoC(hass, config_entry, vehicle_data)], True)
async_add_entities([BatteryChargeTime(hass, config_entry, vehicle_data)], True)



class BatterySoC(KiaUvoEntity):
def __init__(self, hass, config_entry, vehicle_data):
super().__init__(hass, config_entry, vehicle_data)

@property
def icon(self):
"""Return the icon."""
#return "mdi:battery"
return "mdi:battery-charging" if self._vehicle_data.status["evStatus"]["batteryCharge"] else "mdi:battery"
@property
def state(self):
return self._vehicle_data.status["evStatus"]["batteryStatus"]

@property
def state_attributes(self):
return {
'unit_of_measurement': '%',
'minutes_to_charged': self._vehicle_data.status["evStatus"]["remainTime2"]["atc"]["value"],
}

@property
def device_class(self):
"""Return the device class."""
return "battery"

@property
def name(self):
return f'{self._vehicle_data.vehicle["nickName"]} SoC'

@property
def unique_id(self):
return f'kiauvo-SoC-{self._vehicle_data.vehicle["vehicleId"]}'


class BatteryChargeTime(KiaUvoEntity):
def __init__(self, hass, config_entry, vehicle_data):
super().__init__(hass, config_entry, vehicle_data)

@property
def icon(self):
"""Return the icon."""
return "mdi:battery"
#return "mdi:battery-charging" if self._vehicle_data.status["evStatus"]["batteryCharge"] else "mdi:battery"
@property
def state(self):
return self._vehicle_data.status["evStatus"]["remainTime2"]["atc"]["value"]

@property
def state_attributes(self):
return {
'unit_of_measurement': 'min',
}

@property
def device_class(self):
"""Return the device class."""
return "battery"

@property
def name(self):
return f'{self._vehicle_data.vehicle["nickName"]} Charge Time'

@property
def unique_id(self):
return f'kiauvo-Charge-Time-{self._vehicle_data.vehicle["vehicleId"]}'