mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-10-09 00:48:01 +00:00
Make device initialisation easier by reducing required imports (#936)
Adds username and password arguments to discovery to remove the need to import Credentials. Creates TypeAliases in Device for connection configuration classes and DeviceType. Using the API with these changes will only require importing either Discover or Device depending on whether using Discover.discover() or Device.connect() to initialize and interact with the API.
This commit is contained in:
@@ -6,12 +6,14 @@ This page contains guides of how to perform common actions using the library.
|
||||
|
||||
```{eval-rst}
|
||||
.. automodule:: kasa.discover
|
||||
:noindex:
|
||||
```
|
||||
|
||||
## Connect without discovery
|
||||
|
||||
```{eval-rst}
|
||||
.. automodule:: kasa.deviceconfig
|
||||
:noindex:
|
||||
```
|
||||
|
||||
## Get Energy Consumption and Usage Statistics
|
||||
|
@@ -1,10 +1,11 @@
|
||||
# API Reference
|
||||
|
||||
```{currentmodule} kasa
|
||||
```
|
||||
|
||||
## Discover
|
||||
|
||||
|
||||
```{module} kasa.discover
|
||||
```
|
||||
|
||||
```{eval-rst}
|
||||
.. autoclass:: kasa.Discover
|
||||
:members:
|
||||
@@ -12,8 +13,51 @@
|
||||
|
||||
## Device
|
||||
|
||||
```{module} kasa.device
|
||||
```
|
||||
|
||||
```{eval-rst}
|
||||
.. autoclass:: kasa.Device
|
||||
.. autoclass:: Device
|
||||
:members:
|
||||
:undoc-members:
|
||||
```
|
||||
|
||||
|
||||
## Device Config
|
||||
|
||||
```{module} kasa.credentials
|
||||
```
|
||||
|
||||
```{eval-rst}
|
||||
.. autoclass:: Credentials
|
||||
:members:
|
||||
:undoc-members:
|
||||
```
|
||||
|
||||
```{module} kasa.deviceconfig
|
||||
```
|
||||
|
||||
```{eval-rst}
|
||||
.. autoclass:: DeviceConfig
|
||||
:members:
|
||||
:undoc-members:
|
||||
```
|
||||
|
||||
|
||||
```{eval-rst}
|
||||
.. autoclass:: kasa.DeviceFamily
|
||||
:members:
|
||||
:undoc-members:
|
||||
```
|
||||
|
||||
```{eval-rst}
|
||||
.. autoclass:: kasa.DeviceConnection
|
||||
:members:
|
||||
:undoc-members:
|
||||
```
|
||||
|
||||
```{eval-rst}
|
||||
.. autoclass:: kasa.DeviceEncryption
|
||||
:members:
|
||||
:undoc-members:
|
||||
```
|
||||
|
@@ -11,11 +11,11 @@ The main entry point for the API is :meth:`~kasa.Discover.discover` and
|
||||
|
||||
Most newer devices require your TP-Link cloud username and password, but this can be omitted for older devices.
|
||||
|
||||
>>> from kasa import Device, Discover, Credentials
|
||||
>>> from kasa import Discover
|
||||
|
||||
:func:`~kasa.Discover.discover` returns a dict[str,Device] of devices on your network:
|
||||
|
||||
>>> devices = await Discover.discover(credentials=Credentials("user@example.com", "great_password"))
|
||||
>>> devices = await Discover.discover(username="user@example.com", password="great_password")
|
||||
>>> for dev in devices.values():
|
||||
>>> await dev.update()
|
||||
>>> print(dev.host)
|
||||
@@ -27,7 +27,7 @@ Most newer devices require your TP-Link cloud username and password, but this ca
|
||||
|
||||
:meth:`~kasa.Discover.discover_single` returns a single device by hostname:
|
||||
|
||||
>>> dev = await Discover.discover_single("127.0.0.3", credentials=Credentials("user@example.com", "great_password"))
|
||||
>>> dev = await Discover.discover_single("127.0.0.3", username="user@example.com", password="great_password")
|
||||
>>> await dev.update()
|
||||
>>> dev.alias
|
||||
Living Room Bulb
|
||||
|
Reference in New Issue
Block a user