python-kasa 0.7.1__py3-none-any.whl → 0.7.2__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 +1 -2
- kasa/device_factory.py +5 -2
- kasa/discover.py +1 -1
- kasa/emeterstatus.py +1 -1
- kasa/feature.py +3 -2
- kasa/iot/iotbulb.py +9 -3
- kasa/iot/iotdevice.py +3 -14
- kasa/iot/iotdimmer.py +8 -8
- kasa/iot/iotmodule.py +9 -8
- kasa/klaptransport.py +14 -14
- kasa/smart/modules/color.py +11 -5
- kasa/smart/modules/firmware.py +51 -24
- kasa/smart/modules/lighteffect.py +1 -1
- kasa/smart/smartmodule.py +1 -1
- kasa/smartprotocol.py +3 -2
- kasa/tests/conftest.py +1 -1
- kasa/tests/discovery_fixtures.py +2 -2
- kasa/tests/fakeprotocol_iot.py +3 -1
- kasa/tests/smart/features/test_brightness.py +8 -6
- kasa/tests/smart/features/test_colortemp.py +2 -2
- kasa/tests/smart/modules/test_autooff.py +1 -1
- kasa/tests/smart/modules/test_contact.py +1 -1
- kasa/tests/smart/modules/test_fan.py +2 -2
- kasa/tests/smart/modules/test_firmware.py +35 -5
- kasa/tests/smart/modules/test_humidity.py +1 -1
- kasa/tests/smart/modules/test_light_effect.py +1 -1
- kasa/tests/smart/modules/test_light_strip_effect.py +1 -1
- kasa/tests/smart/modules/test_motionsensor.py +1 -1
- kasa/tests/smart/modules/test_temperature.py +1 -1
- kasa/tests/smart/modules/test_temperaturecontrol.py +16 -7
- kasa/tests/smart/modules/test_waterleak.py +1 -1
- kasa/tests/test_aestransport.py +3 -3
- kasa/tests/test_bulb.py +80 -21
- kasa/tests/test_common_modules.py +12 -14
- kasa/tests/test_device.py +4 -2
- kasa/tests/test_dimmer.py +30 -10
- kasa/tests/test_discovery.py +4 -4
- kasa/tests/test_emeter.py +2 -2
- kasa/tests/test_feature.py +4 -4
- kasa/tests/test_httpclient.py +2 -2
- kasa/tests/test_iotdevice.py +20 -1
- kasa/tests/test_klapprotocol.py +6 -6
- kasa/tests/test_lightstrip.py +3 -1
- kasa/tests/test_protocol.py +22 -29
- kasa/tests/test_readme_examples.py +3 -49
- kasa/tests/test_smartprotocol.py +1 -1
- kasa/tests/test_usage.py +2 -1
- {python_kasa-0.7.1.dist-info → python_kasa-0.7.2.dist-info}/METADATA +2 -1
- {python_kasa-0.7.1.dist-info → python_kasa-0.7.2.dist-info}/RECORD +52 -52
- {python_kasa-0.7.1.dist-info → python_kasa-0.7.2.dist-info}/LICENSE +0 -0
- {python_kasa-0.7.1.dist-info → python_kasa-0.7.2.dist-info}/WHEEL +0 -0
- {python_kasa-0.7.1.dist-info → python_kasa-0.7.2.dist-info}/entry_points.txt +0 -0
kasa/aestransport.py
CHANGED
|
@@ -278,9 +278,8 @@ class AesTransport(BaseTransport):
|
|
|
278
278
|
+ "\n-----END PUBLIC KEY-----\n"
|
|
279
279
|
)
|
|
280
280
|
handshake_params = {"key": pub_key}
|
|
281
|
-
_LOGGER.debug(f"Handshake params: {handshake_params}")
|
|
282
281
|
request_body = {"method": "handshake", "params": handshake_params}
|
|
283
|
-
_LOGGER.debug(
|
|
282
|
+
_LOGGER.debug("Handshake request: %s", request_body)
|
|
284
283
|
yield json_dumps(request_body).encode()
|
|
285
284
|
|
|
286
285
|
async def perform_handshake(self) -> None:
|
kasa/device_factory.py
CHANGED
|
@@ -84,8 +84,11 @@ async def _connect(config: DeviceConfig, protocol: BaseProtocol) -> Device:
|
|
|
84
84
|
if debug_enabled:
|
|
85
85
|
end_time = time.perf_counter()
|
|
86
86
|
_LOGGER.debug(
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
"Device %s with connection params %s took %.2f seconds to %s",
|
|
88
|
+
config.host,
|
|
89
|
+
has_params,
|
|
90
|
+
end_time - start_time,
|
|
91
|
+
perf_type,
|
|
89
92
|
)
|
|
90
93
|
start_time = time.perf_counter()
|
|
91
94
|
|
kasa/discover.py
CHANGED
|
@@ -262,7 +262,7 @@ class _DiscoverProtocol(asyncio.DatagramProtocol):
|
|
|
262
262
|
self._handle_discovered_event()
|
|
263
263
|
return
|
|
264
264
|
except KasaException as ex:
|
|
265
|
-
_LOGGER.debug(
|
|
265
|
+
_LOGGER.debug("[DISCOVERY] Unable to find device type for %s: %s", ip, ex)
|
|
266
266
|
self.invalid_device_exceptions[ip] = ex
|
|
267
267
|
self._handle_discovered_event()
|
|
268
268
|
return
|
kasa/emeterstatus.py
CHANGED
kasa/feature.py
CHANGED
|
@@ -31,9 +31,10 @@ Cloud connection (cloud_connection): True
|
|
|
31
31
|
HSV (hsv): HSV(hue=0, saturation=100, value=100)
|
|
32
32
|
Color temperature (color_temperature): 2700
|
|
33
33
|
Auto update enabled (auto_update_enabled): False
|
|
34
|
-
Update available (update_available):
|
|
34
|
+
Update available (update_available): None
|
|
35
35
|
Current firmware version (current_firmware_version): 1.1.6 Build 240130 Rel.173828
|
|
36
|
-
Available firmware version (available_firmware_version):
|
|
36
|
+
Available firmware version (available_firmware_version): None
|
|
37
|
+
Check latest firmware (check_latest_firmware): <Action>
|
|
37
38
|
Light effect (light_effect): Off
|
|
38
39
|
Light preset (light_preset): Not set
|
|
39
40
|
Smooth transition on (smooth_transition_on): 2
|
kasa/iot/iotbulb.py
CHANGED
|
@@ -388,10 +388,14 @@ class IotBulb(IotDevice):
|
|
|
388
388
|
if not self._is_color:
|
|
389
389
|
raise KasaException("Bulb does not support color.")
|
|
390
390
|
|
|
391
|
-
if not isinstance(hue, int)
|
|
391
|
+
if not isinstance(hue, int):
|
|
392
|
+
raise TypeError("Hue must be an integer.")
|
|
393
|
+
if not (0 <= hue <= 360):
|
|
392
394
|
raise ValueError(f"Invalid hue value: {hue} (valid range: 0-360)")
|
|
393
395
|
|
|
394
|
-
if not isinstance(saturation, int)
|
|
396
|
+
if not isinstance(saturation, int):
|
|
397
|
+
raise TypeError("Saturation must be an integer.")
|
|
398
|
+
if not (0 <= saturation <= 100):
|
|
395
399
|
raise ValueError(
|
|
396
400
|
f"Invalid saturation value: {saturation} (valid range: 0-100%)"
|
|
397
401
|
)
|
|
@@ -445,7 +449,9 @@ class IotBulb(IotDevice):
|
|
|
445
449
|
return await self._set_light_state(light_state, transition=transition)
|
|
446
450
|
|
|
447
451
|
def _raise_for_invalid_brightness(self, value):
|
|
448
|
-
if not isinstance(value, int)
|
|
452
|
+
if not isinstance(value, int):
|
|
453
|
+
raise TypeError("Brightness must be an integer")
|
|
454
|
+
if not (0 <= value <= 100):
|
|
449
455
|
raise ValueError(f"Invalid brightness value: {value} (valid range: 0-100%)")
|
|
450
456
|
|
|
451
457
|
@property # type: ignore
|
kasa/iot/iotdevice.py
CHANGED
|
@@ -14,7 +14,6 @@ http://www.apache.org/licenses/LICENSE-2.0
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
-
import collections.abc
|
|
18
17
|
import functools
|
|
19
18
|
import inspect
|
|
20
19
|
import logging
|
|
@@ -29,22 +28,12 @@ from ..feature import Feature
|
|
|
29
28
|
from ..module import Module
|
|
30
29
|
from ..modulemapping import ModuleMapping, ModuleName
|
|
31
30
|
from ..protocol import BaseProtocol
|
|
32
|
-
from .iotmodule import IotModule
|
|
31
|
+
from .iotmodule import IotModule, merge
|
|
33
32
|
from .modules import Emeter
|
|
34
33
|
|
|
35
34
|
_LOGGER = logging.getLogger(__name__)
|
|
36
35
|
|
|
37
36
|
|
|
38
|
-
def merge(d, u):
|
|
39
|
-
"""Update dict recursively."""
|
|
40
|
-
for k, v in u.items():
|
|
41
|
-
if isinstance(v, collections.abc.Mapping):
|
|
42
|
-
d[k] = merge(d.get(k, {}), v)
|
|
43
|
-
else:
|
|
44
|
-
d[k] = v
|
|
45
|
-
return d
|
|
46
|
-
|
|
47
|
-
|
|
48
37
|
def requires_update(f):
|
|
49
38
|
"""Indicate that `update` should be called before accessing this method.""" # noqa: D202
|
|
50
39
|
if inspect.iscoroutinefunction(f):
|
|
@@ -209,7 +198,7 @@ class IotDevice(Device):
|
|
|
209
198
|
def add_module(self, name: str | ModuleName[Module], module: IotModule):
|
|
210
199
|
"""Register a module."""
|
|
211
200
|
if name in self._modules:
|
|
212
|
-
_LOGGER.debug("Module %s already registered, ignoring..."
|
|
201
|
+
_LOGGER.debug("Module %s already registered, ignoring...", name)
|
|
213
202
|
return
|
|
214
203
|
|
|
215
204
|
_LOGGER.debug("Adding module %s", module)
|
|
@@ -382,7 +371,7 @@ class IotDevice(Device):
|
|
|
382
371
|
est_response_size = 1024 if "system" in req else 0
|
|
383
372
|
for module in self._modules.values():
|
|
384
373
|
if not module.is_supported:
|
|
385
|
-
_LOGGER.debug("Module %s not supported, skipping"
|
|
374
|
+
_LOGGER.debug("Module %s not supported, skipping", module)
|
|
386
375
|
continue
|
|
387
376
|
|
|
388
377
|
est_response_size += module.estimated_query_response_size
|
kasa/iot/iotdimmer.py
CHANGED
|
@@ -118,7 +118,9 @@ class IotDimmer(IotPlug):
|
|
|
118
118
|
)
|
|
119
119
|
|
|
120
120
|
if not 0 <= brightness <= 100:
|
|
121
|
-
raise ValueError(
|
|
121
|
+
raise ValueError(
|
|
122
|
+
f"Invalid brightness value: {brightness} (valid range: 0-100%)"
|
|
123
|
+
)
|
|
122
124
|
|
|
123
125
|
# Dimmers do not support a brightness of 0, but bulbs do.
|
|
124
126
|
# Coerce 0 to 1 to maintain the same interface between dimmers and bulbs.
|
|
@@ -161,20 +163,18 @@ class IotDimmer(IotPlug):
|
|
|
161
163
|
A brightness value of 0 will turn off the dimmer.
|
|
162
164
|
"""
|
|
163
165
|
if not isinstance(brightness, int):
|
|
164
|
-
raise
|
|
165
|
-
"Brightness must be integer, " "not of %s.", type(brightness)
|
|
166
|
-
)
|
|
166
|
+
raise TypeError(f"Brightness must be an integer, not {type(brightness)}.")
|
|
167
167
|
|
|
168
168
|
if not 0 <= brightness <= 100:
|
|
169
|
-
raise ValueError(
|
|
169
|
+
raise ValueError(
|
|
170
|
+
f"Invalid brightness value: {brightness} (valid range: 0-100%)"
|
|
171
|
+
)
|
|
170
172
|
|
|
171
173
|
# If zero set to 1 millisecond
|
|
172
174
|
if transition == 0:
|
|
173
175
|
transition = 1
|
|
174
176
|
if not isinstance(transition, int):
|
|
175
|
-
raise
|
|
176
|
-
"Transition must be integer, " "not of %s.", type(transition)
|
|
177
|
-
)
|
|
177
|
+
raise TypeError(f"Transition must be integer, not of {type(transition)}.")
|
|
178
178
|
if transition <= 0:
|
|
179
179
|
raise ValueError("Transition value %s is not valid." % transition)
|
|
180
180
|
|
kasa/iot/iotmodule.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"""Base class for IOT module implementations."""
|
|
2
2
|
|
|
3
|
-
import collections
|
|
4
3
|
import logging
|
|
5
4
|
|
|
6
5
|
from ..exceptions import KasaException
|
|
@@ -9,15 +8,17 @@ from ..module import Module
|
|
|
9
8
|
_LOGGER = logging.getLogger(__name__)
|
|
10
9
|
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
def merge(d, u):
|
|
11
|
+
def _merge_dict(dest: dict, source: dict) -> dict:
|
|
14
12
|
"""Update dict recursively."""
|
|
15
|
-
for k, v in
|
|
16
|
-
if
|
|
17
|
-
|
|
13
|
+
for k, v in source.items():
|
|
14
|
+
if k in dest and type(v) is dict: # noqa: E721 - only accepts `dict` type
|
|
15
|
+
_merge_dict(dest[k], v)
|
|
18
16
|
else:
|
|
19
|
-
|
|
20
|
-
return
|
|
17
|
+
dest[k] = v
|
|
18
|
+
return dest
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
merge = _merge_dict
|
|
21
22
|
|
|
22
23
|
|
|
23
24
|
class IotModule(Module):
|
kasa/klaptransport.py
CHANGED
|
@@ -153,8 +153,8 @@ class KlapTransport(BaseTransport):
|
|
|
153
153
|
|
|
154
154
|
if _LOGGER.isEnabledFor(logging.DEBUG):
|
|
155
155
|
_LOGGER.debug(
|
|
156
|
-
"Handshake1 posted at %s. Host is %s,
|
|
157
|
-
|
|
156
|
+
"Handshake1 posted at %s. Host is %s, "
|
|
157
|
+
"Response status is %s, Request was %s",
|
|
158
158
|
datetime.datetime.now(),
|
|
159
159
|
self._host,
|
|
160
160
|
response_status,
|
|
@@ -179,7 +179,7 @@ class KlapTransport(BaseTransport):
|
|
|
179
179
|
if _LOGGER.isEnabledFor(logging.DEBUG):
|
|
180
180
|
_LOGGER.debug(
|
|
181
181
|
"Handshake1 success at %s. Host is %s, "
|
|
182
|
-
|
|
182
|
+
"Server remote_seed is: %s, server hash is: %s",
|
|
183
183
|
datetime.datetime.now(),
|
|
184
184
|
self._host,
|
|
185
185
|
remote_seed.hex(),
|
|
@@ -211,9 +211,10 @@ class KlapTransport(BaseTransport):
|
|
|
211
211
|
|
|
212
212
|
if default_credentials_seed_auth_hash == server_hash:
|
|
213
213
|
_LOGGER.debug(
|
|
214
|
-
"Server response doesn't match our expected hash on ip %s"
|
|
215
|
-
|
|
214
|
+
"Server response doesn't match our expected hash on ip %s, "
|
|
215
|
+
"but an authentication with %s default credentials matched",
|
|
216
216
|
self._host,
|
|
217
|
+
key,
|
|
217
218
|
)
|
|
218
219
|
return local_seed, remote_seed, self._default_credentials_auth_hash[key] # type: ignore
|
|
219
220
|
|
|
@@ -231,8 +232,8 @@ class KlapTransport(BaseTransport):
|
|
|
231
232
|
|
|
232
233
|
if blank_seed_auth_hash == server_hash:
|
|
233
234
|
_LOGGER.debug(
|
|
234
|
-
"Server response doesn't match our expected hash on ip %s"
|
|
235
|
-
|
|
235
|
+
"Server response doesn't match our expected hash on ip %s, "
|
|
236
|
+
"but an authentication with blank credentials matched",
|
|
236
237
|
self._host,
|
|
237
238
|
)
|
|
238
239
|
return local_seed, remote_seed, self._blank_auth_hash # type: ignore
|
|
@@ -260,8 +261,8 @@ class KlapTransport(BaseTransport):
|
|
|
260
261
|
|
|
261
262
|
if _LOGGER.isEnabledFor(logging.DEBUG):
|
|
262
263
|
_LOGGER.debug(
|
|
263
|
-
"Handshake2 posted %s.
|
|
264
|
-
|
|
264
|
+
"Handshake2 posted %s. Host is %s, "
|
|
265
|
+
"Response status is %s, Request was %s",
|
|
265
266
|
datetime.datetime.now(),
|
|
266
267
|
self._host,
|
|
267
268
|
response_status,
|
|
@@ -338,18 +339,17 @@ class KlapTransport(BaseTransport):
|
|
|
338
339
|
+ f"Response status is {response_status}, Request was {request}"
|
|
339
340
|
)
|
|
340
341
|
if response_status != 200:
|
|
341
|
-
_LOGGER.error("Query failed after successful authentication "
|
|
342
|
+
_LOGGER.error("Query failed after successful authentication: %s", msg)
|
|
342
343
|
# If we failed with a security error, force a new handshake next time.
|
|
343
344
|
if response_status == 403:
|
|
344
345
|
self._handshake_done = False
|
|
345
346
|
raise _RetryableError(
|
|
346
|
-
|
|
347
|
-
+ "completed"
|
|
347
|
+
"Got a security error from %s after handshake completed", self._host
|
|
348
348
|
)
|
|
349
349
|
else:
|
|
350
350
|
raise KasaException(
|
|
351
|
-
f"Device {self._host} responded with {response_status} to"
|
|
352
|
-
|
|
351
|
+
f"Device {self._host} responded with {response_status} to "
|
|
352
|
+
f"request with seq {seq}"
|
|
353
353
|
)
|
|
354
354
|
else:
|
|
355
355
|
_LOGGER.debug("Device %s query posted %s", self._host, msg)
|
kasa/smart/modules/color.py
CHANGED
|
@@ -51,10 +51,12 @@ class Color(SmartModule):
|
|
|
51
51
|
|
|
52
52
|
return HSV(hue=h, saturation=s, value=v)
|
|
53
53
|
|
|
54
|
-
def _raise_for_invalid_brightness(self, value
|
|
54
|
+
def _raise_for_invalid_brightness(self, value):
|
|
55
55
|
"""Raise error on invalid brightness value."""
|
|
56
|
-
if not isinstance(value, int)
|
|
57
|
-
raise
|
|
56
|
+
if not isinstance(value, int):
|
|
57
|
+
raise TypeError("Brightness must be an integer")
|
|
58
|
+
if not (0 <= value <= 100):
|
|
59
|
+
raise ValueError(f"Invalid brightness value: {value} (valid range: 0-100%)")
|
|
58
60
|
|
|
59
61
|
async def set_hsv(
|
|
60
62
|
self,
|
|
@@ -73,10 +75,14 @@ class Color(SmartModule):
|
|
|
73
75
|
:param int value: value in percentage [0, 100]
|
|
74
76
|
:param int transition: transition in milliseconds.
|
|
75
77
|
"""
|
|
76
|
-
if not isinstance(hue, int)
|
|
78
|
+
if not isinstance(hue, int):
|
|
79
|
+
raise TypeError("Hue must be an integer")
|
|
80
|
+
if not (0 <= hue <= 360):
|
|
77
81
|
raise ValueError(f"Invalid hue value: {hue} (valid range: 0-360)")
|
|
78
82
|
|
|
79
|
-
if not isinstance(saturation, int)
|
|
83
|
+
if not isinstance(saturation, int):
|
|
84
|
+
raise TypeError("Saturation must be an integer")
|
|
85
|
+
if not (0 <= saturation <= 100):
|
|
80
86
|
raise ValueError(
|
|
81
87
|
f"Invalid saturation value: {saturation} (valid range: 0-100%)"
|
|
82
88
|
)
|
kasa/smart/modules/firmware.py
CHANGED
|
@@ -6,13 +6,14 @@ import asyncio
|
|
|
6
6
|
import logging
|
|
7
7
|
from collections.abc import Coroutine
|
|
8
8
|
from datetime import date
|
|
9
|
-
from typing import TYPE_CHECKING,
|
|
9
|
+
from typing import TYPE_CHECKING, Callable, Optional
|
|
10
10
|
|
|
11
11
|
# When support for cpython older than 3.11 is dropped
|
|
12
12
|
# async_timeout can be replaced with asyncio.timeout
|
|
13
13
|
from async_timeout import timeout as asyncio_timeout
|
|
14
14
|
from pydantic.v1 import BaseModel, Field, validator
|
|
15
15
|
|
|
16
|
+
from ...exceptions import KasaException
|
|
16
17
|
from ...feature import Feature
|
|
17
18
|
from ..smartmodule import SmartModule, allow_update_after
|
|
18
19
|
|
|
@@ -70,6 +71,11 @@ class Firmware(SmartModule):
|
|
|
70
71
|
|
|
71
72
|
def __init__(self, device: SmartDevice, module: str):
|
|
72
73
|
super().__init__(device, module)
|
|
74
|
+
self._firmware_update_info: UpdateInfo | None = None
|
|
75
|
+
|
|
76
|
+
def _initialize_features(self):
|
|
77
|
+
"""Initialize features."""
|
|
78
|
+
device = self._device
|
|
73
79
|
if self.supported_version > 1:
|
|
74
80
|
self._add_feature(
|
|
75
81
|
Feature(
|
|
@@ -115,13 +121,34 @@ class Firmware(SmartModule):
|
|
|
115
121
|
type=Feature.Type.Sensor,
|
|
116
122
|
)
|
|
117
123
|
)
|
|
124
|
+
self._add_feature(
|
|
125
|
+
Feature(
|
|
126
|
+
device,
|
|
127
|
+
id="check_latest_firmware",
|
|
128
|
+
name="Check latest firmware",
|
|
129
|
+
container=self,
|
|
130
|
+
attribute_setter="check_latest_firmware",
|
|
131
|
+
category=Feature.Category.Info,
|
|
132
|
+
type=Feature.Type.Action,
|
|
133
|
+
)
|
|
134
|
+
)
|
|
118
135
|
|
|
119
136
|
def query(self) -> dict:
|
|
120
137
|
"""Query to execute during the update cycle."""
|
|
121
|
-
req: dict[str, Any] = {"get_latest_fw": None}
|
|
122
138
|
if self.supported_version > 1:
|
|
123
|
-
|
|
124
|
-
return
|
|
139
|
+
return {"get_auto_update_info": None}
|
|
140
|
+
return {}
|
|
141
|
+
|
|
142
|
+
async def check_latest_firmware(self) -> UpdateInfo | None:
|
|
143
|
+
"""Check for the latest firmware for the device."""
|
|
144
|
+
try:
|
|
145
|
+
fw = await self.call("get_latest_fw")
|
|
146
|
+
self._firmware_update_info = UpdateInfo.parse_obj(fw["get_latest_fw"])
|
|
147
|
+
return self._firmware_update_info
|
|
148
|
+
except Exception:
|
|
149
|
+
_LOGGER.exception("Error getting latest firmware for %s:", self._device)
|
|
150
|
+
self._firmware_update_info = None
|
|
151
|
+
return None
|
|
125
152
|
|
|
126
153
|
@property
|
|
127
154
|
def current_firmware(self) -> str:
|
|
@@ -129,26 +156,23 @@ class Firmware(SmartModule):
|
|
|
129
156
|
return self._device.hw_info["sw_ver"]
|
|
130
157
|
|
|
131
158
|
@property
|
|
132
|
-
def latest_firmware(self) -> str:
|
|
159
|
+
def latest_firmware(self) -> str | None:
|
|
133
160
|
"""Return the latest firmware version."""
|
|
134
|
-
|
|
161
|
+
if not self._firmware_update_info:
|
|
162
|
+
return None
|
|
163
|
+
return self._firmware_update_info.version
|
|
135
164
|
|
|
136
165
|
@property
|
|
137
|
-
def firmware_update_info(self):
|
|
166
|
+
def firmware_update_info(self) -> UpdateInfo | None:
|
|
138
167
|
"""Return latest firmware information."""
|
|
139
|
-
|
|
140
|
-
# Error in response, probably disconnected from the cloud.
|
|
141
|
-
return UpdateInfo(type=0, need_to_upgrade=False)
|
|
142
|
-
|
|
143
|
-
fw = self.data.get("get_latest_fw") or self.data
|
|
144
|
-
return UpdateInfo.parse_obj(fw)
|
|
168
|
+
return self._firmware_update_info
|
|
145
169
|
|
|
146
170
|
@property
|
|
147
171
|
def update_available(self) -> bool | None:
|
|
148
172
|
"""Return True if update is available."""
|
|
149
|
-
if not self._device.is_cloud_connected:
|
|
173
|
+
if not self._device.is_cloud_connected or not self._firmware_update_info:
|
|
150
174
|
return None
|
|
151
|
-
return self.
|
|
175
|
+
return self._firmware_update_info.update_available
|
|
152
176
|
|
|
153
177
|
async def get_update_state(self) -> DownloadState:
|
|
154
178
|
"""Return update state."""
|
|
@@ -161,11 +185,17 @@ class Firmware(SmartModule):
|
|
|
161
185
|
self, progress_cb: Callable[[DownloadState], Coroutine] | None = None
|
|
162
186
|
):
|
|
163
187
|
"""Update the device firmware."""
|
|
188
|
+
if not self._firmware_update_info:
|
|
189
|
+
raise KasaException(
|
|
190
|
+
"You must call check_latest_firmware before calling update"
|
|
191
|
+
)
|
|
192
|
+
if not self.update_available:
|
|
193
|
+
raise KasaException("A new update must be available to call update")
|
|
164
194
|
current_fw = self.current_firmware
|
|
165
195
|
_LOGGER.info(
|
|
166
196
|
"Going to upgrade from %s to %s",
|
|
167
197
|
current_fw,
|
|
168
|
-
self.
|
|
198
|
+
self._firmware_update_info.version,
|
|
169
199
|
)
|
|
170
200
|
await self.call("fw_download")
|
|
171
201
|
|
|
@@ -181,14 +211,14 @@ class Firmware(SmartModule):
|
|
|
181
211
|
)
|
|
182
212
|
continue
|
|
183
213
|
|
|
184
|
-
_LOGGER.debug("Update state: %s"
|
|
214
|
+
_LOGGER.debug("Update state: %s", state)
|
|
185
215
|
if progress_cb is not None:
|
|
186
216
|
asyncio.create_task(progress_cb(state))
|
|
187
217
|
|
|
188
218
|
if state.status == 0:
|
|
189
219
|
_LOGGER.info(
|
|
190
220
|
"Update idle, hopefully updated to %s",
|
|
191
|
-
self.
|
|
221
|
+
self._firmware_update_info.version,
|
|
192
222
|
)
|
|
193
223
|
break
|
|
194
224
|
elif state.status == 2:
|
|
@@ -207,15 +237,12 @@ class Firmware(SmartModule):
|
|
|
207
237
|
_LOGGER.warning("Unhandled state code: %s", state)
|
|
208
238
|
|
|
209
239
|
@property
|
|
210
|
-
def auto_update_enabled(self):
|
|
240
|
+
def auto_update_enabled(self) -> bool:
|
|
211
241
|
"""Return True if autoupdate is enabled."""
|
|
212
|
-
return
|
|
213
|
-
"get_auto_update_info" in self.data
|
|
214
|
-
and self.data["get_auto_update_info"]["enable"]
|
|
215
|
-
)
|
|
242
|
+
return "enable" in self.data and self.data["enable"]
|
|
216
243
|
|
|
217
244
|
@allow_update_after
|
|
218
245
|
async def set_auto_update_enabled(self, enabled: bool):
|
|
219
246
|
"""Change autoupdate setting."""
|
|
220
|
-
data = {**self.data
|
|
247
|
+
data = {**self.data, "enable": enabled}
|
|
221
248
|
await self.call("set_auto_update_info", data)
|
|
@@ -90,7 +90,7 @@ class LightEffect(SmartModule, SmartLightEffect):
|
|
|
90
90
|
"""
|
|
91
91
|
if effect != self.LIGHT_EFFECTS_OFF and effect not in self._scenes_names_to_id:
|
|
92
92
|
raise ValueError(
|
|
93
|
-
f"
|
|
93
|
+
f"The effect {effect} is not a built in effect. Possible values "
|
|
94
94
|
f"are: {self.LIGHT_EFFECTS_OFF} "
|
|
95
95
|
f"{' '.join(self._scenes_names_to_id.keys())}"
|
|
96
96
|
)
|
kasa/smart/smartmodule.py
CHANGED
|
@@ -77,7 +77,7 @@ class SmartModule(Module):
|
|
|
77
77
|
|
|
78
78
|
def __init_subclass__(cls, **kwargs):
|
|
79
79
|
name = getattr(cls, "NAME", cls.__name__)
|
|
80
|
-
_LOGGER.debug("Registering %s"
|
|
80
|
+
_LOGGER.debug("Registering %s", cls)
|
|
81
81
|
cls.REGISTERED_MODULES[name] = cls
|
|
82
82
|
|
|
83
83
|
def _set_error(self, err: Exception | None):
|
kasa/smartprotocol.py
CHANGED
|
@@ -309,8 +309,9 @@ class SmartProtocol(BaseProtocol):
|
|
|
309
309
|
# In case the device returns empty lists avoid infinite looping
|
|
310
310
|
if not next_batch[response_list_name]:
|
|
311
311
|
_LOGGER.error(
|
|
312
|
-
|
|
313
|
-
|
|
312
|
+
"Device %s returned empty results list for method %s",
|
|
313
|
+
self._host,
|
|
314
|
+
method,
|
|
314
315
|
)
|
|
315
316
|
break
|
|
316
317
|
response_result[response_list_name].extend(next_batch[response_list_name])
|
kasa/tests/conftest.py
CHANGED
kasa/tests/discovery_fixtures.py
CHANGED
|
@@ -75,7 +75,7 @@ new_discovery = parametrize_discovery(
|
|
|
75
75
|
async def discovery_mock(request, mocker):
|
|
76
76
|
"""Mock discovery and patch protocol queries to use Fake protocols."""
|
|
77
77
|
fixture_info: FixtureInfo = request.param
|
|
78
|
-
|
|
78
|
+
return patch_discovery({DISCOVERY_MOCK_IP: fixture_info}, mocker)
|
|
79
79
|
|
|
80
80
|
|
|
81
81
|
def create_discovery_mock(ip: str, fixture_data: dict):
|
|
@@ -253,4 +253,4 @@ def unsupported_device_info(request, mocker):
|
|
|
253
253
|
|
|
254
254
|
mocker.patch("kasa.discover._DiscoverProtocol.do_discover", mock_discover)
|
|
255
255
|
|
|
256
|
-
|
|
256
|
+
return discovery_data
|
kasa/tests/fakeprotocol_iot.py
CHANGED
|
@@ -425,7 +425,9 @@ class FakeIotTransport(BaseTransport):
|
|
|
425
425
|
return error(msg=f"command {cmd} not found")
|
|
426
426
|
|
|
427
427
|
params = request[target][cmd]
|
|
428
|
-
_LOGGER.debug(
|
|
428
|
+
_LOGGER.debug(
|
|
429
|
+
"Going to execute %s.%s (params: %s).. ", target, cmd, params
|
|
430
|
+
)
|
|
429
431
|
|
|
430
432
|
if callable(proto[target][cmd]):
|
|
431
433
|
res = proto[target][cmd](self, params, child_ids)
|
|
@@ -18,17 +18,18 @@ async def test_brightness_component(dev: SmartDevice):
|
|
|
18
18
|
# Test getting the value
|
|
19
19
|
feature = brightness._device.features["brightness"]
|
|
20
20
|
assert isinstance(feature.value, int)
|
|
21
|
-
assert feature.value > 1
|
|
21
|
+
assert feature.value > 1
|
|
22
|
+
assert feature.value <= 100
|
|
22
23
|
|
|
23
24
|
# Test setting the value
|
|
24
25
|
await feature.set_value(10)
|
|
25
26
|
await dev.update()
|
|
26
27
|
assert feature.value == 10
|
|
27
28
|
|
|
28
|
-
with pytest.raises(ValueError):
|
|
29
|
+
with pytest.raises(ValueError, match="out of range"):
|
|
29
30
|
await feature.set_value(feature.minimum_value - 10)
|
|
30
31
|
|
|
31
|
-
with pytest.raises(ValueError):
|
|
32
|
+
with pytest.raises(ValueError, match="out of range"):
|
|
32
33
|
await feature.set_value(feature.maximum_value + 10)
|
|
33
34
|
|
|
34
35
|
|
|
@@ -41,15 +42,16 @@ async def test_brightness_dimmable(dev: IotDevice):
|
|
|
41
42
|
# Test getting the value
|
|
42
43
|
feature = dev.features["brightness"]
|
|
43
44
|
assert isinstance(feature.value, int)
|
|
44
|
-
assert feature.value > 0
|
|
45
|
+
assert feature.value > 0
|
|
46
|
+
assert feature.value <= 100
|
|
45
47
|
|
|
46
48
|
# Test setting the value
|
|
47
49
|
await feature.set_value(10)
|
|
48
50
|
await dev.update()
|
|
49
51
|
assert feature.value == 10
|
|
50
52
|
|
|
51
|
-
with pytest.raises(ValueError):
|
|
53
|
+
with pytest.raises(ValueError, match="out of range"):
|
|
52
54
|
await feature.set_value(feature.minimum_value - 10)
|
|
53
55
|
|
|
54
|
-
with pytest.raises(ValueError):
|
|
56
|
+
with pytest.raises(ValueError, match="out of range"):
|
|
55
57
|
await feature.set_value(feature.maximum_value + 10)
|
|
@@ -23,8 +23,8 @@ async def test_colortemp_component(dev: SmartDevice):
|
|
|
23
23
|
await dev.update()
|
|
24
24
|
assert feature.value == new_value
|
|
25
25
|
|
|
26
|
-
with pytest.raises(ValueError):
|
|
26
|
+
with pytest.raises(ValueError, match="out of range"):
|
|
27
27
|
await feature.set_value(feature.minimum_value - 10)
|
|
28
28
|
|
|
29
|
-
with pytest.raises(ValueError):
|
|
29
|
+
with pytest.raises(ValueError, match="out of range"):
|
|
30
30
|
await feature.set_value(feature.maximum_value + 10)
|
|
@@ -76,8 +76,8 @@ async def test_fan_module(dev: SmartDevice, mocker: MockerFixture):
|
|
|
76
76
|
await dev.update()
|
|
77
77
|
assert not device.is_on
|
|
78
78
|
|
|
79
|
-
with pytest.raises(ValueError):
|
|
79
|
+
with pytest.raises(ValueError, match="Invalid level"):
|
|
80
80
|
await fan.set_fan_speed_level(-1)
|
|
81
81
|
|
|
82
|
-
with pytest.raises(ValueError):
|
|
82
|
+
with pytest.raises(ValueError, match="Invalid level"):
|
|
83
83
|
await fan.set_fan_speed_level(5)
|