Skip to content

Conversation

@jules43
Copy link
Contributor

@jules43 jules43 commented Nov 11, 2022

This is an initial fix for the issue discussed here:

Fixes #373

This code largely duplicates the solution used for the Emeter module.

I have work in progress on a pydantic based version for which I will create a second PR.

@codecov-commenter
Copy link

codecov-commenter commented Nov 15, 2022

Codecov Report

Base: 78.95% // Head: 79.28% // Increases project coverage by +0.32% 🎉

Coverage data is based on head (85f16c6) compared to base (12c98eb).
Patch coverage: 83.78% of modified lines in pull request are covered.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #394      +/-   ##
==========================================
+ Coverage   78.95%   79.28%   +0.32%     
==========================================
  Files          25       25              
  Lines        1863     1868       +5     
  Branches      269      266       -3     
==========================================
+ Hits         1471     1481      +10     
+ Misses        358      353       -5     
  Partials       34       34              
Impacted Files Coverage Δ
kasa/smartdevice.py 86.93% <ø> (+2.76%) ⬆️
kasa/modules/usage.py 69.64% <62.50%> (-4.17%) ⬇️
kasa/modules/emeter.py 97.77% <100.00%> (+0.15%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great, thanks! 💯 I added a couple of comments for your consideration prior merging this.

@rytilahti rytilahti changed the title Initial fix for usage get_daystat and get_monthstat not returning data in correct format Fix usage module's get_{monthstat,daystat} not returning data in correct format Nov 15, 2022
@rytilahti rytilahti added the bug Something isn't working label Nov 15, 2022
@jules43
Copy link
Contributor Author

jules43 commented Nov 17, 2022

Hopefully I've made changes based on all the feedback. The only thing I haven't done is added additional tests to test_usage.py. This is definitely a good idea but, as I understand it, would require extending newfakes which I think is probably outside this PR. I also feel I'll need to understand newfakes a bit better before having a go, so any hints would be great.

@rytilahti
Copy link
Member

I think it's not worth trying to force the tests inside the existing ones, but rather add module level tests separately, especially as the fixture files do not contain the necessary information. This reminded me about that I was exploring this idea earlier, see #404 if you wish.

Anyway, it is good as it is also without that. I'll do a review later tonight/tomorrow.

Copy link
Member

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me after fixing some minor changes to the docs 👍

jules43 and others added 5 commits February 18, 2023 20:14
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
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
Tidied up some doc string comments
Added a check for explicit values from conversion function
@rytilahti
Copy link
Member

rytilahti commented Feb 18, 2023

Uhh, I should've used merge instead of rebase to save the review comments, oh well... I rebased this on top of the current master and changed the docstrings a bit, I think this is good to go for the next release. Thanks again @jules43! 🥇

@rytilahti rytilahti added this to the 0.5.1 milestone Feb 18, 2023
@rytilahti rytilahti changed the title Fix usage module's get_{monthstat,daystat} not returning data in correct format Return usage.get_{monthstat,daystat} in expected format Feb 18, 2023
@rytilahti rytilahti merged commit 43ed47e into python-kasa:master Feb 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cli.py usage year and month options do not output data as expected

3 participants