mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-01-09 06:17:08 +00:00
be5202ccb7
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.
45 lines
1.3 KiB
Markdown
45 lines
1.3 KiB
Markdown
# How-to Guides
|
|
|
|
This page contains guides of how to perform common actions using the library.
|
|
|
|
## Discover devices
|
|
|
|
```{eval-rst}
|
|
.. automodule:: kasa.discover
|
|
:noindex:
|
|
```
|
|
|
|
## Connect without discovery
|
|
|
|
```{eval-rst}
|
|
.. automodule:: kasa.deviceconfig
|
|
:noindex:
|
|
```
|
|
|
|
## Get Energy Consumption and Usage Statistics
|
|
|
|
:::{note}
|
|
In order to use the helper methods to calculate the statistics correctly, your devices need to have correct time set.
|
|
The devices use NTP and public servers from [NTP Pool Project](https://www.ntppool.org/) to synchronize their time.
|
|
:::
|
|
|
|
### Energy Consumption
|
|
|
|
The availability of energy consumption sensors depend on the device.
|
|
While most of the bulbs support it, only specific switches (e.g., HS110) or strips (e.g., HS300) support it.
|
|
You can use {attr}`~Device.has_emeter` to check for the availability.
|
|
|
|
|
|
### Usage statistics
|
|
|
|
You can use {attr}`~Device.on_since` to query for the time the device has been turned on.
|
|
Some devices also support reporting the usage statistics on daily or monthly basis.
|
|
You can access this information using through the usage module ({class}`kasa.modules.Usage`):
|
|
|
|
```py
|
|
dev = SmartPlug("127.0.0.1")
|
|
usage = dev.modules["usage"]
|
|
print(f"Minutes on this month: {usage.usage_this_month}")
|
|
print(f"Minutes on today: {usage.usage_today}")
|
|
```
|