from pyinteno import inteno_device_from_dict

EXAMPLE_DEVICE_LIST = {
    "client-1": {
        "hostname": "device-1",
        "ipaddr": "192.168.0.1",
        "macaddr": "00:00:00:00:00:01",
        "network": "guest",
        "device": "br-guest",
        "dhcp": True,
        "connected": True,
        "active_connections": 1,
        "wireless": True,
        "wdev": "wl1.1",
        "frequency": "2.4GHz",
        "rssi": -65,
        "snr": 13,
        "idle": 2,
        "in_network": 6925,
        "wme": True,
        "ps": True,
        "n_cap": True,
        "vht_cap": True,
        "tx_bytes": 505476,
        "rx_bytes": 927209,
        "tx_rate": 65000,
        "rx_rate": 39000,
    },
    "client-2": {
        "hostname": "device-2",
        "ipaddr": "192.168.0.2",
        "macaddr": "00:00:00:00:00:02",
        "network": "lan",
        "device": "br-lan",
        "dhcp": True,
        "connected": True,
        "active_connections": 16,
        "wireless": True,
        "wdev": "wl1",
        "frequency": "2.4GHz",
        "rssi": -58,
        "snr": 20,
        "idle": 7,
        "in_network": 2914,
        "wme": True,
        "ps": True,
        "n_cap": True,
        "vht_cap": True,
        "tx_bytes": 394140601,
        "rx_bytes": 5963717,
        "tx_rate": 78000,
        "rx_rate": 1000,
    },
    "client-3": {
        "hostname": "device-3",
        "ipaddr": "192.168.0.3",
        "macaddr": "00:00:00:00:00:03",
        "network": "lan",
        "device": "br-lan",
        "dhcp": True,
        "connected": True,
        "active_connections": 123,
        "wireless": True,
        "wdev": "wl0",
        "frequency": "5GHz",
        "rssi": -60,
        "snr": 11,
        "idle": 0,
        "in_network": 6257,
        "wme": True,
        "ps": True,
        "n_cap": True,
        "vht_cap": True,
        "tx_bytes": 298324460,
        "rx_bytes": 58884648,
        "tx_rate": 866667,
        "rx_rate": 650000,
    },
    "client-4": {
        "hostname": "device-4",
        "ipaddr": "192.168.0.4",
        "macaddr": "00:00:00:00:00:04",
        "network": "lan",
        "device": "br-lan",
        "dhcp": True,
        "connected": True,
        "active_connections": 1,
        "wireless": False,
        "ethport": "eth4",
        "linkspeed": "Auto-negotiated 1000 Mbps Full Duplex",
    },
    "client-5": {
        "hostname": "device-5",
        "ipaddr": "192.168.0.5",
        "macaddr": "00:00:00:00:00:05",
        "network": "lan",
        "device": "br-lan",
        "dhcp": True,
        "connected": True,
        "active_connections": 4,
        "wireless": True,
        "wdev": "wl1",
        "frequency": "2.4GHz",
        "rssi": -66,
        "snr": 12,
        "idle": 0,
        "in_network": 6933,
        "wme": True,
        "ps": True,
        "n_cap": True,
        "vht_cap": True,
        "tx_bytes": 157539330,
        "rx_bytes": 5052784,
        "tx_rate": 65000,
        "rx_rate": 24000,
    },
    "client-6": {
        "hostname": "device-6",
        "ipaddr": "192.168.0.6",
        "macaddr": "00:00:00:00:00:06",
        "network": "lan",
        "device": "br-lan",
        "dhcp": True,
        "connected": True,
        "active_connections": 1,
        "wireless": True,
        "wdev": "wl1",
        "frequency": "2.4GHz",
        "rssi": -68,
        "snr": 10,
        "idle": 1,
        "in_network": 6918,
        "wme": True,
        "ps": True,
        "n_cap": True,
        "vht_cap": True,
        "tx_bytes": 156116082,
        "rx_bytes": 993680,
        "tx_rate": 54000,
        "rx_rate": 24000,
    },
    "client-7": {
        "hostname": "device-7",
        "ipaddr": "192.168.0.7",
        "macaddr": "00:00:00:00:00:07",
        "network": "lan",
        "device": "br-lan",
        "dhcp": True,
        "connected": True,
        "active_connections": 2,
        "wireless": True,
        "wdev": "wl1",
        "frequency": "2.4GHz",
        "rssi": -47,
        "snr": 31,
        "idle": 1,
        "in_network": 6914,
        "wme": True,
        "ps": True,
        "n_cap": True,
        "vht_cap": True,
        "tx_bytes": 155972022,
        "rx_bytes": 755234,
        "tx_rate": 58500,
        "rx_rate": 1000,
    },
    "client-8": {
        "hostname": "device-8",
        "ipaddr": "192.168.0.8",
        "macaddr": "00:00:00:00:00:08",
        "network": "lan",
        "device": "br-lan",
        "dhcp": True,
        "connected": True,
        "active_connections": 2,
        "wireless": True,
        "wdev": "wl1",
        "frequency": "2.4GHz",
        "rssi": -59,
        "snr": 19,
        "idle": 0,
        "in_network": 6894,
        "wme": True,
        "ps": True,
        "n_cap": True,
        "vht_cap": True,
        "tx_bytes": 155971721,
        "rx_bytes": 749581,
        "tx_rate": 39000,
        "rx_rate": 1000,
    },
    "client-9": {
        "hostname": "device-9",
        "ipaddr": "192.168.0.9",
        "macaddr": "00:00:00:00:00:09",
        "network": "lan",
        "device": "br-lan",
        "dhcp": True,
        "connected": True,
        "active_connections": 0,
        "wireless": True,
        "wdev": "wl0",
        "frequency": "5GHz",
        "rssi": -43,
        "snr": 28,
        "idle": 57,
        "in_network": 7057,
        "wme": True,
        "ps": True,
        "n_cap": True,
        "vht_cap": True,
        "tx_bytes": 155177002,
        "rx_bytes": 47129,
        "tx_rate": 390000,
        "rx_rate": 24000,
    },
    "client-10": {
        "hostname": "device-10",
        "ipaddr": "192.168.0.10",
        "macaddr": "00:00:00:00:00:0A",
        "network": "lan",
        "device": "br-lan",
        "dhcp": False,
        "connected": False,
        "wireless": False,
    },
}


