pyFroniusReg/tests/test_regs.py

53 lines
1.5 KiB
Python
Raw Normal View History

2024-10-11 14:58:48 +11:00
#!/usr/bin/env python3
import unittest
from pyfroniusreg import gen24_registers
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-11 14:58:48 +11:00
class TestRead(unittest.TestCase):
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-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-14 17:02:50 +11:00
if __name__ == "__main__":
2024-10-11 14:58:48 +11:00
unittest.main()
fronius1.close()