Skip to content

Commit

Permalink
Merge pull request #6 from videojedi/add-libbi-tests
Browse files Browse the repository at this point in the history
Add libbi tests
  • Loading branch information
trizmark authored Sep 21, 2023
2 parents 3ba6827 + e3d2365 commit e87819b
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pymyenergi/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.28
0.0.29
8 changes: 4 additions & 4 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-r requirements_dev.txt
pytest-sugar==0.9.4
pytest-timeout==1.4.2
pytest-sugar==0.9.7
pytest-timeout==2.1.0
pytest-httpx
pytest-xdist==2.2.1
pytest==6.2.4
pytest-xdist==3.3.1
pytest==7.4.2
pytest-asyncio
9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ def harvi_fetch_data_fixture():
yield


@pytest.fixture(name="libbi_fetch_data_fixture")
def libbi_fetch_data_fixture():
"""Mock data from client.fetch_data()"""
with patch(
"pymyenergi.libbi.Libbi.fetch_data", return_value=load_fixture_json("libbi")
):
yield


# @pytest.fixture
# def eddi_connection_mock():
# with patch("pymyenergi.eddi.Eddi._connection"):
Expand Down
46 changes: 46 additions & 0 deletions tests/fixtures/client.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
{ "key": "Z17005900", "val": "Test Zappi 2" },
{ "key": "H10645200", "val": "Test Harvi 1" },
{ "key": "H10644500", "val": "Test Harvi 2" },
{ "key": "L24047164", "val": "Test Libbi 1" },
{ "key": "siteName", "val": "Test Site" }
]
},
Expand Down Expand Up @@ -154,6 +155,51 @@
}
]
},
{
"libbi": [
{
"sno": 24047164,
"dat": "20-09-2023",
"tim": "14: 53: 03",
"ectp1": -457,
"ectp2": -72,
"ectp3": 0,
"ectt1": "Internal Load",
"ectt2": "Grid",
"ectt3": "None",
"ectp4": 0,
"ectp5": 320,
"ectt4": "None",
"ectt5": "DCPV",
"ectt6": "None",
"dst": 1,
"tz": 0,
"lmo": "BALANCE",
"sta": 6,
"frq": 49.92,
"pri": 1,
"soc": 45,
"isp": "True",
"pha": 1,
"vol": 2350,
"mbc": 20400,
"mic": 5000,
"gen": 320,
"grd": -38,
"div": -457,
"ect1p": 1,
"ect2p": 1,
"ect3p": 1,
"batteryDischargingBoost": "False",
"pvDirectlyConnected": "True",
"g100LockoutState": "NONE",
"cmt": 254,
"fwv": "3702S5.041",
"newAppAvailable": "False",
"newBootloaderAvailable": "False"
}
]
},
{
"asn": "s8.myenergi.net",
"fwv": "3401S3077"
Expand Down
41 changes: 41 additions & 0 deletions tests/fixtures/libbi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"sno": 24047164,
"dat": "20-09-2023",
"tim": "14: 53: 03",
"ectp1": -457,
"ectp2": -72,
"ectp3": 0,
"ectt1": "Internal Load",
"ectt2": "Grid",
"ectt3": "None",
"ectp4": 0,
"ectp5": 320,
"ectt4": "None",
"ectt5": "DCPV",
"ectt6": "None",
"dst": 1,
"tz": 0,
"lmo": "BALANCE",
"sta": 6,
"frq": 49.92,
"pri": 1,
"soc": 45,
"isp": "True",
"pha": 1,
"vol": 2350,
"mbc": 20400,
"mic": 5000,
"gen": 320,
"grd": -38,
"div": -457,
"ect1p": 1,
"ect2p": 1,
"ect3p": 1,
"batteryDischargingBoost": "False",
"pvDirectlyConnected": "True",
"g100LockoutState": "NONE",
"cmt": 254,
"fwv": "3702S5.041",
"newAppAvailable": "False",
"newBootloaderAvailable": "False"
}
10 changes: 9 additions & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pymyenergi.eddi import Eddi
from pymyenergi.harvi import Harvi
from pymyenergi.zappi import Zappi
from pymyenergi.libbi import Libbi

# All test coroutines will be treated as marked.
pytestmark = pytest.mark.asyncio
Expand All @@ -25,7 +26,7 @@ async def test_init_error(error_on_client_fetch_data):
async def test_get_all_devices(client_fetch_data_fixture):
client = MyenergiClient(conn)
devices = await client.get_devices()
assert len(devices) == 5
assert len(devices) == 6


async def test_get_eddi_devices(client_fetch_data_fixture):
Expand Down Expand Up @@ -62,3 +63,10 @@ async def test_1p_harvi_eddi_solar_battery(client_1p_zappi_harvi_solar_battery_f
assert client.power_battery == 3000
assert client.power_charging == 2000
assert client.consumption_home == 16000


async def test_get_libbi_devices(client_fetch_data_fixture):
client = MyenergiClient(conn)
devices = await client.get_devices("libbi")
assert len(devices) == 1
assert isinstance(devices[0], Libbi)
11 changes: 11 additions & 0 deletions tests/test_libbi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pytest
from pymyenergi.libbi import Libbi

pytestmark = pytest.mark.asyncio


async def test_refresh(libbi_fetch_data_fixture):
"""Test Libbi data"""
libbi = Libbi({}, 24047164)
await libbi.refresh()
assert libbi.serial_number == 24047164

0 comments on commit e87819b

Please sign in to comment.