From 51db2f52abd5cd173d6015464da6a7827d3d74f6 Mon Sep 17 00:00:00 2001 From: Guzz-T Date: Tue, 17 Mar 2026 20:58:18 +0100 Subject: [PATCH 1/8] Add a datatype for Energy with a scaling factor of 0.01 --- luxtronik/datatypes.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/luxtronik/datatypes.py b/luxtronik/datatypes.py index 39d77828..343fa428 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.""" From f1a9929e1f7edf53ec1fe16c2a0321dff3eebd12 Mon Sep 17 00:00:00 2001 From: Guzz-T Date: Tue, 17 Mar 2026 20:59:49 +0100 Subject: [PATCH 2/8] Change the scaling factor of 'ID_Waermemenge' parameters from 0.1 to 0.01 --- CHANGELOG.md | 18 +++++++++----- luxtronik/definitions/parameters.py | 38 ++++++++++++++--------------- tests/test_compatibility.py | 6 ++--- tests/test_datatypes.py | 31 +++++++++++++++++++++++ 4 files changed, 65 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e30202c..8965fe91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1133,17 +1133,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 @@ -1277,9 +1277,15 @@ from `Unknown` to `Bool` - Type of `ID_Einst_WW_Nachheizung_max` (index `1020`) changed from `Unknown` to `Hours2` - Type of `ID_Waermemenge_ZWE` (index `1059`) changed -from `Unknown` to `Energy` +from `Unknown` to `Energy2` - 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` diff --git a/luxtronik/definitions/parameters.py b/luxtronik/definitions/parameters.py index afa9d46f..aca917df 100644 --- a/luxtronik/definitions/parameters.py +++ b/luxtronik/definitions/parameters.py @@ -16,7 +16,7 @@ AccessLevel, Bool, Count, - Energy, + Energy2, Kelvin, Celsius, CoolingMode, @@ -8571,10 +8571,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 +8591,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 +8831,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": '', }, { @@ -10641,20 +10641,20 @@ "index": 1059, "count": 1, "names": ['ID_Waermemenge_ZWE'], - "type": Energy, + "type": Energy2, "writeable": False, "datatype": 'UINT32', - "unit": 'kWh/10', + "unit": 'kWh/100', "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 +11561,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 +11577,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 +11603,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..f225e924 100644 --- a/tests/test_compatibility.py +++ b/tests/test_compatibility.py @@ -1259,12 +1259,12 @@ def get_compatibility_issues(self): "Unknown_Parameter_1134": (1134, Unknown), "Unknown_Parameter_1135": (1135, Unknown), "Unknown_Parameter_1136": (1136, Unknown), - "HEAT_ENERGY_INPUT": (1136, Energy), + "HEAT_ENERGY_INPUT": (1136, Energy, True), # See #198 -> type change allowed "Unknown_Parameter_1137": (1137, Unknown), - "DHW_ENERGY_INPUT": (1137, Energy), + "DHW_ENERGY_INPUT": (1137, Energy, True), # See #198 -> type change allowed "Unknown_Parameter_1138": (1138, Unknown), "Unknown_Parameter_1139": (1139, Unknown), - "COOLING_ENERGY_INPUT": (1139, Energy), + "COOLING_ENERGY_INPUT": (1139, Energy, True), # See #198 -> type change allowed "Unknown_Parameter_1140": (1140, Unknown), "SECOND_HEAT_GENERATOR_AMOUNT_COUNTER": (1140, Unknown), "Unknown_Parameter_1141": (1141, Unknown), diff --git a/tests/test_datatypes.py b/tests/test_datatypes.py index 18f4a026..d80b02ba 100644 --- a/tests/test_datatypes.py +++ b/tests/test_datatypes.py @@ -24,6 +24,7 @@ Power, PowerKW, Energy, + Energy2, Voltage, Hours, HoursUInt32, @@ -872,6 +873,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""" From 77aab3978bf060c3c407680c2ab2810c5e4e6feb Mon Sep 17 00:00:00 2001 From: Guzz-T Date: Tue, 17 Mar 2026 21:02:58 +0100 Subject: [PATCH 3/8] Add a datatype for Voltage with a scaling factor of 0.01 --- luxtronik/datatypes.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/luxtronik/datatypes.py b/luxtronik/datatypes.py index 343fa428..681cbb8e 100755 --- a/luxtronik/datatypes.py +++ b/luxtronik/datatypes.py @@ -604,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.""" From ab91c0429130f6c34e3d6b109095a0bbdd298a96 Mon Sep 17 00:00:00 2001 From: Guzz-T Date: Sun, 22 Nov 2026 17:10:17 +0100 Subject: [PATCH 4/8] Use the new voltage datatype for all calculations --- CHANGELOG.md | 20 +++++++++++++++++ luxtronik/definitions/calculations.py | 22 +++++++++---------- tests/test_compatibility.py | 20 ++++++++--------- tests/test_datatypes.py | 31 +++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8965fe91..0853b0d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1409,6 +1409,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/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/tests/test_compatibility.py b/tests/test_compatibility.py index f225e924..ebfd15f6 100644 --- a/tests/test_compatibility.py +++ b/tests/test_compatibility.py @@ -1476,7 +1476,7 @@ def get_compatibility_issues(self): "ID_WEB_SH_SW": (144, Icon), "ID_WEB_Zaehler_BetrZeitSW": (145, Unknown), "ID_WEB_FreigabKuehl": (146, Bool), - "ID_WEB_AnalogIn": (147, Voltage), + "ID_WEB_AnalogIn": (147, Voltage, True), # See #198 -> type change allowed "ID_WEB_SonderZeichen": (148, Unknown), "ID_WEB_SH_ZIP": (149, Icon), "ID_WEB_WebsrvProgrammWerteBeobarten": (150, Icon), @@ -1485,20 +1485,20 @@ def get_compatibility_issues(self): "ID_WEB_WMZ_Schwimmbad": (153, Energy), "ID_WEB_WMZ_Seit": (154, Energy), "ID_WEB_WMZ_Durchfluss": (155, Flow), - "ID_WEB_AnalogOut1": (156, Voltage), - "ID_WEB_AnalogOut2": (157, Voltage), + "ID_WEB_AnalogOut1": (156, Voltage, True), # See #198 -> type change allowed + "ID_WEB_AnalogOut2": (157, Voltage, True), # See #198 -> type change allowed "ID_WEB_Time_Heissgas": (158, Seconds), "ID_WEB_Temp_Lueftung_Zuluft": (159, Celsius), "ID_WEB_Temp_Lueftung_Abluft": (160, Celsius), "ID_WEB_Zaehler_BetrZeitSolar": (161, Seconds), - "ID_WEB_AnalogOut3": (162, Voltage), - "ID_WEB_AnalogOut4": (163, Voltage), - "ID_WEB_Out_VZU": (164, Voltage), - "ID_WEB_Out_VAB": (165, Voltage), + "ID_WEB_AnalogOut3": (162, Voltage, True), # See #198 -> type change allowed + "ID_WEB_AnalogOut4": (163, Voltage, True), # See #198 -> type change allowed + "ID_WEB_Out_VZU": (164, Voltage, True), # See #198 -> type change allowed + "ID_WEB_Out_VAB": (165, Voltage, True), # See #198 -> type change allowed "ID_WEB_Out_VSK": (166, Bool), "ID_WEB_Out_FRH": (167, Bool), - "ID_WEB_AnalogIn2": (168, Voltage), - "ID_WEB_AnalogIn3": (169, Voltage), + "ID_WEB_AnalogIn2": (168, Voltage, True), # See #198 -> type change allowed + "ID_WEB_AnalogIn3": (169, Voltage, True), # See #198 -> type change allowed "ID_WEB_SAXin": (170, Bool), "ID_WEB_SPLin": (171, Bool), "ID_WEB_Compact_exists": (172, Bool), @@ -1531,7 +1531,7 @@ def get_compatibility_issues(self): "ID_WEB_SEC_FlussigEx": (199, Celsius), "ID_WEB_SEC_UK_EEV": (200, Celsius), "ID_WEB_SEC_EVI_Druck": (201, Pressure), - "ID_WEB_SEC_U_Inv": (202, Voltage), + "ID_WEB_SEC_U_Inv": (202, Voltage, True), # See #198 -> type change allowed "ID_WEB_Temperatur_THG_2": (203, Celsius), "ID_WEB_Temperatur_TWE_2": (204, Celsius), "ID_WEB_LIN_ANSAUG_VERDAMPFER_2": (205, Celsius), diff --git a/tests/test_datatypes.py b/tests/test_datatypes.py index d80b02ba..c238a352 100644 --- a/tests/test_datatypes.py +++ b/tests/test_datatypes.py @@ -26,6 +26,7 @@ Energy, Energy2, Voltage, + Voltage2, Hours, HoursUInt32, Hours2, @@ -933,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""" From 0215c95a91d44e65b9ca75cec0a381253faeb7e1 Mon Sep 17 00:00:00 2001 From: Guzz-T Date: Tue, 17 Mar 2026 21:08:20 +0100 Subject: [PATCH 5/8] Update the CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0853b0d8..822a9267 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 From 68519ddab84b039ba816042061d6bbc6b383d88d Mon Sep 17 00:00:00 2001 From: Guzz-T Date: Sun, 8 Nov 2026 20:46:41 +0100 Subject: [PATCH 6/8] Add an entry for parameter index 1059 for older firmware versions --- CHANGELOG.md | 2 +- luxtronik/definitions/parameters.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 822a9267..eb1175b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1279,7 +1279,7 @@ from `Unknown` to `Bool` - Type of `ID_Einst_WW_Nachheizung_max` (index `1020`) changed from `Unknown` to `Hours2` - Type of `ID_Waermemenge_ZWE` (index `1059`) changed -from `Unknown` to `Energy2` +from `Unknown` to `Energy` - Type of `ID_Waermemenge_Reset` (index `1060`) changed from `Unknown` to `Energy2` - Type of `HEAT_ENERGY_INPUT` (index `1136`) changed diff --git a/luxtronik/definitions/parameters.py b/luxtronik/definitions/parameters.py index aca917df..36c964eb 100644 --- a/luxtronik/definitions/parameters.py +++ b/luxtronik/definitions/parameters.py @@ -16,6 +16,7 @@ AccessLevel, Bool, Count, + Energy, Energy2, Kelvin, Celsius, @@ -10645,6 +10646,18 @@ "writeable": False, "datatype": 'UINT32', "unit": 'kWh/100', + "version": '<3.0', + "description": '', + }, + { + "index": 1059, + "count": 1, + "names": ['ID_Waermemenge_ZWE'], + "type": Energy, + "writeable": False, + "datatype": 'UINT32', + "unit": 'kWh/10', + "version": '>=3.0', "description": '', }, { From d0983f9d536a8018b036aae55c052794dba6a0b9 Mon Sep 17 00:00:00 2001 From: Guzz-T Date: Sun, 22 Nov 2026 23:38:28 +0100 Subject: [PATCH 7/8] Allow duplicated definition names in case the datatype is of the same kind and the index is equal --- tests/test_compatibility.py | 10 ++++---- tests/test_definition_list.py | 46 +++++++++++++++++++++++++++-------- tests/types_of_same_kind.py | 26 ++++++++++++++++++++ 3 files changed, 67 insertions(+), 15 deletions(-) create mode 100644 tests/types_of_same_kind.py diff --git a/tests/test_compatibility.py b/tests/test_compatibility.py index ebfd15f6..fbe44717 100644 --- a/tests/test_compatibility.py +++ b/tests/test_compatibility.py @@ -2325,7 +2325,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 +2345,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_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 From e4b65d5186665accee27d433acbfa8372744adf6 Mon Sep 17 00:00:00 2001 From: Guzz-T Date: Sun, 22 Nov 2026 23:54:00 +0100 Subject: [PATCH 8/8] Use the TypesOfSameKind also in the test_compatibility.py No need to enter type changes that are transparent for the user --- tests/test_compatibility.py | 40 ++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/tests/test_compatibility.py b/tests/test_compatibility.py index fbe44717..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) @@ -1259,12 +1261,12 @@ def get_compatibility_issues(self): "Unknown_Parameter_1134": (1134, Unknown), "Unknown_Parameter_1135": (1135, Unknown), "Unknown_Parameter_1136": (1136, Unknown), - "HEAT_ENERGY_INPUT": (1136, Energy, True), # See #198 -> type change allowed + "HEAT_ENERGY_INPUT": (1136, Energy), "Unknown_Parameter_1137": (1137, Unknown), - "DHW_ENERGY_INPUT": (1137, Energy, True), # See #198 -> type change allowed + "DHW_ENERGY_INPUT": (1137, Energy), "Unknown_Parameter_1138": (1138, Unknown), "Unknown_Parameter_1139": (1139, Unknown), - "COOLING_ENERGY_INPUT": (1139, Energy, True), # See #198 -> type change allowed + "COOLING_ENERGY_INPUT": (1139, Energy), "Unknown_Parameter_1140": (1140, Unknown), "SECOND_HEAT_GENERATOR_AMOUNT_COUNTER": (1140, Unknown), "Unknown_Parameter_1141": (1141, Unknown), @@ -1476,7 +1478,7 @@ def get_compatibility_issues(self): "ID_WEB_SH_SW": (144, Icon), "ID_WEB_Zaehler_BetrZeitSW": (145, Unknown), "ID_WEB_FreigabKuehl": (146, Bool), - "ID_WEB_AnalogIn": (147, Voltage, True), # See #198 -> type change allowed + "ID_WEB_AnalogIn": (147, Voltage), "ID_WEB_SonderZeichen": (148, Unknown), "ID_WEB_SH_ZIP": (149, Icon), "ID_WEB_WebsrvProgrammWerteBeobarten": (150, Icon), @@ -1485,20 +1487,20 @@ def get_compatibility_issues(self): "ID_WEB_WMZ_Schwimmbad": (153, Energy), "ID_WEB_WMZ_Seit": (154, Energy), "ID_WEB_WMZ_Durchfluss": (155, Flow), - "ID_WEB_AnalogOut1": (156, Voltage, True), # See #198 -> type change allowed - "ID_WEB_AnalogOut2": (157, Voltage, True), # See #198 -> type change allowed + "ID_WEB_AnalogOut1": (156, Voltage), + "ID_WEB_AnalogOut2": (157, Voltage), "ID_WEB_Time_Heissgas": (158, Seconds), "ID_WEB_Temp_Lueftung_Zuluft": (159, Celsius), "ID_WEB_Temp_Lueftung_Abluft": (160, Celsius), "ID_WEB_Zaehler_BetrZeitSolar": (161, Seconds), - "ID_WEB_AnalogOut3": (162, Voltage, True), # See #198 -> type change allowed - "ID_WEB_AnalogOut4": (163, Voltage, True), # See #198 -> type change allowed - "ID_WEB_Out_VZU": (164, Voltage, True), # See #198 -> type change allowed - "ID_WEB_Out_VAB": (165, Voltage, True), # See #198 -> type change allowed + "ID_WEB_AnalogOut3": (162, Voltage), + "ID_WEB_AnalogOut4": (163, Voltage), + "ID_WEB_Out_VZU": (164, Voltage), + "ID_WEB_Out_VAB": (165, Voltage), "ID_WEB_Out_VSK": (166, Bool), "ID_WEB_Out_FRH": (167, Bool), - "ID_WEB_AnalogIn2": (168, Voltage, True), # See #198 -> type change allowed - "ID_WEB_AnalogIn3": (169, Voltage, True), # See #198 -> type change allowed + "ID_WEB_AnalogIn2": (168, Voltage), + "ID_WEB_AnalogIn3": (169, Voltage), "ID_WEB_SAXin": (170, Bool), "ID_WEB_SPLin": (171, Bool), "ID_WEB_Compact_exists": (172, Bool), @@ -1531,7 +1533,7 @@ def get_compatibility_issues(self): "ID_WEB_SEC_FlussigEx": (199, Celsius), "ID_WEB_SEC_UK_EEV": (200, Celsius), "ID_WEB_SEC_EVI_Druck": (201, Pressure), - "ID_WEB_SEC_U_Inv": (202, Voltage, True), # See #198 -> type change allowed + "ID_WEB_SEC_U_Inv": (202, Voltage), "ID_WEB_Temperatur_THG_2": (203, Celsius), "ID_WEB_Temperatur_TWE_2": (204, Celsius), "ID_WEB_LIN_ANSAUG_VERDAMPFER_2": (205, Celsius), @@ -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__}`")