示例#1
0
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"})
    hass.states.async_set('group.all_locks', 'on',
                          {'friendly_name': "Evil locks"})

    with patch('homeassistant.components.cloud.Cloud.async_start',
               return_value=mock_coro()):
        setup = yield from async_setup_component(
            hass, 'cloud', {
                'cloud': {
                    'google_actions': {
                        'filter': {
                            'exclude_entities': 'switch.test2'
                        },
                        'entity_config': {
                            'switch.test': {
                                'name': 'Config name',
                                'aliases': 'Config alias',
                                'room': 'living room'
                            }
                        }
                    }
                }
            })
        assert setup

    mock_cloud_prefs(hass)

    reqid = '5711642932632160983'
    data = {'requestId': reqid, 'inputs': [{'intent': 'action.devices.SYNC'}]}

    with patch('homeassistant.components.cloud.Cloud._decode_claims',
               return_value={'cognito:username': '******'}):
        resp = yield from iot.async_handle_google_actions(
            hass, hass.data['cloud'], data)

    assert resp['requestId'] == reqid
    payload = resp['payload']

    assert payload['agentUserId'] == 'myUserName'

    devices = payload['devices']
    assert len(devices) == 1

    device = devices[0]
    assert device['id'] == 'switch.test'
    assert device['name']['name'] == 'Config name'
    assert device['name']['nicknames'] == ['Config alias']
    assert device['type'] == 'action.devices.types.SWITCH'
    assert device['roomHint'] == 'living room'
示例#2
0
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"})
    hass.states.async_set(
        'group.all_locks', 'on', {'friendly_name': "Evil locks"})

    with patch('homeassistant.components.cloud.Cloud.async_start',
               return_value=mock_coro()):
        setup = yield from async_setup_component(hass, 'cloud', {
            'cloud': {
                'google_actions': {
                    'filter': {
                        'exclude_entities': 'switch.test2'
                    },
                    'entity_config': {
                        'switch.test': {
                            'name': 'Config name',
                            'aliases': 'Config alias',
                            'room': 'living room'
                        }
                    }
                }
            }
        })
        assert setup

    mock_cloud_prefs(hass)

    reqid = '5711642932632160983'
    data = {'requestId': reqid, 'inputs': [{'intent': 'action.devices.SYNC'}]}

    with patch('homeassistant.components.cloud.Cloud._decode_claims',
               return_value={'cognito:username': '******'}):
        resp = yield from iot.async_handle_google_actions(
            hass, hass.data['cloud'], data)

    assert resp['requestId'] == reqid
    payload = resp['payload']

    assert payload['agentUserId'] == 'myUserName'

    devices = payload['devices']
    assert len(devices) == 1

    device = devices[0]
    assert device['id'] == 'switch.test'
    assert device['name']['name'] == 'Config name'
    assert device['name']['nicknames'] == ['Config alias']
    assert device['type'] == 'action.devices.types.SWITCH'
    assert device['roomHint'] == 'living room'