Alexa to not use customize for entity config (#11461)
* Alexa to not use customize for entity config * Test Alexa entity config * Improve tests * Fix test
This commit is contained in:
1 parent
71fb7a6ef6
commit
8b57777ce9
5 files changed
+140
-57
No files matched your search
@@ -9,7 +9,7 @@ from homeassistant.helpers import entityfilter
|
||||
|
||||
from tests.common import async_mock_service
|
||||
|
||||
DEFAULT_CONFIG = smart_home.Config(filter=lambda entity_id: True)
|
||||
DEFAULT_CONFIG = smart_home.Config(should_expose=lambda entity_id: True)
|
||||
|
||||
|
||||
def get_new_request(namespace, name, endpoint=None):
|
||||
@@ -338,7 +338,7 @@ def test_exclude_filters(hass):
|
||||
hass.states.async_set(
|
||||
'cover.deny', 'off', {'friendly_name': "Blocked cover"})
|
||||
|
||||
config = smart_home.Config(filter=entityfilter.generate_filter(
|
||||
config = smart_home.Config(should_expose=entityfilter.generate_filter(
|
||||
include_domains=[],
|
||||
include_entities=[],
|
||||
exclude_domains=['script'],
|
||||
@@ -371,7 +371,7 @@ def test_include_filters(hass):
|
||||
hass.states.async_set(
|
||||
'group.allow', 'off', {'friendly_name': "Allowed group"})
|
||||
|
||||
config = smart_home.Config(filter=entityfilter.generate_filter(
|
||||
config = smart_home.Config(should_expose=entityfilter.generate_filter(
|
||||
include_domains=['automation', 'group'],
|
||||
include_entities=['script.deny'],
|
||||
exclude_domains=[],
|
||||
@@ -1116,3 +1116,40 @@ def test_api_mute(hass, domain):
|
||||
assert len(call) == 1
|
||||
assert call[0].data['entity_id'] == '{}.test'.format(domain)
|
||||
assert msg['header']['name'] == 'Response'
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_entity_config(hass):
|
||||
"""Test that we can configure things via entity config."""
|
||||
request = get_new_request('Alexa.Discovery', 'Discover')
|
||||
|
||||
hass.states.async_set(
|
||||
'light.test_1', 'on', {'friendly_name': "Test light 1"})
|
||||
|
||||
config = smart_home.Config(
|
||||
should_expose=lambda entity_id: True,
|
||||
entity_config={
|
||||
'light.test_1': {
|
||||
'name': 'Config name',
|
||||
'display_categories': 'SWITCH',
|
||||
'description': 'Config description'
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
msg = yield from smart_home.async_handle_message(
|
||||
hass, config, request)
|
||||
|
||||
assert 'event' in msg
|
||||
msg = msg['event']
|
||||
|
||||
assert len(msg['payload']['endpoints']) == 1
|
||||
|
||||
appliance = msg['payload']['endpoints'][0]
|
||||
assert appliance['endpointId'] == 'light#test_1'
|
||||
assert appliance['displayCategories'][0] == "SWITCH"
|
||||
assert appliance['friendlyName'] == "Config name"
|
||||
assert appliance['description'] == "Config description"
|
||||
assert len(appliance['capabilities']) == 1
|
||||
assert appliance['capabilities'][-1]['interface'] == \
|
||||
'Alexa.PowerController'
|
||||
@@ -38,16 +38,6 @@ def mock_cloud():
|
||||
return MagicMock(subscription_expired=False)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def cloud_instance(loop, hass):
|
||||
"""Instance of an initialized cloud class."""
|
||||
with patch('homeassistant.components.cloud.Cloud.initialize',
|
||||
return_value=mock_coro(True)):
|
||||
loop.run_until_complete(async_setup_component(hass, 'cloud', {}))
|
||||
|
||||
yield hass.data['cloud']
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_cloud_calling_handler(mock_client, mock_handle_message, mock_cloud):
|
||||
"""Test we call handle message with correct info."""
|
||||
@@ -269,13 +259,35 @@ def test_refresh_token_before_expiration_fails(hass, mock_cloud):
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_handler_alexa(hass, cloud_instance):
|
||||
def test_handler_alexa(hass):
|
||||
"""Test handler Alexa."""
|
||||
hass.states.async_set(
|
||||
'switch.test', 'on', {'friendly_name': "Test switch"})
|
||||
hass.states.async_set(
|
||||
'switch.test2', 'on', {'friendly_name': "Test switch 2"})
|
||||
|
||||
with patch('homeassistant.components.cloud.Cloud.initialize',
|
||||
return_value=mock_coro(True)):
|
||||
setup = yield from async_setup_component(hass, 'cloud', {
|
||||
'cloud': {
|
||||
'alexa': {
|
||||
'filter': {
|
||||
'exclude_entities': 'switch.test2'
|
||||
},
|
||||
'entity_config': {
|
||||
'switch.test': {
|
||||
'name': 'Config name',
|
||||
'description': 'Config description',
|
||||
'display_categories': 'LIGHT'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
assert setup
|
||||
|
||||
resp = yield from iot.async_handle_alexa(
|
||||
hass, cloud_instance,
|
||||
hass, hass.data['cloud'],
|
||||
test_alexa.get_new_request('Alexa.Discovery', 'Discover'))
|
||||
|
||||
endpoints = resp['event']['payload']['endpoints']
|
||||
@@ -283,16 +295,32 @@ def test_handler_alexa(hass, cloud_instance):
|
||||
assert len(endpoints) == 1
|
||||
device = endpoints[0]
|
||||
|
||||
assert device['description'] == 'switch.test'
|
||||
assert device['friendlyName'] == 'Test switch'
|
||||
assert device['description'] == 'Config description'
|
||||
assert device['friendlyName'] == 'Config name'
|
||||
assert device['displayCategories'] == ['LIGHT']
|
||||
assert device['manufacturerName'] == 'Home Assistant'
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_handler_google_actions(hass, cloud_instance):
|
||||
def test_handler_google_actions(hass):
|
||||
"""Test handler Google Actions."""
|
||||
hass.states.async_set(
|
||||
'switch.test', 'on', {'friendly_name': "Test switch"})
|
||||
hass.states.async_set(
|
||||
'switch.test2', 'on', {'friendly_name': "Test switch 2"})
|
||||
|
||||
with patch('homeassistant.components.cloud.Cloud.initialize',
|
||||
return_value=mock_coro(True)):
|
||||
setup = yield from async_setup_component(hass, 'cloud', {
|
||||
'cloud': {
|
||||
'google_actions': {
|
||||
'filter': {
|
||||
'exclude_entities': 'switch.test2'
|
||||
},
|
||||
}
|
||||
}
|
||||
})
|
||||
assert setup
|
||||
|
||||
reqid = '5711642932632160983'
|
||||
data = {'requestId': reqid, 'inputs': [{'intent': 'action.devices.SYNC'}]}
|
||||
@@ -300,7 +328,7 @@ def test_handler_google_actions(hass, cloud_instance):
|
||||
with patch('homeassistant.components.cloud.Cloud._decode_claims',
|
||||
return_value={'cognito:username': 'myUserName'}):
|
||||
resp = yield from iot.async_handle_google_actions(
|
||||
hass, cloud_instance, data)
|
||||
hass, hass.data['cloud'], data)
|
||||
|
||||
assert resp['requestId'] == reqid
|
||||
payload = resp['payload']
|
||||
|
||||
Reference in new issue
Block a user