Support script execution for Alexa (#10517)

* Support script execution for Alexa

* Use PowerController for the script component
This commit is contained in:
Michael Chang 2017-11-15 23:44:27 -06:00 committed by Paulus Schoutsen
parent d5cba0b716
commit 48181a9388
2 changed files with 16 additions and 4 deletions

View file

@ -6,7 +6,7 @@ from uuid import uuid4
from homeassistant.const import ( from homeassistant.const import (
ATTR_SUPPORTED_FEATURES, ATTR_ENTITY_ID, SERVICE_TURN_ON, SERVICE_TURN_OFF) ATTR_SUPPORTED_FEATURES, ATTR_ENTITY_ID, SERVICE_TURN_ON, SERVICE_TURN_OFF)
from homeassistant.components import switch, light from homeassistant.components import switch, light, script
import homeassistant.util.color as color_util import homeassistant.util.color as color_util
from homeassistant.util.decorator import Registry from homeassistant.util.decorator import Registry
@ -21,6 +21,7 @@ API_ENDPOINT = 'endpoint'
MAPPING_COMPONENT = { MAPPING_COMPONENT = {
script.DOMAIN: ['SWITCH', ('Alexa.PowerController',), None],
switch.DOMAIN: ['SWITCH', ('Alexa.PowerController',), None], switch.DOMAIN: ['SWITCH', ('Alexa.PowerController',), None],
light.DOMAIN: [ light.DOMAIN: [
'LIGHT', ('Alexa.PowerController',), { 'LIGHT', ('Alexa.PowerController',), {

View file

@ -114,12 +114,15 @@ def test_discovery_request(hass):
'friendly_name': "Test light 3", 'supported_features': 19 'friendly_name': "Test light 3", 'supported_features': 19
}) })
hass.states.async_set(
'script.test', 'off', {'friendly_name': "Test script"})
msg = yield from smart_home.async_handle_message(hass, request) msg = yield from smart_home.async_handle_message(hass, request)
assert 'event' in msg assert 'event' in msg
msg = msg['event'] msg = msg['event']
assert len(msg['payload']['endpoints']) == 4 assert len(msg['payload']['endpoints']) == 5
assert msg['header']['name'] == 'Discover.Response' assert msg['header']['name'] == 'Discover.Response'
assert msg['header']['namespace'] == 'Alexa.Discovery' assert msg['header']['namespace'] == 'Alexa.Discovery'
@ -170,6 +173,14 @@ def test_discovery_request(hass):
continue continue
if appliance['endpointId'] == 'script#test':
assert appliance['displayCategories'][0] == "SWITCH"
assert appliance['friendlyName'] == "Test script"
assert len(appliance['capabilities']) == 1
assert appliance['capabilities'][-1]['interface'] == \
'Alexa.PowerController'
continue
raise AssertionError("Unknown appliance!") raise AssertionError("Unknown appliance!")
@ -206,7 +217,7 @@ def test_api_function_not_implemented(hass):
@asyncio.coroutine @asyncio.coroutine
@pytest.mark.parametrize("domain", ['light', 'switch']) @pytest.mark.parametrize("domain", ['light', 'switch', 'script'])
def test_api_turn_on(hass, domain): def test_api_turn_on(hass, domain):
"""Test api turn on process.""" """Test api turn on process."""
request = get_new_request( request = get_new_request(
@ -231,7 +242,7 @@ def test_api_turn_on(hass, domain):
@asyncio.coroutine @asyncio.coroutine
@pytest.mark.parametrize("domain", ['light', 'switch']) @pytest.mark.parametrize("domain", ['light', 'switch', 'script'])
def test_api_turn_off(hass, domain): def test_api_turn_off(hass, domain):
"""Test api turn on process.""" """Test api turn on process."""
request = get_new_request( request = get_new_request(