Skip to content

Handle responseData as both string and dict - #79

Merged
piekstra merged 1 commit into
mainfrom
piekstra/65-fix-responsedata-type-handling
Feb 7, 2026
Merged

piekstra merged 1 commit into
mainfrom
piekstra/65-fix-responsedata-type-handling

Conversation

@piekstra

@piekstra piekstra commented Jan 30, 2026 •

Copy link
Copy Markdown
Owner

[#65]

Summary

  • Fix TypeError when devices return responseData as a dict instead of a JSON string
  • Add unit tests for pass_through_request covering both cases

Problem

Some devices (e.g., Archer A8 routers) return responseData as an already-parsed dict rather than a JSON string. The code was unconditionally calling json.loads() which fails with:

TypeError: the JSON object must be str, bytes or bytearray, not dict

Solution

Check the type of responseData before attempting to parse it:

  • If it's a string, parse it with json.loads()
  • If it's already a dict, return it directly

Test plan

  • Added unit tests covering both string and dict responseData cases
  • Added test for failed requests returning None
  • All new tests pass locally

Note

This may not fully resolve Archer router support since the device commands may differ from smart plugs. However, this fix removes the immediate crash and allows further investigation.

CI Note

This PR should be rebased after #80 is merged to get CI passing.

Some devices (e.g., Archer routers) return responseData as an already-
parsed dict instead of a JSON string. This change handles both cases
by checking the type before attempting JSON parsing.

Fixes #65
@piekstra
piekstra force-pushed the piekstra/65-fix-responsedata-type-handling branch from 8bf9dba to 6e9c787 Compare February 7, 2026 04:06
@piekstra
piekstra merged commit 387add1 into main Feb 7, 2026
3 checks passed
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.

1 participant