Skip to content

Commit

Permalink
Allow covers to be inverted again (#414)
Browse files Browse the repository at this point in the history
* Allow covers to be inverted again

* Review: step should also be inverted

* Review: Tests
  • Loading branch information
marvin-w committed Sep 22, 2020
1 parent 17fefb9 commit 0aa8107
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
45 changes: 45 additions & 0 deletions test/devices_tests/cover_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,28 @@ def test_set_short_down(self):
telegram, Telegram(GroupAddress("1/2/1"), payload=DPTBinary(1))
)

#
# TEST SET DOWN INVERTED
#
def test_set_down_inverted(self):
"""Test moving cover to 'down' position."""
xknx = XKNX(loop=self.loop)
cover = Cover(
xknx,
"TestCover",
group_address_long="1/2/1",
group_address_short="1/2/2",
group_address_position="1/2/3",
group_address_position_state="1/2/4",
invert_position=True,
)
self.loop.run_until_complete(cover.set_down())
self.assertEqual(xknx.telegrams.qsize(), 1)
telegram = xknx.telegrams.get_nowait()
self.assertEqual(
telegram, Telegram(GroupAddress("1/2/1"), payload=DPTBinary(0))
)

#
# TEST SET SHORT UP
#
Expand All @@ -253,6 +275,29 @@ def test_set_short_up(self):
telegram, Telegram(GroupAddress("1/2/2"), payload=DPTBinary(0))
)

#
# TEST SET UP INVERTED
#
def test_set_up_inverted(self):
"""Test moving cover 'short up'."""
xknx = XKNX(loop=self.loop)
cover = Cover(
xknx,
"TestCover",
group_address_long="1/2/1",
group_address_short="1/2/2",
group_address_position="1/2/3",
group_address_position_state="1/2/4",
invert_position=True,
)
self.loop.run_until_complete(cover.set_short_up())
self.assertEqual(xknx.telegrams.qsize(), 1)
telegram = xknx.telegrams.get_nowait()
# DPT 1.008 - 0:up 1:down
self.assertEqual(
telegram, Telegram(GroupAddress("1/2/2"), payload=DPTBinary(1))
)

#
# TEST SET SHORT DOWN
#
Expand Down
7 changes: 6 additions & 1 deletion xknx/devices/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,19 @@ def __init__(
# travelcalculator (in process_group_write and set_*) - angle changes
# are updated from RemoteValue objects
self.updown = RemoteValueUpDown(
xknx, group_address_long, device_name=self.name, after_update_cb=None
xknx,
group_address_long,
device_name=self.name,
after_update_cb=None,
invert=invert_position,
)

self.step = RemoteValueStep(
xknx,
group_address_short,
device_name=self.name,
after_update_cb=self.after_update,
invert=invert_position,
)

self.stop_ = RemoteValueSwitch(
Expand Down

0 comments on commit 0aa8107

Please sign in to comment.