Skip to content

Commit

Permalink
Add charge state
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Feb 2, 2024
1 parent 13c5392 commit bded9c5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions custom_components/teslemetry/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
)
from .models import TeslemetryEnergyData, TeslemetryVehicleData

ChargeStates = {
"Starting": "starting",
"Charging": "charging",
"Stopped": "stopped",
"Complete": "complete",
"Disconnected": "disconnected",
"NoPower": "no_power",
}

@dataclass(frozen=True, kw_only=True)
class TeslemetrySensorEntityDescription(SensorEntityDescription):
Expand All @@ -50,6 +58,13 @@ class TeslemetrySensorEntityDescription(SensorEntityDescription):


VEHICLE_DESCRIPTIONS: tuple[TeslemetrySensorEntityDescription, ...] = (
TeslemetrySensorEntityDescription(
key="charge_state_charging_state",
icon="mdi:ev-station",
options=list(ChargeStates.values()),
device_class=SensorDeviceClass.ENUM,
value_fn=lambda value: ChargeStates[cast(str, value)],
),
TeslemetrySensorEntityDescription(
key="charge_state_usable_battery_level",
state_class=SensorStateClass.MEASUREMENT,
Expand Down

0 comments on commit bded9c5

Please sign in to comment.