python-kasa 0.10.2__py3-none-any.whl → 0.12.0__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/cli/common.py +3 -3
- kasa/cli/hub.py +5 -5
- kasa/cli/main.py +1 -2
- kasa/cli/schedule.py +1 -1
- kasa/cli/wifi.py +14 -4
- kasa/credentials.py +29 -4
- kasa/device.py +18 -10
- kasa/device_factory.py +16 -4
- kasa/deviceconfig.py +4 -4
- kasa/discover.py +20 -8
- kasa/exceptions.py +3 -0
- kasa/feature.py +6 -6
- kasa/httpclient.py +4 -1
- kasa/interfaces/childsetup.py +6 -6
- kasa/interfaces/light.py +5 -5
- kasa/interfaces/lighteffect.py +6 -6
- kasa/interfaces/lightpreset.py +6 -6
- kasa/interfaces/thermostat.py +2 -0
- kasa/iot/iotbulb.py +45 -33
- kasa/iot/iotdevice.py +39 -4
- kasa/iot/iotdimmer.py +4 -4
- kasa/iot/iotlightstrip.py +2 -2
- kasa/iot/iotplug.py +2 -2
- kasa/iot/iotstrip.py +32 -6
- kasa/iot/iottimezone.py +105 -15
- kasa/iot/modules/__init__.py +2 -0
- kasa/iot/modules/homekit.py +53 -0
- kasa/iot/modules/time.py +53 -4
- kasa/module.py +13 -8
- kasa/protocols/iotprotocol.py +3 -0
- kasa/protocols/smartcamprotocol.py +2 -0
- kasa/protocols/smartprotocol.py +16 -1
- kasa/smart/modules/__init__.py +2 -0
- kasa/smart/modules/childdevice.py +6 -6
- kasa/smart/modules/clean.py +170 -2
- kasa/smart/modules/consumables.py +6 -6
- kasa/smart/modules/energy.py +76 -23
- kasa/smart/modules/lightstripsegment.py +52 -0
- kasa/smart/modules/lighttransition.py +38 -0
- kasa/smart/modules/mop.py +4 -3
- kasa/smart/modules/powerprotection.py +7 -2
- kasa/smart/modules/temperaturecontrol.py +4 -2
- kasa/smart/modules/waterleaksensor.py +14 -1
- kasa/smart/smartchilddevice.py +1 -0
- kasa/smart/smartdevice.py +21 -4
- kasa/smartcam/__init__.py +2 -1
- kasa/smartcam/detectionmodule.py +58 -0
- kasa/smartcam/modules/__init__.py +12 -0
- kasa/smartcam/modules/babycrydetection.py +6 -31
- kasa/smartcam/modules/barkdetection.py +24 -0
- kasa/smartcam/modules/battery.py +56 -32
- kasa/smartcam/modules/glassdetection.py +24 -0
- kasa/smartcam/modules/lastalertdetection.py +102 -0
- kasa/smartcam/modules/linecrossingdetection.py +24 -0
- kasa/smartcam/modules/meowdetection.py +24 -0
- kasa/smartcam/modules/motiondetection.py +6 -31
- kasa/smartcam/modules/pantilt.py +72 -4
- kasa/smartcam/modules/persondetection.py +6 -31
- kasa/smartcam/modules/petdetection.py +6 -31
- kasa/smartcam/modules/tamperdetection.py +6 -31
- kasa/smartcam/modules/time.py +37 -15
- kasa/smartcam/modules/vehicledetection.py +24 -0
- kasa/smartcam/smartcamdevice.py +162 -1
- kasa/smartcam/smartcammodule.py +20 -0
- kasa/transports/aestransport.py +9 -0
- kasa/transports/basetransport.py +22 -0
- kasa/transports/klaptransport.py +22 -32
- kasa/transports/linkietransport.py +2 -28
- kasa/transports/sslaestransport.py +34 -33
- kasa/transports/sslcontext.py +40 -0
- kasa/transports/ssltransport.py +11 -0
- kasa/transports/xortransport.py +6 -1
- {python_kasa-0.10.2.dist-info → python_kasa-0.12.0.dist-info}/METADATA +16 -20
- {python_kasa-0.10.2.dist-info → python_kasa-0.12.0.dist-info}/RECORD +77 -67
- {python_kasa-0.10.2.dist-info → python_kasa-0.12.0.dist-info}/WHEEL +1 -1
- {python_kasa-0.10.2.dist-info → python_kasa-0.12.0.dist-info}/entry_points.txt +0 -0
- {python_kasa-0.10.2.dist-info → python_kasa-0.12.0.dist-info}/licenses/LICENSE +0 -0
kasa/cli/common.py
CHANGED
|
@@ -34,7 +34,7 @@ except ImportError:
|
|
|
34
34
|
# but only lower case tags to avoid stripping out
|
|
35
35
|
# raw data from the device that is printed from
|
|
36
36
|
# the device state.
|
|
37
|
-
rich_formatting = re.compile(r"\[/?[a-z]+]")
|
|
37
|
+
rich_formatting = re.compile(r"\[/?[a-z]+(?: [a-z]+)*]")
|
|
38
38
|
|
|
39
39
|
def _strip_rich_formatting(echo_func):
|
|
40
40
|
"""Strip rich formatting from messages."""
|
|
@@ -96,7 +96,7 @@ def json_formatter_cb(result: Any, **kwargs) -> None:
|
|
|
96
96
|
|
|
97
97
|
|
|
98
98
|
async def invoke_subcommand(
|
|
99
|
-
command: click.
|
|
99
|
+
command: click.Command,
|
|
100
100
|
ctx: click.Context,
|
|
101
101
|
args: list[str] | None = None,
|
|
102
102
|
**extra: Any,
|
|
@@ -200,7 +200,7 @@ async def _get_child_device(
|
|
|
200
200
|
if child_option is not None:
|
|
201
201
|
if child_option is OPTIONAL_VALUE_FLAG:
|
|
202
202
|
msg = _list_children()
|
|
203
|
-
child_index_option = click.prompt(
|
|
203
|
+
child_index_option = await click.prompt(
|
|
204
204
|
f"\n{msg}\nEnter the index number of the child device",
|
|
205
205
|
type=click.IntRange(0, len(device.children) - 1),
|
|
206
206
|
)
|
kasa/cli/hub.py
CHANGED
|
@@ -4,7 +4,7 @@ import asyncio
|
|
|
4
4
|
|
|
5
5
|
import asyncclick as click
|
|
6
6
|
|
|
7
|
-
from kasa import DeviceType, Module
|
|
7
|
+
from kasa import Device, DeviceType, Module
|
|
8
8
|
from kasa.smart import SmartChildDevice
|
|
9
9
|
|
|
10
10
|
from .common import (
|
|
@@ -21,7 +21,7 @@ def pretty_category(cat: str):
|
|
|
21
21
|
|
|
22
22
|
@click.group()
|
|
23
23
|
@pass_dev
|
|
24
|
-
async def hub(dev:
|
|
24
|
+
async def hub(dev: Device):
|
|
25
25
|
"""Commands controlling hub child device pairing."""
|
|
26
26
|
if dev.device_type is not DeviceType.Hub:
|
|
27
27
|
error(f"{dev} is not a hub.")
|
|
@@ -32,7 +32,7 @@ async def hub(dev: SmartDevice):
|
|
|
32
32
|
|
|
33
33
|
@hub.command(name="list")
|
|
34
34
|
@pass_dev
|
|
35
|
-
async def hub_list(dev:
|
|
35
|
+
async def hub_list(dev: Device):
|
|
36
36
|
"""List hub paired child devices."""
|
|
37
37
|
for c in dev.children:
|
|
38
38
|
echo(f"{c.device_id}: {c}")
|
|
@@ -40,7 +40,7 @@ async def hub_list(dev: SmartDevice):
|
|
|
40
40
|
|
|
41
41
|
@hub.command(name="supported")
|
|
42
42
|
@pass_dev
|
|
43
|
-
async def hub_supported(dev:
|
|
43
|
+
async def hub_supported(dev: Device):
|
|
44
44
|
"""List supported hub child device categories."""
|
|
45
45
|
cs = dev.modules[Module.ChildSetup]
|
|
46
46
|
|
|
@@ -51,7 +51,7 @@ async def hub_supported(dev: SmartDevice):
|
|
|
51
51
|
@hub.command(name="pair")
|
|
52
52
|
@click.option("--timeout", default=10)
|
|
53
53
|
@pass_dev
|
|
54
|
-
async def hub_pair(dev:
|
|
54
|
+
async def hub_pair(dev: Device, timeout: int):
|
|
55
55
|
"""Pair all pairable device.
|
|
56
56
|
|
|
57
57
|
This will pair any child devices currently in pairing mode.
|
kasa/cli/main.py
CHANGED
|
@@ -312,7 +312,6 @@ async def cli(
|
|
|
312
312
|
if type == "camera":
|
|
313
313
|
encrypt_type = "AES"
|
|
314
314
|
https = True
|
|
315
|
-
login_version = 2
|
|
316
315
|
device_family = "SMART.IPCAMERA"
|
|
317
316
|
|
|
318
317
|
from kasa.device import Device
|
|
@@ -415,7 +414,7 @@ async def shell(dev: Device) -> None:
|
|
|
415
414
|
@click.argument("parameters", default=None, required=False)
|
|
416
415
|
async def raw_command(ctx, module, command, parameters):
|
|
417
416
|
"""Run a raw command on the device."""
|
|
418
|
-
logging.warning("Deprecated, use 'kasa command --module %s %s'", module, command)
|
|
417
|
+
logging.warning("Deprecated, use 'kasa command --module %s %s'", module, command) # noqa: LOG015
|
|
419
418
|
return await ctx.forward(cmd_command)
|
|
420
419
|
|
|
421
420
|
|
kasa/cli/schedule.py
CHANGED
|
@@ -38,7 +38,7 @@ async def _schedule_list(dev, type):
|
|
|
38
38
|
async def delete_rule(dev, id):
|
|
39
39
|
"""Delete rule from device."""
|
|
40
40
|
schedule = dev.modules["schedule"]
|
|
41
|
-
rule_to_delete = next(filter(lambda rule:
|
|
41
|
+
rule_to_delete = next(filter(lambda rule: rule.id == id, schedule.rules), None)
|
|
42
42
|
if rule_to_delete:
|
|
43
43
|
echo(f"Deleting rule id {id}")
|
|
44
44
|
return await schedule.delete_rule(rule_to_delete)
|
kasa/cli/wifi.py
CHANGED
|
@@ -6,6 +6,7 @@ import asyncclick as click
|
|
|
6
6
|
|
|
7
7
|
from kasa import (
|
|
8
8
|
Device,
|
|
9
|
+
KasaException,
|
|
9
10
|
)
|
|
10
11
|
|
|
11
12
|
from .common import (
|
|
@@ -15,8 +16,7 @@ from .common import (
|
|
|
15
16
|
|
|
16
17
|
|
|
17
18
|
@click.group()
|
|
18
|
-
|
|
19
|
-
def wifi(dev) -> None:
|
|
19
|
+
def wifi() -> None:
|
|
20
20
|
"""Commands to control wifi settings."""
|
|
21
21
|
|
|
22
22
|
|
|
@@ -35,13 +35,23 @@ async def scan(dev):
|
|
|
35
35
|
|
|
36
36
|
@wifi.command()
|
|
37
37
|
@click.argument("ssid")
|
|
38
|
-
@click.option(
|
|
38
|
+
@click.option(
|
|
39
|
+
"--keytype",
|
|
40
|
+
default="",
|
|
41
|
+
help="KeyType (Not needed for SmartCamDevice).",
|
|
42
|
+
)
|
|
39
43
|
@click.option("--password", prompt=True, hide_input=True)
|
|
40
44
|
@pass_dev
|
|
41
45
|
async def join(dev: Device, ssid: str, password: str, keytype: str):
|
|
42
46
|
"""Join the given wifi network."""
|
|
43
47
|
echo(f"Asking the device to connect to {ssid}..")
|
|
44
|
-
|
|
48
|
+
try:
|
|
49
|
+
res = await dev.wifi_join(ssid, password, keytype=keytype)
|
|
50
|
+
except KasaException as e:
|
|
51
|
+
if type(e) is KasaException:
|
|
52
|
+
echo(str(e))
|
|
53
|
+
return
|
|
54
|
+
raise
|
|
45
55
|
echo(
|
|
46
56
|
f"Response: {res} - if the device is not able to join the network, "
|
|
47
57
|
f"it will revert back to its previous state."
|
kasa/credentials.py
CHANGED
|
@@ -5,6 +5,8 @@ from __future__ import annotations
|
|
|
5
5
|
import base64
|
|
6
6
|
from dataclasses import dataclass, field
|
|
7
7
|
|
|
8
|
+
from kasa.json import loads as json_loads
|
|
9
|
+
|
|
8
10
|
|
|
9
11
|
@dataclass
|
|
10
12
|
class Credentials:
|
|
@@ -15,11 +17,33 @@ class Credentials:
|
|
|
15
17
|
#: Password of the cloud account
|
|
16
18
|
password: str = field(default="", repr=False)
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
def
|
|
20
|
+
@classmethod
|
|
21
|
+
def _from_plaintext_hash(cls, credentials_hash: str) -> Credentials | None:
|
|
22
|
+
"""Recover the credentials from a hash that stores them in plaintext.
|
|
23
|
+
|
|
24
|
+
The ssl aes and tpap transports store base64 json of the plaintext
|
|
25
|
+
credentials, so a transport handed one of those after a device changed
|
|
26
|
+
its encryption type can derive its own hash rather than failing to
|
|
27
|
+
authenticate. Klap and aes hashes are one way, so this only works in
|
|
28
|
+
that direction.
|
|
29
|
+
"""
|
|
30
|
+
try:
|
|
31
|
+
decoded = json_loads(base64.b64decode(credentials_hash.encode()))
|
|
32
|
+
except (ValueError, UnicodeDecodeError):
|
|
33
|
+
return None
|
|
34
|
+
if not isinstance(decoded, dict):
|
|
35
|
+
return None
|
|
36
|
+
username = decoded.get("un")
|
|
37
|
+
password = decoded.get("pwd")
|
|
38
|
+
if isinstance(username, str) and isinstance(password, str):
|
|
39
|
+
return cls(username, password)
|
|
40
|
+
return None
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def get_default_credentials(crdentials: tuple[str, str]) -> Credentials:
|
|
20
44
|
"""Return decoded default credentials."""
|
|
21
|
-
un = base64.b64decode(
|
|
22
|
-
pw = base64.b64decode(
|
|
45
|
+
un = base64.b64decode(crdentials[0].encode()).decode()
|
|
46
|
+
pw = base64.b64decode(crdentials[1].encode()).decode()
|
|
23
47
|
return Credentials(un, pw)
|
|
24
48
|
|
|
25
49
|
|
|
@@ -28,4 +52,5 @@ DEFAULT_CREDENTIALS = {
|
|
|
28
52
|
"KASACAMERA": ("YWRtaW4=", "MjEyMzJmMjk3YTU3YTVhNzQzODk0YTBlNGE4MDFmYzM="),
|
|
29
53
|
"TAPO": ("dGVzdEB0cC1saW5rLm5ldA==", "dGVzdA=="),
|
|
30
54
|
"TAPOCAMERA": ("YWRtaW4=", "YWRtaW4="),
|
|
55
|
+
"TAPOCAMERA_LV3": ("YWRtaW4=", "VFBMMDc1NTI2NDYwNjAz"),
|
|
31
56
|
}
|
kasa/device.py
CHANGED
|
@@ -6,10 +6,10 @@ Once you have a device via :ref:`Discovery <discover_target>` or
|
|
|
6
6
|
>>> from kasa import Discover
|
|
7
7
|
>>>
|
|
8
8
|
>>> dev = await Discover.discover_single(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
... "127.0.0.2",
|
|
10
|
+
... username="user@example.com",
|
|
11
|
+
... password="great_password"
|
|
12
|
+
... )
|
|
13
13
|
>>>
|
|
14
14
|
|
|
15
15
|
Most devices can be turned on and off
|
|
@@ -46,7 +46,7 @@ Devices support different functionality that are exposed via
|
|
|
46
46
|
:ref:`modules <module_target>` that you can access via :attr:`~kasa.Device.modules`:
|
|
47
47
|
|
|
48
48
|
>>> for module_name in dev.modules:
|
|
49
|
-
|
|
49
|
+
... print(module_name)
|
|
50
50
|
Energy
|
|
51
51
|
schedule
|
|
52
52
|
usage
|
|
@@ -80,11 +80,12 @@ They are useful if you want write code that dynamically adapts as new features a
|
|
|
80
80
|
added to the API.
|
|
81
81
|
|
|
82
82
|
>>> for feature_name in dev.features:
|
|
83
|
-
|
|
83
|
+
... print(feature_name)
|
|
84
84
|
state
|
|
85
85
|
rssi
|
|
86
86
|
on_since
|
|
87
87
|
reboot
|
|
88
|
+
...
|
|
88
89
|
current_consumption
|
|
89
90
|
consumption_today
|
|
90
91
|
consumption_this_month
|
|
@@ -136,15 +137,18 @@ class WifiNetwork:
|
|
|
136
137
|
"""Wifi network container."""
|
|
137
138
|
|
|
138
139
|
ssid: str
|
|
139
|
-
|
|
140
|
+
# This is available on both netif and on softaponboarding
|
|
141
|
+
key_type: int | None = None
|
|
140
142
|
# These are available only on softaponboarding
|
|
141
143
|
cipher_type: int | None = None
|
|
142
|
-
bssid: str | None = None
|
|
143
144
|
channel: int | None = None
|
|
145
|
+
# These are available on softaponboarding, SMART, and SMARTCAM devices
|
|
146
|
+
bssid: str | None = None
|
|
144
147
|
rssi: int | None = None
|
|
145
|
-
|
|
146
|
-
# For SMART devices
|
|
148
|
+
# These are available on both SMART and SMARTCAM devices
|
|
147
149
|
signal_level: int | None = None
|
|
150
|
+
auth: int | None = None
|
|
151
|
+
encryption: int | None = None
|
|
148
152
|
|
|
149
153
|
|
|
150
154
|
_LOGGER = logging.getLogger(__name__)
|
|
@@ -259,6 +263,10 @@ class Device(ABC):
|
|
|
259
263
|
def modules(self) -> ModuleMapping[Module]:
|
|
260
264
|
"""Return the device modules."""
|
|
261
265
|
|
|
266
|
+
async def supports_module(self, module: ModuleName[Module] | str) -> bool:
|
|
267
|
+
"""Return True if the device supports the module, may query the device."""
|
|
268
|
+
return module in self.modules
|
|
269
|
+
|
|
262
270
|
@property
|
|
263
271
|
@abstractmethod
|
|
264
272
|
def is_on(self) -> bool:
|
kasa/device_factory.py
CHANGED
|
@@ -104,9 +104,9 @@ async def _connect(config: DeviceConfig, protocol: BaseProtocol) -> Device:
|
|
|
104
104
|
device_class: type[Device] | None
|
|
105
105
|
device: Device | None = None
|
|
106
106
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
):
|
|
107
|
+
# For IOT devices, we need to obtain the initial sysinfo in order decide
|
|
108
|
+
# on the device class to initialize.
|
|
109
|
+
if isinstance(protocol, IotProtocol):
|
|
110
110
|
info = await protocol.query(GET_SYSINFO_QUERY)
|
|
111
111
|
_perf_log(True, "get_sysinfo")
|
|
112
112
|
device_class = get_device_class_from_sys_info(info)
|
|
@@ -142,7 +142,13 @@ def get_device_class_from_sys_info(sysinfo: dict[str, Any]) -> type[IotDevice]:
|
|
|
142
142
|
# Disabled until properly implemented
|
|
143
143
|
# DeviceType.Camera: IotCamera,
|
|
144
144
|
}
|
|
145
|
-
|
|
145
|
+
device_type = IotDevice._get_device_type_from_sys_info(sysinfo)
|
|
146
|
+
if (cls := TYPE_TO_CLASS.get(device_type)) is None:
|
|
147
|
+
raise UnsupportedDeviceError(
|
|
148
|
+
f"Unsupported device type: {device_type}",
|
|
149
|
+
discovery_result=sysinfo,
|
|
150
|
+
)
|
|
151
|
+
return cls
|
|
146
152
|
|
|
147
153
|
|
|
148
154
|
def get_device_class_from_family(
|
|
@@ -239,4 +245,10 @@ def get_protocol(config: DeviceConfig, *, strict: bool = False) -> BaseProtocol
|
|
|
239
245
|
if not (prot_tran_cls := supported_device_protocols.get(protocol_transport_key)):
|
|
240
246
|
return None
|
|
241
247
|
protocol_cls, transport_cls = prot_tran_cls
|
|
248
|
+
if (
|
|
249
|
+
protocol_transport_key == "IOT.KLAP"
|
|
250
|
+
and ctype.login_version
|
|
251
|
+
and ctype.login_version >= 2
|
|
252
|
+
):
|
|
253
|
+
transport_cls = KlapTransportV2
|
|
242
254
|
return protocol_cls(transport=transport_cls(config=config))
|
kasa/deviceconfig.py
CHANGED
|
@@ -7,10 +7,10 @@ Discovery returns a list of discovered devices:
|
|
|
7
7
|
|
|
8
8
|
>>> from kasa import Discover, Device
|
|
9
9
|
>>> device = await Discover.discover_single(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
... "127.0.0.3",
|
|
11
|
+
... username="user@example.com",
|
|
12
|
+
... password="great_password",
|
|
13
|
+
... )
|
|
14
14
|
>>> print(device.alias) # Alias is None because update() has not been called
|
|
15
15
|
None
|
|
16
16
|
|
kasa/discover.py
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"""Discover TPLink Smart Home devices.
|
|
2
2
|
|
|
3
|
-
The main entry point for this library is :
|
|
3
|
+
The main entry point for this library is :meth:`Discover.discover()`,
|
|
4
4
|
which returns a dictionary of the found devices. The key is the IP address
|
|
5
5
|
of the device and the value contains ready-to-use, SmartDevice-derived
|
|
6
6
|
device object.
|
|
7
7
|
|
|
8
|
-
:
|
|
8
|
+
:meth:`discover_single()` can be used to initialize a single device given its
|
|
9
9
|
IP address. If the :class:`DeviceConfig` of the device is already known,
|
|
10
10
|
you can initialize the corresponding device class directly without discovery.
|
|
11
11
|
|
|
@@ -27,9 +27,9 @@ Discovery returns a dict of {ip: discovered devices}:
|
|
|
27
27
|
You can pass username and password for devices requiring authentication
|
|
28
28
|
|
|
29
29
|
>>> devices = await Discover.discover(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
... username="user@example.com",
|
|
31
|
+
... password="great_password",
|
|
32
|
+
... )
|
|
33
33
|
>>> print(len(devices))
|
|
34
34
|
6
|
|
35
35
|
|
|
@@ -61,8 +61,8 @@ None
|
|
|
61
61
|
It is also possible to pass a coroutine to be executed for each found device:
|
|
62
62
|
|
|
63
63
|
>>> async def print_dev_info(dev):
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
... await dev.update()
|
|
65
|
+
... print(f"Discovered {dev.alias} (model: {dev.model})")
|
|
66
66
|
>>>
|
|
67
67
|
>>> devices = await Discover.discover(on_discovered=print_dev_info, credentials=creds)
|
|
68
68
|
Discovered Bedroom Power Strip (model: KP303)
|
|
@@ -264,6 +264,7 @@ class _DiscoverProtocol(asyncio.DatagramProtocol):
|
|
|
264
264
|
self.target = target
|
|
265
265
|
self.target_1 = (target, self.discovery_port)
|
|
266
266
|
self.target_2 = (target, Discover.DISCOVERY_PORT_2)
|
|
267
|
+
self.target_3 = (target, Discover.DISCOVERY_PORT_3)
|
|
267
268
|
|
|
268
269
|
self.discovered_devices = {}
|
|
269
270
|
self.unsupported_device_exceptions: dict = {}
|
|
@@ -333,6 +334,7 @@ class _DiscoverProtocol(asyncio.DatagramProtocol):
|
|
|
333
334
|
break
|
|
334
335
|
self.transport.sendto(encrypted_req[4:], self.target_1) # type: ignore
|
|
335
336
|
self.transport.sendto(aes_discovery_query, self.target_2) # type: ignore
|
|
337
|
+
self.transport.sendto(aes_discovery_query, self.target_3) # type: ignore
|
|
336
338
|
await asyncio.sleep(sleep_between_packets)
|
|
337
339
|
|
|
338
340
|
def datagram_received(
|
|
@@ -361,7 +363,7 @@ class _DiscoverProtocol(asyncio.DatagramProtocol):
|
|
|
361
363
|
if port == self.discovery_port:
|
|
362
364
|
json_func = Discover._get_discovery_json_legacy
|
|
363
365
|
device_func = Discover._get_device_instance_legacy
|
|
364
|
-
elif port
|
|
366
|
+
elif port in (Discover.DISCOVERY_PORT_2, Discover.DISCOVERY_PORT_3):
|
|
365
367
|
json_func = Discover._get_discovery_json
|
|
366
368
|
device_func = Discover._get_device_instance
|
|
367
369
|
else:
|
|
@@ -422,6 +424,7 @@ class Discover:
|
|
|
422
424
|
}
|
|
423
425
|
|
|
424
426
|
DISCOVERY_PORT_2 = 20002
|
|
427
|
+
DISCOVERY_PORT_3 = 20004
|
|
425
428
|
DISCOVERY_QUERY_2 = binascii.unhexlify("020000010000000000000000463cb5d3")
|
|
426
429
|
|
|
427
430
|
_redact_data = True
|
|
@@ -743,6 +746,8 @@ class Discover:
|
|
|
743
746
|
device = device_class(config.host, config=config)
|
|
744
747
|
sys_info = _extract_sys_info(info)
|
|
745
748
|
device_type = sys_info.get("mic_type", sys_info.get("type"))
|
|
749
|
+
if device_type is None:
|
|
750
|
+
raise UnsupportedDeviceError("type nor mic_type found in sysinfo response")
|
|
746
751
|
login_version = (
|
|
747
752
|
sys_info.get("stream_version") if device_type == "IOT.IPCAMERA" else None
|
|
748
753
|
)
|
|
@@ -826,6 +831,13 @@ class Discover:
|
|
|
826
831
|
# Reuse the login_version attribute to pass the max to transport
|
|
827
832
|
login_version = max([int(i) for i in et])
|
|
828
833
|
|
|
834
|
+
if not encrypt_type and encrypt_schm.is_support_https and login_version == 3:
|
|
835
|
+
# Some camera firmwares (C460 1.2.2 for one) leave encrypt_type out
|
|
836
|
+
# of mgt_encrypt_schm and send no encrypt_info, only the top level
|
|
837
|
+
# encrypt_type list. "3" is the AES login that every other camera
|
|
838
|
+
# reports as sym_schm AES.
|
|
839
|
+
encrypt_type = DeviceEncryptionType.Aes.value
|
|
840
|
+
|
|
829
841
|
if not encrypt_type:
|
|
830
842
|
raise UnsupportedDeviceError(
|
|
831
843
|
f"Unsupported device {discovery_result.ip} of type {type_} "
|
kasa/exceptions.py
CHANGED
|
@@ -135,6 +135,9 @@ class SmartErrorCode(IntEnum):
|
|
|
135
135
|
# Camera error codes
|
|
136
136
|
SESSION_EXPIRED = -40401
|
|
137
137
|
BAD_USERNAME = -40411 # determined from testing
|
|
138
|
+
# determined from testing, returned by secure-login devices (C200, H200)
|
|
139
|
+
# for an unaccepted username
|
|
140
|
+
UNKNOWN_USERNAME = -60502
|
|
138
141
|
HOMEKIT_LOGIN_FAIL = -40412
|
|
139
142
|
DEVICE_BLOCKED = -40404
|
|
140
143
|
DEVICE_FACTORY = -40405
|
kasa/feature.py
CHANGED
|
@@ -6,10 +6,10 @@ state, time, firmware.
|
|
|
6
6
|
>>> from kasa import Discover, Module
|
|
7
7
|
>>>
|
|
8
8
|
>>> dev = await Discover.discover_single(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
... "127.0.0.3",
|
|
10
|
+
... username="user@example.com",
|
|
11
|
+
... password="great_password"
|
|
12
|
+
... )
|
|
13
13
|
>>> await dev.update()
|
|
14
14
|
>>> print(dev.alias)
|
|
15
15
|
Living Room Bulb
|
|
@@ -18,7 +18,7 @@ Features allow for instrospection and can be interacted with as new features are
|
|
|
18
18
|
to the API:
|
|
19
19
|
|
|
20
20
|
>>> for feature_id, feature in dev.features.items():
|
|
21
|
-
|
|
21
|
+
... print(f"{feature.name} ({feature_id}): {feature.value}")
|
|
22
22
|
Device ID (device_id): 0000000000000000000000000000000000000000
|
|
23
23
|
State (state): True
|
|
24
24
|
Signal Level (signal_level): 2
|
|
@@ -44,7 +44,7 @@ Overheated (overheated): False
|
|
|
44
44
|
To see whether a device supports a feature, check for the existence of it:
|
|
45
45
|
|
|
46
46
|
>>> if feature := dev.features.get("brightness"):
|
|
47
|
-
|
|
47
|
+
... print(feature.value)
|
|
48
48
|
100
|
|
49
49
|
|
|
50
50
|
You can update the value of a feature
|
kasa/httpclient.py
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import asyncio
|
|
6
|
+
import builtins
|
|
6
7
|
import logging
|
|
7
8
|
import ssl
|
|
8
9
|
import time
|
|
@@ -144,7 +145,9 @@ class HttpClient:
|
|
|
144
145
|
raise _ConnectionError(
|
|
145
146
|
f"Device connection error: {self._config.host}: {ex}", ex
|
|
146
147
|
) from ex
|
|
147
|
-
|
|
148
|
+
# TimeoutError is imported from kasa.exceptions and shadows the builtin,
|
|
149
|
+
# which is what aiohttp raises when ClientTimeout(total=...) expires.
|
|
150
|
+
except (aiohttp.ServerTimeoutError, builtins.TimeoutError) as ex:
|
|
148
151
|
raise TimeoutError(
|
|
149
152
|
"Unable to query the device, "
|
|
150
153
|
+ f"timed out: {self._config.host}: {ex}",
|
kasa/interfaces/childsetup.py
CHANGED
|
@@ -6,10 +6,10 @@ hubs.
|
|
|
6
6
|
>>> from kasa import Discover, Module, LightState
|
|
7
7
|
>>>
|
|
8
8
|
>>> dev = await Discover.discover_single(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
... "127.0.0.6",
|
|
10
|
+
... username="user@example.com",
|
|
11
|
+
... password="great_password"
|
|
12
|
+
... )
|
|
13
13
|
>>> await dev.update()
|
|
14
14
|
>>> print(dev.alias)
|
|
15
15
|
Tapo Hub
|
|
@@ -27,7 +27,7 @@ The hub will pair with all supported devices in pairing mode:
|
|
|
27
27
|
'device_model': 'S200B', 'name': 'I01BU0tFRF9OQU1FIw===='}]
|
|
28
28
|
|
|
29
29
|
>>> for child in dev.children:
|
|
30
|
-
|
|
30
|
+
... print(f"{child.device_id} - {child.model}")
|
|
31
31
|
SCRUBBED_CHILD_DEVICE_ID_1 - T310
|
|
32
32
|
SCRUBBED_CHILD_DEVICE_ID_2 - T315
|
|
33
33
|
SCRUBBED_CHILD_DEVICE_ID_3 - T110
|
|
@@ -38,7 +38,7 @@ Unpair with the child `device_id`:
|
|
|
38
38
|
|
|
39
39
|
>>> await childsetup.unpair("SCRUBBED_CHILD_DEVICE_ID_4")
|
|
40
40
|
>>> for child in dev.children:
|
|
41
|
-
|
|
41
|
+
... print(f"{child.device_id} - {child.model}")
|
|
42
42
|
SCRUBBED_CHILD_DEVICE_ID_1 - T310
|
|
43
43
|
SCRUBBED_CHILD_DEVICE_ID_2 - T315
|
|
44
44
|
SCRUBBED_CHILD_DEVICE_ID_3 - T110
|
kasa/interfaces/light.py
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
>>> from kasa import Discover, Module
|
|
4
4
|
>>>
|
|
5
5
|
>>> dev = await Discover.discover_single(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
... "127.0.0.3",
|
|
7
|
+
... username="user@example.com",
|
|
8
|
+
... password="great_password"
|
|
9
|
+
... )
|
|
10
10
|
>>> await dev.update()
|
|
11
11
|
>>> print(dev.alias)
|
|
12
12
|
Living Room Bulb
|
|
@@ -44,7 +44,7 @@ All known bulbs support changing the brightness:
|
|
|
44
44
|
Bulbs supporting color temperature can be queried for the supported range:
|
|
45
45
|
|
|
46
46
|
>>> if color_temp_feature := light.get_feature("color_temp"):
|
|
47
|
-
|
|
47
|
+
... print(f"{color_temp_feature.minimum_value}, {color_temp_feature.maximum_value}")
|
|
48
48
|
2500, 6500
|
|
49
49
|
>>> await light.set_color_temp(3000)
|
|
50
50
|
>>> await dev.update()
|
kasa/interfaces/lighteffect.py
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
>>> from kasa import Discover, Module, LightState
|
|
4
4
|
>>>
|
|
5
5
|
>>> dev = await Discover.discover_single(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
... "127.0.0.3",
|
|
7
|
+
... username="user@example.com",
|
|
8
|
+
... password="great_password"
|
|
9
|
+
... )
|
|
10
10
|
>>> await dev.update()
|
|
11
11
|
>>> print(dev.alias)
|
|
12
12
|
Living Room Bulb
|
|
@@ -32,8 +32,8 @@ Party
|
|
|
32
32
|
If the device supports it you can set custom effects:
|
|
33
33
|
|
|
34
34
|
>>> if light_effect.has_custom_effects:
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
... effect_list = {"brightness": 50}
|
|
36
|
+
... await light_effect.set_custom_effect(effect_list)
|
|
37
37
|
>>> light_effect.has_custom_effects # The device in this examples does not support \
|
|
38
38
|
custom effects
|
|
39
39
|
False
|
kasa/interfaces/lightpreset.py
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
>>> from kasa import Discover, Module, LightState
|
|
4
4
|
>>>
|
|
5
5
|
>>> dev = await Discover.discover_single(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
... "127.0.0.3",
|
|
7
|
+
... username="user@example.com",
|
|
8
|
+
... password="great_password"
|
|
9
|
+
... )
|
|
10
10
|
>>> await dev.update()
|
|
11
11
|
>>> print(dev.alias)
|
|
12
12
|
Living Room Bulb
|
|
@@ -48,9 +48,9 @@ LightState(light_on=True, brightness=50, hue=0,\
|
|
|
48
48
|
You can save a new preset state if the device supports it:
|
|
49
49
|
|
|
50
50
|
>>> if light_preset.has_save_preset:
|
|
51
|
-
|
|
51
|
+
... new_preset_state = LightState(light_on=True, brightness=75, hue=0,\
|
|
52
52
|
saturation=100, color_temp=2700, transition=None)
|
|
53
|
-
|
|
53
|
+
... await light_preset.save_preset("Light preset 1", new_preset_state)
|
|
54
54
|
>>> await dev.update()
|
|
55
55
|
>>> light_preset.preset # Saving updates the preset state for the preset, it does not \
|
|
56
56
|
set the preset
|