Skip to content

Added exception handling the ex.py client as some routers return 406 on the Memory request - #85

Draft
FriedrichM wants to merge 4 commits into
AlexandrErohin:mainfrom
FriedrichM:exception-handling
Draft

FriedrichM wants to merge 4 commits into
AlexandrErohin:mainfrom
FriedrichM:exception-handling

Conversation

@FriedrichM

Copy link
Copy Markdown
Contributor

As described in AlexandrErohin/home-assistant-tplink-router#180 sometimes certain routers return 406 for the memory state request.
This is one way to handle those 406 responses feel free to give me feedback on this draft.
Do you want to handle it in another way ?

@FriedrichM
FriedrichM marked this pull request as draft June 10, 2025 17:47
@FriedrichM

Copy link
Copy Markdown
Contributor Author

ive been able to recreate the 406 error code by running the readme script in quick succession / even in parallel. so it seems to be tied to that maybe something with logins or request ratelimiting

@AlexandrErohin

Copy link
Copy Markdown
Owner

Hi!
Thank you for your PR!
If you would like to add retries - it is better to add it to client directly - like https://github.com/AlexandrErohin/TP-Link-Archer-C6U/blob/main/tplinkrouterc6u/client/mr.py#L543


_, values = self.req_act(acts)

if not values or any(x is None for x in values[:-2]):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great if you could add test for this behavior

free = int(values[4]["free"])
status.mem_usage = ((total - free) / total)
try:
total = int(values[4]['total'])

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great if you could add test for this behavior

status.mem_usage = 0

status.cpu_usage = int(values[5]['CPUUsage']) / 100
try:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great if you could add test for this behavior

attrs=['IPAddress', 'physAddress', 'hostName', 'leaseTimeRemaining']),
]
_, values = self.req_act(acts)
if not values or values[0] is None:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great if you could add test for this behavior

'connIPv4DnsServer']),
]
_, values = self.req_act(acts)
if not values or any(v is None for v in values):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great if you could add test for this behavior

self.ActItem(self.ActItem.GL, 'DEV2_PVPN_CLIENT', attrs=['connAct']),
]
_, values = self.req_act(acts)
if not values or any(v is None for v in values):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great if you could add test for this behavior

_, values = self.req_act(acts)

if not values:
if not values or values[0] is None:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great if you could add test for this behavior

self.ActItem(self.ActItem.GL, 'DEV2_DHCPV4_POOL_STATICADDR', attrs=['enable', 'chaddr', 'yiaddr']),
]
_, values = self.req_act(acts)
if not values or values[0] is None:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great if you could add test for this behavior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants