Skip to content
2 changes: 1 addition & 1 deletion luxtronik/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(self, parameters=None, calculations=None, visibilities=None, safe=T
self.visibilities = Visibilities() if visibilities is None else visibilities

def get_firmware_version(self):
return "".join([self.calculations.get(i).value for i in range(81, 91)])
return self.calculations.get_firmware_version()


class LuxtronikSocketInterface:
Expand Down
495 changes: 259 additions & 236 deletions luxtronik/calculations.py

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion luxtronik/data_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ def _lookup(self, target, with_index=False):
# Get entry by name
target_index = None
for index, entry in self._data.items():
if entry.name == target:
check_result = entry.check_name(target)
if check_result in ["preferred", "obsolete"]:
target_index = index
if check_result == "obsolete":
self.logger.debug(f"The name '{target}' is obsolete! Use '{entry.name}' instead.")
elif isinstance(target, int):
# Get entry by id
target_index = target
Expand Down
27 changes: 26 additions & 1 deletion luxtronik/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ def __init__(self, name, writeable=False):
# save the raw value only since the user value
# could be build at any time
self._raw = None
self.name = name
if isinstance(name, list):
self._names = name
else:
self._names = [name]
assert len(self._names) > 0 , "At least one name is required"
self.writeable = writeable

@classmethod
Expand All @@ -32,6 +36,27 @@ def from_heatpump(cls, value):
"""Converts value from heatpump units."""
return value

@property
def name(self):
"""Return the (most common) name of the entry."""
return self._names[0]

def get_supported_names(self):
"""Return a list of all supported entry names."""
return self._names

def check_name(self, name):
"""
Check whether a name matches one of the supported entry names.
The result string can be used to trigger a debug message for obsolete names.
"""
if name == self.name:
return "preferred"
elif name in self.get_supported_names():
return "obsolete"
else:
return "none"

@property
def value(self):
"""Return the stored value converted from heatpump units."""
Expand Down
2,220 changes: 1,112 additions & 1,108 deletions luxtronik/parameters.py

Large diffs are not rendered by default.

704 changes: 354 additions & 350 deletions luxtronik/visibilities.py

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions tests/test_LuxtronikData.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Test suite for LuxtronikData"""

import pytest
from luxtronik import LuxtronikData, Parameters, Calculations, Visibilities


Expand Down Expand Up @@ -47,3 +48,36 @@ def test_get_firmware_version(self):

a.calculations.get(84).raw = ord("1")
assert a.get_firmware_version() == "V3.1"

# Test of downward compatibility with outdated entry name
assert a.calculations.get("ID_WEB_SoftStand").value == "V3.1"

@pytest.mark.parametrize("vector, index, names", [
("para", 1106, ["ID_Einst_SilenceTimer_13", "Unknown_Parameter_1106"]),
("para", 1109, ["ID_Einst_SilenceTimer_16", "Unknown_Parameter_1109"]),
("calc", 232, ["Vapourisation_Temperature", "Unknown_Calculation_232"]),
("calc", 241, ["HUP_PWM", "Circulation_Pump", "Unknown_Calculation_241"]),
("visi", 182, ["ID_Visi_Heizung_Zeitschaltprogramm", "ID_Visi_Heizung_Zeitschlaltprogramm", "Unknown_Visibility_182"]),
("visi", 326, ["Unknown_Visibility_326"]),
])
def test_downward_compatibility(self, vector, index, names):
"""Test data access with outdated names"""

a = LuxtronikData()

match vector:
case "para":
vector = a.parameters
case "calc":
vector = a.calculations
case _:
vector = a.visibilities

entry = vector.get(index)
for name in names:
e = vector.get(name)
assert e == entry
assert e.name == names[0]
assert e.get_supported_names() == names


Loading