From 44742a970b1cf9ff1d703c8ffb885b2d4505ab9c Mon Sep 17 00:00:00 2001 From: bkobus-bbx Date: Thu, 30 Apr 2026 12:08:14 +0200 Subject: [PATCH] fix: incorrect position inversion for blebox gateBox cover (#168893) --- homeassistant/components/blebox/cover.py | 4 ++- tests/components/blebox/test_cover.py | 31 +++++++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/blebox/cover.py b/homeassistant/components/blebox/cover.py index c52c551bbacc..f6aba3240c99 100644 --- a/homeassistant/components/blebox/cover.py +++ b/homeassistant/components/blebox/cover.py @@ -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: diff --git a/tests/components/blebox/test_cover.py b/tests/components/blebox/test_cover.py index b8ce67102c66..ae169760180a 100644 --- a/tests/components/blebox/test_cover.py +++ b/tests/components/blebox/test_cover.py @@ -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"] )