Skip to content

Conversation

@rytilahti
Copy link
Member

@rytilahti rytilahti commented Jun 14, 2020

The README.md has grown over time very heavy, so it's time to move (at least most) of API instructions out from it to the code base. Besides making the readme more approachable (tangentially related to #60), this allows us to introduce doctests (using xdoctest) to verify that the code examples are really runnable and working.

The generated api docs could be uploaded to readthedocs after the rest of the devices are also converted and the README.md is cleaned.

TODO:

  • Doctestify SmartDevice
  • Doctestify SmartPlug
  • Doctestify SmartStrip
  • Doctestify Discover
  • Doctestify SmartBulb
  • Doctestify SmartDimmer
  • Cleanup README.md
  • Add sphinx doc generation
  • Create hooks to upload updated API docs to readthedocs

@codecov-commenter
Copy link

codecov-commenter commented Jun 14, 2020

Codecov Report

Merging #73 into master will increase coverage by 10.96%.
The diff coverage is 68.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master      #73       +/-   ##
===========================================
+ Coverage   61.33%   72.30%   +10.96%     
===========================================
  Files           9        9               
  Lines        1169     1177        +8     
  Branches      177      180        +3     
===========================================
+ Hits          717      851      +134     
+ Misses        413      292      -121     
+ Partials       39       34        -5     
Impacted Files Coverage Δ
kasa/discover.py 40.36% <0.00%> (-1.15%) ⬇️
kasa/smartdimmer.py 93.10% <ø> (+36.20%) ⬆️
kasa/smartplug.py 100.00% <ø> (+3.33%) ⬆️
kasa/smartdevice.py 82.53% <42.85%> (+18.50%) ⬆️
kasa/smartbulb.py 96.92% <100.00%> (+22.70%) ⬆️
kasa/smartstrip.py 78.19% <100.00%> (+0.75%) ⬆️
kasa/cli.py 53.45% <0.00%> (+0.62%) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 99e0c4a...46140db. Read the comment docs.

def emeter_today(self) -> Optional[float]:
"""Return today's energy consumption in kWh."""
if not self.has_emeter:
raise SmartDeviceException("Device has no emeter")
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this WIP, but shouldn't this be in a separate PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's such a minor change (just to avoid crashing if someone tries to access those), that it doesn't really matter.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, so this is related, and not a separate bugfix. Makes sense then!

Copy link
Member Author

Choose a reason for hiding this comment

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

So, there are a few minor things I noticed thanks to having those doctests (like this one, and the invalid return value for SmartStripPlug's is_on), that I think were worth fixing here rather than separately.

@rytilahti rytilahti added this to the Initial release milestone Jun 20, 2020

device_class = Discover._get_device_class(info)
device = device_class(ip)
asyncio.ensure_future(device.update())
Copy link
Member Author

Choose a reason for hiding this comment

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

This changes behavior, so that there is no need to separately call update on the discovered devices, which is reasonable, I think.

The code is just fine, but some reason the mocking behaves differently between 3.7 and 3.8.
The latter seems to accept a discrete object for asyncio.run where the former expects a coroutine..
@rytilahti rytilahti merged commit f9a987c into python-kasa:master Jun 30, 2020
@rytilahti rytilahti deleted the refactor/improve_docs branch June 30, 2020 00:29
@rytilahti
Copy link
Member Author

I merged this prior to publishing the docs at readthedocs as that's easier to test when the sphinx docs are already in place.

This was referenced Jul 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants