コード例 #1
0
ファイル: test_regex.py プロジェクト: maweki/aioasuswrt
async def test_get_wl_empty(event_loop, mocker):
    """Testing wl."""
    mocker.patch('aioasuswrt.connection.SshConnection.async_run_command',
                 side_effect=RunCommandEmptyMock)
    scanner = AsusWrt(host="localhost", port=22)
    devices = await scanner.async_get_wl()
    assert {} == devices
コード例 #2
0
async def async_setup(hass, config):
    """Set up the asuswrt component."""
    from aioasuswrt.asuswrt import AsusWrt
    conf = config[DOMAIN]

    api = AsusWrt(conf[CONF_HOST], conf.get(CONF_PORT),
                  conf.get(CONF_PROTOCOL) == 'telnet',
                  conf[CONF_USERNAME],
                  conf.get(CONF_PASSWORD, ''),
                  conf.get('ssh_key', conf.get('pub_key', '')),
                  conf.get(CONF_MODE), conf.get(CONF_REQUIRE_IP))

    await api.connection.async_connect()
    if not api.is_connected:
        _LOGGER.error("Unable to setup asuswrt component")
        return False

    hass.data[DATA_ASUSWRT] = api

    hass.async_create_task(async_load_platform(
        hass, 'sensor', DOMAIN, config[DOMAIN].get(CONF_SENSORS), config))
    hass.async_create_task(async_load_platform(
        hass, 'device_tracker', DOMAIN, {}, config))

    return True
コード例 #3
0
ファイル: test_regex.py プロジェクト: maweki/aioasuswrt
async def test_get_connected_devices_no_ip(event_loop, mocker):
    """Test for get asuswrt_data and not requiring ip."""
    mocker.patch('aioasuswrt.connection.SshConnection.async_run_command',
                 side_effect=RunCommandMock)
    scanner = AsusWrt(host="localhost", port=22, mode='ap', require_ip=False)
    data = await scanner.async_get_connected_devices()
    assert WAKE_DEVICES_NO_IP == data
コード例 #4
0
ファイル: test_regex.py プロジェクト: maweki/aioasuswrt
async def test_get_neigh(event_loop, mocker):
    """Testing neigh."""
    mocker.patch('aioasuswrt.connection.SshConnection.async_run_command',
                 side_effect=RunCommandMock)
    scanner = AsusWrt(host="localhost", port=22)
    data = await scanner.async_get_neigh(NEIGH_DEVICES.copy())
    assert NEIGH_DEVICES == data
コード例 #5
0
async def async_setup(hass, config):
    """Set up the asuswrt component."""

    conf = config[DOMAIN]

    api = AsusWrt(
        conf[CONF_HOST],
        conf[CONF_PORT],
        conf[CONF_PROTOCOL] == "telnet",
        conf[CONF_USERNAME],
        conf.get(CONF_PASSWORD, ""),
        conf.get("ssh_key", conf.get("pub_key", "")),
        conf[CONF_MODE],
        conf[CONF_REQUIRE_IP],
        interface=conf[CONF_INTERFACE],
        dnsmasq=conf[CONF_DNSMASQ],
    )

    await api.connection.async_connect()
    if not api.is_connected:
        _LOGGER.error("Unable to setup component")
        return False

    hass.data[DATA_ASUSWRT] = api

    hass.async_create_task(
        async_load_platform(
            hass, "sensor", DOMAIN, config[DOMAIN].get(CONF_SENSORS), config
        )
    )
    hass.async_create_task(
        async_load_platform(hass, "device_tracker", DOMAIN, {}, config)
    )

    return True
コード例 #6
0
async def test_async_get_interfaces_counts(event_loop, mocker):
    """Test getting loadavg."""
    mocker.patch(
        'aioasuswrt.connection.SshConnection.async_run_command',
        side_effect=RunCommandMock)
    scanner = AsusWrt(host="localhost", port=22, mode='ap', require_ip=False)
    data = await scanner.async_get_interfaces_counts()
    assert data == INTERFACES_COUNT
