-
-
Notifications
You must be signed in to change notification settings - Fork 239
Simplify API documentation by using doctests #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify API documentation by using doctests #73
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
| def emeter_today(self) -> Optional[float]: | ||
| """Return today's energy consumption in kWh.""" | ||
| if not self.has_emeter: | ||
| raise SmartDeviceException("Device has no emeter") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
|
|
||
| device_class = Discover._get_device_class(info) | ||
| device = device_class(ip) | ||
| asyncio.ensure_future(device.update()) |
There was a problem hiding this comment.
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.
…is fixes the tests
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..
|
I merged this prior to publishing the docs at readthedocs as that's easier to test when the sphinx docs are already in place. |
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: