Example #1
0
async def test_device_setup_get_fwversion_broadlink_exception(opp):
    """Test we load the device even if we cannot read the firmware version."""
    device = get_device("Office")
    mock_api = device.get_mock_api()
    mock_api.get_fwversion.side_effect = blke.BroadlinkException()

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

    assert mock_entry.state is ConfigEntryState.LOADED
    forward_entries = {c[1][1] for c in mock_forward.mock_calls}
    domains = get_domains(mock_api.type)
    assert mock_forward.call_count == len(domains)
    assert forward_entries == domains
Example #2
0
async def test_device_setup_broadlink_exception(opp):
    """Test we handle a Broadlink exception."""
    device = get_device("Office")
    mock_api = device.get_mock_api()
    mock_api.auth.side_effect = blke.BroadlinkException()

    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_ERROR
    assert mock_api.auth.call_count == 1
    assert mock_forward.call_count == 0
    assert mock_init.call_count == 0
async def test_device_setup_update_broadlink_exception(hass):
    """Test we handle a Broadlink exception in the update step."""
    device = get_device("Garage")
    mock_api = device.get_mock_api()
    mock_api.check_sensors.side_effect = blke.BroadlinkException()

    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_setup = await device.setup_entry(hass, mock_api=mock_api)

    assert mock_setup.entry.state is ConfigEntryState.SETUP_RETRY
    assert mock_setup.api.auth.call_count == 1
    assert mock_setup.api.check_sensors.call_count == 1
    assert mock_forward.call_count == 0
    assert mock_init.call_count == 0
Example #4
0
async def test_device_setup_get_fwversion_broadlink_exception(hass):
    """Test we load the device even if we cannot read the firmware version."""
    device = get_device("Office")
    mock_api = device.get_mock_api()
    mock_api.get_fwversion.side_effect = blke.BroadlinkException()
    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:
        await hass.config_entries.async_setup(mock_entry.entry_id)

    assert mock_entry.state == ENTRY_STATE_LOADED
    forward_entries = {c[1][1] for c in mock_forward.mock_calls}
    domains = get_domains(mock_api.type)
    assert mock_forward.call_count == len(domains)
    assert forward_entries == domains
Example #5
0
async def test_flow_auth_firmware_error(hass):
    """Test we handle a firmware error in the auth step."""
    device = get_device("Living Room")
    mock_api = device.get_mock_api()
    mock_api.auth.side_effect = blke.BroadlinkException()

    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": "unknown"}
Example #6
0
async def test_device_setup_broadlink_exception(hass):
    """Test we handle a Broadlink exception."""
    device = get_device("Office")
    mock_api = device.get_mock_api()
    mock_api.auth.side_effect = blke.BroadlinkException()
    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_ERROR
    assert mock_api.auth.call_count == 1
    assert mock_forward.call_count == 0
    assert mock_init.call_count == 0