fix: incorrect position inversion for blebox gateBox cover (#168893)

This commit is contained in:
bkobus-bbx
2026-04-30 12:08:14 +02:00
committed by GitHub
parent fd34aa0de8
commit 44742a970b
2 changed files with 30 additions and 5 deletions
+3 -1
View File
@@ -85,7 +85,9 @@ class BleBoxCoverEntity(BleBoxEntity[blebox_uniapi.cover.Cover], CoverEntity):
if position == -1: # possible for shutterBox
return None
return None if position is None else 100 - position
if position is None:
return None
return 100 - position if self._feature.is_position_inverted else position
@property
def current_cover_tilt_position(self) -> int | None:
+27 -4
View File
@@ -51,6 +51,7 @@ def shutterbox_fixture():
has_stop=True,
has_tilt=True,
is_slider=True,
is_position_inverted=True,
)
product = feature.product
type(product).name = PropertyMock(return_value="My shutter")
@@ -71,6 +72,7 @@ def gatebox_fixture():
state=None,
has_stop=False,
is_slider=False,
is_position_inverted=False,
)
product = feature.product
type(product).name = PropertyMock(return_value="My gatebox")
@@ -91,6 +93,7 @@ def gate_fixture():
state=None,
has_stop=True,
is_slider=True,
is_position_inverted=True,
)
product = feature.product
type(product).name = PropertyMock(return_value="My gate controller")
@@ -276,14 +279,16 @@ async def test_stop(feature, hass: HomeAssistant) -> None:
assert hass.states.get(entity_id).state == CoverState.OPEN
@pytest.mark.parametrize("feature", ALL_COVER_FIXTURES, indirect=["feature"])
async def test_update(feature, hass: HomeAssistant) -> None:
"""Test cover updating."""
@pytest.mark.parametrize(
"feature", ["gatecontroller", "shutterbox"], indirect=["feature"]
)
async def test_update_inverted(feature, hass: HomeAssistant) -> None:
"""Test cover position is inverted for shutterBox and gateController."""
feature_mock, entity_id = feature
def initial_update():
feature_mock.current = 29 # inverted
feature_mock.current = 29 # device: 29% closed = 71% open
feature_mock.state = 2 # manually stopped
feature_mock.async_update = AsyncMock(side_effect=initial_update)
@@ -295,6 +300,24 @@ async def test_update(feature, hass: HomeAssistant) -> None:
assert state.state == CoverState.OPEN
async def test_update_not_inverted(gatebox, hass: HomeAssistant) -> None:
"""Test cover position is not inverted for gateBox."""
feature_mock, entity_id = gatebox
def initial_update():
feature_mock.current = 100 # fully open
feature_mock.state = 4 # open
feature_mock.async_update = AsyncMock(side_effect=initial_update)
await async_setup_entity(hass, entity_id)
state = hass.states.get(entity_id)
assert state.attributes[ATTR_CURRENT_POSITION] == 100
assert state.state == CoverState.OPEN
@pytest.mark.parametrize(
"feature", ["gatecontroller", "shutterbox"], indirect=["feature"]
)