mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Use explicit open/close for covers (#46602)
This commit is contained in:
parent
6986fa4eb6
commit
0bfcd5e1ee
@ -1685,17 +1685,17 @@ class OpenCloseTrait(_Trait):
|
||||
else:
|
||||
position = params["openPercent"]
|
||||
|
||||
if features & cover.SUPPORT_SET_POSITION:
|
||||
service = cover.SERVICE_SET_COVER_POSITION
|
||||
if position > 0:
|
||||
should_verify = True
|
||||
svc_params[cover.ATTR_POSITION] = position
|
||||
elif position == 0:
|
||||
if position == 0:
|
||||
service = cover.SERVICE_CLOSE_COVER
|
||||
should_verify = False
|
||||
elif position == 100:
|
||||
service = cover.SERVICE_OPEN_COVER
|
||||
should_verify = True
|
||||
elif features & cover.SUPPORT_SET_POSITION:
|
||||
service = cover.SERVICE_SET_COVER_POSITION
|
||||
if position > 0:
|
||||
should_verify = True
|
||||
svc_params[cover.ATTR_POSITION] = position
|
||||
else:
|
||||
raise SmartHomeError(
|
||||
ERR_NOT_SUPPORTED, "No support for partial open close"
|
||||
|
@ -1933,14 +1933,18 @@ async def test_openclose_cover(hass):
|
||||
assert trt.sync_attributes() == {}
|
||||
assert trt.query_attributes() == {"openPercent": 75}
|
||||
|
||||
calls = async_mock_service(hass, cover.DOMAIN, cover.SERVICE_SET_COVER_POSITION)
|
||||
calls_set = async_mock_service(hass, cover.DOMAIN, cover.SERVICE_SET_COVER_POSITION)
|
||||
calls_open = async_mock_service(hass, cover.DOMAIN, cover.SERVICE_OPEN_COVER)
|
||||
|
||||
await trt.execute(trait.COMMAND_OPENCLOSE, BASIC_DATA, {"openPercent": 50}, {})
|
||||
await trt.execute(
|
||||
trait.COMMAND_OPENCLOSE_RELATIVE, BASIC_DATA, {"openRelativePercent": 50}, {}
|
||||
)
|
||||
assert len(calls) == 2
|
||||
assert calls[0].data == {ATTR_ENTITY_ID: "cover.bla", cover.ATTR_POSITION: 50}
|
||||
assert calls[1].data == {ATTR_ENTITY_ID: "cover.bla", cover.ATTR_POSITION: 100}
|
||||
assert len(calls_set) == 1
|
||||
assert calls_set[0].data == {ATTR_ENTITY_ID: "cover.bla", cover.ATTR_POSITION: 50}
|
||||
|
||||
assert len(calls_open) == 1
|
||||
assert calls_open[0].data == {ATTR_ENTITY_ID: "cover.bla"}
|
||||
|
||||
|
||||
async def test_openclose_cover_unknown_state(hass):
|
||||
@ -2111,6 +2115,7 @@ async def test_openclose_cover_secure(hass, device_class):
|
||||
assert trt.query_attributes() == {"openPercent": 75}
|
||||
|
||||
calls = async_mock_service(hass, cover.DOMAIN, cover.SERVICE_SET_COVER_POSITION)
|
||||
calls_close = async_mock_service(hass, cover.DOMAIN, cover.SERVICE_CLOSE_COVER)
|
||||
|
||||
# No challenge data
|
||||
with pytest.raises(error.ChallengeNeeded) as err:
|
||||
@ -2136,8 +2141,8 @@ async def test_openclose_cover_secure(hass, device_class):
|
||||
|
||||
# no challenge on close
|
||||
await trt.execute(trait.COMMAND_OPENCLOSE, PIN_DATA, {"openPercent": 0}, {})
|
||||
assert len(calls) == 2
|
||||
assert calls[1].data == {ATTR_ENTITY_ID: "cover.bla", cover.ATTR_POSITION: 0}
|
||||
assert len(calls_close) == 1
|
||||
assert calls_close[0].data == {ATTR_ENTITY_ID: "cover.bla"}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
Loading…
x
Reference in New Issue
Block a user