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
355 stars 36 forks source link

Monthly data reading crashes when device somehow has negative values #243

Open hattabatatta opened 2 months ago

hattabatatta commented 2 months ago

Hey there!

The python library crashes, when there are somehow negative values in monthly data. Don't ask me why, but one of my P110 does have negative values in its monthly data records (-51kwH) which lead into a crash when try to read the data through the python library:

Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 190, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "xxxxx/main.py", line 50, in main energy_data_monthly = await device.get_energy_data( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Exception: Serde(Error("invalid value: integer -50784, expected u64", line: 1, column: 70))

mihai-dinculescu commented 2 months ago

That is very interesting indeed. Do you know why that number might be negative in your particular case?

hattabatatta commented 2 months ago

Tbh: No ... I have absolutely no clue, why this device responds with a negative number. But as I found out ... there are more than 1 P110 plugs, which have negative results in their stored monthly energy data. All I can assume that this behavior is based on a bug by TP-Link and we with the python library only can do a workaround by not using unsigned int64

mihai-dinculescu commented 2 weeks ago

Sorry for the long delay in response. How's the Tapo App displaying that negative value?