Repository: XKNX/xknx
Pull request #952 (2022-05-15 20:58:55)

Cover: decouple inversion of updown and position
<!--
  You are awesome! Thanks for contributing to our project!
  Please, DO NOT DELETE ANY TEXT from this template!.
-->
## Description
<!--
Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context.
List any dependencies that are required for this change.
-->
Cover: decouple inversion of updown and position

Fixes # (issue)

## Type of change
<!--
Please tick the applicable options.
NOTE: Ticking multiple options most likely indicates
that your change is to big and it is suggested to split it into several smaller PRs.
-->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update

## Checklist:

- [x] I have performed a self-review of my own code
- [x] The documentation has been adjusted accordingly
- [x] The changes generate no new warnings
- [x] Tests have been added that prove the fix is effective or that the feature works
- [x] The changes are documented in the changelog
- [ ] The Homeassistant plugin has been adjusted in case of new config options


codecov[bot]: # [Codecov](https://codecov.io/gh/XKNX/xknx/pull/952?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX) Report
> Merging [#952](https://codecov.io/gh/XKNX/xknx/pull/952?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX) (6cee381) into [main](https://codecov.io/gh/XKNX/xknx/commit/9793eeb870b56bd7f4f5fca75a67b70b90923856?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX) (9793eeb) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/XKNX/xknx/pull/952/graphs/tree.svg?width=650&height=150&src=pr&token=irWbIygS84&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX)](https://codecov.io/gh/XKNX/xknx/pull/952?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX)

```diff
@@           Coverage Diff           @@
##             main     #952   +/-   ##
=======================================
  Coverage   96.00%   96.00%           
=======================================
  Files         131      131           
  Lines        7894     7894           
=======================================
  Hits         7579     7579           
  Misses        315      315           
```


| [Impacted Files](https://codecov.io/gh/XKNX/xknx/pull/952?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX) | Coverage Δ | |
|---|---|---|
| [xknx/devices/cover.py](https://codecov.io/gh/XKNX/xknx/pull/952/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=XKNX#diff-eGtueC9kZXZpY2VzL2NvdmVyLnB5) | `100.00% <ø> (ø)` | |


Patch:
diff --git a/changelog.md b/changelog.md
index bd47ef59..b978f734 100644
--- a/changelog.md
+++ b/changelog.md
@@ -4,6 +4,7 @@
 
 ### Devices
 
+- Cover: add `invert_updown` option to decouple updown from position
 - Cover: fix travel time prediction when receiving updates from bus while moving
 
 ### Protocol
diff --git a/docs/cover.md b/docs/cover.md
index f4529690..0e9aace9 100644
--- a/docs/cover.md
+++ b/docs/cover.md
@@ -26,8 +26,9 @@ Shutters are simple representations of blind/roller cover actuators. With XKNX y
 - `sync_state` defines if and how often the value should be actively read from the bus. If `False` no GroupValueRead telegrams will be sent to its group address. Defaults to `True`
 - `travel_time_down` seconds to reach lower end position. Default: 22
 - `travel_time_up` seconds to reach upper end position. Default: 22
-- `invert_position` invert position (payload for eg. set_up() and relative position). Default: False
-- `invert_angle` invert angle. Default: False
+- `invert_updown` invert up/down binary payload. Default: False
+- `invert_position` invert position percentage from / to KNX bus. Default: False
+- `invert_angle` invert angle from / to KNX bus. Default: False
 - `device_updated_cb` awaitable callback for each update.
 
 ## [](#header-2)Example
diff --git a/xknx/devices/cover.py b/xknx/devices/cover.py
index c870bac4..949922c7 100644
--- a/xknx/devices/cover.py
+++ b/xknx/devices/cover.py
@@ -52,6 +52,7 @@ class Cover(Device):
         sync_state: bool | int | float | str = True,
         travel_time_down: float = DEFAULT_TRAVEL_TIME_DOWN,
         travel_time_up: float = DEFAULT_TRAVEL_TIME_UP,
+        invert_updown: bool = False,
         invert_position: bool = False,
         invert_angle: bool = False,
         device_updated_cb: DeviceCallbackType | None = None,
@@ -66,7 +67,7 @@ class Cover(Device):
             group_address_long,
             device_name=self.name,
             after_update_cb=None,
-            invert=invert_position,
+            invert=invert_updown,
         )
 
         self.step = RemoteValueStep(
@@ -74,7 +75,7 @@ class Cover(Device):
             group_address_short,
             device_name=self.name,
             after_update_cb=self.after_update,
-            invert=invert_position,
+            invert=invert_updown,
         )
 
         self.stop_ = RemoteValueSwitch(


Test patch:
diff --git a/test/devices_tests/cover_test.py b/test/devices_tests/cover_test.py
index e17d0677..84f8b2e7 100644
--- a/test/devices_tests/cover_test.py
+++ b/test/devices_tests/cover_test.py
@@ -253,7 +253,7 @@ class TestCover:
             group_address_short="1/2/2",
             group_address_position="1/2/3",
             group_address_position_state="1/2/4",
-            invert_position=True,
+            invert_updown=True,
         )
         await cover.set_down()
         assert xknx.telegrams.qsize() == 1
@@ -299,7 +299,7 @@ class TestCover:
             group_address_short="1/2/2",
             group_address_position="1/2/3",
             group_address_position_state="1/2/4",
-            invert_position=True,
+            invert_updown=True,
         )
         await cover.set_short_up()
         assert xknx.telegrams.qsize() == 1