async def test_flow_unlock_network_timeout(hass):
    """Test we handle a network timeout in the unlock step."""
    device = get_device("Living Room")
    mock_api = device.get_mock_api()
    mock_api.is_locked = True
    mock_api.set_lock.side_effect = blke.NetworkTimeoutError()

    result = await hass.config_entries.flow.async_init(
        DOMAIN, context={"source": config_entries.SOURCE_USER}
    )

    with patch(DEVICE_DISCOVERY, return_value=[mock_api]):
        result = await hass.config_entries.flow.async_configure(
            result["flow_id"],
            {"host": device.host, "timeout": device.timeout},
        )

    result = await hass.config_entries.flow.async_configure(
        result["flow_id"],
        {"unlock": True},
    )

    assert result["type"] == "form"
    assert result["step_id"] == "unlock"
    assert result["errors"] == {"base": "cannot_connect"}
Пример #2
0
async def test_flow_import_device_not_found(opp):
    """Test we handle a device not found in the import step."""
    with patch(DEVICE_HELLO, side_effect=blke.NetworkTimeoutError()):
        result = await opp.config_entries.flow.async_init(
            DOMAIN,
            context={"source": config_entries.SOURCE_IMPORT},
            data={"host": "192.168.1.32"},
        )

    assert result["type"] == "abort"
    assert result["reason"] == "cannot_connect"
Пример #3
0
async def test_device_setup_network_timeout(opp):
    """Test we handle a network timeout."""
    device = get_device("Office")
    mock_api = device.get_mock_api()
    mock_api.auth.side_effect = blke.NetworkTimeoutError()

    with patch.object(
        opp.config_entries, "async_forward_entry_setup"
    ) as mock_forward, patch.object(opp.config_entries.flow, "async_init") as mock_init:
        mock_api, mock_entry = await device.setup_entry(opp, mock_api=mock_api)

    assert mock_entry.state is ConfigEntryState.SETUP_RETRY
    assert mock_api.auth.call_count == 1
    assert mock_forward.call_count == 0
    assert mock_init.call_count == 0
Пример #4
0
async def test_device_unload_update_failed(hass):
    """Test we unload a device that failed the update step."""
    device = get_device("Office")
    mock_api = device.get_mock_api()
    mock_api.check_sensors.side_effect = blke.NetworkTimeoutError()

    with patch.object(hass.config_entries, "async_forward_entry_setup"):
        _, mock_entry = await device.setup_entry(hass, mock_api=mock_api)

    with patch.object(hass.config_entries,
                      "async_forward_entry_unload",
                      return_value=True) as mock_forward:
        await hass.config_entries.async_unload(mock_entry.entry_id)

    assert mock_entry.state == ENTRY_STATE_NOT_LOADED
    assert mock_forward.call_count == 0
Пример #5
0
async def test_flow_user_device_not_found(hass):
    """Test we handle a device not found in the user step."""
    device = get_device("Living Room")

    result = await hass.config_entries.flow.async_init(
        DOMAIN, context={"source": config_entries.SOURCE_USER})

    with patch(DEVICE_HELLO, side_effect=blke.NetworkTimeoutError()):
        result = await hass.config_entries.flow.async_configure(
            result["flow_id"],
            {"host": device.host},
        )

    assert result["type"] == "form"
    assert result["step_id"] == "user"
    assert result["errors"] == {"base": "cannot_connect"}
Пример #6
0
async def test_dhcp_fails_to_connect(opp):
    """Test DHCP discovery flow that fails to connect."""
    await setup.async_setup_component(opp, "persistent_notification", {})
    with patch(DEVICE_HELLO, side_effect=blke.NetworkTimeoutError()):
        result = await opp.config_entries.flow.async_init(
            DOMAIN,
            context={"source": config_entries.SOURCE_DHCP},
            data={
                HOSTNAME: "broadlink",
                IP_ADDRESS: "1.2.3.4",
                MAC_ADDRESS: "34:ea:34:b4:3b:5a",
            },
        )
        await opp.async_block_till_done()

    assert result["type"] == "abort"
    assert result["reason"] == "cannot_connect"
Пример #7
0
async def test_dhcp_fails_to_connect(hass):
    """Test DHCP discovery flow that fails to connect."""

    with patch(DEVICE_HELLO, side_effect=blke.NetworkTimeoutError()):
        result = await hass.config_entries.flow.async_init(
            DOMAIN,
            context={"source": config_entries.SOURCE_DHCP},
            data=dhcp.DhcpServiceInfo(
                hostname="broadlink",
                ip="1.2.3.4",
                macaddress="34:ea:34:b4:3b:5a",
            ),
        )
        await hass.async_block_till_done()

    assert result["type"] == "abort"
    assert result["reason"] == "cannot_connect"
Пример #8
0
async def test_device_setup_update_network_timeout(hass):
    """Test we handle a network timeout in the update step."""
    device = get_device("Office")
    mock_api = device.get_mock_api()
    mock_api.check_sensors.side_effect = blke.NetworkTimeoutError()

    with patch.object(
            hass.config_entries,
            "async_forward_entry_setup") as mock_forward, patch.object(
                hass.config_entries.flow, "async_init") as mock_init:
        mock_api, mock_entry = await device.setup_entry(hass,
                                                        mock_api=mock_api)

    assert mock_entry.state == ENTRY_STATE_SETUP_RETRY
    assert mock_api.auth.call_count == 1
    assert mock_api.check_sensors.call_count == 1
    assert mock_forward.call_count == 0
    assert mock_init.call_count == 0
Пример #9
0
async def test_flow_auth_network_timeout(hass):
    """Test we handle a network timeout in the auth step."""
    device = get_device("Living Room")
    mock_api = device.get_mock_api()
    mock_api.auth.side_effect = blke.NetworkTimeoutError()

    result = await hass.config_entries.flow.async_init(
        DOMAIN, context={"source": config_entries.SOURCE_USER})

    with patch(DEVICE_HELLO, return_value=mock_api):
        result = await hass.config_entries.flow.async_configure(
            result["flow_id"],
            {"host": device.host},
        )

    assert result["type"] == "form"
    assert result["step_id"] == "auth"
    assert result["errors"] == {"base": "cannot_connect"}