示例#1
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.DeviceOfflineError()

    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
示例#2
0
async def test_device_setup_device_offline(hass):
    """Test we handle a device offline."""
    device = get_device("Office")
    mock_api = device.get_mock_api()
    mock_api.auth.side_effect = blke.DeviceOfflineError()

    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_forward.call_count == 0
    assert mock_init.call_count == 0
示例#3
0
async def test_flow_auth_device_offline(hass):
    """Test we handle a device offline in the auth step."""
    device = get_device("Living Room")
    mock_api = device.get_mock_api()
    mock_api.auth.side_effect = blke.DeviceOfflineError()

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

    with patch("broadlink.discover", 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"}
示例#4
0
async def test_device_setup_device_offline(hass):
    """Test we handle a device offline."""
    device = get_device("Office")
    mock_api = device.get_mock_api()
    mock_api.auth.side_effect = blke.DeviceOfflineError()
    mock_entry = device.get_mock_entry()
    mock_entry.add_to_hass(hass)

    with patch("broadlink.gendevice", return_value=mock_api), patch.object(
            hass.config_entries,
            "async_forward_entry_setup") as mock_forward, patch.object(
                hass.config_entries.flow, "async_init") as mock_init:
        await hass.config_entries.async_setup(mock_entry.entry_id)

    assert mock_entry.state == ENTRY_STATE_SETUP_RETRY
    assert mock_api.auth.call_count == 1
    assert mock_forward.call_count == 0
    assert mock_init.call_count == 0