Skip to content

Commit 5d52bbe

Browse files
authored
feat: add more energy sensors properties (#208)
* feat: add more energy sensors properties * formatting * update tests * formatting * update tests
1 parent 326cf1b commit 5d52bbe

File tree

4 files changed

+176
-3
lines changed

4 files changed

+176
-3
lines changed

openevsehttp/__main__.py

+44
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,8 @@ def current_capacity(self) -> int:
719719
def usage_total(self) -> float:
720720
"""Return the total energy usage in Wh."""
721721
assert self._status is not None
722+
if "total_energy" in self._status:
723+
return self._status["total_energy"]
722724
return self._status["watthour"]
723725

724726
@property
@@ -781,8 +783,50 @@ def usage_session(self) -> float:
781783
Return the energy usage in Wh.
782784
"""
783785
assert self._status is not None
786+
if "session_energy" in self._status:
787+
return self._status["session_energy"]
784788
return float(round(self._status["wattsec"] / 3600, 2))
785789

790+
@property
791+
def total_day(self) -> float | None:
792+
"""Get the total day energy usage."""
793+
assert self._status is not None
794+
if "total_day" in self._status:
795+
return self._status["total_day"]
796+
return None
797+
798+
@property
799+
def total_week(self) -> float | None:
800+
"""Get the total week energy usage."""
801+
assert self._status is not None
802+
if "total_week" in self._status:
803+
return self._status["total_week"]
804+
return None
805+
806+
@property
807+
def total_month(self) -> float | None:
808+
"""Get the total week energy usage."""
809+
assert self._status is not None
810+
if "total_month" in self._status:
811+
return self._status["total_month"]
812+
return None
813+
814+
@property
815+
def total_year(self) -> float | None:
816+
"""Get the total year energy usage."""
817+
assert self._status is not None
818+
if "total_year" in self._status:
819+
return self._status["total_year"]
820+
return None
821+
822+
@property
823+
def has_limit(self) -> bool | None:
824+
"""Return if a limit has been set."""
825+
assert self._status is not None
826+
if "has_limit" in self._status:
827+
return self._status["has_limit"]
828+
return None
829+
786830
@property
787831
def protocol_version(self) -> str | None:
788832
"""Return the protocol version."""

tests/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def test_charger_new(mock_aioclient):
8181
mock_aioclient.get(
8282
TEST_URL_STATUS,
8383
status=200,
84-
body=load_fixture("v4_json/status.json"),
84+
body=load_fixture("v4_json/status-new.json"),
8585
)
8686
mock_aioclient.get(
8787
TEST_URL_CONFIG,
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"mode": "STA",
3+
"wifi_client_connected": 1,
4+
"eth_connected": 0,
5+
"net_connected": 1,
6+
"ipaddress": "192.168.21.10",
7+
"emoncms_connected": 0,
8+
"packets_sent": 0,
9+
"packets_success": 0,
10+
"mqtt_connected": 1,
11+
"ohm_hour": "NotConnected",
12+
"free_heap": 223464,
13+
"comm_sent": 345660,
14+
"comm_success": 332432,
15+
"rapi_connected": 1,
16+
"evse_connected": 1,
17+
"amp": 32.2,
18+
"voltage": 240,
19+
"pilot": 48,
20+
"wh": 64582,
21+
"temp": 503,
22+
"temp1": false,
23+
"temp2": 503,
24+
"temp3": false,
25+
"temp4": 560,
26+
"state": 254,
27+
"vehicle": 1,
28+
"colour": 6,
29+
"freeram": 223464,
30+
"divertmode": 0,
31+
"srssi": -61,
32+
"elapsed": 246,
33+
"wattsec": 992549,
34+
"watthour": 64582,
35+
"gfcicount": 1,
36+
"nogndcount": 0,
37+
"stuckcount": 0,
38+
"solar": 0,
39+
"grid_ie": 2891,
40+
"charge_rate": 0,
41+
"divert_update": 11,
42+
"ota_update": 0,
43+
"time": "2021-08-10T23:00:11Z",
44+
"offset": "-0700",
45+
"shaper": 1,
46+
"shaper_live_pwr": 2299,
47+
"shaper_max_pwr": 4000,
48+
"shaper_cur": 21,
49+
"vehicle_soc": 75,
50+
"vehicle_range": 468,
51+
"vehicle_eta": 18000,
52+
"session_energy": 7004,
53+
"has_limit": false,
54+
"total_day": 1234,
55+
"total_week": 12345,
56+
"total_month": 123456,
57+
"total_year": 1234567,
58+
"total_energy": 12345678
59+
}

tests/test_main.py

+72-2
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,12 @@ async def test_get_current_capacity(fixture, expected, request):
360360

361361

362362
@pytest.mark.parametrize(
363-
"fixture, expected", [("test_charger", 64582), ("test_charger_v2", 1585443)]
363+
"fixture, expected",
364+
[
365+
("test_charger", 64582),
366+
("test_charger_v2", 1585443),
367+
("test_charger_new", 12345678),
368+
],
364369
)
365370
async def test_get_usage_total(fixture, expected, request):
366371
"""Test v4 Status reply."""
@@ -427,7 +432,12 @@ async def test_get_time(fixture, expected, request):
427432

428433

429434
@pytest.mark.parametrize(
430-
"fixture, expected", [("test_charger", 275.71), ("test_charger_v2", 7003.41)]
435+
"fixture, expected",
436+
[
437+
("test_charger", 275.71),
438+
("test_charger_v2", 7003.41),
439+
("test_charger_new", 7004),
440+
],
431441
)
432442
async def test_get_usage_session(fixture, expected, request):
433443
"""Test v4 Status reply."""
@@ -1319,3 +1329,63 @@ async def test_set_service_level(test_charger, mock_aioclient, caplog):
13191329
)
13201330
with pytest.raises(ValueError):
13211331
await test_charger.set_service_level("A")
1332+
1333+
1334+
@pytest.mark.parametrize(
1335+
"fixture, expected",
1336+
[("test_charger", None), ("test_charger_v2", None), ("test_charger_new", False)],
1337+
)
1338+
async def test_get_has_limit(fixture, expected, request):
1339+
"""Test has_limit reply."""
1340+
charger = request.getfixturevalue(fixture)
1341+
await charger.update()
1342+
status = charger.has_limit
1343+
assert status == expected
1344+
1345+
1346+
@pytest.mark.parametrize(
1347+
"fixture, expected",
1348+
[("test_charger", None), ("test_charger_v2", None), ("test_charger_new", 1234)],
1349+
)
1350+
async def test_get_total_day(fixture, expected, request):
1351+
"""Test total_day reply."""
1352+
charger = request.getfixturevalue(fixture)
1353+
await charger.update()
1354+
status = charger.total_day
1355+
assert status == expected
1356+
1357+
1358+
@pytest.mark.parametrize(
1359+
"fixture, expected",
1360+
[("test_charger", None), ("test_charger_v2", None), ("test_charger_new", 12345)],
1361+
)
1362+
async def test_get_total_week(fixture, expected, request):
1363+
"""Test total_week reply."""
1364+
charger = request.getfixturevalue(fixture)
1365+
await charger.update()
1366+
status = charger.total_week
1367+
assert status == expected
1368+
1369+
1370+
@pytest.mark.parametrize(
1371+
"fixture, expected",
1372+
[("test_charger", None), ("test_charger_v2", None), ("test_charger_new", 123456)],
1373+
)
1374+
async def test_get_total_month(fixture, expected, request):
1375+
"""Test total_month reply."""
1376+
charger = request.getfixturevalue(fixture)
1377+
await charger.update()
1378+
status = charger.total_month
1379+
assert status == expected
1380+
1381+
1382+
@pytest.mark.parametrize(
1383+
"fixture, expected",
1384+
[("test_charger", None), ("test_charger_v2", None), ("test_charger_new", 1234567)],
1385+
)
1386+
async def test_get_total_year(fixture, expected, request):
1387+
"""Test total_year reply."""
1388+
charger = request.getfixturevalue(fixture)
1389+
await charger.update()
1390+
status = charger.total_year
1391+
assert status == expected

0 commit comments

Comments
 (0)