6adb2b5c28
## [0.8.0](https://github.com/python-kasa/python-kasa/tree/0.8.0) (2024-11-26) [Full Changelog](https://github.com/python-kasa/python-kasa/compare/0.7.7...0.8.0) **Release highlights:** - **Initial support for devices using the Tapo camera protocol, i.e. Tapo cameras and the Tapo H200 hub.** - New camera functionality such as exposing RTSP streaming urls and camera pan/tilt. - New way of testing module support for individual features with `has_feature` and `get_feature`. - Adding voltage and current monitoring to `smart` devices. - Migration from pydantic to mashumaro for serialization. Special thanks to @ryenitcher and @Puxtril for their new contributions to the improvement of the project! Also thanks to everyone who has helped with testing, contributing fixtures, and reporting issues! **Breaking change notes:** - Removed support for python <3.11. If you haven't got a compatible version try [uv](https://docs.astral.sh/uv/). - Renamed `device_config.to_dict()` to `device_config.to_dict_control_credentials()`. `to_dict()` is still available but takes no parameters. - From the `iot.Cloud` module the `iot.CloudInfo` class attributes have been converted to snake case. **Breaking changes:** - Migrate iot cloud module to mashumaro [\#1282](https://github.com/python-kasa/python-kasa/pull/1282) (@sdb9696) - Replace custom deviceconfig serialization with mashumaru [\#1274](https://github.com/python-kasa/python-kasa/pull/1274) (@sdb9696) - Remove support for python \<3.11 [\#1273](https://github.com/python-kasa/python-kasa/pull/1273) (@sdb9696) **Implemented enhancements:** - Update cli modify presets to support smart devices [\#1295](https://github.com/python-kasa/python-kasa/pull/1295) (@sdb9696) - Use credentials\_hash for smartcamera rtsp url [\#1293](https://github.com/python-kasa/python-kasa/pull/1293) (@sdb9696) - Add voltage and current monitoring to smart Devices [\#1281](https://github.com/python-kasa/python-kasa/pull/1281) (@ryenitcher) - Update cli feature command for actions not to require a value [\#1264](https://github.com/python-kasa/python-kasa/pull/1264) (@sdb9696) - Add pan tilt camera module [\#1261](https://github.com/python-kasa/python-kasa/pull/1261) (@sdb9696) - Add alarm module for smartcamera hubs [\#1258](https://github.com/python-kasa/python-kasa/pull/1258) (@sdb9696) - Move TAPO smartcamera out of experimental package [\#1255](https://github.com/python-kasa/python-kasa/pull/1255) (@sdb9696) - Add SmartCamera Led Module [\#1249](https://github.com/python-kasa/python-kasa/pull/1249) (@sdb9696) - Use component queries to select smartcamera modules [\#1248](https://github.com/python-kasa/python-kasa/pull/1248) (@sdb9696) - Print formatting for IotLightPreset [\#1216](https://github.com/python-kasa/python-kasa/pull/1216) (@Puxtril) - Allow getting Annotated features from modules [\#1018](https://github.com/python-kasa/python-kasa/pull/1018) (@sdb9696) - Add common Thermostat module [\#977](https://github.com/python-kasa/python-kasa/pull/977) (@sdb9696) **Fixed bugs:** - TP-Link Tapo S505D cannot disable gradual on/off [\#1309](https://github.com/python-kasa/python-kasa/issues/1309) - Inconsistent emeter information between features and emeter cli [\#1308](https://github.com/python-kasa/python-kasa/issues/1308) - How to dump power usage after latest updates? [\#1306](https://github.com/python-kasa/python-kasa/issues/1306) - kasa.discover: Got unsupported connection type: 'device\_family': 'SMART.IPCAMERA' [\#1267](https://github.com/python-kasa/python-kasa/issues/1267) - device \_\_repr\_\_ fails if no sys\_info [\#1262](https://github.com/python-kasa/python-kasa/issues/1262) - Tapo P110M: Error processing Energy for device, module will be unavailable: get\_energy\_usage for Energy [\#1243](https://github.com/python-kasa/python-kasa/issues/1243) - Listing light presets throws error [\#1201](https://github.com/python-kasa/python-kasa/issues/1201) - Include duration when disabling smooth transition on/off [\#1313](https://github.com/python-kasa/python-kasa/pull/1313) (@rytilahti) - Expose energy command to cli [\#1307](https://github.com/python-kasa/python-kasa/pull/1307) (@rytilahti) - Make discovery on unsupported devices less noisy [\#1291](https://github.com/python-kasa/python-kasa/pull/1291) (@rytilahti) - Fix repr for device created with no sysinfo or discovery info" [\#1266](https://github.com/python-kasa/python-kasa/pull/1266) (@sdb9696) - Fix discovery by alias for smart devices [\#1260](https://github.com/python-kasa/python-kasa/pull/1260) (@sdb9696) - Make \_\_repr\_\_ work on discovery info [\#1233](https://github.com/python-kasa/python-kasa/pull/1233) (@rytilahti) **Added support for devices:** - Add HS200 \(US\) Smart Fixture [\#1303](https://github.com/python-kasa/python-kasa/pull/1303) (@ZeliardM) - Add smartcamera devices to supported docs [\#1257](https://github.com/python-kasa/python-kasa/pull/1257) (@sdb9696) - Add P110M\(AU\) fixture [\#1244](https://github.com/python-kasa/python-kasa/pull/1244) (@rytilahti) - Add L630 fixture [\#1240](https://github.com/python-kasa/python-kasa/pull/1240) (@rytilahti) - Add EP40M Fixture [\#1238](https://github.com/python-kasa/python-kasa/pull/1238) (@ryenitcher) - Add KS220 Fixture [\#1237](https://github.com/python-kasa/python-kasa/pull/1237) (@ryenitcher) **Documentation updates:** - Use markdown footnotes in supported.md [\#1310](https://github.com/python-kasa/python-kasa/pull/1310) (@sdb9696) - Update docs for the new module attributes has/get feature [\#1301](https://github.com/python-kasa/python-kasa/pull/1301) (@sdb9696) - Fixup contributing.md for running test against a real device [\#1236](https://github.com/python-kasa/python-kasa/pull/1236) (@sdb9696) **Project maintenance:** - Rename tests/smartcamera to tests/smartcam [\#1315](https://github.com/python-kasa/python-kasa/pull/1315) (@sdb9696) - Do not error on smartcam hub attached smartcam child devices [\#1314](https://github.com/python-kasa/python-kasa/pull/1314) (@sdb9696) - Add P110M\(EU\) fixture [\#1305](https://github.com/python-kasa/python-kasa/pull/1305) (@sdb9696) - Run tests with caplog in a single worker [\#1304](https://github.com/python-kasa/python-kasa/pull/1304) (@sdb9696) - Rename smartcamera to smartcam [\#1300](https://github.com/python-kasa/python-kasa/pull/1300) (@sdb9696) - Move iot fixtures into iot subfolder [\#1299](https://github.com/python-kasa/python-kasa/pull/1299) (@sdb9696) - Annotate fan\_speed\_level of Fan interface [\#1298](https://github.com/python-kasa/python-kasa/pull/1298) (@sdb9696) - Add PIR ADC Values to Test Fixtures [\#1296](https://github.com/python-kasa/python-kasa/pull/1296) (@ryenitcher) - Exclude \_\_getattr\_\_ for deprecated attributes from type checkers [\#1294](https://github.com/python-kasa/python-kasa/pull/1294) (@sdb9696) - Simplify omit http\_client in DeviceConfig serialization [\#1292](https://github.com/python-kasa/python-kasa/pull/1292) (@sdb9696) - Add SMART Voltage Monitoring to Fixtures [\#1290](https://github.com/python-kasa/python-kasa/pull/1290) (@ryenitcher) - Remove pydantic dependency [\#1289](https://github.com/python-kasa/python-kasa/pull/1289) (@sdb9696) - Do not print out all the fixture names at the start of test runs [\#1287](https://github.com/python-kasa/python-kasa/pull/1287) (@sdb9696) - dump\_devinfo: iot light strip commands [\#1286](https://github.com/python-kasa/python-kasa/pull/1286) (@sdb9696) - Migrate TurnOnBehaviours to mashumaro [\#1285](https://github.com/python-kasa/python-kasa/pull/1285) (@sdb9696) - dump\_devinfo: query smartlife.iot.common.cloud for fw updates [\#1284](https://github.com/python-kasa/python-kasa/pull/1284) (@rytilahti) - Migrate RuleModule to mashumaro [\#1283](https://github.com/python-kasa/python-kasa/pull/1283) (@sdb9696) - Update sphinx dependency to 6.2 to fix docs build [\#1280](https://github.com/python-kasa/python-kasa/pull/1280) (@sdb9696) - Update DiscoveryResult to use mashu Annotated Alias [\#1279](https://github.com/python-kasa/python-kasa/pull/1279) (@sdb9696) - Extend dump\_devinfo iot queries [\#1278](https://github.com/python-kasa/python-kasa/pull/1278) (@sdb9696) - Migrate triggerlogs to mashumaru [\#1277](https://github.com/python-kasa/python-kasa/pull/1277) (@sdb9696) - Migrate smart firmware module to mashumaro [\#1276](https://github.com/python-kasa/python-kasa/pull/1276) (@sdb9696) - Migrate IotLightPreset to mashumaru [\#1275](https://github.com/python-kasa/python-kasa/pull/1275) (@sdb9696) - Allow callable coroutines for feature setters [\#1272](https://github.com/python-kasa/python-kasa/pull/1272) (@sdb9696) - Fix deprecated SSLContext\(\) usage [\#1271](https://github.com/python-kasa/python-kasa/pull/1271) (@sdb9696) - Use \_get\_device\_info methods for smart and iot devs in devtools [\#1265](https://github.com/python-kasa/python-kasa/pull/1265) (@sdb9696) - Remove experimental support [\#1256](https://github.com/python-kasa/python-kasa/pull/1256) (@sdb9696) - Move protocol modules into protocols package [\#1254](https://github.com/python-kasa/python-kasa/pull/1254) (@sdb9696) - Add linkcheck to readthedocs CI [\#1253](https://github.com/python-kasa/python-kasa/pull/1253) (@rytilahti) - Update cli energy command to use energy module [\#1252](https://github.com/python-kasa/python-kasa/pull/1252) (@sdb9696) - Consolidate warnings for fixtures missing child devices [\#1251](https://github.com/python-kasa/python-kasa/pull/1251) (@sdb9696) - Update smartcamera fixtures with components [\#1250](https://github.com/python-kasa/python-kasa/pull/1250) (@sdb9696) - Move transports into their own package [\#1247](https://github.com/python-kasa/python-kasa/pull/1247) (@rytilahti) - Fix warnings in our test suite [\#1246](https://github.com/python-kasa/python-kasa/pull/1246) (@rytilahti) - Move tests folder to top level of project [\#1242](https://github.com/python-kasa/python-kasa/pull/1242) (@sdb9696) - Fix test framework running against real devices [\#1235](https://github.com/python-kasa/python-kasa/pull/1235) (@sdb9696) - Add Additional Firmware Test Fixures [\#1234](https://github.com/python-kasa/python-kasa/pull/1234) (@ryenitcher) - Update DiscoveryResult to use Mashumaro instead of pydantic [\#1231](https://github.com/python-kasa/python-kasa/pull/1231) (@sdb9696) - Update fixture for ES20M 1.0.11 [\#1215](https://github.com/python-kasa/python-kasa/pull/1215) (@rytilahti) - Enable ruff check for ANN [\#1139](https://github.com/python-kasa/python-kasa/pull/1139) (@rytilahti) **Closed issues:** - Expose Fan speed range from the library [\#1008](https://github.com/python-kasa/python-kasa/issues/1008) - \[META\] 0.7 series - module support for SMART devices, support for introspectable device features and refactoring the library [\#783](https://github.com/python-kasa/python-kasa/issues/783) |
||
---|---|---|
.github | ||
devtools | ||
docs | ||
kasa | ||
tests | ||
.gitattributes | ||
.github_changelog_generator | ||
.gitignore | ||
.pre-commit-config.yaml | ||
.readthedocs.yml | ||
CHANGELOG.md | ||
CONTRIBUTING.md | ||
HISTORY.md | ||
LICENSE | ||
pyproject.toml | ||
README.md | ||
RELEASING.md | ||
SUPPORTED.md | ||
uv.lock |
python-kasa
python-kasa is a Python library to control TPLink's smart home devices (plugs, wall switches, power strips, and bulbs).
This is a voluntary, community-driven effort and is not affiliated, sponsored, or endorsed by TPLink.
Contributions in any form (adding missing features, reporting issues, fixing or triaging existing ones, improving the documentation, or device donations) are more than welcome!
Getting started
You can install the most recent release using pip:
pip install python-kasa
Alternatively, you can clone this repository and use uv
to install the development version:
git clone https://github.com/python-kasa/python-kasa.git
cd python-kasa/
uv sync --all-extras
uv run kasa
If you have not yet provisioned your device, you can do so using the cli tool.
Discovering devices
Running kasa discover
will send discovery packets to the default broadcast address (255.255.255.255
) to discover supported devices.
If your device requires authentication to control it,
you need to pass the credentials using --username
and --password
options or define KASA_USERNAME
and KASA_PASSWORD
environment variables.
Note
If your system has multiple network interfaces, you can specify the broadcast address using the
--target
option.
The discover
command will automatically execute the state
command on all the discovered devices:
$ kasa discover
Discovering devices on 255.255.255.255 for 3 seconds
== Bulb McBulby - L530 ==
Host: 192.0.2.123
Port: 80
Device state: False
Time: 2024-06-22 15:42:15+02:00 (tz: {'timezone': 'CEST'}
Hardware: 3.0
Software: 1.1.6 Build 240130 Rel.173828
MAC (rssi): 5C:E9:31:aa:bb:cc (-50)
== Primary features ==
State (state): False
Brightness (brightness): 11 (range: 0-100)
Color temperature (color_temperature): 0 (range: 2500-6500)
Light effect (light_effect): *Off* Party Relax
== Information ==
Signal Level (signal_level): 2
Overheated (overheated): False
Cloud connection (cloud_connection): False
Update available (update_available): None
Device time (device_time): 2024-06-22 15:42:15+02:00
== Configuration ==
HSV (hsv): HSV(hue=35, saturation=70, value=11)
Auto update enabled (auto_update_enabled): False
Light preset (light_preset): *Not set* Light preset 1 Light preset 2 Light preset 3 Light preset 4 Light preset 5 Light preset 6 Light preset 7
Smooth transition on (smooth_transition_on): 2 (range: 0-60)
Smooth transition off (smooth_transition_off): 20 (range: 0-60)
== Debug ==
Device ID (device_id): soneuniqueidentifier
RSSI (rssi): -50 dBm
SSID (ssid): HomeNet
Current firmware version (current_firmware_version): 1.1.6 Build 240130 Rel.173828
Available firmware version (available_firmware_version): None
Command line usage
All devices support a variety of common commands (like on
, off
, and state
).
The syntax to control device is kasa --host <host> <command>
:
$ kasa --host 192.0.2.123 on
Use kasa --help
(or consult the documentation) to get a list of all available commands and options.
Some examples of available options include JSON output (--json
), more verbose output (--verbose
), and defining timeouts (--timeout
and --discovery-timeout
).
Refer the documentation for more details.
Note
Each individual command may also have additional options, which are shown when called with the
--help
option.
Feature interface
All devices are also controllable through a generic feature-based interface.
The available features differ from device to device and are accessible using kasa feature
command:
$ kasa --host 192.0.2.123 feature
== Primary features ==
State (state): False
Brightness (brightness): 11 (range: 0-100)
Color temperature (color_temperature): 0 (range: 2500-6500)
Light effect (light_effect): *Off* Party Relax
== Information ==
Signal Level (signal_level): 2
Overheated (overheated): False
Cloud connection (cloud_connection): False
Update available (update_available): None
Device time (device_time): 2024-06-22 15:39:44+02:00
== Configuration ==
HSV (hsv): HSV(hue=35, saturation=70, value=11)
Auto update enabled (auto_update_enabled): False
Light preset (light_preset): *Not set* Light preset 1 Light preset 2 Light preset 3 Light preset 4 Light preset 5 Light preset 6 Light preset 7
Smooth transition on (smooth_transition_on): 2 (range: 0-60)
Smooth transition off (smooth_transition_off): 20 (range: 0-60)
== Debug ==
Device ID (device_id): soneuniqueidentifier
RSSI (rssi): -50 dBm
SSID (ssid): HomeNet
Current firmware version (current_firmware_version): 1.1.6 Build 240130 Rel.173828
Available firmware version (available_firmware_version): None
Some features present configuration that can be changed:
kasa --host 192.0.2.123 feature color_temperature 2500
Changing color_temperature from 0 to 2500
New state: 2500
Note
When controlling hub-connected devices, you need to pass the device ID of the connected device as an option:
kasa --host 192.0.2.200 feature --child someuniqueidentifier target_temperature 21
Library usage
import asyncio
from kasa import Discover
async def main():
dev = await Discover.discover_single("192.0.2.123", username="un@example.com", password="pw")
await dev.turn_on()
await dev.update()
if __name__ == "__main__":
asyncio.run(main())
If you want to use this library in your own project, a good starting point is the tutorial in the documentation.
You can find several code examples in the API documentation How to guides.
Information about the library design and the way the devices work can be found in the topics section.
Contributing
Contributions are very welcome! The easiest way to contribute is by creating a fixture file for the automated test suite if your device hardware and firmware version is not currently listed as supported. Please refer to our contributing guidelines.
Supported devices
The following devices have been tested and confirmed as working. If your device is unlisted but working, please consider contributing a fixture file.
Note
The hub attached Tapo buttons S200B and S200D do not currently support alerting when the button is pressed.
Supported Kasa devices
- Plugs: EP10, EP251, HS1002, HS103, HS105, HS110, KP100, KP105, KP115, KP125, KP125M1, KP401
- Power Strips: EP40, EP40M1, HS107, HS300, KP200, KP303, KP400
- Wall Switches: ES20M, HS2002, HS210, HS2202, KP405, KS200M, KS2051, KS220, KS220M, KS2251, KS230, KS2401
- Bulbs: KL110, KL120, KL125, KL130, KL135, KL50, KL60, LB110
- Light Strips: KL400L5, KL420L5, KL430
- Hubs: KH1001
- Hub-Connected Devices3: KE1001
Supported Tapo1 devices
- Plugs: P100, P110, P110M, P115, P125M, P135, TP15
- Power Strips: P300, P304M, TP25
- Wall Switches: S500D, S505, S505D
- Bulbs: L510B, L510E, L530E, L630
- Light Strips: L900-10, L900-5, L920-5, L930-5
- Cameras: C210, TC65
- Hubs: H100, H200
- Hub-Connected Devices3: S200B, S200D, T100, T110, T300, T310, T315
See supported devices in our documentation for more detailed information about tested hardware and software versions.
Resources
Developer Resources
- softScheck's github contains lot of information and wireshark dissector
- TP-Link Smart Home Device Simulator
- Unofficial API documentation
- Another unofficial API documentation
- pyHS100 provides synchronous interface and is the unmaintained predecessor of this library.