コード例 #7
0
async def test_get_packets_total(event_loop, mocker):
    """Test getting packet totals."""
    mock_run_cmd(mocker, [TX_DATA, RX_DATA])
    scanner = AsusWrt(host="localhost", port=22, mode="ap", require_ip=False)
    data = await scanner.async_get_tx()
    assert TX == data
    data = await scanner.async_get_rx()
    assert RX == data
コード例 #8
0
async def test_get_connected_devices_ap(event_loop, mocker):
    """Test for get asuswrt_data in ap mode."""
    # Note, unfortunately the order of data is important and should be the
    # same as in the `async_get_connected_devices` function.
    mock_run_cmd(mocker, [WL_DATA, ARP_DATA, NEIGH_DATA, LEASES_DATA])
    scanner = AsusWrt(host="localhost", port=22, mode="ap", require_ip=True)
    data = await scanner.async_get_connected_devices()
    assert WAKE_DEVICES_AP == data
コード例 #9
0
async def test_async_get_temperature(event_loop, mocker):
    """Test getting temperature."""
    mocker.patch(
        'aioasuswrt.connection.SshConnection.async_run_command',
        side_effect=RunCommandMock)
    scanner = AsusWrt(host="localhost", port=22, mode='ap', require_ip=False)
    data = await scanner.async_get_temperature()
    assert data == {'2.4GHz': 49.5, '5.0GHz': 54.5, 'CPU': 77.0}
コード例 #10
0
ファイル: test_regex.py プロジェクト: maweki/aioasuswrt
async def test_get_packets_total(event_loop, mocker):
    """Test getting packet totals."""
    mocker.patch('aioasuswrt.connection.SshConnection.async_run_command',
                 side_effect=RunCommandMock)
    scanner = AsusWrt(host="localhost", port=22, mode='ap', require_ip=False)
    data = await scanner.async_get_tx(use_cache=False)
    assert IFCONFIG_TX == data
    data = await scanner.async_get_rx(use_cache=False)
    assert IFCONFIG_RX == data
コード例 #11
0
ファイル: __init__.py プロジェクト: alexlia/homeassistant
async def async_setup(hass, config, retry_delay=FIRST_RETRY_TIME):
    """Set up the asuswrt component."""

    conf = config[DOMAIN]

    api = AsusWrt(
        conf[CONF_HOST],
        conf[CONF_PORT],
        conf[CONF_PROTOCOL] == "telnet",
        conf[CONF_USERNAME],
        conf.get(CONF_PASSWORD, ""),
        conf.get("ssh_key", conf.get("pub_key", "")),
        conf[CONF_MODE],
        conf[CONF_REQUIRE_IP],
        interface=conf[CONF_INTERFACE],
        dnsmasq=conf[CONF_DNSMASQ],
    )

    try:
        await api.connection.async_connect()
    except OSError as ex:
        _LOGGER.warning(
            "Error [%s] connecting %s to %s. Will retry in %s seconds...",
            str(ex),
            DOMAIN,
            conf[CONF_HOST],
            retry_delay,
        )

        async def retry_setup(now):
            """Retry setup if a error happens on asuswrt API."""
            await async_setup(
                hass, config, retry_delay=min(2 * retry_delay, MAX_RETRY_TIME)
            )

        async_call_later(hass, retry_delay, retry_setup)

        return True

    if not api.is_connected:
        _LOGGER.error("Error connecting %s to %s.", DOMAIN, conf[CONF_HOST])
        return False

    hass.data[DATA_ASUSWRT] = api

    hass.async_create_task(
        async_load_platform(
            hass, "sensor", DOMAIN, config[DOMAIN].get(CONF_SENSORS), config
        )
    )
    hass.async_create_task(
        async_load_platform(hass, "device_tracker", DOMAIN, {}, config)
    )

    return True
コード例 #12
0
    def __init__(self, config):
        """Initialize the scanner."""
        from aioasuswrt.asuswrt import AsusWrt

        self.last_results = {}
        self.success_init = False
        self.connection = AsusWrt(
            config[CONF_HOST], config[CONF_PORT],
            config[CONF_PROTOCOL] == 'telnet', config[CONF_USERNAME],
            config.get(CONF_PASSWORD, ''),
            config.get('ssh_key', config.get('pub_key', '')),
            config[CONF_MODE], config[CONF_REQUIRE_IP])
