Пример #1
0
async def test_handler_alexa_disabled(hass, mock_cloud_fixture):
    """Test handler Alexa when user has disabled it."""
    mock_cloud_fixture._prefs[PREF_ENABLE_ALEXA] = False
    cloud = hass.data["cloud"]

    resp = await cloud.client.async_alexa_message(
        test_alexa.get_new_request("Alexa.Discovery", "Discover"))

    assert resp["event"]["header"]["namespace"] == "Alexa"
    assert resp["event"]["header"]["name"] == "ErrorResponse"
    assert resp["event"]["payload"]["type"] == "BRIDGE_UNREACHABLE"
Пример #2
0
async def test_handler_alexa_disabled(hass, mock_cloud_fixture):
    """Test handler Alexa when user has disabled it."""
    mock_cloud_fixture[PREF_ENABLE_ALEXA] = False
    cloud = hass.data['cloud']

    resp = await cloud.client.async_alexa_message(
        test_alexa.get_new_request('Alexa.Discovery', 'Discover'))

    assert resp['event']['header']['namespace'] == 'Alexa'
    assert resp['event']['header']['name'] == 'ErrorResponse'
    assert resp['event']['payload']['type'] == 'BRIDGE_UNREACHABLE'
Пример #3
0
def test_handler_alexa_disabled(hass, mock_cloud_fixture):
    """Test handler Alexa when user has disabled it."""
    mock_cloud_fixture[STORAGE_ENABLE_ALEXA] = False

    resp = yield from iot.async_handle_alexa(
        hass, hass.data['cloud'],
        test_alexa.get_new_request('Alexa.Discovery', 'Discover'))

    assert resp['event']['header']['namespace'] == 'Alexa'
    assert resp['event']['header']['name'] == 'ErrorResponse'
    assert resp['event']['payload']['type'] == 'BRIDGE_UNREACHABLE'
Пример #4
0
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.async_start',
               return_value=mock_coro()):
        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

    mock_cloud_prefs(hass)

    resp = yield from iot.async_handle_alexa(
        hass, hass.data['cloud'],
        test_alexa.get_new_request('Alexa.Discovery', 'Discover'))

    endpoints = resp['event']['payload']['endpoints']

    assert len(endpoints) == 1
    device = endpoints[0]

    assert device['description'] == 'Config description'
    assert device['friendlyName'] == 'Config name'
    assert device['displayCategories'] == ['LIGHT']
    assert device['manufacturerName'] == 'Home Assistant'
Пример #5
0
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.async_start',
               return_value=mock_coro()):
        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

    mock_cloud_prefs(hass)

    resp = yield from iot.async_handle_alexa(
        hass, hass.data['cloud'],
        test_alexa.get_new_request('Alexa.Discovery', 'Discover'))

    endpoints = resp['event']['payload']['endpoints']

    assert len(endpoints) == 1
    device = endpoints[0]

    assert device['description'] == 'Config description'
    assert device['friendlyName'] == 'Config name'
    assert device['displayCategories'] == ['LIGHT']
    assert device['manufacturerName'] == 'Home Assistant'
Пример #6
0
async 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"})

    await mock_cloud(
        hass,
        {
            "alexa": {
                "filter": {
                    "exclude_entities": "switch.test2"
                },
                "entity_config": {
                    "switch.test": {
                        "name": "Config name",
                        "description": "Config description",
                        "display_categories": "LIGHT",
                    }
                },
            }
        },
    )

    mock_cloud_prefs(hass)
    cloud = hass.data["cloud"]

    resp = await cloud.client.async_alexa_message(
        test_alexa.get_new_request("Alexa.Discovery", "Discover"))

    endpoints = resp["event"]["payload"]["endpoints"]

    assert len(endpoints) == 1
    device = endpoints[0]

    assert device["description"] == "Config description via Home Assistant"
    assert device["friendlyName"] == "Config name"
    assert device["displayCategories"] == ["LIGHT"]
    assert device["manufacturerName"] == "Home Assistant"
Пример #7
0
async 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"})

    await mock_cloud(
        hass, {
            'alexa': {
                'filter': {
                    'exclude_entities': 'switch.test2'
                },
                'entity_config': {
                    'switch.test': {
                        'name': 'Config name',
                        'description': 'Config description',
                        'display_categories': 'LIGHT'
                    }
                }
            }
        })

    mock_cloud_prefs(hass)
    cloud = hass.data['cloud']

    resp = await cloud.client.async_alexa_message(
        test_alexa.get_new_request('Alexa.Discovery', 'Discover'))

    endpoints = resp['event']['payload']['endpoints']

    assert len(endpoints) == 1
    device = endpoints[0]

    assert device['description'] == 'Config description'
    assert device['friendlyName'] == 'Config name'
    assert device['displayCategories'] == ['LIGHT']
    assert device['manufacturerName'] == 'Home Assistant'