def test_inteno_device_from_dict():
    device = inteno_device_from_dict(EXAMPLE_DEVICE_LIST["client-1"])
    assert device.hostname == "device-1"
    # check that all devices are parsed correctly
    for key, value in EXAMPLE_DEVICE_LIST.items():
        device = inteno_device_from_dict(value)
        assert device.hostname == value["hostname"]
        assert device.ipaddr == value["ipaddr"]
        assert device.macaddr == value["macaddr"]
        assert device.network == value["network"]
        assert device.device == value["device"]
        assert device.dhcp == value["dhcp"]
        assert device.connected == value["connected"]
        if "active_connections" in value:
            assert device.active_connections == value["active_connections"]
        if "wireless" in value:
            assert device.wireless == value["wireless"]
            if device.wireless:
                assert device.wdev == value["wdev"]
                assert device.frequency == value["frequency"]
                assert device.rssi == value["rssi"]
                assert device.snr == value["snr"]
                assert device.idle == value["idle"]
                assert device.in_network == value["in_network"]
                assert device.wme == value["wme"]
                assert device.ps == value["ps"]
                assert device.n_cap == value["n_cap"]
                assert device.vht_cap == value["vht_cap"]
                assert device.tx_bytes == value["tx_bytes"]
                assert device.rx_bytes == value["rx_bytes"]
                assert device.tx_rate == value["tx_rate"]
                assert device.rx_rate == value["rx_rate"]
