remove all eval() calls

This commit is contained in:
Stefan Allius
2024-10-25 23:41:25 +02:00
parent 10a18237c7
commit 4993676614
6 changed files with 56 additions and 63 deletions

View File

@@ -520,15 +520,3 @@ def test_invalid_data_type(invalid_data_seq):
val = i.dev_value(Register.INVALID_DATA_TYPE) # check invalid data type counter
assert val == 1
def test_result_eval(inv_data_seq2: bytes):
# add eval to convert temperature from °F to °C
RegisterMap.map[0x00000514]['eval'] = '(result-32)/1.8'
i = InfosG3()
for _, _ in i.parse (inv_data_seq2):
pass # side effect is calling generator i.parse()
assert math.isclose(-5.0, round (i.get_db_value(Register.INVERTER_TEMP, 0),4), rel_tol=1e-09, abs_tol=1e-09)
del RegisterMap.map[0x00000514]['eval'] # remove eval

View File

@@ -256,12 +256,12 @@ def test_build_ha_conf4():
assert tests==1
def test_exception_and_eval(inverter_data: bytes):
def test_exception_and_calc(inverter_data: bytes):
# add eval to convert temperature from °F to °C
# patch table to convert temperature from °F to °C
ofs = RegisterMap.map[0x420100d8]['offset']
del RegisterMap.map[0x420100d8]['offset']
RegisterMap.map[0x420100d8]['eval'] = '(result-32)/1.8'
RegisterMap.map[0x420100d8]['quotient'] = 1.8
RegisterMap.map[0x420100d8]['offset'] = -32/1.8
# map PV1_VOLTAGE to invalid register
RegisterMap.map[0x420100e0]['reg'] = Register.TEST_REG2
# set invalid maping entry for OUTPUT_POWER (string instead of dict type)
@@ -274,7 +274,9 @@ def test_exception_and_eval(inverter_data: bytes):
for key, update in i.parse (inverter_data, 0x42, 1):
pass # side effect is calling generator i.parse()
assert math.isclose(12.2222, round (i.get_db_value(Register.INVERTER_TEMP, 0),4), rel_tol=1e-09, abs_tol=1e-09)
del RegisterMap.map[0x420100d8]['eval'] # remove eval
del RegisterMap.map[0x420100d8]['quotient']
del RegisterMap.map[0x420100d8]['offset']
RegisterMap.map[0x420100e0]['reg'] = Register.PV1_VOLTAGE # reset mapping
RegisterMap.map[0x420100de] = backup # reset mapping