Extend effect of invert_position to cover status for slide_local (#150418)

This commit is contained in:
dontinelli
2025-09-01 17:25:59 +02:00
committed by GitHub
parent ac0ff96f26
commit 1e4fa40a77
3 changed files with 11 additions and 10 deletions

View File

@@ -28,7 +28,7 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from .const import DEFAULT_OFFSET, DOMAIN
from .const import CONF_INVERT_POSITION, DEFAULT_OFFSET, DOMAIN
_LOGGER = logging.getLogger(__name__)
@@ -100,19 +100,22 @@ class SlideCoordinator(DataUpdateCoordinator[dict[str, Any]]):
data["pos"] = max(0, min(1, data["pos"]))
if not self.config_entry.options.get(CONF_INVERT_POSITION, False):
# For slide 0->open, 1->closed; for HA 0->closed, 1->open
# Value has therefore to be inverted, unless CONF_INVERT_POSITION is true
data["pos"] = 1 - data["pos"]
if oldpos is None or oldpos == data["pos"]:
data["state"] = (
STATE_CLOSED if data["pos"] > (1 - DEFAULT_OFFSET) else STATE_OPEN
STATE_CLOSED if data["pos"] < DEFAULT_OFFSET else STATE_OPEN
)
elif oldpos < data["pos"]:
elif oldpos > data["pos"]:
data["state"] = (
STATE_CLOSED
if data["pos"] >= (1 - DEFAULT_OFFSET)
else STATE_CLOSING
STATE_CLOSED if data["pos"] <= DEFAULT_OFFSET else STATE_CLOSING
)
else:
data["state"] = (
STATE_OPEN if data["pos"] <= DEFAULT_OFFSET else STATE_OPENING
STATE_OPEN if data["pos"] >= (1 - DEFAULT_OFFSET) else STATE_OPENING
)
_LOGGER.debug("Data successfully updated: %s", data)

View File

@@ -78,8 +78,6 @@ class SlideCoverLocal(SlideEntity, CoverEntity):
if pos is not None:
if (1 - pos) <= DEFAULT_OFFSET or pos <= DEFAULT_OFFSET:
pos = round(pos)
if not self.invert:
pos = 1 - pos
pos = int(pos * 100)
return pos

View File

@@ -31,7 +31,7 @@
'curtain_type': 0,
'device_name': 'slide bedroom',
'mac': '1234567890ab',
'pos': 0,
'pos': 1,
'slide_id': 'slide_1234567890ab',
'state': 'open',
'touch_go': True,