Skip to content

Commit 1e4fa40

Browse files
authored
Extend effect of invert_position to cover status for slide_local (home-assistant#150418)
1 parent ac0ff96 commit 1e4fa40

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

homeassistant/components/slide_local/coordinator.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from homeassistant.core import HomeAssistant
2929
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
3030

31-
from .const import DEFAULT_OFFSET, DOMAIN
31+
from .const import CONF_INVERT_POSITION, DEFAULT_OFFSET, DOMAIN
3232

3333
_LOGGER = logging.getLogger(__name__)
3434

@@ -100,19 +100,22 @@ async def _async_update_data(self) -> dict[str, Any]:
100100

101101
data["pos"] = max(0, min(1, data["pos"]))
102102

103+
if not self.config_entry.options.get(CONF_INVERT_POSITION, False):
104+
# For slide 0->open, 1->closed; for HA 0->closed, 1->open
105+
# Value has therefore to be inverted, unless CONF_INVERT_POSITION is true
106+
data["pos"] = 1 - data["pos"]
107+
103108
if oldpos is None or oldpos == data["pos"]:
104109
data["state"] = (
105-
STATE_CLOSED if data["pos"] > (1 - DEFAULT_OFFSET) else STATE_OPEN
110+
STATE_CLOSED if data["pos"] < DEFAULT_OFFSET else STATE_OPEN
106111
)
107-
elif oldpos < data["pos"]:
112+
elif oldpos > data["pos"]:
108113
data["state"] = (
109-
STATE_CLOSED
110-
if data["pos"] >= (1 - DEFAULT_OFFSET)
111-
else STATE_CLOSING
114+
STATE_CLOSED if data["pos"] <= DEFAULT_OFFSET else STATE_CLOSING
112115
)
113116
else:
114117
data["state"] = (
115-
STATE_OPEN if data["pos"] <= DEFAULT_OFFSET else STATE_OPENING
118+
STATE_OPEN if data["pos"] >= (1 - DEFAULT_OFFSET) else STATE_OPENING
116119
)
117120

118121
_LOGGER.debug("Data successfully updated: %s", data)

homeassistant/components/slide_local/cover.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ def current_cover_position(self) -> int | None:
7878
if pos is not None:
7979
if (1 - pos) <= DEFAULT_OFFSET or pos <= DEFAULT_OFFSET:
8080
pos = round(pos)
81-
if not self.invert:
82-
pos = 1 - pos
8381
pos = int(pos * 100)
8482
return pos
8583

tests/components/slide_local/snapshots/test_diagnostics.ambr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
'curtain_type': 0,
3232
'device_name': 'slide bedroom',
3333
'mac': '1234567890ab',
34-
'pos': 0,
34+
'pos': 1,
3535
'slide_id': 'slide_1234567890ab',
3636
'state': 'open',
3737
'touch_go': True,

0 commit comments

Comments
 (0)