Skip to content

Commit

Permalink
Add data types to client models.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zach Cheatham committed Feb 12, 2023
1 parent 4d9d9c2 commit ae8f633
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 72 deletions.
106 changes: 53 additions & 53 deletions custom_components/omada/api/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
]


class Clients(APIItems):
class Clients(APIItems):
def __init__(self, request):
super().__init__(request, END_POINT, "mac", Client, data_key="data")

Expand All @@ -30,128 +30,128 @@ class Client(APIItem):
"""Defines all the properties for a Client"""

@property
def mac(self):
def mac(self) -> str:
return self._raw.get("mac", "")

@property
def name(self):
return self._raw.get("name", "")
def name(self) -> str | None:
return self._raw.get("name")

@property
def hostname(self):
return self._raw.get("hostName", "")
def hostname(self) -> str | None:
return self._raw.get("hostName")

@property
def device_type(self):
return self._raw.get("deviceType", "")
def device_type(self) -> str | None:
return self._raw.get("deviceType")

@property
def ip(self):
return self._raw.get("ip", "")
def ip(self) -> str | None:
return self._raw.get("ip")

@property
def connect_type(self):
return self._raw.get("connectType", "")
def connect_type(self) -> int | None:
return self._raw.get("connectType")

@property
def connect_dev_type(self):
return self._raw.get("connectDevType", "")
def connect_dev_type(self) -> str | None:
return self._raw.get("connectDevType")

@property
def wireless(self):
def wireless(self) -> bool:
return self._raw.get("wireless", False)

@property
def ssid(self):
return self._raw.get("ssid", "")
def ssid(self) -> str | None:
return self._raw.get("ssid")

@property
def signal_level(self):
return self._raw.get("signalLevel")
def signal_level(self) -> int:
return self._raw.get("signalLevel", 0)

@property
def signal_rank(self):
return self._raw.get("signalRank")
def signal_rank(self) -> int:
return self._raw.get("signalRank", 0)

@property
def wifi_mode(self):
def wifi_mode(self) -> str:
return WIFI_MODE[self._raw.get("wifiMode")]

@property
def ap_name(self):
def ap_name(self) -> str | None:
return self._raw.get("apName")

@property
def ap_mac(self):
def ap_mac(self) -> str | None:
return self._raw.get("apMac")

@property
def radio(self):
def radio(self) -> str:
return RADIO[self._raw.get("radioId")]

@property
def channel(self):
def channel(self) -> int | None:
return self._raw.get("channel")

@property
def rx_rate(self):
def rx_rate(self) -> int | None:
return self._raw.get("rxRate")

@property
def tx_rate(self):
def tx_rate(self) -> int | None:
return self._raw.get("txRate")

@property
def power_save(self):
return self._raw.get("powerSave")
def power_save(self) -> bool:
return self._raw.get("powerSave", False)

@property
def rssi(self):
def rssi(self) -> int | None:
return self._raw.get("rssi")

@property
def activity(self):
return self._raw.get("activity")
def activity(self) -> int:
return self._raw.get("activity", 0)

@property
def traffic_down(self):
return self._raw.get("trafficDown")
def traffic_down(self) -> int:
return self._raw.get("trafficDown", 0)

@property
def traffic_up(self):
return self._raw.get("trafficUp")
def traffic_up(self) -> int:
return self._raw.get("trafficUp", 0)

@property
def uptime(self):
return self._raw.get("uptime")
def uptime(self) -> int:
return self._raw.get("uptime", -1)

@property
def last_seen(self):
return self._raw.get("lastSeen")
def last_seen(self) -> int:
return self._raw.get("lastSeen", -1)

@property
def auth_status(self):
return self._raw.get("auth_status")
def auth_status(self) -> int | None:
return self._raw.get("authStatus")

@property
def guest(self):
return self._raw.get("guest")
def guest(self) -> bool:
return self._raw.get("guest", False)

@property
def active(self):
return self._raw.get("active")
def active(self) -> bool:
return self._raw.get("active", False)

@property
def manager(self):
return self._raw.get("manager")
def manager(self) -> bool:
return self._raw.get("manager", False)

@property
def down_packet(self):
return self._raw.get("downPacket")
def down_packet(self) -> int:
return self._raw.get("downPacket", 0)

@property
def up_packet(self):
return self._raw.get("upPacket")
def up_packet(self) -> int:
return self._raw.get("upPacket", 0)

def __repr__(self):
name = self.name or self.mac
Expand Down
38 changes: 19 additions & 19 deletions custom_components/omada/api/known_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,44 @@ async def async_set_block(self, mac: str, block: bool) -> None:

class KnownClient(APIItem):
@property
def mac(self):
def mac(self) -> str:
return self._raw.get("mac", "")

@property
def name(self):
return self._raw.get("name", "")
def name(self) -> str | None:
return self._raw.get("name", None)

@property
def wireless(self):
return self._raw.get("wireless")
def wireless(self) -> bool:
return self._raw.get("wireless", False)

@property
def guest(self):
return self._raw.get("guest")
def guest(self) -> bool:
return self._raw.get("guest", False)

@property
def download(self):
return self._raw.get("download")
def download(self) -> int:
return self._raw.get("download", 0)

@property
def upload(self):
return self._raw.get("upload")
def upload(self) -> int:
return self._raw.get("upload", 0)

@property
def duration(self):
return self._raw.get("duration")
def duration(self) -> int:
return self._raw.get("duration", 0)

@property
def last_seen(self):
return self._raw.get("lastSeen")
def last_seen(self) -> int:
return self._raw.get("lastSeen", 0)

@property
def block(self):
return self._raw.get("block")
def block(self) -> bool:
return self._raw.get("block", False)

@property
def manager(self):
return self._raw.get("manager")
def manager(self) -> bool:
return self._raw.get("manager", False)

def __repr__(self):
name = self.name or self.mac
Expand Down

0 comments on commit ae8f633

Please sign in to comment.