Beispiel #1
0
async def test_invalid_credential(mock_get, mock_post, opp):
    """Testing invalid credential handling."""
    config = {
        DOMAIN: xiaomi.PLATFORM_SCHEMA(
            {
                CONF_PLATFORM: xiaomi.DOMAIN,
                CONF_HOST: "192.168.0.1",
                CONF_USERNAME: INVALID_USERNAME,
                CONF_PASSWORD: "******",
            }
        )
    }
    assert get_scanner(opp, config) is None
Beispiel #2
0
async def test_valid_credential(mock_get, mock_post, opp):
    """Testing valid refresh."""
    config = {
        DOMAIN: xiaomi.PLATFORM_SCHEMA(
            {
                CONF_PLATFORM: xiaomi.DOMAIN,
                CONF_HOST: "192.168.0.1",
                CONF_USERNAME: "******",
                CONF_PASSWORD: "******",
            }
        )
    }
    scanner = get_scanner(opp, config)
    assert scanner is not None
    assert len(scanner.scan_devices()) == 2
    assert scanner.get_device_name("23:83:BF:F6:38:A0") == "Device1"
    assert scanner.get_device_name("1D:98:EC:5E:D5:A6") == "Device2"
Beispiel #3
0
async def test_config(xiaomi_mock, opp):
    """Testing minimal configuration."""
    config = {
        DOMAIN: xiaomi.PLATFORM_SCHEMA(
            {
                CONF_PLATFORM: xiaomi.DOMAIN,
                CONF_HOST: "192.168.0.1",
                CONF_PASSWORD: "******",
            }
        )
    }
    xiaomi.get_scanner(opp, config)
    assert xiaomi_mock.call_count == 1
    assert xiaomi_mock.call_args == call(config[DOMAIN])
    call_arg = xiaomi_mock.call_args[0][0]
    assert call_arg["username"] == "admin"
    assert call_arg["password"] == "passwordTest"
    assert call_arg["host"] == "192.168.0.1"
    assert call_arg["platform"] == "device_tracker"
Beispiel #4
0
async def test_token_timed_out(mock_get, mock_post, opp):
    """Testing refresh with a timed out token.

    New token is requested and list is downloaded a second time.
    """
    config = {
        DOMAIN: xiaomi.PLATFORM_SCHEMA(
            {
                CONF_PLATFORM: xiaomi.DOMAIN,
                CONF_HOST: "192.168.0.1",
                CONF_USERNAME: TOKEN_TIMEOUT_USERNAME,
                CONF_PASSWORD: "******",
            }
        )
    }
    scanner = get_scanner(opp, config)
    assert scanner is not None
    assert len(scanner.scan_devices()) == 2
    assert scanner.get_device_name("23:83:BF:F6:38:A0") == "Device1"
    assert scanner.get_device_name("1D:98:EC:5E:D5:A6") == "Device2"