Extend blebox shutterbox tilt support (#110547)
* blebox: extend shutterbox tilt support * feat: add test for new open/close tilt code in blebox covers * blebox: resign from using future compat branch for cover open/close tilt * Update homeassistant/components/blebox/cover.py Co-authored-by: Erik Montnemery <erik@montnemery.com> * blebox: revert changes to BLEBOX_TO_HASS_COVER_STATES --------- Co-authored-by: Erik Montnemery <erik@montnemery.com>pull/124363/head
parent
a287c8259d
commit
316a57864a
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue