| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
A credentials_hash is specific to the transport that made it. Klap stores the base64 of a raw digest, aes and ssltransport store base64 json of hashed credentials, and sslaestransport stores base64 json of the plaintext. Nothing checked that the hash a transport was handed was its own. A device can change its encryption type without the credentials changing. Toggling Third-Party Compatibility on a Tapo device moves it between tpap and klap, and discovery then hands the transport a stored hash the other transport wrote. Klap decodes any base64 successfully, so it built _local_auth_hash out of another transport's json and failed handshake1, reporting "Device response did not match our challenge". Callers cannot tell that from a wrong password; Home Assistant acts on it by deleting the stored hash and asking the user to reauthenticate. aestransport and ssltransport are worse and raise UnicodeDecodeError from the constructor, and sslaestransport raises KeyError. Check the hash has the shape the transport produces and treat a foreign one as absent instead.
Codecov Report❌ Patch coverage is 98.18182% with 1 line in your changes missing coverage. Please review.
@@ Coverage Diff @@
## master #1749 +/- ##
==========================================
+ Coverage 93.29% 93.36% +0.06%
==========================================
Files 157 158 +1
Lines 9932 10032 +100
Branches 1022 1030 +8
==========================================
+ Hits 9266 9366 +100
- Misses 471 472 +1
+ Partials 195 194 -1 ☔ View full report in Codecov by Harness.
|
Sorry, something went wrong.
sslaestransport and the tpap transport on python-kasa#1592 store a credentials_hash that is base64 json of the plaintext credentials, so the credentials can be read back out of it. klap and aes hashes are one way and cannot. When a device changes its encryption type the stored hash is the one the old transport wrote. The previous commit stops that being mistaken for a bad password, but the connection still has no credentials to offer and the caller has to prompt for them again. Home Assistant stores the hash as the only copy of the credentials for a device, so that prompt loses them. Read the credentials back out when the hash is one of the plaintext forms and let the transport derive its own. A tpap device that reverts to klap because Third-Party Compatibility was turned on then reconnects without a reauth. This only works in that direction.
There was a problem hiding this comment.
I really like the idea, thanks for the PR @nopoz!
We should take a look how this behaves in the bigger picture (and I have wanted to contain other logic, e.g., the get_credentias/defaultcreds logic properly), but this is a good starter to make the Credentials a bit more self-contained. I added a couple of suggestions inline, please take a look and let me know what you think!
Sorry, something went wrong.
Give BaseTransport an is_transport_credentials_hash hook that defaults to accepting the hash, and do the discard and plaintext recovery once in its constructor rather than in each transport. Recovering the credentials is now a Credentials classmethod instead of a module level function. The ssl transport gains the recovery it did not have before, so it is covered by a new test.
## [0.11.0](https://github.com/python-kasa/python-kasa/tree/0.11.0) (2026-10-04) [Full Changelog](0.10.2...0.11.0) **Release summary:** This is a huge and long overdue release, coming more than a year and a half after the previous one. Hopefully the next one follows sooner, as the TPAP transport (which did not make it into this release) is used more and more on newer devices. This release brings broader camera support, new modules for lights, vacuums and cameras, and many connectivity fixes for newer firmware versions. Some other highlights: - Improved Tapo camera support: login version 3, presets, wifi handling, last alert detection, and more robust authentication and discovery. - Selective room cleaning for robot vacuums. - Configurable light strip length via the new strip segment module, and an exposed light transition state change flag. - Basic HomeKit module for Kasa (iot) devices. - Energy monitoring V2 support (S515D). - Better hub and thermostat state reporting (hold, summer mode, low battery). - Connection fixes for newer Tapo firmware and older SSL devices, plus KLAP v2 for iot devices. - More resilient time handling, with failover and UTC fallback for iot devices. - Python 3.14 is now supported. - Inclusion of fixtures for 29 devices or firmware versions, including the Tapo C460, C200 and C101 cameras and the KH100 hub with KE100/KE110 thermostats. **Thank you to all contributors!** A big thank you to everyone who contributed to this release, whether through code, device fixtures, bug reports or testing. Special thanks to @ZeliardM for a huge effort on both features and project maintenance, including but not limited to: - Features like the HomeKit module for iot devices, iot time module failover, wifi handling and credential improvements for cameras, Tapo login version 3, and V2 energy monitoring for S515D. - A lot of necessary maintenance work including type annotations and cleanups throughout the test suite, modernized docstrings, CI hardening with SHA-pinned actions, and many bug fixes. This helps us to keep the library maintainable and open to new contributions. A warm welcome to our new contributors, with special thanks to those who contributed improvements and fixes: - @alams154: discovery on port 20004 - @bluntman001: iot device classification fix - @bm1549: KLAP v2 transport for iot devices - @darylldelfin: cipher support for newer Tapo firmware - @davidefiocco: vacuum mop water level fix - @epg-pers: selective room cleaning for vacuums - @freeKC: camera discovery and authentication fixes - @gpongelli: extended camera detection - @Ikstar: KL420 color temperature range - @juherr: last alert detection module for cameras, camera error codes and a C200 fixture - @kad: SSL connections to older devices - @KaloyanNaumov: multi-request timeout handling - @loganrosen: KL400L5 color temperature range - @markvanpraet: Tapo C460 support and camera battery fix - @monteccarlos: iot timezone mapping fix - @mrwogu: preset support for Tapo cameras - @nopoz: strip segment module, light transition flag and credentials hash fix - @tk1475: UTC fallback for unset iot device clocks - @wh1t3f1r3: non-retryable network error handling Thanks also to our new contributors who provided device fixtures to help future development efforts: @emanueleg, @fantandrea, @HarryPehkonen, @ijaron, @Krotu, @LostLuma, @mjbohr and @TheLinuxGuy. **This release in numbers:** - 68 merged pull requests from 29 contributors, 27 of them first-time contributors - 8 new modules - 29 new device fixtures - 203 files changed, with 25,199 lines added and 2,585 removed **Implemented enhancements:** - \[Feature Request\] C220 camera line crossing detection on-off switch [\#1551](#1551) - SslAesTransport: handshake again when a camera answers 401 to passthrough [\#1771](#1771) (@freeKC) - Add LastAlertDetection module for smartcam devices [\#1762](#1762) (@juherr) - Add KL420 to TPLINK\_KELVIN color temperature ranges [\#1757](#1757) (@Ikstar) - Do not authenticate with a credentials\_hash from a different transport [\#1749](#1749) (@nopoz) - Expose the light transition state change flag [\#1745](#1745) (@nopoz) - Add strip segment module for configurable light strip length [\#1744](#1744) (@nopoz) - Add KL400L5 color temperature range [\#1719](#1719) (@loganrosen) - Update smartcam credential handling and tests [\#1664](#1664) (@ZeliardM) - Add support for V2 Energy Monitoring for S515D [\#1663](#1663) (@ZeliardM) - Add selective room cleaning to vacuum clean module [\#1660](#1660) (@epg-pers) - New Wi-Fi handling for SMARTCAM devices [\#1639](#1639) (@ZeliardM) - Add support for tapo login\_version 3 in sslaestransport [\#1638](#1638) (@ZeliardM) - Add preset support for Tapo cameras [\#1615](#1615) (@mrwogu) - Add python 3.14 to supported versions [\#1599](#1599) (@rytilahti) - Add discovery port 20004 [\#1595](#1595) (@alams154) - Implement IOT Time Module Failover [\#1583](#1583) (@ZeliardM) - Add bare bones homekit module for iot devices [\#1566](#1566) (@ZeliardM) - Extend smartcam detection support [\#1552](#1552) (@gpongelli) **Fixed bugs:** - Time module unavailable for waterleak sensor [\#1613](#1613) - 'No time zone found with key EST' in debian 13 [\#1579](#1579) - Discovery: accept cameras that only send the encrypt\_type list [\#1770](#1770) (@freeKC) - Classify IOT devices via sysinfo regardless of transport \(fixes \#1740\) [\#1769](#1769) (@bluntman001) - Fall back to UTC for iot time when the device clock is not set [\#1768](#1768) (@tk1475) - Add UNKNOWN\_USERNAME \(-60502\) camera error code [\#1761](#1761) (@juherr) - Disable multi requests on timeout during multi-request [\#1759](#1759) (@KaloyanNaumov) - Add ECDHE-RSA-AES256 cipher for newer Tapo firmware [\#1755](#1755) (@darylldelfin) - Map iot timezone index 18 to America/New\_York instead of EST [\#1743](#1743) (@monteccarlos) - fix: use KLAP v2 transport for IOT devices with login version 2 [\#1731](#1731) (@bm1549) - Add ENETUNREACH to non-retryable errors in XorTransport [\#1668](#1668) (@wh1t3f1r3) - Fix mop set\_waterlevel sending setCleanAttr without type field [\#1667](#1667) (@davidefiocco) - Fix SMARTCAM Time module and update tests [\#1659](#1659) (@ZeliardM) - Fix camera login version in CLI [\#1658](#1658) (@ZeliardM) - Allow SSL connections to older devices [\#1654](#1654) (@kad) - waterleaksensor: use parent's Time for alert timestamp [\#1614](#1614) (@rytilahti) - Add hold state to thermostatstate [\#1609](#1609) (@rytilahti) - Fix thermostat idle reporting on low battery [\#1598](#1598) (@rytilahti) - Add shutdown \(summer mode\) to thermostatstate [\#1588](#1588) (@rytilahti) - Fix iotstrip child device time handling [\#1584](#1584) (@ZeliardM) **Added support for devices:** - Add C200 device fixture [\#1760](#1760) (@juherr) - Add P125M fixture for firmware 1.4.4 [\#1746](#1746) (@HarryPehkonen) - Add fixtures for KH100, KE100 and KE110 and simulate TRV states [\#1726](#1726) (@Krotu) - Add L530EA\(EU\) device fixture [\#1694](#1694) (@ZeliardM) - Add C101 test fixture [\#1673](#1673) (@ijaron) - Add LB130\(US\) device fixture [\#1669](#1669) (@ZeliardM) - Add KL110B\(UN\) device fixture [\#1657](#1657) (@ZeliardM) - Add TS15\(US\) device fixture [\#1649](#1649) (@ZeliardM) - Add Tapo C460 support [\#1645](#1645) (@markvanpraet) - Add P105\(US\) device fixture [\#1644](#1644) (@ZeliardM) - Add L430C\(EU\) device fixture [\#1643](#1643) (@ZeliardM) - Add L430P\(EU\) device fixture [\#1607](#1607) (@LostLuma) - Add S500\(US\)\_1.0\_1.2.0 fixture [\#1569](#1569) (@ZeliardM) - Add device fixture for P316M\(US\) [\#1568](#1568) (@TheLinuxGuy) - Add L535E\(EU\) 3.0 1.1.8 fixture [\#1545](#1545) (@fantandrea) - Adding KL400L10\(US\)\_1.0\_1.0.10 fixture [\#1539](#1539) (@mjbohr) - Add TP10\(IT\) 1.0 1.2.5 fixture [\#1538](#1538) (@emanueleg) - Add LB100\(US\)\_1.0\_1.8.11 fixture file [\#1515](#1515) (@ZeliardM) - Add KS225\(US\)\_1.0\_1.1.1 and L930-5\(EU\)\_1.0\_1.2.5 [\#1509](#1509) (@ZeliardM) **Documentation updates:** - How to hash credentials to make use of --credentials-hash flag? [\#1517](#1517) - docs: modernize docstrings across the repository [\#1682](#1682) (@ZeliardM) - Add a note to emeter guide being kasa-only [\#1512](#1512) (@rytilahti) **Project maintenance:** - tests: add type annotations to top-level test files [\#1688](#1688) (@ZeliardM) - tests: add type annotations to CLI, protocol, and smartcam tests [\#1687](#1687) (@ZeliardM) - tests: add type annotations to Smart tests [\#1686](#1686) (@ZeliardM) - tests: add type annotations to IoT tests [\#1685](#1685) (@ZeliardM) - tests: add type annotations to transport tests [\#1684](#1684) (@ZeliardM) - tests: centralize transport and session cleanup in conftest [\#1683](#1683) (@ZeliardM) - ci: pin all GitHub Actions to SHA hashes and update versions [\#1681](#1681) (@ZeliardM) - tests: fix typos, child device subtype, CLI patch path, and deprecation test logic [\#1677](#1677) (@ZeliardM) - Update GitHub Workflows and Actions [\#1622](#1622) (@ZeliardM) - Use log-level debug for smartdevice query error reporting [\#1587](#1587) (@rytilahti) - Use Device instead of SmartDevice where feasible [\#1585](#1585) (@ZeliardM) **Closed issues:** - Python 3.14 Support [\#1597](#1597) - HS300 Child State - Time Module Error [\#1445](#1445)
## [0.11.0.1](https://github.com/python-kasa/python-kasa/tree/0.11.0.1) (2026-10-04) [Full Changelog](0.10.2...0.11.0.1) **Release summary:** *Note: 0.11.0 was tagged but never published to PyPI due to a packaging issue. 0.11.0.1 contains the same changes plus a fix for the release workflow.* This is a huge and long overdue release, coming more than a year and a half after the previous one. Hopefully the next one follows sooner, as the TPAP transport (which did not make it into this release) is used more and more on newer devices. This release brings broader camera support, new modules for lights, vacuums and cameras, and many connectivity fixes for newer firmware versions. Some other highlights: - Improved Tapo camera support: login version 3, presets, wifi handling, last alert detection, and more robust authentication and discovery. - Selective room cleaning for robot vacuums. - Configurable light strip length via the new strip segment module, and an exposed light transition state change flag. - Basic HomeKit module for Kasa (iot) devices. - Energy monitoring V2 support (S515D). - Better hub and thermostat state reporting (hold, summer mode, low battery). - Connection fixes for newer Tapo firmware and older SSL devices, plus KLAP v2 for iot devices. - More resilient time handling, with failover and UTC fallback for iot devices. - Python 3.14 is now supported. - Inclusion of fixtures for 29 devices or firmware versions, including the Tapo C460, C200 and C101 cameras and the KH100 hub with KE100/KE110 thermostats. **Thank you to all contributors!** A big thank you to everyone who contributed to this release, whether through code, device fixtures, bug reports or testing. Special thanks to @ZeliardM for a huge effort on both features and project maintenance, including but not limited to: - Features like the HomeKit module for iot devices, iot time module failover, wifi handling and credential improvements for cameras, Tapo login version 3, and V2 energy monitoring for S515D. - A lot of necessary maintenance work including type annotations and cleanups throughout the test suite, modernized docstrings, CI hardening with SHA-pinned actions, and many bug fixes. This helps us to keep the library maintainable and open to new contributions. A warm welcome to our new contributors, with special thanks to those who contributed improvements and fixes: - @alams154: discovery on port 20004 - @bluntman001: iot device classification fix - @bm1549: KLAP v2 transport for iot devices - @darylldelfin: cipher support for newer Tapo firmware - @davidefiocco: vacuum mop water level fix - @epg-pers: selective room cleaning for vacuums - @freeKC: camera discovery and authentication fixes - @gpongelli: extended camera detection - @Ikstar: KL420 color temperature range - @juherr: last alert detection module for cameras, camera error codes and a C200 fixture - @kad: SSL connections to older devices - @KaloyanNaumov: multi-request timeout handling - @loganrosen: KL400L5 color temperature range - @markvanpraet: Tapo C460 support and camera battery fix - @monteccarlos: iot timezone mapping fix - @mrwogu: preset support for Tapo cameras - @nopoz: strip segment module, light transition flag and credentials hash fix - @tk1475: UTC fallback for unset iot device clocks - @wh1t3f1r3: non-retryable network error handling Thanks also to our new contributors who provided device fixtures to help future development efforts: @emanueleg, @fantandrea, @HarryPehkonen, @ijaron, @Krotu, @LostLuma, @mjbohr and @TheLinuxGuy. **This release in numbers:** - 68 merged pull requests from 29 contributors, 27 of them first-time contributors - 8 new modules - 29 new device fixtures - 203 files changed, with 25,199 lines added and 2,585 removed **Implemented enhancements:** - \[Feature Request\] C220 camera line crossing detection on-off switch [\#1551](#1551) - SslAesTransport: handshake again when a camera answers 401 to passthrough [\#1771](#1771) (@freeKC) - Add LastAlertDetection module for smartcam devices [\#1762](#1762) (@juherr) - Add KL420 to TPLINK\_KELVIN color temperature ranges [\#1757](#1757) (@Ikstar) - Do not authenticate with a credentials\_hash from a different transport [\#1749](#1749) (@nopoz) - Expose the light transition state change flag [\#1745](#1745) (@nopoz) - Add strip segment module for configurable light strip length [\#1744](#1744) (@nopoz) - Add KL400L5 color temperature range [\#1719](#1719) (@loganrosen) - Update smartcam credential handling and tests [\#1664](#1664) (@ZeliardM) - Add support for V2 Energy Monitoring for S515D [\#1663](#1663) (@ZeliardM) - Add selective room cleaning to vacuum clean module [\#1660](#1660) (@epg-pers) - New Wi-Fi handling for SMARTCAM devices [\#1639](#1639) (@ZeliardM) - Add support for tapo login\_version 3 in sslaestransport [\#1638](#1638) (@ZeliardM) - Add preset support for Tapo cameras [\#1615](#1615) (@mrwogu) - Add python 3.14 to supported versions [\#1599](#1599) (@rytilahti) - Add discovery port 20004 [\#1595](#1595) (@alams154) - Implement IOT Time Module Failover [\#1583](#1583) (@ZeliardM) - Add bare bones homekit module for iot devices [\#1566](#1566) (@ZeliardM) - Extend smartcam detection support [\#1552](#1552) (@gpongelli) **Fixed bugs:** - Time module unavailable for waterleak sensor [\#1613](#1613) - 'No time zone found with key EST' in debian 13 [\#1579](#1579) - Discovery: accept cameras that only send the encrypt\_type list [\#1770](#1770) (@freeKC) - Classify IOT devices via sysinfo regardless of transport \(fixes \#1740\) [\#1769](#1769) (@bluntman001) - Fall back to UTC for iot time when the device clock is not set [\#1768](#1768) (@tk1475) - Add UNKNOWN\_USERNAME \(-60502\) camera error code [\#1761](#1761) (@juherr) - Disable multi requests on timeout during multi-request [\#1759](#1759) (@KaloyanNaumov) - Add ECDHE-RSA-AES256 cipher for newer Tapo firmware [\#1755](#1755) (@darylldelfin) - Map iot timezone index 18 to America/New\_York instead of EST [\#1743](#1743) (@monteccarlos) - fix: use KLAP v2 transport for IOT devices with login version 2 [\#1731](#1731) (@bm1549) - Add ENETUNREACH to non-retryable errors in XorTransport [\#1668](#1668) (@wh1t3f1r3) - Fix mop set\_waterlevel sending setCleanAttr without type field [\#1667](#1667) (@davidefiocco) - Fix SMARTCAM Time module and update tests [\#1659](#1659) (@ZeliardM) - Fix camera login version in CLI [\#1658](#1658) (@ZeliardM) - Allow SSL connections to older devices [\#1654](#1654) (@kad) - waterleaksensor: use parent's Time for alert timestamp [\#1614](#1614) (@rytilahti) - Add hold state to thermostatstate [\#1609](#1609) (@rytilahti) - Fix thermostat idle reporting on low battery [\#1598](#1598) (@rytilahti) - Add shutdown \(summer mode\) to thermostatstate [\#1588](#1588) (@rytilahti) - Fix iotstrip child device time handling [\#1584](#1584) (@ZeliardM) **Added support for devices:** - Add C200 device fixture [\#1760](#1760) (@juherr) - Add P125M fixture for firmware 1.4.4 [\#1746](#1746) (@HarryPehkonen) - Add fixtures for KH100, KE100 and KE110 and simulate TRV states [\#1726](#1726) (@Krotu) - Add L530EA\(EU\) device fixture [\#1694](#1694) (@ZeliardM) - Add C101 test fixture [\#1673](#1673) (@ijaron) - Add LB130\(US\) device fixture [\#1669](#1669) (@ZeliardM) - Add KL110B\(UN\) device fixture [\#1657](#1657) (@ZeliardM) - Add TS15\(US\) device fixture [\#1649](#1649) (@ZeliardM) - Add Tapo C460 support [\#1645](#1645) (@markvanpraet) - Add P105\(US\) device fixture [\#1644](#1644) (@ZeliardM) - Add L430C\(EU\) device fixture [\#1643](#1643) (@ZeliardM) - Add L430P\(EU\) device fixture [\#1607](#1607) (@LostLuma) - Add S500\(US\)\_1.0\_1.2.0 fixture [\#1569](#1569) (@ZeliardM) - Add device fixture for P316M\(US\) [\#1568](#1568) (@TheLinuxGuy) - Add L535E\(EU\) 3.0 1.1.8 fixture [\#1545](#1545) (@fantandrea) - Adding KL400L10\(US\)\_1.0\_1.0.10 fixture [\#1539](#1539) (@mjbohr) - Add TP10\(IT\) 1.0 1.2.5 fixture [\#1538](#1538) (@emanueleg) - Add LB100\(US\)\_1.0\_1.8.11 fixture file [\#1515](#1515) (@ZeliardM) - Add KS225\(US\)\_1.0\_1.1.1 and L930-5\(EU\)\_1.0\_1.2.5 [\#1509](#1509) (@ZeliardM) **Documentation updates:** - How to hash credentials to make use of --credentials-hash flag? [\#1517](#1517) - docs: modernize docstrings across the repository [\#1682](#1682) (@ZeliardM) - Add a note to emeter guide being kasa-only [\#1512](#1512) (@rytilahti) **Project maintenance:** - Fix PyPI publishing for packages with metadata 2.5 [\#1779](#1779) (@rytilahti) - tests: add type annotations to top-level test files [\#1688](#1688) (@ZeliardM) - tests: add type annotations to CLI, protocol, and smartcam tests [\#1687](#1687) (@ZeliardM) - tests: add type annotations to Smart tests [\#1686](#1686) (@ZeliardM) - tests: add type annotations to IoT tests [\#1685](#1685) (@ZeliardM) - tests: add type annotations to transport tests [\#1684](#1684) (@ZeliardM) - tests: centralize transport and session cleanup in conftest [\#1683](#1683) (@ZeliardM) - ci: pin all GitHub Actions to SHA hashes and update versions [\#1681](#1681) (@ZeliardM) - tests: fix typos, child device subtype, CLI patch path, and deprecation test logic [\#1677](#1677) (@ZeliardM) - Update GitHub Workflows and Actions [\#1622](#1622) (@ZeliardM) - Use log-level debug for smartdevice query error reporting [\#1587](#1587) (@rytilahti) - Use Device instead of SmartDevice where feasible [\#1585](#1585) (@ZeliardM) **Closed issues:** - Python 3.14 Support [\#1597](#1597) - HS300 Child State - Time Module Error [\#1445](#1445)
| Back | FazBrowse Home | New Git URL |
A credentials_hash is specific to the transport that produced it, but nothing checked that the hash a transport was handed was its own.
This matters because a device can change its encryption type without the credentials changing. Toggling Third-Party Compatibility in the Tapo app moves a plug or strip between TPAP and KLAP, as described in #1590. Discovery correctly rewrites the encryption type, and the transport is then handed a stored hash that a different transport wrote.
KlapTransport decodes any base64 successfully, so it built _local_auth_hash out of another transport's json and failed handshake1 with:
That is indistinguishable from a wrong password, and it is acted on as one. homeassistant/components/tplink/__init__.py catches AuthenticationError, deletes CONF_CREDENTIALS_HASH from the config entry and raises ConfigEntryAuthFailed. Where there is no separate credential store, that hash is the only copy of the credentials, so the encryption change costs the user their credentials and a reauth.
AesTransport and SslTransport fail less quietly and raise UnicodeDecodeError from the constructor when handed a klap hash; SslAesTransport raises KeyError.
What this changes
First commit adds a per-transport check that the hash has the shape that transport produces, and treats a foreign hash as absent rather than as a bad password. This makes the failure honest but still ends in a reauth.
Second commit reads the credentials back out when the hash is one of the plaintext forms and lets the transport derive its own, so the change of encryption type needs no reauth. klap and aes hashes are one way, so this only works in that direction, and the first commit's behaviour is what applies otherwise.
Notes
Testing
New tests/transports/test_credentials_hash.py covers, per transport, that a foreign hash is not used to authenticate, that the transport's own hash still is, and that the plaintext forms are recovered. Full suite passes.
Also verified against hardware: an L920 strip that reverted from TPAP to KLAP authenticates over KLAP when given the TPAP-format hash, and rederives its own klap hash.