almottier / TapoP100

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

Add support for `get_energy_data` #23

Closed maresmar closed 4 months ago

maresmar commented 4 months ago

This pull request adds support for get_energy_data calls. It allow you to query for a historical data about power consumption. You could specify time window and interval. I tested my PR on Tapo P110 with firmware 1.3.0:

>>> from PyP100 import PyP110
>>> dev = PyP110.P110("10.0.0.1", "abc", "cdf")
>>> dev.getEnergyData(1706825847, 1708643847, MeasureInterval.DAYS) # Show power consumption per day sice 1st Feb 24
{'local_time': '2024-02-23 00:18:54', 'data': [806, 820, 925, 892, 852, 854, 839, 836, 842, 831, 841, 821, 809, 822, 800, 805, 793, 794, 0, 0, 0, 344, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'start_timestamp': 1706825847, 'end_timestamp': 1708643847, 'interval': 1440}

This PR was based on code and comments from https://github.com/fishbigger/TapoP100/pull/87, it will probably resolve #17

almottier commented 4 months ago

Hello, thanks a lot for your contribution! I am not able to test it because I only have P100 here. Could you add it to the documentation in the README.md under Energy Monitoring - P110?

maresmar commented 4 months ago

Hi, I added a few lines to the README.md. I haven't been able to experiment with the current implementation in a long term yet, so I summed up an observation from others.