diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e30202c..eb1175b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,8 @@ never released and has been replaced. - SHI holding `66` (`heat_overall_offset`): the documented range is now -50..50 (+/-5.0 K) instead of -200..200. - Document that `LevelMode` values 1 and 2 are identical on firmware V3.92.3. +- Change the scaling factor of 'ID_Waermemenge' parameters from 0.1 to 0.01 [#198] +- Change the scaling factor of the voltage data fields to 0.01 [#198] ### Removed @@ -1133,17 +1135,17 @@ from `Unknown` to `TimeOfDay` - Type of `ID_Einst_SuMk3Tg_zeit_2_13` (index `848`) changed from `Unknown` to `TimeOfDay` - Type of `ID_Waermemenge_Seit` (index `852`) changed -from `Unknown` to `Energy` +from `Unknown` to `Energy2` - Type of `ID_Waermemenge_Hz` (index `854`) changed -from `Unknown` to `Energy` +from `Unknown` to `Energy2` - Type of `ID_Zaehler_BetrZeitSW` (index `859`) changed from `Unknown` to `Seconds` - Type of `ID_Einst_Popt_Nachlauf_akt` (index `864`) changed from `Unknown` to `Minutes` - Type of `ID_Waermemenge_BW` (index `878`) changed -from `Unknown` to `Energy` +from `Unknown` to `Energy2` - Type of `ID_Waermemenge_SW` (index `879`) changed -from `Unknown` to `Energy` +from `Unknown` to `Energy2` - Type of `ID_Waermemenge_Datum` (index `880`) changed from `Unknown` to `Timestamp` - Type of `ID_Einst_SuLuf_akt` (index `895`) changed @@ -1279,7 +1281,13 @@ from `Unknown` to `Hours2` - Type of `ID_Waermemenge_ZWE` (index `1059`) changed from `Unknown` to `Energy` - Type of `ID_Waermemenge_Reset` (index `1060`) changed -from `Unknown` to `Energy` +from `Unknown` to `Energy2` +- Type of `HEAT_ENERGY_INPUT` (index `1136`) changed +from `Energy` to `Energy2` +- Type of `DHW_ENERGY_INPUT` (index `1137`) changed +from `Energy` to `Energy2` +- Type of `COOLING_ENERGY_INPUT` (index `1139`) changed +from `Energy` to `Energy2` - Add `SILENT_MODE` (index `1087`) of type `OnOffMode` - Add `ID_Einst_SuSilence` (index `1092`) of type `TimerProgram` - Add `ID_Einst_SilenceTimer_0` (index `1093`) of type `TimeOfDay2` @@ -1403,6 +1411,26 @@ from `IPAddress` to `IPv4Address` from `IPAddress` to `IPv4Address` - Type of `ID_WEB_Add_StdGateway` (index `94`) changed from `IPAddress` to `IPv4Address` +- Type of `ID_WEB_AnalogIn` (index `147`) changed +from `Voltage` to `Voltage2` +- Type of `ID_WEB_AnalogOut1` (index `156`) changed +from `Voltage` to `Voltage2` +- Type of `ID_WEB_AnalogOut2` (index `157`) changed +from `Voltage` to `Voltage2` +- Type of `ID_WEB_AnalogOut3` (index `162`) changed +from `Voltage` to `Voltage2` +- Type of `ID_WEB_AnalogOut4` (index `163`) changed +from `Voltage` to `Voltage2` +- Type of `ID_WEB_Out_VZU` (index `164`) changed +from `Voltage` to `Voltage2` +- Type of `ID_WEB_Out_VAB` (index `165`) changed +from `Voltage` to `Voltage2` +- Type of `ID_WEB_AnalogIn2` (index `168`) changed +from `Voltage` to `Voltage2` +- Type of `ID_WEB_AnalogIn3` (index `169`) changed +from `Voltage` to `Voltage2` +- Type of `ID_WEB_SEC_U_Inv` (index `202`) changed +from `Voltage` to `Voltage2` - Add `ID_WEB_SoftStand_0` (index `81`) of type `Character` - Add `ID_WEB_SoftStand_1` (index `82`) of type `Character` - Add `ID_WEB_SoftStand_2` (index `83`) of type `Character` diff --git a/luxtronik/datatypes.py b/luxtronik/datatypes.py index 39d77828..681cbb8e 100755 --- a/luxtronik/datatypes.py +++ b/luxtronik/datatypes.py @@ -588,6 +588,14 @@ class Energy(ScalingBase): scaling_factor = 0.1 +class Energy2(ScalingBase): + """Energy datatype, converts from and to Energy.""" + + datatype_class = "energy" + datatype_unit = "kWh" + scaling_factor = 0.01 + + class Voltage(ScalingBase): """Voltage datatype, converts from and to Voltage.""" @@ -596,6 +604,14 @@ class Voltage(ScalingBase): scaling_factor = 0.1 +class Voltage2(ScalingBase): + """Voltage datatype, converts from and to Voltage.""" + + datatype_class = "voltage" + datatype_unit = "V" + scaling_factor = 0.01 + + class Hours(ScalingBase): """Hours datatype, converts from and to Hours.""" diff --git a/luxtronik/definitions/calculations.py b/luxtronik/definitions/calculations.py index 4b0d8140..9af61897 100644 --- a/luxtronik/definitions/calculations.py +++ b/luxtronik/definitions/calculations.py @@ -42,7 +42,7 @@ Unknown, MajorMinorVersion, Version, - Voltage, + Voltage2, ) # Offset which must be added to the calculation indices @@ -1538,7 +1538,7 @@ "index": 147, "count": 1, "names": ['ID_WEB_AnalogIn'], - "type": Voltage, + "type": Voltage2, "writeable": False, "datatype": 'INT32', "unit": 'V/10', @@ -1628,7 +1628,7 @@ "index": 156, "count": 1, "names": ['ID_WEB_AnalogOut1'], - "type": Voltage, + "type": Voltage2, "writeable": False, "datatype": 'INT32', "unit": 'V/10', @@ -1638,7 +1638,7 @@ "index": 157, "count": 1, "names": ['ID_WEB_AnalogOut2'], - "type": Voltage, + "type": Voltage2, "writeable": False, "datatype": 'INT32', "unit": 'V/10', @@ -1688,7 +1688,7 @@ "index": 162, "count": 1, "names": ['ID_WEB_AnalogOut3'], - "type": Voltage, + "type": Voltage2, "writeable": False, "datatype": 'INT32', "unit": 'V/10', @@ -1698,7 +1698,7 @@ "index": 163, "count": 1, "names": ['ID_WEB_AnalogOut4'], - "type": Voltage, + "type": Voltage2, "writeable": False, "datatype": 'INT32', "unit": 'V/10', @@ -1708,7 +1708,7 @@ "index": 164, "count": 1, "names": ['ID_WEB_Out_VZU'], - "type": Voltage, + "type": Voltage2, "writeable": False, "datatype": 'INT32', "unit": 'V/10', @@ -1718,7 +1718,7 @@ "index": 165, "count": 1, "names": ['ID_WEB_Out_VAB'], - "type": Voltage, + "type": Voltage2, "writeable": False, "datatype": 'INT32', "unit": 'V/10', @@ -1748,7 +1748,7 @@ "index": 168, "count": 1, "names": ['ID_WEB_AnalogIn2'], - "type": Voltage, + "type": Voltage2, "writeable": False, "datatype": 'INT32', "unit": 'V/10', @@ -1758,7 +1758,7 @@ "index": 169, "count": 1, "names": ['ID_WEB_AnalogIn3'], - "type": Voltage, + "type": Voltage2, "writeable": False, "datatype": 'INT32', "unit": 'V/10', @@ -2088,7 +2088,7 @@ "index": 202, "count": 1, "names": ['ID_WEB_SEC_U_Inv'], - "type": Voltage, + "type": Voltage2, "writeable": False, "datatype": 'INT32', "unit": 'V/10', diff --git a/luxtronik/definitions/parameters.py b/luxtronik/definitions/parameters.py index afa9d46f..36c964eb 100644 --- a/luxtronik/definitions/parameters.py +++ b/luxtronik/definitions/parameters.py @@ -17,6 +17,7 @@ Bool, Count, Energy, + Energy2, Kelvin, Celsius, CoolingMode, @@ -8571,10 +8572,10 @@ "index": 852, "count": 1, "names": ['ID_Waermemenge_Seit'], - "type": Energy, + "type": Energy2, "writeable": False, "datatype": 'UINT32', - "unit": 'kWh/10', + "unit": 'kWh/100', "description": '', }, { @@ -8591,10 +8592,10 @@ "index": 854, "count": 1, "names": ['ID_Waermemenge_Hz'], - "type": Energy, + "type": Energy2, "writeable": False, "datatype": 'UINT32', - "unit": 'kWh/10', + "unit": 'kWh/100', "description": '', }, { @@ -8831,20 +8832,20 @@ "index": 878, "count": 1, "names": ['ID_Waermemenge_BW'], - "type": Energy, + "type": Energy2, "writeable": False, "datatype": 'UINT32', - "unit": 'kWh/10', + "unit": 'kWh/100', "description": '', }, { "index": 879, "count": 1, "names": ['ID_Waermemenge_SW'], - "type": Energy, + "type": Energy2, "writeable": False, "datatype": 'UINT32', - "unit": 'kWh/10', + "unit": 'kWh/100', "description": '', }, { @@ -10637,6 +10638,17 @@ "unit": '', "description": '', }, + { + "index": 1059, + "count": 1, + "names": ['ID_Waermemenge_ZWE'], + "type": Energy2, + "writeable": False, + "datatype": 'UINT32', + "unit": 'kWh/100', + "version": '<3.0', + "description": '', + }, { "index": 1059, "count": 1, @@ -10645,16 +10657,17 @@ "writeable": False, "datatype": 'UINT32', "unit": 'kWh/10', + "version": '>=3.0', "description": '', }, { "index": 1060, "count": 1, "names": ['ID_Waermemenge_Reset'], - "type": Energy, + "type": Energy2, "writeable": False, "datatype": 'UINT32', - "unit": 'kWh/10', + "unit": 'kWh/100', "description": '', }, { @@ -11561,10 +11574,10 @@ "index": 1136, "count": 1, "names": ['HEAT_ENERGY_INPUT'], - "type": Energy, + "type": Energy2, "writeable": False, "datatype": 'UINT32', - "unit": 'kWh/10', + "unit": 'kWh/100', "description": '', }, { @@ -11577,10 +11590,10 @@ "index": 1137, "count": 1, "names": ['DHW_ENERGY_INPUT'], - "type": Energy, + "type": Energy2, "writeable": False, "datatype": 'UINT32', - "unit": 'kWh/10', + "unit": 'kWh/100', "description": '', }, { @@ -11603,10 +11616,10 @@ "index": 1139, "count": 1, "names": ['COOLING_ENERGY_INPUT'], - "type": Energy, + "type": Energy2, "writeable": False, "datatype": 'UINT32', - "unit": 'kWh/10', + "unit": 'kWh/100', "description": '', }, { diff --git a/tests/test_compatibility.py b/tests/test_compatibility.py index efe12b4d..99d30cb4 100644 --- a/tests/test_compatibility.py +++ b/tests/test_compatibility.py @@ -70,6 +70,8 @@ Voltage, ) +from tests.types_of_same_kind import TypesOfSameKind + logging.disable(logging.CRITICAL) @@ -2284,7 +2286,17 @@ def get_mappings(d): # new name available -> no error # we allow type changes if we already use a name, but the type is still unknown - type_change_allowed = old_type_changed or (not old_name.lower().startswith("unknown_") and old_type == Unknown) + type_change_allowed = ( + # allowed via parameter + old_type_changed + # allowed from unknown to x + or ( + not old_name.lower().startswith("unknown_") + and old_type == Unknown + ) + # allowed for similar types + or TypesOfSameKind.match(old_type, def_by_name.field_type) + ) if old_type != def_by_name.field_type: if type_change_allowed: r["old_type_changed_info"].append(f"- Type of `{old_name}` (index `{old_idx}`) changed\nfrom `{old_type.__name__}` to `{def_by_name.field_type.__name__}`") @@ -2325,7 +2337,7 @@ def test_compatibilities(self): for caption, item in data.items(): ok = not item["obsolete_found"] and not item["old_not_found"] \ and not item["old_idx_wrong"] and not item["old_type_changed_err"] - do_print = not ok or len(item["old_type_changed_info"]) > 0 + do_print = not ok #or len(item["old_type_changed_info"]) > 0 if do_print: print(f"############################## Incompatibilities - {caption}:") @@ -2345,10 +2357,10 @@ def test_compatibilities(self): print("############################## type change error") for err in item["old_type_changed_err"]: print(err) - if item["old_type_changed_info"]: - print("############################## type change info") - for err in item["old_type_changed_info"]: - print(err) + #if item["old_type_changed_info"]: + # print("############################## type change info") + # for err in item["old_type_changed_info"]: + # print(err) all_ok &= ok assert all_ok, "Found incompatibilities. Please consider to add them to compatibilities.py" diff --git a/tests/test_datatypes.py b/tests/test_datatypes.py index 18f4a026..c238a352 100644 --- a/tests/test_datatypes.py +++ b/tests/test_datatypes.py @@ -24,7 +24,9 @@ Power, PowerKW, Energy, + Energy2, Voltage, + Voltage2, Hours, HoursUInt32, Hours2, @@ -872,6 +874,36 @@ def test_energy_to_heatpump(self): assert Energy.to_heatpump("g") is None +class TestEnergy2: + """Test suite for Energy datatype""" + + def test_init(self): + """Test cases for initialization""" + + a = Energy2("energy") + assert a.name == "energy" + assert a.datatype_class == "energy" + assert a.datatype_unit == "kWh" + + def test_energy_from_heatpump(self): + """Test cases for from_heatpump function""" + + assert Energy2.from_heatpump(None) is None + + assert Energy2.from_heatpump(10) == 0.1 + assert Energy2.from_heatpump(11) == 0.11 + + def test_energy_to_heatpump(self): + """Test cases for to_heatpump function""" + + assert Energy2.to_heatpump(1) == 100 + assert Energy2.to_heatpump(1.1) == 110 + + assert Energy2.to_heatpump(None) is None + assert Energy2.to_heatpump("5") == 500 + assert Energy2.to_heatpump("g") is None + + class TestVoltage: """Test suite for Voltage datatype""" @@ -902,6 +934,36 @@ def test_voltage_to_heatpump(self): assert Voltage.to_heatpump("h") is None +class TestVoltage2: + """Test suite for Voltage2 datatype""" + + def test_init(self): + """Test cases for initialization""" + + a = Voltage2("voltage") + assert a.name == "voltage" + assert a.datatype_class == "voltage" + assert a.datatype_unit == "V" + + def test_voltage_from_heatpump(self): + """Test cases for from_heatpump function""" + + assert Voltage2.from_heatpump(None) is None + + assert Voltage2.from_heatpump(10) == 0.1 + assert Voltage2.from_heatpump(11) == 0.11 + + def test_voltage_to_heatpump(self): + """Test cases for to_heatpump function""" + + assert Voltage2.to_heatpump(1) == 100 + assert Voltage2.to_heatpump(1.1) == 110 + + assert Voltage2.to_heatpump(None) is None + assert Voltage2.to_heatpump("6") == 600 + assert Voltage2.to_heatpump("h") is None + + class TestHours: """Test suite for Hours datatype""" diff --git a/tests/test_definition_list.py b/tests/test_definition_list.py index 3582f261..a5d46332 100644 --- a/tests/test_definition_list.py +++ b/tests/test_definition_list.py @@ -8,6 +8,7 @@ from luxtronik.definitions.inputs import INPUTS_DEFINITIONS_LIST from luxtronik.definitions.parameters import PARAMETERS_DEFINITIONS_LIST from luxtronik.definitions.visibilities import VISIBILITIES_DEFINITIONS_LIST +from types_of_same_kind import TypesOfSameKind class RunTestDefinitionList: @@ -154,21 +155,46 @@ def test_name_valid(self): except Exception: pass + def do_unique_self_check(self, definition): + names = self.get_names(definition) + length = len(names) + for i in range(length): + name_i = names[i] + for j in range(i + 1, length): + name_j = names[j] + assert (name_i != name_j), \ + "All names of the same definition must be unique. " \ + f"definition = {definition}" + + def do_unique_compare_check(self, def_a, def_b): + names_a = self.get_names(def_a) + index_a = def_a.get(Keys.IDX, -1) + type_a = def_a.get(Keys.TYPE, Base) + names_b = self.get_names(def_b) + index_b = def_a.get(Keys.IDX, -2) + type_b = def_b.get(Keys.TYPE, Base) + + # We allow duplicate names at the same index + duplicated_allowed = (index_a == index_b) and TypesOfSameKind.match(type_a, type_b) + + for name_a in names_a: + for name_b in names_b: + assert (name_a != name_b) or duplicated_allowed, \ + "All names of the same definition type must be unique " \ + "(except for the same index). " \ + f"this = {def_a}" \ + f"other = {def_b}" + return True + def test_name_unique(self): length = len(self.definitions) for i in range(length): - i_def = self.definitions[i] - i_names = self.get_names(i_def) + def_i = self.definitions[i] + self.do_unique_self_check(def_i) for j in range(i + 1, length): - j_def = self.definitions[j] - j_names = self.get_names(j_def) - for i_name in i_names: - for j_name in j_names: - assert i_name!= j_name, \ - "All names of the same type must be unique. " \ - f"this = {i_def}" \ - f"other = {j_def}" + def_j = self.definitions[j] + self.do_unique_compare_check(def_i, def_j) def test_field_type(self): for definition in self.definitions: diff --git a/tests/types_of_same_kind.py b/tests/types_of_same_kind.py new file mode 100644 index 00000000..870ac40a --- /dev/null +++ b/tests/types_of_same_kind.py @@ -0,0 +1,26 @@ +import inspect +import luxtronik.datatypes as datatypes + +# A dictionary of sets containing data types. +# Entries within the same set are functionally equivalent to the user +# and can be substituted transparently. For example, when the scaling of raw values changes. +# Because they are interchangeable, duplicate names are permitted within the same set. +class TypesOfSameKind: + + class_dict = {} + for name, cls in inspect.getmembers(datatypes, inspect.isclass): + if cls.__module__ == datatypes.__name__: + if cls.datatype_class is not None and cls.datatype_unit is not None: + unit_dict = class_dict.setdefault(cls.datatype_class, {}) + type_set = unit_dict.setdefault(cls.datatype_unit, set()) + type_set.add(cls) + + @classmethod + def match(cls, a, b): + unit_dict = cls.class_dict.get(a.datatype_class, None) + if unit_dict is None: + return False + type_set = unit_dict.get(a.datatype_unit, None) + if type_set is None: + return + return b in type_set