From 6844166c0dd2ed939468020d19ff3a548c502eac Mon Sep 17 00:00:00 2001 From: Teemu R Date: Mon, 20 Jul 2020 16:42:37 +0200 Subject: [PATCH] add a small example script to show library usage (#90) * add a small example script to show library usage * asyncio.run++ --- docs/source/smartdevice.rst | 27 +++++++++++++++++++++++++++ kasa/smartdevice.py | 1 + 2 files changed, 28 insertions(+) diff --git a/docs/source/smartdevice.rst b/docs/source/smartdevice.rst index f2ab6ff3..dd08ac91 100644 --- a/docs/source/smartdevice.rst +++ b/docs/source/smartdevice.rst @@ -12,6 +12,33 @@ These methods will return the device response, which can be useful for some use Errors are raised as :class:`SmartDeviceException` instances for the library user to handle. +Simple example script showing some functionality: + +.. code-block:: python + + import asyncio + from kasa import SmartPlug + + async def main(): + p = SmartPlug("127.0.0.1") + + await p.update() + print(p.alias) + + await p.turn_off() + + + if __name__ == "__main__": + asyncio.run(main()) + + +Refer to device type specific classes for more examples: + +* :class:`SmartPlug` +* :class:`SmartBulb` +* :class:`SmartStrip` +* :class:`SmartDimmer` +* :class:`SmartLightStrip` .. autoclass:: kasa.SmartDevice :members: diff --git a/kasa/smartdevice.py b/kasa/smartdevice.py index c4f71fa6..19589bba 100755 --- a/kasa/smartdevice.py +++ b/kasa/smartdevice.py @@ -128,6 +128,7 @@ class SmartDevice: * :class:`SmartBulb` * :class:`SmartStrip` * :class:`SmartDimmer` + * :class:`SmartLightStrip` To initialize, you have to await :func:`update()` at least once. This will allow accessing the properties using the exposed properties.