Skip to content

Commit

Permalink
Added setter serial number.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julius2342 committed May 22, 2020
1 parent 3f86d67 commit 7b9c636
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 23 deletions.
13 changes: 13 additions & 0 deletions pyvlx/frames/frame_get_all_nodes_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pyvlx.const import Command, NodeTypeWithSubtype, NodeVariation, Velocity
from pyvlx.parameter import Parameter
from pyvlx.string_helper import bytes_to_string, string_to_bytes
from pyvlx.exception import PyVLXException

from .frame import FrameBase

Expand Down Expand Up @@ -93,6 +94,18 @@ def serial_number(self):
return None
return ":".join("{:02x}".format(c) for c in self._serial_number)

@serial_number.setter
def serial_number(self, serial_number):
"""Set serial number."""
if serial_number is None:
self._serial_number = bytes(8)
return
self._serial_number = b''
for elem in (serial_number.split(":")):
self._serial_number += bytes.fromhex(elem)
if len(self._serial_number) != 8:
raise PyVLXException("could_not_parse_serial_number")

def get_payload(self):
"""Return Payload."""
payload = bytes()
Expand Down
11 changes: 10 additions & 1 deletion pyvlx/frames/frame_get_node_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pyvlx.const import Command, NodeTypeWithSubtype, NodeVariation, Velocity
from pyvlx.parameter import Parameter
from pyvlx.string_helper import bytes_to_string, string_to_bytes
from pyvlx.exception import PyVLXException

from .frame import FrameBase

Expand Down Expand Up @@ -109,7 +110,15 @@ def serial_number(self):

@serial_number.setter
def serial_number(self, serial_number):
self._serial_number = serial_number
"""Set serial number."""
if serial_number is None:
self._serial_number = bytes(8)
return
self._serial_number = b''
for elem in (serial_number.split(":")):
self._serial_number += bytes.fromhex(elem)
if len(self._serial_number) != 8:
raise PyVLXException("could_not_parse_serial_number")

def get_payload(self):
"""Return Payload."""
Expand Down
22 changes: 16 additions & 6 deletions test/frame_get_all_nodes_information_ntf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pyvlx.frame_creation import frame_from_raw
from pyvlx.frames import FrameGetAllNodesInformationNotification
from pyvlx.parameter import Position
from pyvlx.exception import PyVLXException


class TestFrameGetAllNodesInformationNotification(unittest.TestCase):
Expand Down Expand Up @@ -38,9 +39,8 @@ def test_bytes(self):
frame.node_variation = NodeVariation.TOPHUNG
frame.power_mode = 1
frame.build_number = 7
frame._serial_number = ( # pylint: disable=protected-access
b"\x01\x02\x03\x04\x05\x06\x06\x08"
)
frame.serial_number = "01:02:03:04:05:06:06:08"

frame.state = 1
frame.current_position = Position(position=12)
frame.target = Position(position=123)
Expand Down Expand Up @@ -104,12 +104,22 @@ def test_str(self):
def test_serial_number(self):
"""Test serial number property."""
frame = FrameGetAllNodesInformationNotification()
frame._serial_number = ( # pylint: disable=protected-access
b"\x01\x02\x03\x04\x05\x06\x06\x08"
)
frame.serial_number = "01:02:03:04:05:06:06:08"
self.assertEqual(frame.serial_number, "01:02:03:04:05:06:06:08")

def test_serial_number_none(self):
"""Test serial number property with no value set."""
frame = FrameGetAllNodesInformationNotification()
frame.serial_number = None
self.assertEqual(frame.serial_number, None)

def test_serial_number_not_set(self):
"""Test serial number property with not set."""
frame = FrameGetAllNodesInformationNotification()
self.assertEqual(frame.serial_number, None)

def test_wrong_serial_number(self):
"""Test setting a wrong serial number."""
frame = FrameGetAllNodesInformationNotification()
with self.assertRaises(PyVLXException):
frame.serial_number = "01:02:03:04:05:06:06"
22 changes: 16 additions & 6 deletions test/frame_get_node_information_ntf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pyvlx.frame_creation import frame_from_raw
from pyvlx.frames import FrameGetNodeInformationNotification
from pyvlx.parameter import Position
from pyvlx.exception import PyVLXException


class TestFrameGetNodeInformationNotification(unittest.TestCase):
Expand Down Expand Up @@ -38,9 +39,8 @@ def test_bytes(self):
frame.node_variation = NodeVariation.TOPHUNG
frame.power_mode = 1
frame.build_number = 7
frame._serial_number = ( # pylint: disable=protected-access
b"\x01\x02\x03\x04\x05\x06\x06\x08"
)
frame.serial_number = "01:02:03:04:05:06:06:08"

frame.state = 1
frame.current_position = Position(position=12)
frame.target = Position(position=123)
Expand Down Expand Up @@ -104,12 +104,22 @@ def test_str(self):
def test_serial_number(self):
"""Test serial number property."""
frame = FrameGetNodeInformationNotification()
frame._serial_number = ( # pylint: disable=protected-access
b"\x01\x02\x03\x04\x05\x06\x06\x08"
)
frame.serial_number = "01:02:03:04:05:06:06:08"
self.assertEqual(frame.serial_number, "01:02:03:04:05:06:06:08")

def test_serial_number_none(self):
"""Test serial number property with no value set."""
frame = FrameGetNodeInformationNotification()
frame.serial_number = None
self.assertEqual(frame.serial_number, None)

def test_serial_number_not_set(self):
"""Test serial number property with not set."""
frame = FrameGetNodeInformationNotification()
self.assertEqual(frame.serial_number, None)

def test_wrong_serial_number(self):
"""Test setting a wrong serial number."""
frame = FrameGetNodeInformationNotification()
with self.assertRaises(PyVLXException):
frame.serial_number = "01:02:03:04:05:06:06"
20 changes: 10 additions & 10 deletions test/node_helper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_window(self):
frame.node_id = 23
frame.name = "Fnord23"
frame.node_type = NodeTypeWithSubtype.WINDOW_OPENER
frame.serial_number = bytes.fromhex("aa bb aa bb aa bb aa 23")
frame.serial_number = "aa:bb:aa:bb:aa:bb:aa:23"
pyvlx = PyVLX()
node = convert_frame_to_node(pyvlx, frame)
self.assertEqual(
Expand All @@ -37,7 +37,7 @@ def test_window_with_rain_sensor(self):
frame.node_id = 23
frame.name = "Fnord23"
frame.node_type = NodeTypeWithSubtype.WINDOW_OPENER_WITH_RAIN_SENSOR
frame.serial_number = bytes.fromhex("aa bb aa bb aa bb aa 23")
frame.serial_number = "aa:bb:aa:bb:aa:bb:aa:23"
pyvlx = PyVLX()
node = convert_frame_to_node(pyvlx, frame)
self.assertEqual(
Expand All @@ -57,7 +57,7 @@ def test_blind(self):
frame.node_id = 23
frame.name = "Fnord23"
frame.node_type = NodeTypeWithSubtype.EXTERIOR_VENETIAN_BLIND
frame.serial_number = bytes.fromhex("aa bb aa bb aa bb aa 23")
frame.serial_number = "aa:bb:aa:bb:aa:bb:aa:23"
pyvlx = PyVLX()
node = convert_frame_to_node(pyvlx, frame)
self.assertEqual(
Expand All @@ -76,7 +76,7 @@ def test_roller_shutter(self):
frame.node_id = 23
frame.name = "Fnord23"
frame.node_type = NodeTypeWithSubtype.ROLLER_SHUTTER
frame.serial_number = bytes.fromhex("aa bb aa bb aa bb aa 23")
frame.serial_number = "aa:bb:aa:bb:aa:bb:aa:23"
pyvlx = PyVLX()
node = convert_frame_to_node(pyvlx, frame)
self.assertEqual(
Expand All @@ -95,7 +95,7 @@ def test_garage_door(self):
frame.node_id = 23
frame.name = "Fnord23"
frame.node_type = NodeTypeWithSubtype.GARAGE_DOOR_OPENER
frame.serial_number = bytes.fromhex("aa bb aa bb aa bb aa 23")
frame.serial_number = "aa:bb:aa:bb:aa:bb:aa:23"
pyvlx = PyVLX()
node = convert_frame_to_node(pyvlx, frame)
self.assertEqual(
Expand All @@ -114,7 +114,7 @@ def test_gate(self):
frame.node_id = 23
frame.name = "Fnord23"
frame.node_type = NodeTypeWithSubtype.GATE_OPENER
frame.serial_number = bytes.fromhex("aa bb aa bb aa bb aa 23")
frame.serial_number = "aa:bb:aa:bb:aa:bb:aa:23"
pyvlx = PyVLX()
node = convert_frame_to_node(pyvlx, frame)
self.assertEqual(
Expand All @@ -133,7 +133,7 @@ def test_gate_with_angular_position(self):
frame.node_id = 23
frame.name = "Fnord23"
frame.node_type = NodeTypeWithSubtype.GATE_OPENER_ANGULAR_POSITION
frame.serial_number = bytes.fromhex("aa bb aa bb aa bb aa 23")
frame.serial_number = "aa:bb:aa:bb:aa:bb:aa:23"
pyvlx = PyVLX()
node = convert_frame_to_node(pyvlx, frame)
self.assertEqual(
Expand All @@ -152,7 +152,7 @@ def test_blade(self):
frame.node_id = 23
frame.name = "Fnord23"
frame.node_type = NodeTypeWithSubtype.BLADE_OPENER
frame.serial_number = bytes.fromhex("aa bb aa bb aa bb aa 23")
frame.serial_number = "aa:bb:aa:bb:aa:bb:aa:23"
pyvlx = PyVLX()
node = convert_frame_to_node(pyvlx, frame)
self.assertEqual(
Expand All @@ -171,7 +171,7 @@ def test_no_type(self):
frame.node_id = 23
frame.name = "Fnord23"
frame.node_type = NodeTypeWithSubtype.NO_TYPE
frame.serial_number = bytes.fromhex("aa bb aa bb aa bb aa 23")
frame.serial_number = "aa:bb:aa:bb:aa:bb:aa:23"
pyvlx = PyVLX()
self.assertEqual(convert_frame_to_node(pyvlx, frame), None)

Expand All @@ -181,7 +181,7 @@ def test_light(self):
frame.node_id = 23
frame.name = "Fnord23"
frame.node_type = NodeTypeWithSubtype.LIGHT
frame.serial_number = bytes.fromhex("aa bb aa bb aa bb aa 23")
frame.serial_number = "aa:bb:aa:bb:aa:bb:aa:23"
pyvlx = PyVLX()
node = convert_frame_to_node(pyvlx, frame)
self.assertEqual(
Expand Down

0 comments on commit 7b9c636

Please sign in to comment.