diff --git a/homeassistant/components/emulated_hue/hue_api.py b/homeassistant/components/emulated_hue/hue_api.py index 0bb6b82f813..be30de01286 100644 --- a/homeassistant/components/emulated_hue/hue_api.py +++ b/homeassistant/components/emulated_hue/hue_api.py @@ -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 diff --git a/tests/components/emulated_hue/test_hue_api.py b/tests/components/emulated_hue/test_hue_api.py index 38288270a1b..c0adad38c9d 100644 --- a/tests/components/emulated_hue/test_hue_api.py +++ b/tests/components/emulated_hue/test_hue_api.py @@ -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):