Skip to content

Commit

Permalink
Add EV battery charge sensor (#142)
Browse files Browse the repository at this point in the history
* Add EV battery charge sensor

* Update sensor.py

* sensor.py: Fix linter errors, remove
  EV remaining charge from attributes
README.md: Added sensor
  • Loading branch information
uphillbattle authored May 2, 2023
1 parent 53cf22a commit 29867e9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ See [here](https://github.com/widewing/ha-toyota-na) for North America.
| <div style="width:250px">Name</div> | Description |
| ------------------------------------ | ------------------------------------------------------------------------ |
| `sensor.corolla` | Static data about your car. |
| `sensor.corolla_hvac` | EV battery information |
| `sensor.corolla_ev_battery_status` | EV battery information |
| `sensor.corolla_ev_remaining_charge` | EV battery remaining charge (in per cent of full capacity) |
| `sensor.corolla_fuel_tank` | Fuel tank information. |
| `sensor.corolla_hvac` | HVAC sensor showing current and target temperature, including other data |
| `sensor.corolla_odometer` | Odometer information. |
Expand Down
1 change: 1 addition & 0 deletions custom_components/toyota/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

# ICONS
ICON_BATTERY = "mdi:car-battery"
ICON_EV_BATTERY = "mdi:battery"
ICON_CAR = "mdi:car-info"
ICON_CAR_DOOR = "mdi:car-door"
ICON_CAR_DOOR_LOCK = "mdi:car-door-lock"
Expand Down
23 changes: 20 additions & 3 deletions custom_components/toyota/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
ICON_BATTERY,
ICON_CAR,
ICON_EV,
ICON_EV_BATTERY,
ICON_FUEL,
ICON_ODOMETER,
ICON_RANGE,
Expand Down Expand Up @@ -62,6 +63,9 @@ async def async_setup_entry(hass, config_entry, async_add_devices):

if vehicle.energy.chargeinfo:
sensors.append(ToyotaEVSensor(coordinator, index, "EV battery status"))
sensors.append(
ToyotaEVBatterySensor(coordinator, index, "EV remaining charge")
)

sensors.extend(
[
Expand Down Expand Up @@ -208,9 +212,6 @@ def extra_state_attributes(self):
"Remaining_time": self.coordinator.data[self.index].energy.chargeinfo.get(
"remaining_time", None
),
"Remaining_amount": self.coordinator.data[self.index].energy.chargeinfo.get(
"remaining_amount", None
),
}

return attribute
Expand All @@ -222,6 +223,22 @@ def state(self):
return self.coordinator.data[self.index].energy.chargeinfo.get("status", None)


class ToyotaEVBatterySensor(ToyotaBaseEntity):
"""Class for EV battery sensor."""

_attr_icon = ICON_EV_BATTERY
_attr_device_class = SensorDeviceClass.BATTERY
_attr_unit_of_measurement = PERCENTAGE

@property
def state(self) -> StateType:
"""Return remaining charge of the EV battery."""
level = self.coordinator.data[self.index].energy.chargeinfo.get(
"remaining_amount", None
)
return round(level, 0) if level else None


class ToyotaHVACSensor(ToyotaBaseEntity):
"""Class for hvac temperature sensor"""

Expand Down

0 comments on commit 29867e9

Please sign in to comment.