adjust tests to new naming
This commit is contained in:
parent
733997f247
commit
65b84d1503
6 changed files with 46 additions and 63 deletions
|
@ -38,4 +38,3 @@ print("Post CRate: %d%%" % charge)
|
||||||
|
|
||||||
mode = froniusreg.StorCtl_Mode.getValue(fronius1)
|
mode = froniusreg.StorCtl_Mode.getValue(fronius1)
|
||||||
print("Post Mode: %d" % mode)
|
print("Post Mode: %d" % mode)
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import os
|
||||||
def lint(session):
|
def lint(session):
|
||||||
session.install("ruff")
|
session.install("ruff")
|
||||||
session.run("ruff", "check", "--exclude", "examples")
|
session.run("ruff", "check", "--exclude", "examples")
|
||||||
|
session.run("ruff", "check", "--extend-select", "N", "src/pyfroniusreg/froniusreg.py")
|
||||||
|
|
||||||
|
|
||||||
@nox.session
|
@nox.session
|
||||||
|
|
|
@ -61,21 +61,15 @@ string16 = DataType(8, decode_string16, BinaryPayloadBuilder.add_string)
|
||||||
string32 = DataType(16, decode_string32, BinaryPayloadBuilder.add_string)
|
string32 = DataType(16, decode_string32, BinaryPayloadBuilder.add_string)
|
||||||
int16 = DataType(1, BinaryPayloadDecoder.decode_16bit_int, encode_16bit_int)
|
int16 = DataType(1, BinaryPayloadDecoder.decode_16bit_int, encode_16bit_int)
|
||||||
uint16 = DataType(1, BinaryPayloadDecoder.decode_16bit_uint, encode_16bit_int)
|
uint16 = DataType(1, BinaryPayloadDecoder.decode_16bit_uint, encode_16bit_int)
|
||||||
int32 = DataType(
|
int32 = DataType(2, BinaryPayloadDecoder.decode_32bit_int, BinaryPayloadBuilder.add_32bit_int)
|
||||||
2, BinaryPayloadDecoder.decode_32bit_int, BinaryPayloadBuilder.add_32bit_int
|
uint32 = DataType(2, BinaryPayloadDecoder.decode_32bit_uint, BinaryPayloadBuilder.add_32bit_uint)
|
||||||
)
|
|
||||||
uint32 = DataType(
|
|
||||||
2, BinaryPayloadDecoder.decode_32bit_uint, BinaryPayloadBuilder.add_32bit_uint
|
|
||||||
)
|
|
||||||
float32 = DataType(
|
float32 = DataType(
|
||||||
2, BinaryPayloadDecoder.decode_32bit_float, BinaryPayloadBuilder.add_32bit_float
|
2, BinaryPayloadDecoder.decode_32bit_float, BinaryPayloadBuilder.add_32bit_float
|
||||||
)
|
)
|
||||||
uint64 = DataType(
|
uint64 = DataType(4, BinaryPayloadDecoder.decode_64bit_uint, BinaryPayloadBuilder.add_64bit_uint)
|
||||||
4, BinaryPayloadDecoder.decode_64bit_uint, BinaryPayloadBuilder.add_64bit_uint
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class registerReadError(Exception):
|
class RegisterReadError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -100,46 +94,46 @@ class FroniusReg:
|
||||||
self.unit = unit
|
self.unit = unit
|
||||||
self.description = description
|
self.description = description
|
||||||
|
|
||||||
def getValue(self, modbusClient):
|
def get(self, modbus_client):
|
||||||
return self.__getRegisterValue(modbusClient)
|
return self.__get_register_value(modbus_client)
|
||||||
|
|
||||||
def setValue(self, modbusClient, value):
|
def set(self, modbus_client, value):
|
||||||
return self.__setRegisterValue(modbusClient, value)
|
return self._set_register_value(modbus_client, value)
|
||||||
|
|
||||||
def __getRegisterValue(self, modbusClient):
|
def __get_register_value(self, modbus_client):
|
||||||
modbusValue = modbusClient.read_holding_registers(
|
modbus_value = modbus_client.read_holding_registers(
|
||||||
self.address - 1, self.datatype.width, slave=self.unit
|
self.address - 1, self.datatype.width, slave=self.unit
|
||||||
)
|
)
|
||||||
if modbusValue.isError():
|
if modbus_value.isError():
|
||||||
raise registerReadError(
|
raise RegisterReadError(
|
||||||
"Unable to read from Fronius Register: %d, %s\n%s"
|
"Unable to read from Fronius Register: %d, %s\n%s"
|
||||||
% (self.address, self.description, modbusValue)
|
% (self.address, self.description, modbus_value)
|
||||||
)
|
)
|
||||||
if modbusValue is None:
|
if modbus_value is None:
|
||||||
raise registerReadError("It's NONE!")
|
raise RegisterReadError("It's NONE!")
|
||||||
return self.datatype.decode_from_register(modbusValue.registers)
|
return self.datatype.decode_from_register(modbus_value.registers)
|
||||||
|
|
||||||
def __setRegisterValue(self, modbusClient, value):
|
def _set_register_value(self, modbus_client, value):
|
||||||
modbusValue = modbusClient.write_registers(
|
modbus_value = modbus_client.write_registers(
|
||||||
self.address - 1,
|
self.address - 1,
|
||||||
self.datatype.encode_to_buffer(value),
|
self.datatype.encode_to_buffer(value),
|
||||||
slave=self.unit,
|
slave=self.unit,
|
||||||
skip_encode=True,
|
skip_encode=True,
|
||||||
)
|
)
|
||||||
return modbusValue
|
return modbus_value
|
||||||
|
|
||||||
|
|
||||||
class ScaledFroniusReg:
|
class ScaledFroniusReg:
|
||||||
def __init__(self, valueReg, scaleReg):
|
def __init__(self, value_register, scale_register):
|
||||||
self.valueReg = valueReg
|
self.value_register = value_register
|
||||||
self.scaleReg = scaleReg
|
self.scale_register = scale_register
|
||||||
|
|
||||||
def getValue(self, modbusClient):
|
def get(self, modbus_client):
|
||||||
return self.valueReg.getValue(modbusClient) * 10 ** self.scaleReg.getValue(
|
return self.value_register.get(modbus_client) * 10 ** self.scale_register.get(
|
||||||
modbusClient
|
modbus_client
|
||||||
)
|
)
|
||||||
|
|
||||||
def setValue(self, modbusClient, value):
|
def set(self, modbus_client, value):
|
||||||
return self.valueReg.setValue(
|
return self.value_register.set(
|
||||||
modbusClient, value / 10 ** self.scaleReg.getValue(modbusClient)
|
modbus_client, value / 10 ** self.scale_register.get(modbus_client)
|
||||||
)
|
)
|
||||||
|
|
|
@ -10,9 +10,7 @@ storageStateOfCharge = froniusreg.FroniusReg(
|
||||||
storageStateOfChargeSF = froniusreg.FroniusReg(
|
storageStateOfChargeSF = froniusreg.FroniusReg(
|
||||||
40376, froniusreg.int16, 1, "Storage State of Charge Scaling Factor"
|
40376, froniusreg.int16, 1, "Storage State of Charge Scaling Factor"
|
||||||
)
|
)
|
||||||
scaledStateOfCharge = froniusreg.ScaledFroniusReg(
|
scaledStateOfCharge = froniusreg.ScaledFroniusReg(storageStateOfCharge, storageStateOfChargeSF)
|
||||||
storageStateOfCharge, storageStateOfChargeSF
|
|
||||||
)
|
|
||||||
|
|
||||||
ID = froniusreg.FroniusReg(
|
ID = froniusreg.FroniusReg(
|
||||||
40003,
|
40003,
|
||||||
|
@ -20,9 +18,7 @@ ID = froniusreg.FroniusReg(
|
||||||
1,
|
1,
|
||||||
"Well-known value. Uniquely identifies this as a sunspec model 'common' (1)",
|
"Well-known value. Uniquely identifies this as a sunspec model 'common' (1)",
|
||||||
)
|
)
|
||||||
L = froniusreg.FroniusReg(
|
L = froniusreg.FroniusReg(40004, froniusreg.uint16, 1, "Sunspec model commen register count")
|
||||||
40004, froniusreg.uint16, 1, "Sunspec model commen register count"
|
|
||||||
)
|
|
||||||
Mn = froniusreg.FroniusReg(40005, froniusreg.string16, 1, "Manufacturer")
|
Mn = froniusreg.FroniusReg(40005, froniusreg.string16, 1, "Manufacturer")
|
||||||
Md = froniusreg.FroniusReg(40021, froniusreg.string16, 1, "Device Model")
|
Md = froniusreg.FroniusReg(40021, froniusreg.string16, 1, "Device Model")
|
||||||
Vr = froniusreg.FroniusReg(40045, froniusreg.string8, 1, "SW version")
|
Vr = froniusreg.FroniusReg(40045, froniusreg.string8, 1, "SW version")
|
||||||
|
@ -50,12 +46,8 @@ DCW_SF = froniusreg.FroniusReg(40268, froniusreg.int16, 1, "DC Power Scaling fac
|
||||||
|
|
||||||
OutWRte = froniusreg.FroniusReg(40366, froniusreg.int16, 1, "DischargeRate")
|
OutWRte = froniusreg.FroniusReg(40366, froniusreg.int16, 1, "DischargeRate")
|
||||||
InWRte = froniusreg.FroniusReg(40367, froniusreg.int16, 1, "ChargeRate")
|
InWRte = froniusreg.FroniusReg(40367, froniusreg.int16, 1, "ChargeRate")
|
||||||
WRteSF = froniusreg.FroniusReg(
|
WRteSF = froniusreg.FroniusReg(40379, froniusreg.int16, 1, "ScalingFactor for storage Watts")
|
||||||
40379, froniusreg.int16, 1, "ScalingFactor for storage Watts"
|
StorCtl_Mode = froniusreg.FroniusReg(40359, froniusreg.uint16, 1, "Hold/Charge/Discharge limit")
|
||||||
)
|
|
||||||
StorCtl_Mode = froniusreg.FroniusReg(
|
|
||||||
40359, froniusreg.uint16, 1, "Hold/Charge/Discharge limit"
|
|
||||||
)
|
|
||||||
MinRsvPct = froniusreg.FroniusReg(40361, froniusreg.uint16, 1, "Reserve Percentage")
|
MinRsvPct = froniusreg.FroniusReg(40361, froniusreg.uint16, 1, "Reserve Percentage")
|
||||||
InOutWRte_RvrtTms = froniusreg.FroniusReg(
|
InOutWRte_RvrtTms = froniusreg.FroniusReg(
|
||||||
40369, froniusreg.uint16, 1, "Revert timer for charge settings"
|
40369, froniusreg.uint16, 1, "Revert timer for charge settings"
|
||||||
|
@ -63,12 +55,8 @@ InOutWRte_RvrtTms = froniusreg.FroniusReg(
|
||||||
ChaGriSet = froniusreg.FroniusReg(
|
ChaGriSet = froniusreg.FroniusReg(
|
||||||
40371, froniusreg.uint16, 1, "enum16, 0 = PV only, 1 = Grid enabled"
|
40371, froniusreg.uint16, 1, "enum16, 0 = PV only, 1 = Grid enabled"
|
||||||
)
|
)
|
||||||
WChaDisChaGra_SF = froniusreg.FroniusReg(
|
WChaDisChaGra_SF = froniusreg.FroniusReg(40373, froniusreg.int16, 1, "Charge/Discharge Power SF")
|
||||||
40373, froniusreg.int16, 1, "Charge/Discharge Power SF"
|
MinRsvPct_SF = froniusreg.FroniusReg(40375, froniusreg.int16, 1, "Reserve Percentage Scaling")
|
||||||
)
|
|
||||||
MinRsvPct_SF = froniusreg.FroniusReg(
|
|
||||||
40375, froniusreg.int16, 1, "Reserve Percentage Scaling"
|
|
||||||
)
|
|
||||||
|
|
||||||
scaledOutWRte = froniusreg.ScaledFroniusReg(OutWRte, WRteSF)
|
scaledOutWRte = froniusreg.ScaledFroniusReg(OutWRte, WRteSF)
|
||||||
scaledInWRte = froniusreg.ScaledFroniusReg(InWRte, WRteSF)
|
scaledInWRte = froniusreg.ScaledFroniusReg(InWRte, WRteSF)
|
||||||
|
|
|
@ -3,6 +3,7 @@ import unittest
|
||||||
|
|
||||||
from pyfroniusreg import froniusreg
|
from pyfroniusreg import froniusreg
|
||||||
|
|
||||||
|
|
||||||
class TestDataTypes(unittest.TestCase):
|
class TestDataTypes(unittest.TestCase):
|
||||||
def test_int16(self):
|
def test_int16(self):
|
||||||
int16_buffer = froniusreg.int16.encode_to_buffer(1024)
|
int16_buffer = froniusreg.int16.encode_to_buffer(1024)
|
||||||
|
|
|
@ -11,39 +11,39 @@ fronius1.connect()
|
||||||
|
|
||||||
class TestRead(unittest.TestCase):
|
class TestRead(unittest.TestCase):
|
||||||
def test_read_scaled(self):
|
def test_read_scaled(self):
|
||||||
soc = gen24_registers.scaledStateOfCharge.getValue(fronius1)
|
soc = gen24_registers.scaledStateOfCharge.get(fronius1)
|
||||||
assert isinstance(soc, float)
|
assert isinstance(soc, float)
|
||||||
|
|
||||||
def test_read_direct(self):
|
def test_read_direct(self):
|
||||||
dr = gen24_registers.OutWRte.getValue(fronius1)
|
dr = gen24_registers.OutWRte.get(fronius1)
|
||||||
assert isinstance(dr, int)
|
assert isinstance(dr, int)
|
||||||
|
|
||||||
def test_read_string16(self):
|
def test_read_string16(self):
|
||||||
Mn = gen24_registers.Mn.getValue(fronius1)
|
Mn = gen24_registers.Mn.get(fronius1)
|
||||||
assert Mn[0:7] == "Fronius"
|
assert Mn[0:7] == "Fronius"
|
||||||
|
|
||||||
def test_read_string8(self):
|
def test_read_string8(self):
|
||||||
# this isn't a good test, this value changes regularly
|
# this isn't a good test, this value changes regularly
|
||||||
Vr = gen24_registers.Vr.getValue(fronius1)
|
Vr = gen24_registers.Vr.get(fronius1)
|
||||||
assert Vr == "1.33.7-1"
|
assert Vr == "1.33.7-1"
|
||||||
|
|
||||||
def test_read_model(self):
|
def test_read_model(self):
|
||||||
Md = gen24_registers.Md.getValue(fronius1)
|
Md = gen24_registers.Md.get(fronius1)
|
||||||
assert Md == "Primo GEN24 5.0\x00"
|
assert Md == "Primo GEN24 5.0\x00"
|
||||||
|
|
||||||
# def test_read_sn(self):
|
# def test_read_sn(self):
|
||||||
# This doesn't seem to return anything useful
|
# This doesn't seem to return anything useful
|
||||||
# SN = gen24_registers.SN.getValue(fronius1)
|
# SN = gen24_registers.SN.get(fronius1)
|
||||||
# assert SN == "12345567"
|
# assert SN == "12345567"
|
||||||
|
|
||||||
def test_write_direct(self):
|
def test_write_direct(self):
|
||||||
current = gen24_registers.OutWRte.getValue(fronius1)
|
current = gen24_registers.OutWRte.get(fronius1)
|
||||||
retval = gen24_registers.OutWRte.setValue(fronius1, current)
|
retval = gen24_registers.OutWRte.set(fronius1, current)
|
||||||
assert retval is not None
|
assert retval is not None
|
||||||
|
|
||||||
def test_write_scaled(self):
|
def test_write_scaled(self):
|
||||||
current = gen24_registers.scaledInWRte.getValue(fronius1)
|
current = gen24_registers.scaledInWRte.get(fronius1)
|
||||||
retval = gen24_registers.scaledInWRte.setValue(fronius1, current)
|
retval = gen24_registers.scaledInWRte.set(fronius1, current)
|
||||||
assert retval is not None
|
assert retval is not None
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue