Skip to content

Conversation

@MarekSzczypinski
Copy link
Contributor

Description
This pull request adds support for TAPO/TP-Link programmable power strips and single socket devices using python-kasa.

This feature is used to manage TAPO power strip or single socket from Labgrid. It adds tapo model to NetworkPowerPort. As all Tapo devices require credentials this feature requires user to set KASA_LOGIN and KASA_PASSWORD env variables to work (see python-kasa website for details).

I have tested it manually with Labgrid (client build and run wth Python3.9 and 3.12). Additionally I wrote unit tests for it and also I have run the tox -r command (Python: 3.9, 3.10, 3.11 and 3.12). All worked without errors and all the tests passed.

I have used this driver with Tapo P300 power strip and Tapo P100 socket. So it should work with all Tapo strips and sockets.

While there already is support for KASA/TP-Link products in Labgrid using python-kasa, it doesn't work with TAPO devices as they apparently use some other protocol and require password and login to work. In order to not complicate the implementation of tplink model I decided to implement support for Tapo devices as a separate one. Additionally KASA products are not available in Europe so I didn't have means to test current (tplink) solution, which was one more reason to separate this into another model.

Because of the necessity to create credentials this solution is a bit more complicated than the tplink model.

This solution is based on the tplink model. Two key differences are:

  • Support for single sockets like P100 that ignores value of index
  • Requires Tapo cloud credentials in order to communicate with devices

Checklist

  • Documentation for the feature
  • Tests for the feature
  • The arguments and description in doc/configuration.rst have been updated
  • Add a section on how to use the feature to doc/usage.rst
  • Add a section on how to use the feature to doc/development.rst
  • PR has been tested
  • Man pages have been regenerated

Signed-off-by: Marek Szczypiński <[email protected]>
@MarekSzczypinski MarekSzczypinski force-pushed the feature/add-tapo-support branch from d41c2fa to e544fc0 Compare March 23, 2025 20:27
@MarekSzczypinski MarekSzczypinski changed the title Add support for TAPO devices driver/power: Add support for TAPO devices May 4, 2025
# Somewhere between python-kasa 0.7.7 and 0.10.2 the API changed
# Labgrid on Python <= 3.10 uses python-kasa 0.7.7
# Labgrid on Python >= 3.11 uses python-kasa 0.10.2
if sys.version_info < (3, 11):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should instead check the python-kasa version instead of relying on the indirect python dependency here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. All tests as written in the description of this PR were re-done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, @Emantor. Any update on this one? :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Emantor just a friendly reminder that I'm still waiting for review ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Emantor, still waiting for any comment ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Emantor I've fixed problem with pylint (see my comment below). Can you give it another try? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Emantor, just a friendly reminder (checked with pylint and tox -r)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Emantor maybe someone else would have time to take a look?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Emantor just a friendly reminder that I'm still waiting for review ;-)

@MarekSzczypinski
Copy link
Contributor Author

No changes - just updating to the master branch

@MarekSzczypinski
Copy link
Contributor Author

Yet another update to master, nothing changed in my MR

Suppress unexpected-keyword-arg warnings for uses_http and http_port
parameters that exist in different python-kasa API versions.

Additionally tapo.py and test_tapo.py are now ruff formatted.

Signed-off-by: Marek Szczypiński <[email protected]>
@MarekSzczypinski
Copy link
Contributor Author

Added pylint disables for python-kasa version compatibility. This suppresses unexpected-keyword-arg warnings for uses_http and http_port parameters that exist in different python-kasa API versions. Also files are now ruff formatted.

tox -r as been re-run and code has been checked with pylint on python 3.9 through 3.14

@MarekSzczypinski
Copy link
Contributor Author

Yet another update to master, nothing changed in my MR.
tox -r as been re-run and code has been checked with pylint on python 3.9 through 3.14

@MarekSzczypinski
Copy link
Contributor Author

Yet another update to master, nothing changed in my MR.
tox -r as been re-run and code has been checked with pylint on python 3.9 through 3.14

@MarekSzczypinski
Copy link
Contributor Author

Yet another update to master, nothing changed in my MR.
tox -r as been re-run and code has been checked with pylint on python 3.9 through 3.14

@MarekSzczypinski
Copy link
Contributor Author

Yet another update to master, nothing changed in my MR.
tox -r as been re-run and code has been checked with pylint on python 3.9 through 3.14

@codecov
Copy link

codecov bot commented Jan 30, 2026

Codecov Report

❌ Patch coverage is 98.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 45.3%. Comparing base (cf3b5ab) to head (f7088ef).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
labgrid/driver/power/tapo.py 98.0% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #1630     +/-   ##
========================================
+ Coverage    45.1%   45.3%   +0.1%     
========================================
  Files         172     173      +1     
  Lines       13617   13667     +50     
========================================
+ Hits         6143    6192     +49     
- Misses       7474    7475      +1     
Flag Coverage Δ
3.10 45.2% <94.0%> (+0.1%) ⬆️
3.11 45.2% <94.0%> (+0.1%) ⬆️
3.12 45.2% <94.0%> (+0.1%) ⬆️
3.13 45.2% <94.0%> (+0.1%) ⬆️
3.14 45.2% <94.0%> (+0.1%) ⬆️
3.9 45.3% <94.0%> (+0.1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants