Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit a9d2d94

Browse files
authored
Spring clean (#75)
* More testing for utils * Unused import * Change naming for energy sensor
1 parent 3e144b1 commit a9d2d94

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ This integration exposes the following entities:
5757
* Next Charge Slot End - The next time your car will stop charging according to the Ohme-generated charge plan
5858
* Sensors (Other)
5959
* CT Reading (Amps) - Reading from attached CT clamp
60-
* Session Energy Usage (kWh) - Energy used in the current session. *This is supported by the energy dashboard.*
61-
* Accumulative Energy Usage (kWh) - Total energy used by the charger (If enabled in options)
60+
* Energy Usage (kWh) - Energy used in the current/last session. *This is supported by the energy dashboard.*
61+
* Accumulative Energy Usage (kWh) - Deprecated - Total energy used by the charger (If enabled in options)
6262
* 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
6363
* Switches (Settings) - **Only options available to your charger model will show**
6464
* Lock Buttons - Locks buttons on charger

custom_components/ohme/sensor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
SensorStateClass,
77
SensorEntity
88
)
9-
import json
109
import math
1110
import logging
1211
from homeassistant.helpers.update_coordinator import CoordinatorEntity
@@ -263,7 +262,8 @@ def native_value(self):
263262

264263
class EnergyUsageSensor(CoordinatorEntity[OhmeChargeSessionsCoordinator], SensorEntity):
265264
"""Sensor for total energy usage."""
266-
_attr_name = "Session Energy Usage"
265+
_attr_name = "Energy"
266+
_attr_has_entity_name = True
267267
_attr_native_unit_of_measurement = UnitOfEnergy.WATT_HOUR
268268
_attr_suggested_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR
269269
_attr_suggested_display_precision = 1

tests/test_utils.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,51 @@ async def test_charge_graph_in_slot(hass):
5757
expected = True
5858

5959
assert expected == result
60+
61+
62+
async def test_next_slot_no_live_no_in_progress():
63+
"""Test that the _next_slot function returns the correct result when live and in_progress are False."""
64+
TEST_DATA = [{"t": 10, "y": 0}, {"t": 20, "y": 0},
65+
{"t": 30, "y": 10}, {"t": 40, "y": 20},
66+
{"t": 50, "y": 20}, {"t": 60, "y": 0}]
67+
68+
result = utils._next_slot(TEST_DATA, live=False, in_progress=False)
69+
expected = [None, None, 4, 0]
70+
71+
assert expected == result
72+
73+
74+
async def test_next_slot_live_no_in_progress():
75+
"""Test that the _next_slot function returns the correct result when live is True and in_progress is False."""
76+
TEST_DATA = [{"t": 10, "y": 0}, {"t": 20, "y": 0},
77+
{"t": 30, "y": 10}, {"t": 40, "y": 20},
78+
{"t": 50, "y": 20}, {"t": 60, "y": 0}]
79+
80+
result = utils._next_slot(TEST_DATA, live=True, in_progress=False)
81+
expected = [None, 41, 4, 20]
82+
83+
assert expected == result
84+
85+
86+
async def test_next_slot_no_live_in_progress():
87+
"""Test that the _next_slot function returns the correct result when live is False and in_progress is True."""
88+
TEST_DATA = [{"t": 10, "y": 0}, {"t": 20, "y": 0},
89+
{"t": 30, "y": 10}, {"t": 40, "y": 20},
90+
{"t": 50, "y": 20}, {"t": 60, "y": 0}]
91+
92+
result = utils._next_slot(TEST_DATA, live=False, in_progress=True)
93+
expected = [None, None, 4, 0]
94+
95+
assert expected == result
96+
97+
98+
async def test_next_slot_live_in_progress():
99+
"""Test that the _next_slot function returns the correct result when live and in_progress are True."""
100+
TEST_DATA = [{"t": 10, "y": 0}, {"t": 20, "y": 0},
101+
{"t": 30, "y": 10}, {"t": 40, "y": 20},
102+
{"t": 50, "y": 20}, {"t": 60, "y": 0}]
103+
104+
result = utils._next_slot(TEST_DATA, live=True, in_progress=True)
105+
expected = [None, 41, 4, 20]
106+
107+
assert expected == result

0 commit comments

Comments
 (0)