Commit Graph

617 Commits

Author SHA1 Message Date
Steven B.
3086aa8a20
Use component queries to select smartcamera modules (#1248) 2024-11-13 10:21:12 +00:00
Steven B.
254a9af5c1
Update DiscoveryResult to use Mashumaro instead of pydantic (#1231)
Mashumaro is faster and doesn't come with all versioning problems that
pydantic does.

A basic perf test deserializing all of our discovery results fixtures
shows mashumaro as being about 6 times faster deserializing dicts than
pydantic. It's much faster parsing from a json string but that's likely
because it uses orjson under the hood although that's not really our use
case at the moment.

```
PYDANTIC - ms
=================
json       dict
-----------------
4.7665     1.3268
3.1548     1.5922
3.1130     1.8039
4.2834     2.7606
2.0669     1.3757
2.0163     1.6377
3.1667     1.3561
4.1296     2.7297
2.0132     1.3471
4.0648     1.4105

MASHUMARO - ms
=================
json       dict
-----------------
0.5977     0.5543
0.5336     0.2983
0.3955     0.2549
0.6516     0.2742
0.5386     0.2706
0.6678     0.2580
0.4120     0.2511
0.3836     0.2472
0.4020     0.2465
0.4268     0.2487
```
2024-11-12 22:00:04 +01:00
Steven B.
9d5e07b969
Add SmartCamera Led Module (#1249) 2024-11-12 19:34:02 +00:00
Teemu R.
668ba748c5
Move transports into their own package (#1247)
This moves all transport implementations into a new `transports` package
for cleaner main package & easier to understand project structure.
2024-11-12 14:40:44 +01:00
Steven B.
71ae06fa83
Fix test framework running against real devices (#1235) 2024-11-11 17:41:31 +00:00
Steven B.
32671da9e9
Move tests folder to top level of project (#1242) 2024-11-11 10:11:31 +00:00
Teemu R.
e5dd874333
Update fixture for ES20M 1.0.11 (#1215) 2024-11-11 09:31:13 +00:00
Teemu R.
66eb17057e
Enable ruff check for ANN (#1139) 2024-11-10 18:55:13 +00:00
Teemu R.
24d7b8612e
Add L630 fixture (#1240) 2024-11-10 13:56:14 +00:00
Puxtril
4e9a3e6b02
Print formatting for IotLightPreset (#1216)
Now prints presets as such:

```
[0] Hue:   0  Saturation:   0  Brightness/Value: 100  Temp: 6000  Custom: None  Mode: None  Id: None
[1] Hue:   0  Saturation:   0  Brightness/Value: 100  Temp: 2500  Custom: None  Mode: None  Id: None
[2] Hue:   0  Saturation:   0  Brightness/Value:  60  Temp: 2500  Custom: None  Mode: None  Id: None
[3] Hue: 240  Saturation: 100  Brightness/Value: 100  Temp:    0  Custom: None  Mode: None  Id: None
```
2024-11-09 18:03:06 +01:00
Ryan Nitcher
857a706649
Add Additional Firmware Test Fixures (#1234)
Fixtures for the following new firmware versions on existing devices:

- ES20M(US)_1.0_1.0.11
- HS200(US)_3.0_1.1.5
- HS200(US)_5.0_1.0.11
- HS210(US)_2.0_1.1.5
- KP303(US)_2.0_1.0.9
- KS200M(US)_1.0_1.0.10
- KP125M(US)_1.0_1.2.3
- KS240(US)_1.0_1.0.7
2024-11-09 07:16:41 +00:00
Ryan Nitcher
a4df014328
Add KS220 Fixture (#1237)
Add Fixture for
[KS220](https://www.kasasmart.com/us/products/smart-switches/kasa-smart-wifi-light-switch-dimmer-ks220),
Smart Wi-Fi Light Switch, Dimmer (HomeKit).
2024-11-09 02:50:21 +01:00
Ryan Nitcher
6039760186
Add EP40M Fixture (#1238)
Add fixture for
[EP40M](https://www.kasasmart.com/us/products/smart-plugs/smart-wifi-outdoor-plug-ep40m),
Smart Wi-Fi Outdoor Plug (Matter).
2024-11-09 01:47:56 +01:00
Teemu R.
4026e8a80c
Make __repr__ work on discovery info (#1233)
This PR will make `__repr__` also work on smartdevices where only
discovery data is available by modifying the `model` property to
fallback to the data found in the discovery payloads.
2024-11-07 20:09:51 +01:00
Teemu R.
b2f3971a4c
Add PIR&LAS for wall switches mentioning PIR support (#1227)
Some devices (like KS200M) support ambient and motion, but as they are
detected as wall switches, they don't get the modules added.
This PR enables the respective modules for wall switches when the
`dev_name` contains `PIR`.
2024-11-03 16:45:48 +01:00
Teemu R.
0360107e3f
Add childprotection module (#1141)
When turned on, rotating the thermostat will not change the target
temperature.
2024-11-01 20:46:36 +01:00
Steven B.
77b654a9aa
Update try_connect_all to be more efficient and report attempts (#1222) 2024-11-01 18:17:18 +00:00
Teemu R.
70c96b5a5d
Initial trigger logs implementation (#900)
Co-authored-by: Steven B. <51370195+sdb9696@users.noreply.github.com>
2024-11-01 15:36:09 +00:00
Teemu R.
8969b54b87
Update TC65 fixture (#1225) 2024-11-01 15:17:52 +00:00
Steven B.
7335a7d33f
Update smartcamera fixtures from latest dump_devinfo (#1224) 2024-11-01 15:15:13 +00:00
Steven B.
54f0e91c04
Add component queries to smartcamera devices (#1223) 2024-11-01 14:52:39 +00:00
Steven B.
e73da5b677
Fix AES child device creation error (#1220)
Bug exposed when passing credentials_hash and creating child devices for
klap devices as the default is to try to create an AES transport and the
credentials hashes are incompatible.
2024-10-31 15:21:54 +00:00
Teemu R.
5da41fcc11
Use stacklevel=2 for warnings to report on callsites (#1219)
Use stacklevel=2 for warnings, as this will correctly show the callsite
instead of the line where the warning is reported.

Currently:
```
kasa/__init__.py:110
  /home/tpr/code/python-kasa/kasa/__init__.py:110: DeprecationWarning: SmartDevice is deprecated, use IotDevice from package kasa.iot instead or use Discover.discover_single() and Device.connect() to support new protocols
    warn(
```

After:
```
kasa/tests/smart/modules/test_contact.py:3
  /home/tpr/code/python-kasa/kasa/tests/smart/modules/test_contact.py:3: DeprecationWarning: SmartDevice is deprecated, use IotDevice from package kasa.iot instead or use Discover.discover_single() and Device.connect() to support new protocols
    from kasa import Module, SmartDevice

``` 

Currently:
```
kasa/tests/test_lightstrip.py: 56 warnings
  /home/tpr/code/python-kasa/kasa/device.py:559: DeprecationWarning: effect is deprecated, use: Module.LightEffect in device.modules instead
    warn(msg, DeprecationWarning, stacklevel=1)
```

After:
```
kasa/tests/test_lightstrip.py::test_effects_lightstrip_set_effect_transition[500-KL430(US)_2.0_1.0.9.json]
  /home/tpr/code/python-kasa/kasa/tests/test_lightstrip.py:62: DeprecationWarning: set_effect is deprecated, use: Module.LightEffect in device.modules instead
    await dev.set_effect("Candy Cane")
```
2024-10-31 14:12:17 +01:00
Teemu R.
6c141c3b65
Expose ambient light setting for iot dimmers (#1210)
This PR adds a setting to control the ambient light enabled/disabled.

Also fixes the getters.
2024-10-31 12:17:18 +01:00
Teemu R.
9975bbf26a
Expose PIR enabled setting for iot dimmers (#1174)
This adds PIR enabled feature to iot dimmers, making it possible to
enable and disable the motion detection.
2024-10-31 10:41:11 +00:00
Steven B.
673a32258f
Make HSV NamedTuple creation more efficient (#1211) 2024-10-29 17:14:52 +00:00
Steven B.
6d8dc1cc5f
Only send 20002 discovery request with key included (#1207) 2024-10-29 16:21:24 +00:00
Steven B.
b82743a5de
Do not pass None as timeout to http requests (#1203) 2024-10-29 11:52:53 +00:00
Steven B.
450bcf0bde
Add S200B(US) fw 1.12.0 fixture (#1181) 2024-10-29 09:49:49 +00:00
Teemu R.
5cde7cba27
Add S200D button fixtures (#1161)
Co-authored-by: Steven B <51370195+sdb9696@users.noreply.github.com>
2024-10-29 09:37:34 +00:00
Steven B.
4aec9d302f
Allow enabling experimental devices from environment variable (#1194) 2024-10-29 09:30:30 +00:00
Steven B.
ad6472c05d
Add H200(EU) fw 1.3.2 fixture (#1204) 2024-10-29 09:18:17 +00:00
Steven B.
fdadeebaa9
Add S200B(EU) fw 1.11.0 fixture (#1205)
Adds a note about button presses not being supported.
2024-10-29 09:58:47 +01:00
Steven B.
e7f921299a
Fix smartcamera childdevice module (#1206)
Unlike most `smartcamera` queries, the child info query request and response have
different section names, i.e. `controlChild` and `child_device_list` respectively.
2024-10-29 07:11:31 +00:00
Steven B.
440b2d153b
Fix SslAesTransport default login and add tests (#1202)
Co-authored-by: Teemu R. <tpr@iki.fi>
2024-10-28 16:36:34 +00:00
Teemu R.
0287606235
Add TC65 fixture (#1200) 2024-10-28 13:47:24 +01:00
Fulch36
c051e75d1d
Add P304M(UK) test fixture (#1185)
P304M supports energy monitoring on child SMART devices.
2024-10-27 12:15:13 +00:00
Steven B.
5161115621
Update SMART test framework to use fake child protocols (#1199) 2024-10-27 12:08:02 +00:00
Steven B.
88b7951fee
Allow passing an aiohttp client session during discover try_connect_all (#1198) 2024-10-25 19:43:37 +01:00
Steven B.
7eb8d45b6e
Try default logon credentials in SslAesTransport (#1195)
Also ensure `AuthenticationErrors` are raised during handshake1.
2024-10-25 19:27:40 +01:00
Fulch36
8b95b7d557
Fallback to get_current_power if get_energy_usage does not provide current_power (#1186) 2024-10-25 19:24:43 +01:00
Steven B.
1e0ca799bc
Add stream_rtsp_url to camera module (#1197) 2024-10-25 18:30:21 +01:00
Steven B.
91e219f467
Fix device_config serialisation of https value (#1196) 2024-10-25 18:04:43 +01:00
Steven B.
e3610cf37e
Add Time module to SmartCamera devices (#1182) 2024-10-24 19:11:21 +01:00
Steven B.
28361c1727
Add core device, child and camera modules to smartcamera (#1193)
Co-authored-by: Teemu R. <tpr@iki.fi>
2024-10-24 17:22:45 +01:00
Steven B.
8ee8c17bdc
Update smartcamera to support single get/set/do requests (#1187)
Not supported by H200 hub
2024-10-24 13:11:28 +01:00
Steven B.
c839aaa1dd
Add test framework for smartcamera (#1192) 2024-10-24 09:36:18 +01:00
Steven B.
51958d8078
Allow deriving from SmartModule without being registered (#1189) 2024-10-23 21:42:01 +01:00
Steven B.
a88b677776
Combine smartcamera error codes into SmartErrorCode (#1190)
Having these in a seperate place complicates the code unnecessarily.
2024-10-23 20:07:32 +01:00
Steven B.
a0f3f016a2
Rename experimental fixtures folder to smartcamera (#1191) 2024-10-23 19:26:11 +01:00
Steven B.
cd0a74ca96
Improve supported module checks for hub children (#1188)
No devices in `fixtures/smart/child` support the `get_device_time` or
`get_device_usage` methods so this PR tests for whether the device is a
hub child and marks those modules/methods as not supported. This
prevents features being erroneously created on child devices.

It also moves the logic for getting the time from the parent module
behind getting it from the child module which was masking the creation
of these unsupported modules.
2024-10-23 17:17:27 +02:00
Steven B.
048c84d72c
Add https parameter to device class factory (#1184)
`SMART.TAPOHUB` resolves to different device classes based on the https value
2024-10-22 18:09:35 +01:00
Steven B.
3c865b5fb6
Add try_connect_all to allow initialisation without udp broadcast (#1171)
- Try all valid combinations of protocol/transport/device class and attempt to connect. 
- Add cli command `discover config` to return the connection options after connecting via `try_connect_all`.
- The cli command does not return the actual device for processing as this is not a recommended way to regularly connect to devices.
2024-10-22 14:33:46 +01:00
Steven B.
852116795c
Add discovery list command to cli (#1183)
Report discovered devices in a concise table format.
2024-10-22 12:15:08 +01:00
Steven B.
53fafc3994
Add T110(US), T310(US) and T315(US) sensor fixtures (#1179)
Many thanks to @SirWaddles for the fixtures!
2024-10-18 16:05:53 +02:00
Steven B.
d5450d89ff
Add H200 experimental fixture (#1180) 2024-10-18 14:02:08 +01:00
Teemu R.
6ba7c4ac05
Convert fixtures to use unix newlines (#1177)
Also, add a .gitattributes entry to let git handle this automatically
for json files
2024-10-18 14:00:23 +02:00
Teemu R.
8a17752ae2
Add waterleak alert timestamp (#1162)
The T300 reports the timestamp of the last alarm, this exposes it to
consumers.
2024-10-18 13:18:12 +02:00
Steven B.
acd0202cab
Update dump_devinfo for smart camera protocol (#1169)
Introduces the child camera protocol wrapper, required to get the child device info with the new protocol.
2024-10-18 12:06:22 +01:00
Teemu R.
486984fff8
Add motion sensor to known categories (#1176)
Also, improve device type warning on unknown devices
2024-10-18 12:31:52 +02:00
Steven B.
2dd621675a
Drop urllib3 dependency and create ssl context in executor thread (#1175) 2024-10-18 11:40:17 +02:00
Steven B.
c6f2d89d44
Expose smart child device map as a class constant (#1173)
To facilitate distinguishing between smart and smart camera child devices.
2024-10-18 09:55:07 +01:00
Steven B.
dcc36e1dfe
Initial TapoCamera support (#1165)
Adds experimental support for the Tapo Camera protocol also used by the H200 hub.
Creates a new SslAesTransport and a derived SmartCamera and SmartCameraProtocol.
2024-10-16 16:53:52 +01:00
Steven B.
380fbb93c3
Enable newer encrypted discovery protocol (#1168) 2024-10-16 15:28:27 +01:00
Steven B.
7fd8c14c1f
Create common Time module and add time set cli command (#1157) 2024-10-15 08:59:25 +01:00
Steven B.
bd5a24b0ed
Use tzinfo in time constructor instead of astime for iot devices (#1158)
Fixes using `astime` on a non tzinfo aware object which causes issues with daylight saving.
2024-10-08 12:33:19 +01:00
Steven B.
7c1686d3ae
Cache zoneinfo for smart devices (#1156) 2024-10-08 12:21:01 +01:00
Steven B.
9641edcbc0
Make iot time timezone aware (#1147)
Also makes on_since for iot devices use device time.
Changes the return value for device.timezone to be tzinfo instead of a dict.
2024-10-08 08:16:51 +01:00
Steven B.
8bb2cca7cf
Remove async magic patch from tests (#1146)
Not required since AsyncMock available in python 3.8 and probably better
to keep magic to a minimum.
2024-10-02 17:12:10 +02:00
Steven B.
1026e890a1
Correctly define SmartModule.call as an async function (#1148) 2024-10-02 16:00:27 +01:00
Steven B.
1fcf3e44c2
Stabilise on_since value for smart devices (#1144)
Caches the `on_since` value to prevent jitter caused by the device calculations.
2024-10-02 15:04:16 +01:00
Steven B.
81e2685605
Send empty dictionary instead of null for iot queries (#1145) 2024-10-01 12:47:36 +01:00
Teemu R.
d897503b58
Move feature initialization from __init__ to _initialize_features (#1140) 2024-09-28 20:14:31 +02:00
Teemu R.
1ce5af2494
Add factory_reset() to iotdevice (#1125)
Also extend the base device class API to make factory_reset() part of the common API.
2024-09-27 17:42:22 +01:00
Steven B.
d1b43f5408
Fix cli command for device off (#1121)
Was previously missed when using the full `kasa device off` command as
opposed to the shortcut.
2024-09-27 17:36:45 +01:00
Steven B.
b4aba36b73
Use pytest-socket to ensure no tests are performing io (#1133) 2024-09-27 17:20:25 +01:00
Steven B.
936e45cad7
Enable ruff lint pycodestyle warnings (#1132)
Addresses repeated SyntaxWarnings when running linters:
```
kasa/tests/test_bulb.py:254: SyntaxWarning: invalid escape sequence '\d'
  ValueError, match="Temperature should be between \d+ and \d+, was 1000"
kasa/tests/test_bulb.py:258: SyntaxWarning: invalid escape sequence '\d'
  ValueError, match="Temperature should be between \d+ and \d+, was 10000"
kasa/tests/test_common_modules.py:216: SyntaxWarning: invalid escape sequence '\d'
  with pytest.raises(ValueError, match="Temperature should be between \d+ and \d+"):
kasa/tests/test_common_modules.py:219: SyntaxWarning: invalid escape sequence '\d'
  with pytest.raises(ValueError, match="Temperature should be between \d+ and \d+"):
```
2024-09-27 17:36:41 +02:00
Steven B.
db686e191a
Add autouse fixture to patch asyncio.sleep (#1131) 2024-09-27 10:57:23 +01:00
Steven B.
038b6993ca
Speed up and simplify github workflows (#1128)
- Enable parallel tests in the CI with pytest-xdist
- Migrate to the official `astral-sh/setup-uv` github action
- Call `pre-commit` run as a single job in CI instead of relisting each
check
- Use `uv` version 0.4.16
- Fix bug with pre-commit cache
- Update `publish.yml` to use  `astral-sh/setup-uv`
2024-09-27 10:27:53 +01:00
Teemu R.
1ab08f454f
Add fixture for T110 fw 1.9.0 (#1129) 2024-09-27 09:35:17 +01:00
Teemu R.
8321fd08aa
Mock asyncio.sleep for klapprotocol tests (#1130)
Speeds up tests in `test_klapprotocol.py` from 26s to 2s when there's no
sleep between the retries.
2024-09-27 09:34:30 +01:00
Ethan G
69c270055d
Add KS200M(US) fw 1.0.12 fixture (#1127) 2024-09-22 22:29:42 +02:00
Teemu R.
89d611d2cd
Add fixture for KL135(US) fw 1.0.15 (#1122)
By courtesy of @jhemak:
https://github.com/home-assistant/core/issues/126300#issuecomment-2364640319
2024-09-21 20:18:55 +02:00
Teemu R.
73b6d16074
Extend KL135 ct range up to 9000K (#1123) 2024-09-21 16:29:25 +01:00
Teemu R.
b7fa0d2040
Add factory-reset command to cli (#1108)
Allow reseting devices to factory settings using the cli: `kasa device factory-reset`.
2024-09-21 16:52:52 +02:00
Teemu R.
f07341a5a6
Add reboot() to the device interface (#1124)
Both device families have already had a method following this signature,
but defining the interface in the base class will make the contract
clear.
2024-09-21 16:37:38 +02:00
Steven B.
fcf8f07232
Do not regenerate aes key pair (#1114)
And read it from `device_config` if provided.

This is required as key generation can eat up cpu when a device is not fully available and the library is retrying.
2024-09-10 17:24:38 +01:00
Teemu R.
2a89e58ae0
Add missing type hints to alarm module (#1111) 2024-09-10 17:20:00 +01:00
Steven B.
1773f98aad
Fix tests due to yarl URL str output change (#1112)
Latest versions of yarl>=1.9.5 omit the port 80 when calling str(url) which broke tests.
2024-09-06 15:27:23 +01:00
Teemu R.
b0d0c4b703
Add KH100 EU fixtures (#1109) 2024-09-06 14:46:44 +02:00
Steven B.
520b9d7a38
Disable automatic updating of latest firmware (#1103)
To resolve issues with the calls to the tplink cloud to get the latest firmware.
Disables the automatic calling of `get_latest_fw` and requires firmware update checks to be triggered manually.
2024-08-30 18:01:54 +01:00
Teemu R.
6a86ffbbba
Add flake8-pytest-style (PT) for ruff (#1105)
This will catch common issues with pytest code.

* Use `match` when using `pytest.raises()` for base exception types like
`TypeError` or `ValueError`
* Use tuples for `parametrize()`
* Enforces `pytest.raises()` to contain simple statements, using `noqa`
to skip this on some cases for now.
* Fixes incorrect exception type (valueerror instead of typeerror) for
iotdimmer.
* Adds check valid types for `iotbulb.set_hsv` and `color` smart module.
* Consolidate exception messages for common interface modules.
2024-08-30 17:30:07 +02:00
Teemu R.
3e43781bb2
Add flake8-logging (LOG) and flake8-logging-format (G) for ruff (#1104)
Enables rules LOG (flake8-logging) and G (flake8-logging-format) for
ruff. This will catch eager log message formatting, among other similar
issues.
2024-08-30 16:13:14 +02:00
J. Nick Koston
b6339be9ec
Fix logging in iotdevice when a module is module not supported (#1100)
Debug logger was generating the `repr()` of each module and throwing it away because it had a `%` instead of a `,`
2024-08-23 10:56:33 +01:00
Steven B.
ae1ee388f6
Remove top level await xdoctest fixture (#1098)
This is now natively supported since [xdoctest
#158](https://github.com/Erotemic/xdoctest/pull/158) has been released
so no need for the monkey patching fixture anymore.
2024-08-22 17:14:47 +02:00
J. Nick Koston
4669e08605
Improve performance of dict merge code (#1097)
Co-authored-by: Teemu R. <tpr@iki.fi>
2024-08-14 16:33:54 -05:00
Steven B.
31ec27c1c8
Fix iot light effect brightness (#1092)
Fixes issue where the brightness of the `iot` light effect is set properly
on the light effect but read back incorrectly from the light.
2024-07-31 15:58:48 +01:00
Steven B.
cb0077f634
Do not send light_on value to iot bulb set_state (#1090)
Passing this extra value caused the `ignore_default` check in the `IotBulb._set_light_state`
method to fail which causes the device to come back on to the default state.
2024-07-31 15:56:07 +01:00
Steven B.
cb7e904d30
Enable setting brightness with color temp for smart devices (#1091) 2024-07-31 15:52:27 +01:00
Steven B.
7bba9926ed
Allow erroring modules to recover (#1080)
Re-query failed modules after some delay instead of immediately disabling them.
Changes to features so they can still be created when modules are erroring.
2024-07-30 19:23:07 +01:00