Commit Graph

23 Commits

Author SHA1 Message Date
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.
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
Steven B.
1c83675e57
Fix intermittently failing decryption error test (#1082) 2024-07-24 18:58:37 +01:00
Steven B.
06ff598d9c
Raise KasaException on decryption errors (#1078)
Currently if the library encounters an invalid decryption error it
raises a value error. This PR wraps it in a KasaException so consumers
such as HA can catch an expected library exception.
2024-07-22 20:33:31 +02:00
Steven B
a87fc3b766
Retry query on 403 after succesful handshake (#785)
If a handshake session becomes invalid the device returns 403 on send and an `AuthenticationError` is raised which prevents a retry, however a retry would be successful.  In HA this causes devices to go into reauth flow which is not necessary.
2024-02-22 18:02:03 +01:00
Steven B
8c39e81a40
Rename and deprecate exception classes (#739)
# Public #
SmartDeviceException -> KasaException
UnsupportedDeviceException(SmartDeviceException) -> UnsupportedDeviceError(KasaException)
TimeoutException(SmartDeviceException, asyncio.TimeoutError) -> TimeoutError(KasaException, asyncio.TimeoutError)

Add new exception for error codes -> DeviceError(KasaException)
AuthenticationException(SmartDeviceException) -> AuthenticationError(DeviceError)

# Internal #
RetryableException(SmartDeviceException) -> _RetryableError(DeviceError)
ConnectionException(SmartDeviceException) -> _ConnectionError(KasaException)
2024-02-21 16:52:55 +01:00
Steven B
6ab17d823c
Reduce AuthenticationExceptions raising from transports (#740)
* Reduce AuthenticationExceptions raising from transports

* Make auth failed test ids easier to read

* Test invalid klap response length
2024-02-05 21:49:26 +01:00
Teemu R
fae071f0df
Fix port-override for aes&klap transports (#734)
* Fix port-override for aes&klap transports

* Add tests for port override
2024-02-03 15:28:20 +01:00
Teemu R
55525fc58b
Unignore F401 for tests (#724)
* Unignore F401 for tests

* Fix linting
2024-01-30 00:15:58 +01:00
J. Nick Koston
b479b6d84d
Avoid rebuilding urls for every request (#715)
* Avoid rebuilding urls for every request

* more fixes

* more fixes

* make mypy happy

* reduce

* tweak

* fix tests

* fix tests

* tweak

* tweak

* lint

* fix type
2024-01-29 15:26:00 +00:00
Steven B
eb217a748c
Fix test_klapprotocol test duration (#698) 2024-01-23 22:20:44 -10:00
Steven B
1788c50146
Update transport close/reset behaviour (#689)
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-01-23 12:15:18 -10:00
Steven B
718983c401
Try default tapo credentials for klap and aes (#685)
* Try default tapo credentials for klap and aes

* Add tests
2024-01-23 14:44:32 +00:00
Steven B
49cfef087c
Make close behaviour consistent across new protocols and transports (#660) 2024-01-20 13:35:05 +01:00
Steven B
642e9a1f5b
Migrate http client to use aiohttp instead of httpx (#643) 2024-01-18 07:32:26 -10:00
Steven B
3b1b0a3c21
Encapsulate http client dependency (#642)
* Encapsulate http client dependency

* Store cookie dict as variable

* Update post-review
2024-01-18 10:57:33 +01:00
sdb9696
f6fd898faf
Add DeviceConfig to allow specifying configuration parameters (#569)
* Add DeviceConfig handling

* Update post review

* Further update post latest review

* Update following latest review

* Update docstrings and docs
2023-12-29 20:17:15 +01:00
sdb9696
6819c746d7
Enable multiple requests in smartprotocol (#584)
* Enable multiple requests in smartprotocol

* Update following review

* Remove error_code parameter in exceptions
2023-12-20 18:08:04 +01:00
sdb9696
20ea6700a5
Do login entirely within AesTransport (#580)
* Do login entirely within AesTransport

* Remove login and handshake attributes from BaseTransport

* Add AesTransport tests

* Synchronise transport and protocol __init__ signatures and rename internal variables

* Update after review
2023-12-19 15:11:59 +01:00
sdb9696
2e6c41d039
Improve smartprotocol error handling and retries (#578)
* Improve smartprotocol error handling and retries

* Update after review

* Enum to IntEnum and SLEEP_SECONDS_AFTER_TIMEOUT
2023-12-10 16:41:53 +01:00
sdb9696
01f3827d73
Fix transport retries after close (#568) 2023-12-05 15:56:29 +01:00
sdb9696
4a00199506
Add klap support for TAPO protocol by splitting out Transports and Protocols (#557)
* Add support for TAPO/SMART KLAP and seperate transports from protocols

* Add tests and some review changes

* Update following review

* Updates following review
2023-12-04 19:50:05 +01:00
sdb9696
30f217b8ab
Add klap protocol (#509)
* Add support for the new encryption protocol

This adds support for the new TP-Link discovery and encryption
protocols. It is currently incomplete - only devices without
username and password are current supported, and single device
discovery is not implemented.

Discovery should find both old and new devices. When accessing
a device by IP the --klap option can be specified on the command
line to active the new connection protocol.

sdb9696 - This commit also contains 16 later commits from Simon Wilkinson
squashed into the original

* Update klap changes 2023 to fix encryption, deal with kasa credential switching and work with new discovery changes

* Move from aiohttp to httpx

* Changes following review comments

---------

Co-authored-by: Simon Wilkinson <simon@sxw.org.uk>
2023-11-20 14:17:10 +01:00