mihai-dinculescu / tapo

Unofficial Tapo API Client. Works with TP-Link Tapo smart devices. Tested with light bulbs (L510, L520, L530, L610, L630), light strips (L900, L920, L930), plugs (P100, P105, P110, P115, P300), hubs (H100), switches (S200B) and sensors (KE100, T100, T110, T300, T310, T315).
MIT License
351 stars 36 forks source link

tapo-py :- 0.3.1 getting error while calling get_device_info #248

Closed amiyamandal-dev closed 2 weeks ago

amiyamandal-dev commented 1 month ago

Error while fetching info from get_device_info() for P110

Description

When trying to fetch device information using get_device_info() for a P110 device, the following error occurs:

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
Cell In[18], line 1
----> 1 device_info = await device.get_device_info()
Exception: Serde(Error("missing field `overheated`", line: 1, column: 832))

Environment

Steps to Reproduce

  1. Create a device object for P110
  2. Call await device.get_device_info()

Expected Behavior

The function should return the device information without any errors.

image

mihai-dinculescu commented 1 month ago

Can you please post the output of get_device_info_json()?

btab commented 1 month ago

Here's a (redacted) dump from my p110. Looks like they helpfully renamed overheated to overheat_status. So I'd suggest changing the field name and adding a serde alias for the old name (for people on old firmware). Additionally, I'm guessing it's part of the change that introduced overcurrent_status and power_protection_status.

{"auto_off_remain_time":0,"auto_off_status":"off","avatar":"house","charging_status":"normal","default_states":{"state":{"on":false},"type":"custom"},"device_id":"REDACTED","device_on":true,"fw_id":"00000000000000000000000000000000","fw_ver":"1.3.1 Build 240621 Rel.162048","has_set_location_info":true,"hw_id":"REDACTED","hw_ver":"1.0","ip":"REDACTED","lang":"en_US","latitude":0,"longitude":-0"mac":"REDACTED","model":"P110","nickname":"REDACTED","oem_id":"REDACTED","on_time":0,"overcurrent_status":"normal","overheat_status":"normal","power_protection_status":"normal","region":"REDACTED","rssi":0,"signal_level":2,"specs":"","ssid":"REDACTED","time_diff":0,"type":"SMART.TAPOPLUG"}
Dav-v commented 1 month ago

Hi all, same issue on my Tapo P115, firmware version 1.3.1 Build 240621 Rel.162048 . I confirm that there is not overheated field anymore but only 'overheat_status': 'normal'

Toommi commented 4 weeks ago

I have the same issue with P110 -- is there a work around or do we need to wait for a new version?

sledgemhammer commented 3 weeks ago

same here Traceback (most recent call last): File "C:\Program Files (x86)\Domoticz\tapo_p110.py", line 74, in <module> asyncio.run(main()) File "C:\Program Files (x86)\Python310-32\lib\asyncio\runners.py", line 44, in run return loop.run_until_complete(main) File "C:\Program Files (x86)\Python310-32\lib\asyncio\base_events.py", line 646, in run_until_complete return future.result() File "C:\Program Files (x86)\Domoticz\tapo_p110.py", line 40, in main device_info = await device.get_device_info() Exception: Serde(Error("missing fieldoverheated", line: 1, column: 832))

found its defined in (https://github.com/mihai-dinculescu/tapo/tree/main/tapo-py/tapo-py/tapo/responses/device_info_result) /plug_result.pyi

but i have no clue how to change localy this file

Edit 1: did a pip --force-reinstall --no-cache but that did not help dfoh the errors changed a bit Turning device on... Waiting 2 seconds... Turning device off... Traceback (most recent call last): File "tapo_p110.py", line 62, in asyncio.run(main()) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1520.0_x64qbz5n2kfra8p0\Lib\asyncio\runners.py", line 194, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1520.0_x64qbz5n2kfra8p0\Lib\asyncio\runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1520.0_x64__qbz5n2kfra8p0\Lib\asyncio\base_events.py", line 687, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "tapo_p110.py", line 28, in main device_info = await device.get_device_info() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Exception: Serde(Error("missing field overheated", line: 1, column: 830))

I left a couple of remarks to make your life easier and to kindly help identify ( i am still learning how to use python and github)

Edit 2: I also found a fork thats 2 commits ahead and should solve it just dont know how to proceed https://github.com/Toommi/tapo suppose we have to wait for mihai to commit ?

Edit 3: If i skip calling the [get_device_info call and focus on the usage parameters it runs, But there seem to be more changes as i see the code to be very slow sometimes.

Looks like some trottle/loadbalancing is in place on the server side, making multiple data requests in the same call to "hang" at some point ( tried once a minute on one of my p115 devices, and once per 5 min, with same result) If i only request current usage it runs mostly, if i include monthly or daily usage it hangs allmost every time.

I take as starting point the example files, and will try if i can use the codesequence to create a timelimiting mechanisme localy. If i have something nice i will edit again. ( still in the learning curve for python)

smiklosovic commented 3 weeks ago

same here!

padenot commented 2 weeks ago

Fixed in https://github.com/mihai-dinculescu/tapo/pull/254, verified to work on my P110 and P115.

mihai-dinculescu commented 2 weeks ago

I was able to find out the following by decompiling a recent Tapo Android app

Possible values for the overheat_status are

This change seems to affect only plugs (and possibly power strips, but I couldn't test it as I don't have one).

Therefore, I believe that only the plugs should be updated for now to support the new enum.

sledgemhammer commented 2 weeks ago

@mihai-dinculescu Can i buy you one to support your future development ?

mihai-dinculescu commented 2 weeks ago

@sledgemhammer Sponsorship is enabled for the project. Every little bit helps, thank you!

The fix has been released in Tapo Rust v.0.7.13 and Tapo Python v0.3.2. The overheated field for plugs has been replaced by three enums: overcurrent_status, overheat_status, and power_protection_status, thanks to the help from @padenot.

Please let me know how this works for you.