some more tests

This commit is contained in:
Paul Warren 2024-10-26 16:00:49 +11:00
parent 234b519930
commit 6769518f67

View file

@ -1,7 +1,8 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import unittest import unittest
from pyfroniusreg import gen24_registers from pyfroniusreg import gen24_primo_symo_inverter_register_map_float_storage as gen24_registers
from pyfroniusreg import smart_meter_register_map_float as smart_meter
from pymodbus.client.tcp import ModbusTcpClient from pymodbus.client.tcp import ModbusTcpClient
@ -9,7 +10,7 @@ fronius1 = ModbusTcpClient("172.19.107.211", port=502, timeout=10)
fronius1.connect() fronius1.connect()
class TestRead(unittest.TestCase): class TestReadRegs(unittest.TestCase):
def test_read_scaled(self): def test_read_scaled(self):
soc = gen24_registers.scaledChaState.get(fronius1) soc = gen24_registers.scaledChaState.get(fronius1)
assert isinstance(soc, float) assert isinstance(soc, float)
@ -35,7 +36,7 @@ class TestRead(unittest.TestCase):
# This doesn't seem to return anything useful # This doesn't seem to return anything useful
# SN = gen24_registers.SN.get(fronius1) # SN = gen24_registers.SN.get(fronius1)
# assert SN == "12345567" # assert SN == "12345567"
class testWriteRegs(unittest.TestCase):
def test_write_direct(self): def test_write_direct(self):
current = gen24_registers.OutWRte.get(fronius1) current = gen24_registers.OutWRte.get(fronius1)
retval = gen24_registers.OutWRte.set(fronius1, current) retval = gen24_registers.OutWRte.set(fronius1, current)
@ -46,6 +47,15 @@ class TestRead(unittest.TestCase):
retval = gen24_registers.scaledInWRte.set(fronius1, current) retval = gen24_registers.scaledInWRte.set(fronius1, current)
assert retval is not None assert retval is not None
class testSmartMeter(unittest.TestCase):
def test_freq_read(self):
Hz = smart_meter.Hz.get(fronius1)
print(Hz)
assert isinstance(Hz, float)
def test_import_read(self):
wh_import = smart_meter.TotWhImp.get(fronius1)
assert isinstance(wh_import, float)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()