Return usage.get_{monthstat,daystat} in expected format (#394)

* Basic fix for issue: https://github.com/python-kasa/python-kasa/issues/373
Change usage module get_daystat and get_monthat to return dictionaries of date index: time values as spec'd instead of raw usage data. Output matches emeter module get_daystat and get_monthstat

* Fixed some formatting and lint warnings to comply with black/flake8
Use the new _convert function in emeter for all conversions rather than the one in smartdevice.py
Removed unused function _emeter_convert_emeter_data from smartdevice.py

* Added a first pass test module for testing the new usage conversion function

* Changes based on PR feedback
Tidied up some doc string comments
Added a check for explicit values from conversion function

* Rebase on top of current master, fix docstrings

---------

Co-authored-by: Teemu Rytilahti <tpr@iki.fi>
This commit is contained in:
Julian Davis
2023-02-18 19:53:02 +00:00
committed by GitHub
parent 12c98eb58d
commit 43ed47eca8
4 changed files with 95 additions and 44 deletions

View File

@@ -490,25 +490,6 @@ class SmartDevice:
self._verify_emeter()
return self.modules["emeter"].emeter_this_month
def _emeter_convert_emeter_data(self, data, kwh=True) -> Dict:
"""Return emeter information keyed with the day/month.."""
response = [EmeterStatus(**x) for x in data]
if not response:
return {}
energy_key = "energy_wh"
if kwh:
energy_key = "energy"
entry_key = "month"
if "day" in response[0]:
entry_key = "day"
data = {entry[entry_key]: entry[energy_key] for entry in response}
return data
async def get_emeter_daily(
self, year: Optional[int] = None, month: Optional[int] = None, kwh: bool = True
) -> Dict: