Skip to content

Commit

Permalink
Add higher-level function for firmware version
Browse files Browse the repository at this point in the history
Closes #128
  • Loading branch information
gerw authored and Bouni committed Feb 22, 2024
1 parent 14bc7b8 commit 723e51a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions luxtronik/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ def __init__(self, parameters=None, calculations=None, visibilities=None, safe=T
self.calculations = Calculations() if calculations is None else calculations
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)])


class LuxtronikSocketInterface:
"""Luxtronik read/write interface via socket."""
Expand Down
49 changes: 49 additions & 0 deletions tests/test_LuxtronikData.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Test suite for LuxtronikData"""

from luxtronik import LuxtronikData, Parameters, Calculations, Visibilities


class TestLuxtronikData:
"""Test suite for LuxtronikData datatype"""

def test_init(self):
"""Test cases for __init__"""

a = LuxtronikData()
assert a.parameters.safe

b = LuxtronikData(safe=False)
assert not b.parameters.safe

para = Parameters()
c = LuxtronikData(para)
assert c.parameters == para
assert a.parameters != para

calc = Calculations()
visi = Visibilities()
d = LuxtronikData(calculations=calc, visibilities=visi)
assert d.calculations == calc
assert d.visibilities == visi
assert c.calculations != calc
assert c.visibilities != visi

def test_get_firmware_version(self):
"""Test cases for get_firmware_version()"""

a = LuxtronikData()
for i in range(81, 91):
a.calculations.get(i).raw = 0
assert a.get_firmware_version() == ""

a.calculations.get(81).raw = ord("V")
assert a.get_firmware_version() == "V"

a.calculations.get(82).raw = ord("3")
assert a.get_firmware_version() == "V3"

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

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

0 comments on commit 723e51a

Please sign in to comment.