Fix opening cover via emulated_hue without specifying a position (#49570)

This commit is contained in:
Thomas Hollstegge 2021-04-23 07:12:52 +02:00 committed by GitHub
parent e6d94845dd
commit 66dbb17a4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 8 deletions

View file

@ -525,9 +525,10 @@ class HueOneLightChangeView(HomeAssistantView):
# If the requested entity is a cover, convert to open_cover/close_cover
elif entity.domain == cover.DOMAIN:
domain = entity.domain
service = SERVICE_CLOSE_COVER
if service == SERVICE_TURN_ON:
service = SERVICE_OPEN_COVER
else:
service = SERVICE_CLOSE_COVER
if (
entity_features & SUPPORT_SET_POSITION

View file

@ -885,10 +885,10 @@ async def test_put_light_state_media_player(hass_hue, hue_client):
assert walkman.attributes[media_player.ATTR_MEDIA_VOLUME_LEVEL] == level
async def test_close_cover(hass_hue, hue_client):
async def test_open_cover_without_position(hass_hue, hue_client):
"""Test opening cover ."""
cover_id = "cover.living_room_window"
# Turn the office light off first
# Close cover first
await hass_hue.services.async_call(
cover.DOMAIN,
const.SERVICE_CLOSE_COVER,
@ -908,25 +908,44 @@ async def test_close_cover(hass_hue, hue_client):
assert cover_test.state == "closed"
# Go through the API to turn it on
cover_result = await perform_put_light_state(
hass_hue, hue_client, cover_id, True, 100
)
cover_result = await perform_put_light_state(hass_hue, hue_client, cover_id, True)
assert cover_result.status == HTTP_OK
assert CONTENT_TYPE_JSON in cover_result.headers["content-type"]
for _ in range(7):
for _ in range(11):
future = dt_util.utcnow() + timedelta(seconds=1)
async_fire_time_changed(hass_hue, future)
await hass_hue.async_block_till_done()
cover_result_json = await cover_result.json()
assert len(cover_result_json) == 2
assert len(cover_result_json) == 1
# Check to make sure the state changed
cover_test_2 = hass_hue.states.get(cover_id)
assert cover_test_2.state == "open"
assert cover_test_2.attributes.get("current_position") == 100
# Go through the API to turn it off
cover_result = await perform_put_light_state(hass_hue, hue_client, cover_id, False)
assert cover_result.status == HTTP_OK
assert CONTENT_TYPE_JSON in cover_result.headers["content-type"]
for _ in range(11):
future = dt_util.utcnow() + timedelta(seconds=1)
async_fire_time_changed(hass_hue, future)
await hass_hue.async_block_till_done()
cover_result_json = await cover_result.json()
assert len(cover_result_json) == 1
# Check to make sure the state changed
cover_test_2 = hass_hue.states.get(cover_id)
assert cover_test_2.state == "closed"
assert cover_test_2.attributes.get("current_position") == 0
async def test_set_position_cover(hass_hue, hue_client):