Skip to content

Commit

Permalink
Added current draw sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-r committed Dec 29, 2023
1 parent 3f0ea9d commit 551aec6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This integration exposes the following entities:
* Pending Approval - On when a car is connected and waiting for approval
* Sensors
* Power Draw (Watts) - Power draw of connected car
* Current Draw (Amps) - Current draw of connected car
* Accumulative Energy Usage (kWh) - Total energy used by the charger
* Next Smart Charge Slot - The next time your car will start charging according to the Ohme-generated charge plan
* Switches (Settings) - Only options available to your charger model will show
Expand Down
49 changes: 46 additions & 3 deletions custom_components/ohme/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ async def async_setup_entry(
coordinator = hass.data[DOMAIN][DATA_CHARGESESSIONS_COORDINATOR]
stats_coordinator = hass.data[DOMAIN][DATA_STATISTICS_COORDINATOR]

sensors = [PowerDrawSensor(coordinator, hass, client), EnergyUsageSensor(
stats_coordinator, hass, client), NextSlotSensor(coordinator, hass, client)]
sensors = [PowerDrawSensor(coordinator, hass, client),
CurrentDrawSensor(coordinator, hass, client),
EnergyUsageSensor(stats_coordinator, hass, client),
NextSlotSensor(coordinator, hass, client)]

async_add_entities(sensors, update_before_add=True)


class PowerDrawSensor(CoordinatorEntity[OhmeChargeSessionsCoordinator], SensorEntity):
"""Sensor for car power draw."""
_attr_name = "Current Power Draw"
_attr_name = "Power Draw"
_attr_native_unit_of_measurement = UnitOfPower.WATT
_attr_device_class = SensorDeviceClass.POWER

Expand Down Expand Up @@ -73,6 +75,47 @@ def native_value(self):
return 0


class CurrentDrawSensor(CoordinatorEntity[OhmeChargeSessionsCoordinator], SensorEntity):
"""Sensor for car power draw."""
_attr_name = "Current Draw"
_attr_device_class = SensorDeviceClass.CURRENT

def __init__(
self,
coordinator: OhmeChargeSessionsCoordinator,
hass: HomeAssistant,
client):
super().__init__(coordinator=coordinator)

self._state = None
self._attributes = {}
self._last_updated = None
self._client = client

self.entity_id = generate_entity_id(
"sensor.{}", "ohme_current_draw", hass=hass)

self._attr_device_info = hass.data[DOMAIN][DATA_CLIENT].get_device_info(
)

@property
def unique_id(self) -> str:
"""Return the unique ID of the sensor."""
return self._client.get_unique_id("current_draw")

@property
def icon(self):
"""Icon of the sensor."""
return "mdi:current-ac"

@property
def native_value(self):
"""Get value from data returned from API by coordinator"""
if self.coordinator.data and self.coordinator.data['power']:
return self.coordinator.data['power']['amp']
return 0


class EnergyUsageSensor(CoordinatorEntity[OhmeStatisticsCoordinator], SensorEntity):
"""Sensor for total energy usage."""
_attr_name = "Accumulative Energy Usage"
Expand Down

0 comments on commit 551aec6

Please sign in to comment.