diff --git a/homeassistant/components/blebox/cover.py b/homeassistant/components/blebox/cover.py index 71e47d87894..bb75c88ca2a 100644 --- a/homeassistant/components/blebox/cover.py +++ b/homeassistant/components/blebox/cover.py @@ -29,7 +29,6 @@ BLEBOX_TO_COVER_DEVICE_CLASSES = { "shutter": CoverDeviceClass.SHUTTER, } - BLEBOX_TO_HASS_COVER_STATES = { None: None, # all blebox covers @@ -65,14 +64,20 @@ class BleBoxCoverEntity(BleBoxEntity[blebox_uniapi.cover.Cover], CoverEntity): """Initialize a BleBox cover feature.""" super().__init__(feature) self._attr_device_class = BLEBOX_TO_COVER_DEVICE_CLASSES[feature.device_class] - position = CoverEntityFeature.SET_POSITION if feature.is_slider else 0 - stop = CoverEntityFeature.STOP if feature.has_stop else 0 self._attr_supported_features = ( - position | stop | CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE + CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE ) + if feature.is_slider: + self._attr_supported_features |= CoverEntityFeature.SET_POSITION + + if feature.has_stop: + self._attr_supported_features |= CoverEntityFeature.STOP + if feature.has_tilt: - self._attr_supported_features = ( - self._attr_supported_features | CoverEntityFeature.SET_TILT_POSITION + self._attr_supported_features |= ( + CoverEntityFeature.SET_TILT_POSITION + | CoverEntityFeature.OPEN_TILT + | CoverEntityFeature.CLOSE_TILT ) @property @@ -106,16 +111,24 @@ class BleBoxCoverEntity(BleBoxEntity[blebox_uniapi.cover.Cover], CoverEntity): return self._is_state(STATE_CLOSED) async def async_open_cover(self, **kwargs: Any) -> None: - """Open the cover position.""" + """Fully open the cover position.""" await self._feature.async_open() async def async_close_cover(self, **kwargs: Any) -> None: - """Close the cover position.""" + """Fully close the cover position.""" await self._feature.async_close() + async def async_open_cover_tilt(self, **kwargs: Any) -> None: + """Fully open the cover tilt.""" + await self._feature.async_set_tilt_position(0) + + async def async_close_cover_tilt(self, **kwargs: Any) -> None: + """Fully close the cover tilt.""" + # note: values are reversed + await self._feature.async_set_tilt_position(100) + async def async_set_cover_position(self, **kwargs: Any) -> None: """Set the cover position.""" - position = kwargs[ATTR_POSITION] await self._feature.async_set_position(100 - position) @@ -125,7 +138,6 @@ class BleBoxCoverEntity(BleBoxEntity[blebox_uniapi.cover.Cover], CoverEntity): async def async_set_cover_tilt_position(self, **kwargs: Any) -> None: """Set the tilt position.""" - position = kwargs[ATTR_TILT_POSITION] await self._feature.async_set_tilt_position(100 - position) diff --git a/tests/components/blebox/test_cover.py b/tests/components/blebox/test_cover.py index 1596de134c0..1900a6d6834 100644 --- a/tests/components/blebox/test_cover.py +++ b/tests/components/blebox/test_cover.py @@ -22,7 +22,9 @@ from homeassistant.const import ( ATTR_DEVICE_CLASS, ATTR_SUPPORTED_FEATURES, SERVICE_CLOSE_COVER, + SERVICE_CLOSE_COVER_TILT, SERVICE_OPEN_COVER, + SERVICE_OPEN_COVER_TILT, SERVICE_SET_COVER_POSITION, SERVICE_SET_COVER_TILT_POSITION, SERVICE_STOP_COVER, @@ -473,3 +475,57 @@ async def test_set_tilt_position(shutterbox, hass: HomeAssistant) -> None: blocking=True, ) assert hass.states.get(entity_id).state == STATE_OPENING + + +async def test_open_tilt(shutterbox, hass: HomeAssistant) -> None: + """Test closing tilt.""" + feature_mock, entity_id = shutterbox + + def initial_update(): + feature_mock.tilt_current = 100 + + def set_tilt_position(tilt_position): + assert tilt_position == 0 + feature_mock.tilt_current = tilt_position + + feature_mock.async_update = AsyncMock(side_effect=initial_update) + feature_mock.async_set_tilt_position = AsyncMock(side_effect=set_tilt_position) + + await async_setup_entity(hass, entity_id) + feature_mock.async_update = AsyncMock() + + await hass.services.async_call( + "cover", + SERVICE_OPEN_COVER_TILT, + {"entity_id": entity_id}, + blocking=True, + ) + state = hass.states.get(entity_id) + assert state.attributes[ATTR_CURRENT_TILT_POSITION] == 100 # inverted + + +async def test_close_tilt(shutterbox, hass: HomeAssistant) -> None: + """Test closing tilt.""" + feature_mock, entity_id = shutterbox + + def initial_update(): + feature_mock.tilt_current = 0 + + def set_tilt_position(tilt_position): + assert tilt_position == 100 + feature_mock.tilt_current = tilt_position + + feature_mock.async_update = AsyncMock(side_effect=initial_update) + feature_mock.async_set_tilt_position = AsyncMock(side_effect=set_tilt_position) + + await async_setup_entity(hass, entity_id) + feature_mock.async_update = AsyncMock() + + await hass.services.async_call( + "cover", + SERVICE_CLOSE_COVER_TILT, + {"entity_id": entity_id}, + blocking=True, + ) + state = hass.states.get(entity_id) + assert state.attributes[ATTR_CURRENT_TILT_POSITION] == 0 # inverted