Skip to content

Commit

Permalink
Merge pull request #1 from DurgNomis-drol/patch-1
Browse files Browse the repository at this point in the history
Add uptime, mem usage and cpu usage
  • Loading branch information
AlexandrErohin authored Nov 18, 2023
2 parents 7a8adaf + 92d52b2 commit 239ae24
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ asyncio.run(tasks())
| guest_5g_enable | Is guest wifi 5G enabled | bool |
| wifi_2g_enable | Is main wifi 2.4G enabled | bool |
| wifi_5g_enable | Is main wifi 5G enabled | bool |
| wan_ipv4_uptime | Internet Uptime | int |
| mem_usage | Memory usage | float |
| cpu_usage | CPU usage | float |
| devices | List of all wifi clients | list[[Device](#device)] |

### <a id="device">Device</a>
Expand Down
7 changes: 7 additions & 0 deletions tplinkrouterc6u/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,17 @@ async def _get_firmware(self) -> Firmware:
return firmware

async def _get_status(self) -> Status:

def _calc_cpu_usage(data: dict) -> float:
return (data['cpu_usage'] + data['cpu1_usage'] + data['cpu2_usage'] + data['cpu3_usage']) / 4

data = await self._get_data('admin/status?form=all')
status = Status
status.devices = []
status.macaddr = data['lan_macaddr']
status.wan_ipv4_uptime = data.get('wan_ipv4_uptime')
status.mem_usage = data['mem_usage']
status.cpu_usage = _calc_cpu_usage(data)
status.wired_total = len(data['access_devices_wired']) if data.__contains__('access_devices_wired') else 0
status.wifi_clients_total = len(data['access_devices_wireless_host']) if (
data.__contains__('access_devices_wireless_host')) else 0
Expand Down
3 changes: 3 additions & 0 deletions tplinkrouterc6u/dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ class Status:
guest_5g_enable: bool
wifi_2g_enable: bool
wifi_5g_enable: bool
wan_ipv4_uptime: int
mem_usage: float
cpu_usage: float
devices: list[Device]

0 comments on commit 239ae24

Please sign in to comment.