Simplify API documentation by using doctests (#73)

* Add doctests to SmartBulb

* Add SmartDevice doctests, cleanup README.md

* add doctests for smartplug and smartstrip

* add discover doctests

* Fix bulb mock

* add smartdimmer doctests

* add sphinx-generated docs, cleanup readme a bit

* remove sphinx-click as it does not work with asyncclick

* in preparation for rtd hooking, move doc deps to be separate from dev deps

* pytestmark needs to be applied separately for each and every file, this fixes the tests

* use pathlib for resolving relative paths

* Skip discovery doctest on python3.7

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..
This commit is contained in:
Teemu R
2020-06-30 02:29:52 +02:00
committed by GitHub
parent 99e0c4a418
commit f9a987ca18
34 changed files with 748 additions and 303 deletions

View File

@@ -10,24 +10,30 @@ _LOGGER = logging.getLogger(__name__)
class SmartPlug(SmartDevice):
"""Representation of a TP-Link Smart Switch.
Usage example:
```python
p = SmartPlug("192.168.1.105")
To initialize, you have to await :func:`update()` at least once.
This will allow accessing the properties using the exposed properties.
# print the devices alias
print(p.alias)
All changes to the device are done using awaitable methods,
which will not change the cached values, but you must await :func:`update()` separately.
# change state of plug
await p.turn_on()
assert p.is_on is True
await p.turn_off()
# print current state of plug
print(p.state_information)
```
Errors reported by the device are raised as SmartDeviceExceptions,
Errors reported by the device are raised as :class:`SmartDeviceException`s,
and should be handled by the user of the library.
Examples:
>>> import asyncio
>>> plug = SmartPlug("127.0.0.1")
>>> asyncio.run(plug.update())
>>> plug.alias
Kitchen
Setting the LED state:
>>> asyncio.run(plug.set_led(True))
>>> asyncio.run(plug.update())
>>> plug.led
True
For more examples, see the :class:`SmartDevice` class.
"""
def __init__(self, host: str) -> None: