pyFroniusReg/tests/test_regs.py

63 lines
2 KiB
Python
Raw Normal View History

2024-10-11 14:58:48 +11:00
#!/usr/bin/env python3
import unittest
2024-10-26 16:00:49 +11:00
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
2024-10-11 14:58:48 +11:00
from pymodbus.client.tcp import ModbusTcpClient
fronius1 = ModbusTcpClient("172.19.107.211", port=502, timeout=10)
fronius1.connect()
2024-10-14 17:02:50 +11:00
2024-10-26 16:00:49 +11:00
class TestReadRegs(unittest.TestCase):
2024-10-11 14:58:48 +11:00
def test_read_scaled(self):
soc = gen24_registers.scaledChaState.get(fronius1)
2024-10-11 14:58:48 +11:00
assert isinstance(soc, float)
def test_read_direct(self):
2024-10-14 20:19:38 +11:00
dr = gen24_registers.OutWRte.get(fronius1)
2024-10-11 14:58:48 +11:00
assert isinstance(dr, int)
def test_read_string16(self):
2024-10-14 20:19:38 +11:00
Mn = gen24_registers.Mn.get(fronius1)
assert Mn[0:7] == "Fronius"
def test_read_string8(self):
# this isn't a good test, this value changes regularly
2024-10-14 20:19:38 +11:00
Vr = gen24_registers.Vr.get(fronius1)
assert Vr == "1.33.7-1"
def test_read_model(self):
2024-10-14 20:19:38 +11:00
Md = gen24_registers.Md.get(fronius1)
assert Md == "Primo GEN24 5.0\x00"
2024-10-12 20:37:10 +11:00
# def test_read_sn(self):
2024-10-14 17:02:50 +11:00
# This doesn't seem to return anything useful
2024-10-14 20:19:38 +11:00
# SN = gen24_registers.SN.get(fronius1)
2024-10-14 17:02:50 +11:00
# assert SN == "12345567"
2024-10-26 16:00:49 +11:00
class testWriteRegs(unittest.TestCase):
2024-10-11 14:58:48 +11:00
def test_write_direct(self):
2024-10-14 20:19:38 +11:00
current = gen24_registers.OutWRte.get(fronius1)
retval = gen24_registers.OutWRte.set(fronius1, current)
2024-10-11 15:16:36 +11:00
assert retval is not None
2024-10-11 14:58:48 +11:00
def test_write_scaled(self):
2024-10-14 20:19:38 +11:00
current = gen24_registers.scaledInWRte.get(fronius1)
retval = gen24_registers.scaledInWRte.set(fronius1, current)
2024-10-11 15:16:36 +11:00
assert retval is not None
2024-10-11 14:58:48 +11:00
2024-10-26 16:00:49 +11:00
class testSmartMeter(unittest.TestCase):
def test_freq_read(self):
Hz = smart_meter.Hz.get(fronius1)
print(Hz)
assert isinstance(Hz, float)
2024-10-14 17:02:50 +11:00
2024-10-26 16:00:49 +11:00
def test_import_read(self):
wh_import = smart_meter.TotWhImp.get(fronius1)
assert isinstance(wh_import, float)
2024-10-14 17:02:50 +11:00
if __name__ == "__main__":
2024-10-11 14:58:48 +11:00
unittest.main()
fronius1.close()