mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-10-09 17:08:02 +00:00
Update docs for newer devices and DeviceConfig (#614)
* Update docs for newer devices and DeviceConfig * Tweak docs post review * Move sentence to newline * Update post review * Update following review
This commit is contained in:
@@ -26,7 +26,7 @@ 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:
|
||||
Simple example script showing some functionality for legacy devices:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -45,6 +45,31 @@ Simple example script showing some functionality:
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
|
||||
If you are connecting to a newer KASA or TAPO device you can get the device via discovery or
|
||||
connect directly with :class:`DeviceConfig`:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import asyncio
|
||||
from kasa import Discover, Credentials
|
||||
|
||||
async def main():
|
||||
device = await Discover.discover_single(
|
||||
"127.0.0.1",
|
||||
credentials=Credentials("myusername", "mypassword"),
|
||||
discovery_timeout=10
|
||||
)
|
||||
|
||||
config = device.config # DeviceConfig.to_dict() can be used to store for later
|
||||
|
||||
# To connect directly later without discovery
|
||||
|
||||
later_device = await SmartDevice.connect(config=config)
|
||||
|
||||
await later_device.update()
|
||||
|
||||
print(later_device.alias) # Print out the alias
|
||||
|
||||
If you want to perform updates in a loop, you need to make sure that the device accesses are done in the same event loop:
|
||||
|
||||
.. code-block:: python
|
||||
@@ -67,6 +92,22 @@ Refer to device type specific classes for more examples:
|
||||
:class:`SmartPlug`, :class:`SmartBulb`, :class:`SmartStrip`,
|
||||
:class:`SmartDimmer`, :class:`SmartLightStrip`.
|
||||
|
||||
DeviceConfig class
|
||||
******************
|
||||
|
||||
The :class:`DeviceConfig` class can be used to initialise devices with parameters to allow them to be connected to without using
|
||||
discovery.
|
||||
This is required for newer KASA and TAPO devices that use different protocols for communication and will not respond
|
||||
on port 9999 but instead use different encryption protocols over http port 80.
|
||||
Currently there are three known types of encryption for TP-Link devices and two different protocols.
|
||||
Devices with automatic firmware updates enabled may update to newer versions of the encryption without separate notice,
|
||||
so discovery can be helpful to determine the correct config.
|
||||
|
||||
To connect directly pass a :class:`DeviceConfig` object to :meth:`SmartDevice.connect()`.
|
||||
|
||||
A :class:`DeviceConfig` can be constucted manually if you know the :attr:`DeviceConfig.connection_type` values for the device or
|
||||
alternatively the config can be retrieved from :attr:`SmartDevice.config` post discovery and then re-used.
|
||||
|
||||
Energy Consumption and Usage Statistics
|
||||
***************************************
|
||||
|
||||
@@ -103,3 +144,25 @@ API documentation
|
||||
.. autoclass:: SmartDevice
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
.. autoclass:: DeviceConfig
|
||||
:members:
|
||||
:inherited-members:
|
||||
:undoc-members:
|
||||
:member-order: bysource
|
||||
|
||||
.. autoclass:: Credentials
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
.. autoclass:: SmartDeviceException
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
.. autoclass:: AuthenticationException
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
.. autoclass:: UnsupportedDeviceException
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
Reference in New Issue
Block a user