Skip to content

Commit

Permalink
fix for extenders
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandrErohin committed Nov 12, 2024
1 parent 281ff3b commit 5f3c067
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="tplinkrouterc6u",
version="5.0.2",
version="5.0.3",
author="Alex Erohin",
author_email="[email protected]",
description="TP-Link Router API",
Expand Down
4 changes: 2 additions & 2 deletions test/test_client_deco.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions tplinkrouterc6u/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'])

Expand All @@ -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
Expand Down Expand Up @@ -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')
Expand Down
8 changes: 8 additions & 0 deletions tplinkrouterc6u/helper.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
from ipaddress import IPv4Address
from macaddress import EUI48


def get_ip(ip: str) -> IPv4Address:
try:
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')

0 comments on commit 5f3c067

Please sign in to comment.