Пример #1
0
async def test_homekit_discovery(hass: HomeAssistantType,
                                 aioclient_mock: AiohttpClientMocker) -> None:
    """Test the homekit discovery flow."""
    mock_connection(aioclient_mock, device="rokutv", host=HOMEKIT_HOST)

    discovery_info = MOCK_HOMEKIT_DISCOVERY_INFO.copy()
    result = await hass.config_entries.flow.async_init(
        DOMAIN, context={CONF_SOURCE: SOURCE_HOMEKIT}, data=discovery_info)

    assert result["type"] == RESULT_TYPE_FORM
    assert result["step_id"] == "discovery_confirm"
    assert result["description_placeholders"] == {CONF_NAME: NAME_ROKUTV}

    with patch("homeassistant.components.roku.async_setup",
               return_value=True) as mock_setup, patch(
                   "homeassistant.components.roku.async_setup_entry",
                   return_value=True,
               ) as mock_setup_entry:
        result = await hass.config_entries.flow.async_configure(
            flow_id=result["flow_id"], user_input={})
        await hass.async_block_till_done()

    assert result["type"] == RESULT_TYPE_CREATE_ENTRY
    assert result["title"] == NAME_ROKUTV

    assert result["data"]
    assert result["data"][CONF_HOST] == HOMEKIT_HOST
    assert result["data"][CONF_NAME] == NAME_ROKUTV

    assert len(mock_setup.mock_calls) == 1
    assert len(mock_setup_entry.mock_calls) == 1

    # test abort on existing host
    discovery_info = MOCK_HOMEKIT_DISCOVERY_INFO.copy()
    result = await hass.config_entries.flow.async_init(
        DOMAIN, context={CONF_SOURCE: SOURCE_HOMEKIT}, data=discovery_info)

    assert result["type"] == RESULT_TYPE_ABORT
    assert result["reason"] == "already_configured"
Пример #2
0
async def test_homekit_unknown_error(
        hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None:
    """Test we abort homekit flow on unknown error."""
    discovery_info = MOCK_HOMEKIT_DISCOVERY_INFO.copy()
    with patch(
            "homeassistant.components.roku.config_flow.Roku.update",
            side_effect=Exception,
    ):
        result = await hass.config_entries.flow.async_init(
            DOMAIN,
            context={CONF_SOURCE: SOURCE_HOMEKIT},
            data=discovery_info,
        )

    assert result["type"] == RESULT_TYPE_ABORT
    assert result["reason"] == "unknown"
Пример #3
0
async def test_homekit_cannot_connect(
        hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None:
    """Test we abort homekit flow on connection error."""
    mock_connection(
        aioclient_mock,
        host=HOMEKIT_HOST,
        error=True,
    )

    discovery_info = MOCK_HOMEKIT_DISCOVERY_INFO.copy()
    result = await hass.config_entries.flow.async_init(
        DOMAIN,
        context={CONF_SOURCE: SOURCE_HOMEKIT},
        data=discovery_info,
    )

    assert result["type"] == RESULT_TYPE_ABORT
    assert result["reason"] == "cannot_connect"