Skip to content

Commit

Permalink
Spring clean (#75)
Browse files Browse the repository at this point in the history
* More testing for utils

* Unused import

* Change naming for energy sensor
  • Loading branch information
dan-r authored Apr 15, 2024
1 parent 3e144b1 commit a9d2d94
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ This integration exposes the following entities:
* Next Charge Slot End - The next time your car will stop charging according to the Ohme-generated charge plan
* Sensors (Other)
* CT Reading (Amps) - Reading from attached CT clamp
* Session Energy Usage (kWh) - Energy used in the current session. *This is supported by the energy dashboard.*
* Accumulative Energy Usage (kWh) - Total energy used by the charger (If enabled in options)
* Energy Usage (kWh) - Energy used in the current/last session. *This is supported by the energy dashboard.*
* Accumulative Energy Usage (kWh) - Deprecated - Total energy used by the charger (If enabled in options)
* Battery State of Charge (%) - If your car is API connected this is read from the car, if not it is how much charge Ohme thinks it has added
* Switches (Settings) - **Only options available to your charger model will show**
* Lock Buttons - Locks buttons on charger
Expand Down
4 changes: 2 additions & 2 deletions custom_components/ohme/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
SensorStateClass,
SensorEntity
)
import json
import math
import logging
from homeassistant.helpers.update_coordinator import CoordinatorEntity
Expand Down Expand Up @@ -263,7 +262,8 @@ def native_value(self):

class EnergyUsageSensor(CoordinatorEntity[OhmeChargeSessionsCoordinator], SensorEntity):
"""Sensor for total energy usage."""
_attr_name = "Session Energy Usage"
_attr_name = "Energy"
_attr_has_entity_name = True
_attr_native_unit_of_measurement = UnitOfEnergy.WATT_HOUR
_attr_suggested_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR
_attr_suggested_display_precision = 1
Expand Down
48 changes: 48 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,51 @@ async def test_charge_graph_in_slot(hass):
expected = True

assert expected == result


async def test_next_slot_no_live_no_in_progress():
"""Test that the _next_slot function returns the correct result when live and in_progress are False."""
TEST_DATA = [{"t": 10, "y": 0}, {"t": 20, "y": 0},
{"t": 30, "y": 10}, {"t": 40, "y": 20},
{"t": 50, "y": 20}, {"t": 60, "y": 0}]

result = utils._next_slot(TEST_DATA, live=False, in_progress=False)
expected = [None, None, 4, 0]

assert expected == result


async def test_next_slot_live_no_in_progress():
"""Test that the _next_slot function returns the correct result when live is True and in_progress is False."""
TEST_DATA = [{"t": 10, "y": 0}, {"t": 20, "y": 0},
{"t": 30, "y": 10}, {"t": 40, "y": 20},
{"t": 50, "y": 20}, {"t": 60, "y": 0}]

result = utils._next_slot(TEST_DATA, live=True, in_progress=False)
expected = [None, 41, 4, 20]

assert expected == result


async def test_next_slot_no_live_in_progress():
"""Test that the _next_slot function returns the correct result when live is False and in_progress is True."""
TEST_DATA = [{"t": 10, "y": 0}, {"t": 20, "y": 0},
{"t": 30, "y": 10}, {"t": 40, "y": 20},
{"t": 50, "y": 20}, {"t": 60, "y": 0}]

result = utils._next_slot(TEST_DATA, live=False, in_progress=True)
expected = [None, None, 4, 0]

assert expected == result


async def test_next_slot_live_in_progress():
"""Test that the _next_slot function returns the correct result when live and in_progress are True."""
TEST_DATA = [{"t": 10, "y": 0}, {"t": 20, "y": 0},
{"t": 30, "y": 10}, {"t": 40, "y": 20},
{"t": 50, "y": 20}, {"t": 60, "y": 0}]

result = utils._next_slot(TEST_DATA, live=True, in_progress=True)
expected = [None, 41, 4, 20]

assert expected == result

0 comments on commit a9d2d94

Please sign in to comment.