コード例 #13
0
ファイル: router.py プロジェクト: epenet/home-assistant-core
def get_api(conf: dict, options: dict | None = None) -> AsusWrt:
    """Get the AsusWrt API."""
    opt = options or {}

    return AsusWrt(
        conf[CONF_HOST],
        conf[CONF_PORT],
        conf[CONF_PROTOCOL] == PROTOCOL_TELNET,
        conf[CONF_USERNAME],
        conf.get(CONF_PASSWORD, ""),
        conf.get(CONF_SSH_KEY, ""),
        conf[CONF_MODE],
        opt.get(CONF_REQUIRE_IP, True),
        interface=opt.get(CONF_INTERFACE, DEFAULT_INTERFACE),
        dnsmasq=opt.get(CONF_DNSMASQ, DEFAULT_DNSMASQ),
    )
コード例 #14
0
async def test_get_connected_devices_no_ip(event_loop, mocker):
    """Test for get asuswrt_data and not requiring ip."""
    mock_run_cmd(mocker, [WL_DATA, ARP_DATA, NEIGH_DATA, LEASES_DATA])
    scanner = AsusWrt(host="localhost", port=22, mode="ap", require_ip=False)
    data = await scanner.async_get_connected_devices()
    assert WAKE_DEVICES_NO_IP == data
コード例 #15
0
async def test_get_wl_empty(event_loop, mocker):
    """Testing wl."""
    mock_run_cmd(mocker, [""])
    scanner = AsusWrt(host="localhost", port=22)
    devices = await scanner.async_get_wl()
    assert {} == devices
コード例 #16
0
async def test_async_get_loadavg(event_loop, mocker):
    """Test getting loadavg."""
    mock_run_cmd(mocker, [LOADAVG_DATA])
    scanner = AsusWrt(host="localhost", port=22, mode="ap", require_ip=False)
    data = await scanner.async_get_loadavg()
    assert data == [0.23, 0.5, 0.68]
コード例 #17
0
async def test_async_get_temperature(event_loop, mocker):
    """Test getting temperature."""
    mock_run_cmd(mocker, [TEMP_DATA])
    scanner = AsusWrt(host="localhost", port=22, mode="ap", require_ip=False)
    data = await scanner.async_get_temperature()
    assert data == {"2.4GHz": 49.5, "5.0GHz": 54.5, "CPU": 77.0}
コード例 #18
0
async def test_async_get_interfaces_counts(event_loop, mocker):
    """Test getting loadavg."""
    mock_run_cmd(mocker, [NETDEV_DATA])
    scanner = AsusWrt(host="localhost", port=22, mode="ap", require_ip=False)
    data = await scanner.async_get_interfaces_counts()
    assert data == INTERFACES_COUNT
コード例 #19
0
async def test_get_wl(event_loop, mocker):
    """Testing wl."""
    mock_run_cmd(mocker, [WL_DATA])
    scanner = AsusWrt(host="localhost", port=22)
    devices = await scanner.async_get_wl()
    assert WL_DEVICES == devices
コード例 #20
0
async def test_async_get_leases(event_loop, mocker):
    """Testing leases."""
    mock_run_cmd(mocker, [LEASES_DATA])
    scanner = AsusWrt(host="localhost", port=22)
    data = await scanner.async_get_leases(NEIGH_DEVICES.copy())
    assert LEASES_DEVICES == data
コード例 #21
0
async def test_get_neigh(event_loop, mocker):
    """Testing neigh."""
    mock_run_cmd(mocker, [NEIGH_DATA])
    scanner = AsusWrt(host="localhost", port=22)
    data = await scanner.async_get_neigh(NEIGH_DEVICES.copy())
    assert NEIGH_DEVICES == data
コード例 #22
0
async def test_get_arp(event_loop, mocker):
    """Testing arp."""
    mock_run_cmd(mocker, [ARP_DATA])
    scanner = AsusWrt(host="localhost", port=22)
    data = await scanner.async_get_arp()
    assert ARP_DEVICES == data