fishbigger / TapoP100

A module for controlling the TP-Link Tapo P100 Plugs
MIT License
567 stars 139 forks source link

ToFix: payload assumption #50

Closed dmzoneill closed 1 year ago

dmzoneill commented 2 years ago

I'll probably create a PR for this shortly. I get this randomly off a plug

Not sure if this was a design decision, to put the decrypt outside the try statement?

https://github.com/fishbigger/TapoP100/blob/2d3478927928a3c2bec31e730fea150c0d52245b/PyP100/PyP100.py#L156

INFO:root:Traceback (most recent call last):
  File "./plugcontroller.py", line 51, in plug_turn_off
    p100.login()
  File "/usr/local/lib/python3.7/dist-packages/PyP100/PyP100.py", line 156, in login
    decryptedResponse = self.tpLinkCipher.decrypt(r.json()["result"]["response"])
KeyError: 'result'
fishbigger commented 2 years ago

Hi, No it wasn't a design decision I just assumed that a response json with ["result"]["response"] would come and all other errors would be caught by unpacking the body. I don't see any problem with moving it inside the try statement but some more sophisticated error handling might be needed in case there isn't an error code available either.

Thanks for mentioning this! I look forward to the pull request.