From 94ac0b5ed8449b9471fe39909aeb8328ec6eeaaf Mon Sep 17 00:00:00 2001 From: Phil Kates Date: Sun, 24 Dec 2017 15:05:56 -0800 Subject: [PATCH] alexa: Add handling for covers (#11242) * alexa: Add handling for covers Covers don't support either cover.turn_on or homeassistant.turn_on so use cover.[open|close]_cover. * alexa: Add tests for covers --- homeassistant/components/alexa/smart_home.py | 12 ++++++++++-- tests/components/alexa/test_smart_home.py | 14 ++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/alexa/smart_home.py b/homeassistant/components/alexa/smart_home.py index 3c8e9f5d21c..2443e52b766 100644 --- a/homeassistant/components/alexa/smart_home.py +++ b/homeassistant/components/alexa/smart_home.py @@ -243,7 +243,11 @@ def async_api_turn_on(hass, config, request, entity): if entity.domain == group.DOMAIN: domain = ha.DOMAIN - yield from hass.services.async_call(domain, SERVICE_TURN_ON, { + service = SERVICE_TURN_ON + if entity.domain == cover.DOMAIN: + service = cover.SERVICE_OPEN_COVER + + yield from hass.services.async_call(domain, service, { ATTR_ENTITY_ID: entity.entity_id }, blocking=True) @@ -259,7 +263,11 @@ def async_api_turn_off(hass, config, request, entity): if entity.domain == group.DOMAIN: domain = ha.DOMAIN - yield from hass.services.async_call(domain, SERVICE_TURN_OFF, { + service = SERVICE_TURN_OFF + if entity.domain == cover.DOMAIN: + service = cover.SERVICE_CLOSE_COVER + + yield from hass.services.async_call(domain, service, { ATTR_ENTITY_ID: entity.entity_id }, blocking=True) diff --git a/tests/components/alexa/test_smart_home.py b/tests/components/alexa/test_smart_home.py index 55a412af1fd..924931ec21c 100644 --- a/tests/components/alexa/test_smart_home.py +++ b/tests/components/alexa/test_smart_home.py @@ -419,7 +419,7 @@ def test_api_function_not_implemented(hass): @asyncio.coroutine -@pytest.mark.parametrize("domain", ['alert', 'automation', 'group', +@pytest.mark.parametrize("domain", ['alert', 'automation', 'cover', 'group', 'input_boolean', 'light', 'script', 'switch']) def test_api_turn_on(hass, domain): @@ -438,7 +438,10 @@ def test_api_turn_on(hass, domain): if domain == 'group': call_domain = 'homeassistant' - call = async_mock_service(hass, call_domain, 'turn_on') + if domain == 'cover': + call = async_mock_service(hass, call_domain, 'open_cover') + else: + call = async_mock_service(hass, call_domain, 'turn_on') msg = yield from smart_home.async_handle_message( hass, DEFAULT_CONFIG, request) @@ -452,7 +455,7 @@ def test_api_turn_on(hass, domain): @asyncio.coroutine -@pytest.mark.parametrize("domain", ['alert', 'automation', 'group', +@pytest.mark.parametrize("domain", ['alert', 'automation', 'cover', 'group', 'input_boolean', 'light', 'script', 'switch']) def test_api_turn_off(hass, domain): @@ -471,7 +474,10 @@ def test_api_turn_off(hass, domain): if domain == 'group': call_domain = 'homeassistant' - call = async_mock_service(hass, call_domain, 'turn_off') + if domain == 'cover': + call = async_mock_service(hass, call_domain, 'close_cover') + else: + call = async_mock_service(hass, call_domain, 'turn_off') msg = yield from smart_home.async_handle_message( hass, DEFAULT_CONFIG, request)