diff --git a/setup.py b/setup.py index 4a14208..e5d94d0 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="tplinkrouterc6u", - version="5.0.2", + version="5.0.3", author="Alex Erohin", author_email="alexanderErohin@yandex.ru", description="TP-Link Router API", diff --git a/test/test_client_deco.py b/test/test_client_deco.py index 2f4e0b3..ab1223c 100644 --- a/test/test_client_deco.py +++ b/test/test_client_deco.py @@ -70,7 +70,7 @@ def test_get_status(self) -> None: "connection_type": "band5", "space_id": "1", "ip": "192.168.68.104", "client_mesh": true, "online": true, "name": "d2lyZWxlc3M0", "enable_priority": false, "remain_time": 0, "owner_id": "", "client_type": "other", "interface": "guest"}, - {"mac": "56:32:c3:de:ce:f0", "up_speed": 3, "down_speed": 1, "wire_type": "wireless", "access_host": "1", + {"mac": "", "up_speed": 3, "down_speed": 1, "wire_type": "wireless", "access_host": "1", "connection_type": "band2_4", "space_id": "1", "ip": "UNKNOWN", "client_mesh": true, "online": true, "name": "d2lyZWxlc3M1", "enable_priority": false, "remain_time": 0, "owner_id": "", "client_type": "other", "interface": "guest"} @@ -149,7 +149,7 @@ def request(self, path: str, data: str, self.assertEqual(status.devices[3].packets_received, None) self.assertIsInstance(status.devices[4], Device) self.assertEqual(status.devices[4].type, Connection.GUEST_2G) - self.assertEqual(status.devices[4].macaddr, '56-32-C3-DE-CE-F0') + self.assertEqual(status.devices[4].macaddr, '00-00-00-00-00-00') self.assertEqual(status.devices[4].ipaddr, '0.0.0.0') self.assertEqual(status.devices[4].hostname, 'wireless5') self.assertEqual(status.devices[4].packets_sent, None) diff --git a/tplinkrouterc6u/client.py b/tplinkrouterc6u/client.py index fa72967..36f0e2f 100644 --- a/tplinkrouterc6u/client.py +++ b/tplinkrouterc6u/client.py @@ -10,7 +10,7 @@ from macaddress import EUI48 from ipaddress import IPv4Address from logging import Logger -from tplinkrouterc6u.helper import get_ip +from tplinkrouterc6u.helper import get_ip, get_mac from tplinkrouterc6u.encryption import EncryptionWrapper, EncryptionWrapperMR from tplinkrouterc6u.package_enum import Connection from tplinkrouterc6u.dataclass import Firmware, Status, Device, IPv4Reservation, IPv4DHCPLease, IPv4Status @@ -355,7 +355,7 @@ def get_status(self) -> Status: devices = {} def _add_device(conn: Connection, item: dict) -> None: - devices[item['macaddr']] = Device(conn, EUI48(item['macaddr']), + devices[item['macaddr']] = Device(conn, get_mac(item.get('macaddr', '00:00:00:00:00:00')), get_ip(item['ipaddr']), item['hostname']) @@ -382,8 +382,8 @@ def _add_device(conn: Connection, item: dict) -> None: for item in smart_network: if item['mac'] not in devices: conn = self._map_wire_type(item.get('deviceTag'), not item.get('isGuest')) - devices[item['mac']] = Device(conn, EUI48(item['mac']), get_ip(item['ip']), - item['deviceName']) + devices[item['mac']] = Device(conn, get_mac(item.get('mac', '00:00:00:00:00:00')), + get_ip(item['ip']), item['deviceName']) if conn.is_iot(): if status.iot_clients_total is None: status.iot_clients_total = 0 @@ -581,7 +581,7 @@ def get_status(self) -> Status: status.iot_clients_total += 1 device = Device(conn, - EUI48(item['mac']), + get_mac(item.get('mac', '00:00:00:00:00:00')), get_ip(item.get('ip', '0.0.0.0')), b64decode(item['name']).decode()) device.down_speed = item.get('down_speed') diff --git a/tplinkrouterc6u/helper.py b/tplinkrouterc6u/helper.py index 7bd546c..806d409 100644 --- a/tplinkrouterc6u/helper.py +++ b/tplinkrouterc6u/helper.py @@ -1,4 +1,5 @@ from ipaddress import IPv4Address +from macaddress import EUI48 def get_ip(ip: str) -> IPv4Address: @@ -6,3 +7,10 @@ def get_ip(ip: str) -> IPv4Address: return IPv4Address(ip) except Exception: return IPv4Address('0.0.0.0') + + +def get_mac(mac: str) -> EUI48: + try: + return EUI48(mac) + except Exception: + return EUI48('00:00:00:00:00:00')