Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion luxtronik/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ class SelectionBase(Base):

datatype_class = "selection"

unknown_prefix = "Unknown"
unknown_delimiter = "_"
codes = {}

@classmethod
Expand All @@ -145,13 +147,15 @@ def options(cls):
def from_heatpump(cls, value):
if value in cls.codes:
return cls.codes.get(value)
return None
return f"{cls.unknown_prefix}{cls.unknown_delimiter}{value}"

@classmethod
def to_heatpump(cls, value):
for index, code in cls.codes.items():
if code == value:
return index
if value.startswith(cls.unknown_prefix):
return int(value.split(cls.unknown_delimiter)[1])
return None


Expand Down
5 changes: 3 additions & 2 deletions tests/test_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,14 @@ def test_from_heatpump(self):
"""Test cases for from_heatpump function"""

a = SelectionBase("")
assert a.from_heatpump(0) is None
assert a.from_heatpump(0) == 'Unknown_0'

def test_to_heatpump(self):
"""Test cases for to_heatpump function"""

a = SelectionBase("")
assert a.to_heatpump("a") is None
assert a.to_heatpump("Unknown_214") == 214


class SelectionBaseChild(SelectionBase):
Expand Down Expand Up @@ -267,7 +268,7 @@ def test_from_heatpump(self):
assert a.from_heatpump(0) == "a"
assert a.from_heatpump(1) == "b"
assert a.from_heatpump(2) == "c"
assert a.from_heatpump(3) is None
assert a.from_heatpump(3) == "Unknown_3"

def test_to_heatpump(self):
"""Test cases for to_heatpump function"""
Expand Down