python-kasa 0.7.0.dev5__py3-none-any.whl → 0.7.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kasa/aestransport.py +6 -2
- kasa/cli.py +60 -45
- kasa/device.py +105 -2
- kasa/discover.py +2 -1
- kasa/feature.py +85 -10
- kasa/httpclient.py +1 -1
- kasa/interfaces/energy.py +6 -0
- kasa/interfaces/light.py +61 -1
- kasa/interfaces/lighteffect.py +41 -1
- kasa/interfaces/lightpreset.py +70 -2
- kasa/iot/iotdevice.py +6 -1
- kasa/iot/iotstrip.py +14 -3
- kasa/iot/modules/lightpreset.py +2 -1
- kasa/module.py +39 -1
- kasa/smart/modules/alarm.py +1 -0
- kasa/smart/modules/autooff.py +3 -1
- kasa/smart/modules/childdevice.py +39 -1
- kasa/smart/modules/firmware.py +4 -1
- kasa/smart/modules/frostprotection.py +0 -22
- kasa/smart/modules/humiditysensor.py +1 -0
- kasa/smart/modules/led.py +1 -1
- kasa/smart/modules/lightpreset.py +2 -1
- kasa/smart/modules/lighttransition.py +5 -7
- kasa/smart/modules/reportmode.py +2 -0
- kasa/smart/modules/temperaturecontrol.py +3 -2
- kasa/smart/modules/temperaturesensor.py +3 -2
- kasa/smart/modules/time.py +3 -2
- kasa/smart/modules/waterleaksensor.py +2 -0
- kasa/smart/smartdevice.py +10 -5
- kasa/tests/device_fixtures.py +1 -1
- kasa/tests/discovery_fixtures.py +3 -1
- kasa/tests/fakeprotocol_smart.py +2 -2
- kasa/tests/smart/modules/test_firmware.py +12 -1
- kasa/tests/test_cli.py +18 -3
- kasa/tests/test_device.py +2 -1
- kasa/tests/test_emeter.py +8 -8
- kasa/tests/test_feature.py +6 -2
- kasa/tests/test_httpclient.py +2 -2
- kasa/tests/test_iotdevice.py +5 -4
- kasa/tests/test_readme_examples.py +59 -0
- kasa/tests/test_smartdevice.py +4 -3
- kasa/tests/test_strip.py +15 -2
- kasa/xortransport.py +3 -3
- {python_kasa-0.7.0.dev5.dist-info → python_kasa-0.7.0.1.dist-info}/METADATA +102 -129
- {python_kasa-0.7.0.dev5.dist-info → python_kasa-0.7.0.1.dist-info}/RECORD +48 -48
- {python_kasa-0.7.0.dev5.dist-info → python_kasa-0.7.0.1.dist-info}/LICENSE +0 -0
- {python_kasa-0.7.0.dev5.dist-info → python_kasa-0.7.0.1.dist-info}/WHEEL +0 -0
- {python_kasa-0.7.0.dev5.dist-info → python_kasa-0.7.0.1.dist-info}/entry_points.txt +0 -0
kasa/tests/test_cli.py
CHANGED
|
@@ -57,7 +57,15 @@ def runner():
|
|
|
57
57
|
return runner
|
|
58
58
|
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
@pytest.mark.parametrize(
|
|
61
|
+
("device_family", "encrypt_type"),
|
|
62
|
+
[
|
|
63
|
+
pytest.param(None, None, id="No connect params"),
|
|
64
|
+
pytest.param("SMART.TAPOPLUG", None, id="Only device_family"),
|
|
65
|
+
pytest.param(None, "KLAP", id="Only encrypt_type"),
|
|
66
|
+
],
|
|
67
|
+
)
|
|
68
|
+
async def test_update_called_by_cli(dev, mocker, runner, device_family, encrypt_type):
|
|
61
69
|
"""Test that device update is called on main."""
|
|
62
70
|
update = mocker.patch.object(dev, "update")
|
|
63
71
|
|
|
@@ -76,6 +84,10 @@ async def test_update_called_by_cli(dev, mocker, runner):
|
|
|
76
84
|
"foo",
|
|
77
85
|
"--password",
|
|
78
86
|
"bar",
|
|
87
|
+
"--device-family",
|
|
88
|
+
device_family,
|
|
89
|
+
"--encrypt-type",
|
|
90
|
+
encrypt_type,
|
|
79
91
|
],
|
|
80
92
|
catch_exceptions=False,
|
|
81
93
|
)
|
|
@@ -827,7 +839,10 @@ async def test_features_all(discovery_mock, mocker, runner):
|
|
|
827
839
|
["--host", "127.0.0.123", "--debug", "feature"],
|
|
828
840
|
catch_exceptions=False,
|
|
829
841
|
)
|
|
830
|
-
assert "==
|
|
842
|
+
assert "== Primary features ==" in res.output
|
|
843
|
+
assert "== Information ==" in res.output
|
|
844
|
+
assert "== Configuration ==" in res.output
|
|
845
|
+
assert "== Debug ==" in res.output
|
|
831
846
|
assert res.exit_code == 0
|
|
832
847
|
|
|
833
848
|
|
|
@@ -878,7 +893,7 @@ async def test_feature_set(mocker, runner):
|
|
|
878
893
|
)
|
|
879
894
|
|
|
880
895
|
led_setter.assert_called_with(True)
|
|
881
|
-
assert "Changing led from
|
|
896
|
+
assert "Changing led from True to True" in res.output
|
|
882
897
|
assert res.exit_code == 0
|
|
883
898
|
|
|
884
899
|
|
kasa/tests/test_device.py
CHANGED
|
@@ -6,6 +6,7 @@ import importlib
|
|
|
6
6
|
import inspect
|
|
7
7
|
import pkgutil
|
|
8
8
|
import sys
|
|
9
|
+
from contextlib import AbstractContextManager
|
|
9
10
|
from unittest.mock import Mock, patch
|
|
10
11
|
|
|
11
12
|
import pytest
|
|
@@ -161,7 +162,7 @@ async def _test_attribute(
|
|
|
161
162
|
dev: Device, attribute_name, is_expected, module_name, *args, will_raise=False
|
|
162
163
|
):
|
|
163
164
|
if is_expected and will_raise:
|
|
164
|
-
ctx = pytest.raises(will_raise)
|
|
165
|
+
ctx: AbstractContextManager = pytest.raises(will_raise)
|
|
165
166
|
elif is_expected:
|
|
166
167
|
ctx = pytest.deprecated_call(match=(f"{attribute_name} is deprecated, use:"))
|
|
167
168
|
else:
|
kasa/tests/test_emeter.py
CHANGED
|
@@ -5,7 +5,7 @@ import pytest
|
|
|
5
5
|
from voluptuous import (
|
|
6
6
|
All,
|
|
7
7
|
Any,
|
|
8
|
-
Coerce,
|
|
8
|
+
Coerce,
|
|
9
9
|
Range,
|
|
10
10
|
Schema,
|
|
11
11
|
)
|
|
@@ -21,14 +21,14 @@ CURRENT_CONSUMPTION_SCHEMA = Schema(
|
|
|
21
21
|
Any(
|
|
22
22
|
{
|
|
23
23
|
"voltage": Any(All(float, Range(min=0, max=300)), None),
|
|
24
|
-
"power": Any(Coerce(float
|
|
25
|
-
"total": Any(Coerce(float
|
|
26
|
-
"current": Any(All(float
|
|
24
|
+
"power": Any(Coerce(float), None),
|
|
25
|
+
"total": Any(Coerce(float), None),
|
|
26
|
+
"current": Any(All(float), None),
|
|
27
27
|
"voltage_mv": Any(All(float, Range(min=0, max=300000)), int, None),
|
|
28
|
-
"power_mw": Any(Coerce(float
|
|
29
|
-
"total_wh": Any(Coerce(float
|
|
30
|
-
"current_ma": Any(All(float
|
|
31
|
-
"slot_id": Any(Coerce(int
|
|
28
|
+
"power_mw": Any(Coerce(float), None),
|
|
29
|
+
"total_wh": Any(Coerce(float), None),
|
|
30
|
+
"current_ma": Any(All(float), int, None),
|
|
31
|
+
"slot_id": Any(Coerce(int), None),
|
|
32
32
|
},
|
|
33
33
|
None,
|
|
34
34
|
)
|
kasa/tests/test_feature.py
CHANGED
|
@@ -44,8 +44,11 @@ def test_feature_api(dummy_feature: Feature):
|
|
|
44
44
|
assert dummy_feature.unit == "dummyunit"
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
""
|
|
47
|
+
@pytest.mark.parametrize(
|
|
48
|
+
"read_only_type", [Feature.Type.Sensor, Feature.Type.BinarySensor]
|
|
49
|
+
)
|
|
50
|
+
def test_feature_setter_on_sensor(read_only_type):
|
|
51
|
+
"""Test that creating a sensor feature with a setter causes an error."""
|
|
49
52
|
with pytest.raises(ValueError):
|
|
50
53
|
Feature(
|
|
51
54
|
device=DummyDevice(), # type: ignore[arg-type]
|
|
@@ -53,6 +56,7 @@ def test_feature_missing_type():
|
|
|
53
56
|
name="dummy error",
|
|
54
57
|
attribute_getter="dummygetter",
|
|
55
58
|
attribute_setter="dummysetter",
|
|
59
|
+
type=read_only_type,
|
|
56
60
|
)
|
|
57
61
|
|
|
58
62
|
|
kasa/tests/test_httpclient.py
CHANGED
|
@@ -38,7 +38,7 @@ from ..httpclient import HttpClient
|
|
|
38
38
|
),
|
|
39
39
|
(Exception(), KasaException, "Unable to query the device: "),
|
|
40
40
|
(
|
|
41
|
-
aiohttp.ServerFingerprintMismatch("exp", "got", "host", 1),
|
|
41
|
+
aiohttp.ServerFingerprintMismatch(b"exp", b"got", "host", 1),
|
|
42
42
|
KasaException,
|
|
43
43
|
"Unable to query the device: ",
|
|
44
44
|
),
|
|
@@ -84,7 +84,7 @@ async def test_httpclient_errors(mocker, error, error_raises, error_message, moc
|
|
|
84
84
|
client = HttpClient(DeviceConfig(host))
|
|
85
85
|
# Exceptions with parameters print with double quotes, without use single quotes
|
|
86
86
|
full_msg = (
|
|
87
|
-
"
|
|
87
|
+
re.escape("(")
|
|
88
88
|
+ "['\"]"
|
|
89
89
|
+ re.escape(f"{error_message}{host}: {error}")
|
|
90
90
|
+ "['\"]"
|
kasa/tests/test_iotdevice.py
CHANGED
|
@@ -91,9 +91,10 @@ async def test_state_info(dev):
|
|
|
91
91
|
@pytest.mark.requires_dummy
|
|
92
92
|
@device_iot
|
|
93
93
|
async def test_invalid_connection(mocker, dev):
|
|
94
|
-
with
|
|
95
|
-
FakeIotProtocol, "query", side_effect=KasaException
|
|
96
|
-
|
|
94
|
+
with (
|
|
95
|
+
mocker.patch.object(FakeIotProtocol, "query", side_effect=KasaException),
|
|
96
|
+
pytest.raises(KasaException),
|
|
97
|
+
):
|
|
97
98
|
await dev.update()
|
|
98
99
|
|
|
99
100
|
|
|
@@ -207,7 +208,7 @@ async def test_mac(dev):
|
|
|
207
208
|
|
|
208
209
|
@device_iot
|
|
209
210
|
async def test_representation(dev):
|
|
210
|
-
pattern = re.compile("<DeviceType\..+ at .+? - .*? \(.+?\)>")
|
|
211
|
+
pattern = re.compile(r"<DeviceType\..+ at .+? - .*? \(.+?\)>")
|
|
211
212
|
assert pattern.match(str(dev))
|
|
212
213
|
|
|
213
214
|
|
|
@@ -69,6 +69,7 @@ def test_discovery_examples(readmes_mock):
|
|
|
69
69
|
"""Test discovery examples."""
|
|
70
70
|
res = xdoctest.doctest_module("kasa.discover", "all")
|
|
71
71
|
assert res["n_passed"] > 0
|
|
72
|
+
assert res["n_warned"] == 0
|
|
72
73
|
assert not res["failed"]
|
|
73
74
|
|
|
74
75
|
|
|
@@ -76,6 +77,63 @@ def test_deviceconfig_examples(readmes_mock):
|
|
|
76
77
|
"""Test discovery examples."""
|
|
77
78
|
res = xdoctest.doctest_module("kasa.deviceconfig", "all")
|
|
78
79
|
assert res["n_passed"] > 0
|
|
80
|
+
assert res["n_warned"] == 0
|
|
81
|
+
assert not res["failed"]
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def test_device_examples(readmes_mock):
|
|
85
|
+
"""Test device examples."""
|
|
86
|
+
res = xdoctest.doctest_module("kasa.device", "all")
|
|
87
|
+
assert res["n_passed"] > 0
|
|
88
|
+
assert res["n_warned"] == 0
|
|
89
|
+
assert not res["failed"]
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def test_light_examples(readmes_mock):
|
|
93
|
+
"""Test device examples."""
|
|
94
|
+
res = xdoctest.doctest_module("kasa.interfaces.light", "all")
|
|
95
|
+
assert res["n_passed"] > 0
|
|
96
|
+
assert res["n_warned"] == 0
|
|
97
|
+
assert not res["failed"]
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def test_light_preset_examples(readmes_mock):
|
|
101
|
+
"""Test device examples."""
|
|
102
|
+
res = xdoctest.doctest_module("kasa.interfaces.lightpreset", "all")
|
|
103
|
+
assert res["n_passed"] > 0
|
|
104
|
+
assert res["n_warned"] == 0
|
|
105
|
+
assert not res["failed"]
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def test_light_effect_examples(readmes_mock):
|
|
109
|
+
"""Test device examples."""
|
|
110
|
+
res = xdoctest.doctest_module("kasa.interfaces.lighteffect", "all")
|
|
111
|
+
assert res["n_passed"] > 0
|
|
112
|
+
assert res["n_warned"] == 0
|
|
113
|
+
assert not res["failed"]
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def test_child_examples(readmes_mock):
|
|
117
|
+
"""Test device examples."""
|
|
118
|
+
res = xdoctest.doctest_module("kasa.smart.modules.childdevice", "all")
|
|
119
|
+
assert res["n_passed"] > 0
|
|
120
|
+
assert res["n_warned"] == 0
|
|
121
|
+
assert not res["failed"]
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def test_module_examples(readmes_mock):
|
|
125
|
+
"""Test device examples."""
|
|
126
|
+
res = xdoctest.doctest_module("kasa.module", "all")
|
|
127
|
+
assert res["n_passed"] > 0
|
|
128
|
+
assert res["n_warned"] == 0
|
|
129
|
+
assert not res["failed"]
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def test_feature_examples(readmes_mock):
|
|
133
|
+
"""Test device examples."""
|
|
134
|
+
res = xdoctest.doctest_module("kasa.feature", "all")
|
|
135
|
+
assert res["n_passed"] > 0
|
|
136
|
+
assert res["n_warned"] == 0
|
|
79
137
|
assert not res["failed"]
|
|
80
138
|
|
|
81
139
|
|
|
@@ -83,6 +141,7 @@ def test_tutorial_examples(readmes_mock):
|
|
|
83
141
|
"""Test discovery examples."""
|
|
84
142
|
res = xdoctest.doctest_module("docs/tutorial.py", "all")
|
|
85
143
|
assert res["n_passed"] > 0
|
|
144
|
+
assert res["n_warned"] == 0
|
|
86
145
|
assert not res["failed"]
|
|
87
146
|
|
|
88
147
|
|
kasa/tests/test_smartdevice.py
CHANGED
|
@@ -38,9 +38,10 @@ async def test_update_no_device_info(dev: SmartDevice, mocker: MockerFixture):
|
|
|
38
38
|
"get_device_time": {},
|
|
39
39
|
}
|
|
40
40
|
msg = f"get_device_info not found in {mock_response} for device 127.0.0.123"
|
|
41
|
-
with
|
|
42
|
-
dev.protocol, "query", return_value=mock_response
|
|
43
|
-
|
|
41
|
+
with (
|
|
42
|
+
mocker.patch.object(dev.protocol, "query", return_value=mock_response),
|
|
43
|
+
pytest.raises(KasaException, match=msg),
|
|
44
|
+
):
|
|
44
45
|
await dev.update()
|
|
45
46
|
|
|
46
47
|
|
kasa/tests/test_strip.py
CHANGED
|
@@ -2,10 +2,10 @@ from datetime import datetime
|
|
|
2
2
|
|
|
3
3
|
import pytest
|
|
4
4
|
|
|
5
|
-
from kasa import KasaException
|
|
5
|
+
from kasa import Device, KasaException, Module
|
|
6
6
|
from kasa.iot import IotStrip
|
|
7
7
|
|
|
8
|
-
from .conftest import handle_turn_on, strip, turn_on
|
|
8
|
+
from .conftest import handle_turn_on, strip, strip_iot, turn_on
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
@strip
|
|
@@ -147,3 +147,16 @@ def test_children_api(dev):
|
|
|
147
147
|
first = dev.children[0]
|
|
148
148
|
first_by_get_child_device = dev.get_child_device(first.device_id)
|
|
149
149
|
assert first == first_by_get_child_device
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
@strip_iot
|
|
153
|
+
async def test_children_energy(dev: Device):
|
|
154
|
+
if Module.Energy not in dev.modules:
|
|
155
|
+
pytest.skip(f"skipping device {dev.model} does not support energy")
|
|
156
|
+
|
|
157
|
+
for plug in dev.children:
|
|
158
|
+
# For now all known strips with energy support these
|
|
159
|
+
energy = plug.modules[Module.Energy]
|
|
160
|
+
assert "voltage" in energy._module_features
|
|
161
|
+
assert "current" in energy._module_features
|
|
162
|
+
assert "current_consumption" in energy._module_features
|
kasa/xortransport.py
CHANGED
|
@@ -18,8 +18,8 @@ import errno
|
|
|
18
18
|
import logging
|
|
19
19
|
import socket
|
|
20
20
|
import struct
|
|
21
|
+
from collections.abc import Generator
|
|
21
22
|
from pprint import pformat as pf
|
|
22
|
-
from typing import Generator
|
|
23
23
|
|
|
24
24
|
# When support for cpython older than 3.11 is dropped
|
|
25
25
|
# async_timeout can be replaced with asyncio.timeout
|
|
@@ -229,7 +229,7 @@ class XorEncryption:
|
|
|
229
229
|
try:
|
|
230
230
|
from kasa_crypt import decrypt, encrypt
|
|
231
231
|
|
|
232
|
-
XorEncryption.decrypt = decrypt # type: ignore[
|
|
233
|
-
XorEncryption.encrypt = encrypt # type: ignore[
|
|
232
|
+
XorEncryption.decrypt = decrypt # type: ignore[assignment]
|
|
233
|
+
XorEncryption.encrypt = encrypt # type: ignore[assignment]
|
|
234
234
|
except ImportError:
|
|
235
235
|
pass
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: python-kasa
|
|
3
|
-
Version: 0.7.0.
|
|
3
|
+
Version: 0.7.0.1
|
|
4
4
|
Summary: Python API for TP-Link Kasa Smarthome devices
|
|
5
5
|
Home-page: https://github.com/python-kasa/python-kasa
|
|
6
6
|
License: GPL-3.0-or-later
|
|
7
7
|
Author: python-kasa developers
|
|
8
|
-
Requires-Python: >=3.
|
|
8
|
+
Requires-Python: >=3.9,<4.0
|
|
9
9
|
Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
|
|
10
10
|
Classifier: Programming Language :: Python :: 3
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
12
11
|
Classifier: Programming Language :: Python :: 3.9
|
|
13
12
|
Classifier: Programming Language :: Python :: 3.10
|
|
14
13
|
Classifier: Programming Language :: Python :: 3.11
|
|
@@ -17,9 +16,8 @@ Provides-Extra: docs
|
|
|
17
16
|
Provides-Extra: shell
|
|
18
17
|
Provides-Extra: speedups
|
|
19
18
|
Requires-Dist: aiohttp (>=3)
|
|
20
|
-
Requires-Dist: anyio
|
|
21
19
|
Requires-Dist: async-timeout (>=3.0.0)
|
|
22
|
-
Requires-Dist: asyncclick (>=8)
|
|
20
|
+
Requires-Dist: asyncclick (>=8.1.7)
|
|
23
21
|
Requires-Dist: cryptography (>=1.9)
|
|
24
22
|
Requires-Dist: docutils (>=0.17) ; extra == "docs"
|
|
25
23
|
Requires-Dist: kasa-crypt (>=0.2.0) ; extra == "speedups"
|
|
@@ -58,21 +56,6 @@ You can install the most recent release using pip:
|
|
|
58
56
|
pip install python-kasa
|
|
59
57
|
```
|
|
60
58
|
|
|
61
|
-
For enhanced cli tool support (coloring, embedded shell) install with `[shell]`:
|
|
62
|
-
```
|
|
63
|
-
pip install python-kasa[shell]
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
If you are using cpython, it is recommended to install with `[speedups]` to enable orjson (faster json support):
|
|
67
|
-
```
|
|
68
|
-
pip install python-kasa[speedups]
|
|
69
|
-
```
|
|
70
|
-
or for both:
|
|
71
|
-
```
|
|
72
|
-
pip install python-kasa[speedups, shell]
|
|
73
|
-
```
|
|
74
|
-
With `[speedups]`, the protocol overhead is roughly an order of magnitude lower (benchmarks available in devtools).
|
|
75
|
-
|
|
76
59
|
Alternatively, you can clone this repository and use poetry to install the development version:
|
|
77
60
|
```
|
|
78
61
|
git clone https://github.com/python-kasa/python-kasa.git
|
|
@@ -85,7 +68,11 @@ If you have not yet provisioned your device, [you can do so using the cli tool](
|
|
|
85
68
|
## Discovering devices
|
|
86
69
|
|
|
87
70
|
Running `kasa discover` will send discovery packets to the default broadcast address (`255.255.255.255`) to discover supported devices.
|
|
88
|
-
If your
|
|
71
|
+
If your device requires authentication to control it,
|
|
72
|
+
you need to pass the credentials using `--username` and `--password` options or define `KASA_USERNAME` and `KASA_PASSWORD` environment variables.
|
|
73
|
+
|
|
74
|
+
> [!NOTE]
|
|
75
|
+
> If your system has multiple network interfaces, you can specify the broadcast address using the `--target` option.
|
|
89
76
|
|
|
90
77
|
The `discover` command will automatically execute the `state` command on all the discovered devices:
|
|
91
78
|
|
|
@@ -93,134 +80,126 @@ The `discover` command will automatically execute the `state` command on all the
|
|
|
93
80
|
$ kasa discover
|
|
94
81
|
Discovering devices on 255.255.255.255 for 3 seconds
|
|
95
82
|
|
|
96
|
-
== Bulb McBulby -
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
83
|
+
== Bulb McBulby - L530 ==
|
|
84
|
+
Host: 192.0.2.123
|
|
85
|
+
Port: 80
|
|
86
|
+
Device state: False
|
|
87
|
+
Time: 2024-06-22 15:42:15+02:00 (tz: {'timezone': 'CEST'}
|
|
88
|
+
Hardware: 3.0
|
|
89
|
+
Software: 1.1.6 Build 240130 Rel.173828
|
|
90
|
+
MAC (rssi): 5C:E9:31:aa:bb:cc (-50)
|
|
91
|
+
== Primary features ==
|
|
92
|
+
State (state): False
|
|
93
|
+
Brightness (brightness): 11 (range: 0-100)
|
|
94
|
+
Color temperature (color_temperature): 0 (range: 2500-6500)
|
|
95
|
+
Light effect (light_effect): *Off* Party Relax
|
|
96
|
+
|
|
97
|
+
== Information ==
|
|
98
|
+
Signal Level (signal_level): 2
|
|
99
|
+
Overheated (overheated): False
|
|
100
|
+
Cloud connection (cloud_connection): False
|
|
101
|
+
Update available (update_available): None
|
|
102
|
+
Device time (device_time): 2024-06-22 15:42:15+02:00
|
|
103
|
+
|
|
104
|
+
== Configuration ==
|
|
105
|
+
HSV (hsv): HSV(hue=35, saturation=70, value=11)
|
|
106
|
+
Auto update enabled (auto_update_enabled): False
|
|
107
|
+
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
|
|
108
|
+
Smooth transition on (smooth_transition_on): 2 (range: 0-60)
|
|
109
|
+
Smooth transition off (smooth_transition_off): 20 (range: 0-60)
|
|
110
|
+
|
|
111
|
+
== Debug ==
|
|
112
|
+
Device ID (device_id): soneuniqueidentifier
|
|
113
|
+
RSSI (rssi): -50 dBm
|
|
114
|
+
SSID (ssid): HomeNet
|
|
115
|
+
Current firmware version (current_firmware_version): 1.1.6 Build 240130 Rel.173828
|
|
116
|
+
Available firmware version (available_firmware_version): None
|
|
130
117
|
```
|
|
131
118
|
|
|
132
|
-
If your device requires authentication to control it,
|
|
133
|
-
you need to pass the credentials using `--username` and `--password` options.
|
|
134
|
-
|
|
135
|
-
## Basic functionalities
|
|
136
119
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
* `state` which returns state information
|
|
140
|
-
* `on` and `off` for turning the device on or off
|
|
141
|
-
* `emeter` (where applicable) to return energy consumption information
|
|
142
|
-
* `sysinfo` to return raw system information
|
|
143
|
-
|
|
144
|
-
The syntax to control device is `kasa --host <ip address> <command>`.
|
|
145
|
-
Use `kasa --help` ([or consult the documentation](https://python-kasa.readthedocs.io/en/latest/cli.html#kasa-help)) to get a list of all available commands and options.
|
|
146
|
-
Some examples of available options include JSON output (`--json`), defining timeouts (`--timeout` and `--discovery-timeout`).
|
|
120
|
+
## Command line usage
|
|
147
121
|
|
|
148
|
-
|
|
149
|
-
|
|
122
|
+
All devices support a variety of common commands (like `on`, `off`, and `state`).
|
|
123
|
+
The syntax to control device is `kasa --host <host> <command>`:
|
|
150
124
|
|
|
151
125
|
```
|
|
152
|
-
$ kasa on
|
|
153
|
-
|
|
154
|
-
Usage: kasa on [OPTIONS]
|
|
155
|
-
|
|
156
|
-
Turn the device on.
|
|
157
|
-
|
|
158
|
-
Options:
|
|
159
|
-
--index INTEGER
|
|
160
|
-
--name TEXT
|
|
161
|
-
--transition INTEGER
|
|
162
|
-
--help Show this message and exit.
|
|
126
|
+
$ kasa --host 192.0.2.123 on
|
|
163
127
|
```
|
|
164
128
|
|
|
129
|
+
Use `kasa --help` ([or consult the documentation](https://python-kasa.readthedocs.io/en/latest/cli.html#kasa-help)) to get a list of all available commands and options.
|
|
130
|
+
Some examples of available options include JSON output (`--json`), more verbose output (`--verbose`), and defining timeouts (`--timeout` and `--discovery-timeout`).
|
|
131
|
+
Refer [the documentation](https://python-kasa.readthedocs.io/en/latest/cli.html) for more details.
|
|
165
132
|
|
|
166
|
-
|
|
133
|
+
> [!NOTE]
|
|
134
|
+
> Each individual command may also have additional options, which are shown when called with the `--help` option.
|
|
167
135
|
|
|
168
|
-
Common commands for bulbs and light strips include:
|
|
169
136
|
|
|
170
|
-
|
|
171
|
-
* `hsv` to control the colors
|
|
172
|
-
* `temperature` to control the color temperatures
|
|
137
|
+
### Feature interface
|
|
173
138
|
|
|
174
|
-
|
|
139
|
+
All devices are also controllable through a generic feature-based interface.
|
|
140
|
+
The available features differ from device to device and are accessible using `kasa feature` command:
|
|
175
141
|
|
|
176
|
-
Some devices support `--transition` option to perform a smooth state change.
|
|
177
|
-
For example, the following turns the light to 30% brightness over a period of five seconds:
|
|
178
142
|
```
|
|
179
|
-
$ kasa --host
|
|
143
|
+
$ kasa --host 192.0.2.123 feature
|
|
144
|
+
== Primary features ==
|
|
145
|
+
State (state): False
|
|
146
|
+
Brightness (brightness): 11 (range: 0-100)
|
|
147
|
+
Color temperature (color_temperature): 0 (range: 2500-6500)
|
|
148
|
+
Light effect (light_effect): *Off* Party Relax
|
|
149
|
+
|
|
150
|
+
== Information ==
|
|
151
|
+
Signal Level (signal_level): 2
|
|
152
|
+
Overheated (overheated): False
|
|
153
|
+
Cloud connection (cloud_connection): False
|
|
154
|
+
Update available (update_available): None
|
|
155
|
+
Device time (device_time): 2024-06-22 15:39:44+02:00
|
|
156
|
+
|
|
157
|
+
== Configuration ==
|
|
158
|
+
HSV (hsv): HSV(hue=35, saturation=70, value=11)
|
|
159
|
+
Auto update enabled (auto_update_enabled): False
|
|
160
|
+
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
|
|
161
|
+
Smooth transition on (smooth_transition_on): 2 (range: 0-60)
|
|
162
|
+
Smooth transition off (smooth_transition_off): 20 (range: 0-60)
|
|
163
|
+
|
|
164
|
+
== Debug ==
|
|
165
|
+
Device ID (device_id): soneuniqueidentifier
|
|
166
|
+
RSSI (rssi): -50 dBm
|
|
167
|
+
SSID (ssid): HomeNet
|
|
168
|
+
Current firmware version (current_firmware_version): 1.1.6 Build 240130 Rel.173828
|
|
169
|
+
Available firmware version (available_firmware_version): None
|
|
180
170
|
```
|
|
181
171
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
### Power strips
|
|
185
|
-
|
|
186
|
-
Each individual socket can be controlled separately by passing `--index` or `--name` to the command.
|
|
187
|
-
If neither option is defined, the commands act on the whole power strip.
|
|
188
|
-
|
|
189
|
-
For example:
|
|
172
|
+
Some features present configuration that can be changed:
|
|
190
173
|
```
|
|
191
|
-
|
|
192
|
-
|
|
174
|
+
kasa --host 192.0.2.123 feature color_temperature 2500
|
|
175
|
+
Changing color_temperature from 0 to 2500
|
|
176
|
+
New state: 2500
|
|
193
177
|
```
|
|
194
178
|
|
|
195
|
-
|
|
179
|
+
> [!NOTE]
|
|
180
|
+
> 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`
|
|
196
181
|
|
|
197
182
|
|
|
198
|
-
##
|
|
183
|
+
## Library usage
|
|
199
184
|
|
|
200
|
-
Running `kasa emeter` command will return the current consumption.
|
|
201
|
-
Possible options include `--year` and `--month` for retrieving historical state,
|
|
202
|
-
and reseting the counters can be done with `--erase`.
|
|
203
|
-
|
|
204
|
-
```
|
|
205
|
-
$ kasa emeter
|
|
206
|
-
== Emeter ==
|
|
207
|
-
Current state: {'total': 133.105, 'power': 108.223577, 'current': 0.54463, 'voltage': 225.296283}
|
|
208
185
|
```
|
|
186
|
+
import asyncio
|
|
187
|
+
from kasa import Discover
|
|
209
188
|
|
|
210
|
-
|
|
189
|
+
async def main():
|
|
190
|
+
dev = await Discover.discover_single("192.0.2.123", username="un@example.com", password="pw")
|
|
191
|
+
await dev.turn_on()
|
|
192
|
+
await dev.update()
|
|
211
193
|
|
|
212
|
-
|
|
194
|
+
if __name__ == "__main__":
|
|
195
|
+
asyncio.run(main())
|
|
196
|
+
```
|
|
213
197
|
|
|
214
|
-
|
|
198
|
+
If you want to use this library in your own project, a good starting point is [the tutorial in the documentation](https://python-kasa.readthedocs.io/en/latest/tutorial.html).
|
|
215
199
|
|
|
216
|
-
|
|
200
|
+
You can find several code examples in the API documentation [How to guides](https://python-kasa.readthedocs.io/en/latest/guides.html).
|
|
217
201
|
|
|
218
|
-
|
|
219
|
-
* [Plugs](https://python-kasa.readthedocs.io/en/latest/smartplug.html)
|
|
220
|
-
* [Bulbs](https://python-kasa.readthedocs.io/en/latest/smartbulb.html)
|
|
221
|
-
* [Dimmers](https://python-kasa.readthedocs.io/en/latest/smartdimmer.html)
|
|
222
|
-
* [Power strips](https://python-kasa.readthedocs.io/en/latest/smartstrip.html)
|
|
223
|
-
* [Light strips](https://python-kasa.readthedocs.io/en/latest/smartlightstrip.html)
|
|
202
|
+
Information about the library design and the way the devices work can be found in the [topics section](https://python-kasa.readthedocs.io/en/latest/topics.html).
|
|
224
203
|
|
|
225
204
|
## Contributing
|
|
226
205
|
|
|
@@ -276,18 +255,12 @@ See [supported devices in our documentation](SUPPORTED.md) for more detailed inf
|
|
|
276
255
|
* [Home Assistant](https://www.home-assistant.io/integrations/tplink/)
|
|
277
256
|
* [MQTT access to TP-Link devices, using python-kasa](https://github.com/flavio-fernandes/mqtt2kasa)
|
|
278
257
|
|
|
279
|
-
###
|
|
280
|
-
|
|
281
|
-
This library has recently added a limited supported for devices that carry Tapo branding.
|
|
282
|
-
That support is currently limited to the cli. The package `kasa.smart` is in flux and if you
|
|
283
|
-
use it directly you should expect it could break in future releases until this statement is removed.
|
|
284
|
-
|
|
285
|
-
Other TAPO libraries are:
|
|
258
|
+
### Other related projects
|
|
286
259
|
|
|
287
260
|
* [PyTapo - Python library for communication with Tapo Cameras](https://github.com/JurajNyiri/pytapo)
|
|
288
261
|
* [Tapo P100 (Tapo plugs, Tapo bulbs)](https://github.com/fishbigger/TapoP100)
|
|
289
262
|
* [Home Assistant integration](https://github.com/fishbigger/HomeAssistant-Tapo-P100-Control)
|
|
290
263
|
* [plugp100, another tapo library](https://github.com/petretiandrea/plugp100)
|
|
291
264
|
* [Home Assistant integration](https://github.com/petretiandrea/home-assistant-tapo-p100)
|
|
292
|
-
* [rust and python implementation](https://github.com/mihai-dinculescu/tapo/)
|
|
265
|
+
* [rust and python implementation for tapo devices](https://github.com/mihai-dinculescu/tapo/)
|
|
293
266
|
|