Skip to content

driver/power: Add support for TAPO devices#1630

Open
MarekSzczypinski wants to merge 5 commits intolabgrid-project:masterfrom
MarekSzczypinski:feature/add-tapo-support
Open

driver/power: Add support for TAPO devices#1630
MarekSzczypinski wants to merge 5 commits intolabgrid-project:masterfrom
MarekSzczypinski:feature/add-tapo-support

Conversation

@MarekSzczypinski
Copy link
Copy Markdown
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

@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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@Emantor ping :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@Emantor friendly reminder that I'm still here waiting.

@MarekSzczypinski
Copy link
Copy Markdown
Contributor Author

No changes - just updating to the master branch

@MarekSzczypinski
Copy link
Copy Markdown
Contributor Author

Yet another update to master, nothing changed in my MR

@MarekSzczypinski
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

2 similar comments
@MarekSzczypinski
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown

codecov bot commented Jan 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 45.9%. Comparing base (3912486) to head (1d2c4ac).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff            @@
##           master   #1630     +/-   ##
========================================
+ Coverage    45.8%   45.9%   +0.1%     
========================================
  Files         182     183      +1     
  Lines       14718   14768     +50     
========================================
+ Hits         6743    6793     +50     
  Misses       7975    7975             
Flag Coverage Δ
3.10 45.9% <96.0%> (+0.1%) ⬆️
3.11 ?
3.12 45.9% <96.0%> (+0.1%) ⬆️
3.13 45.9% <96.0%> (+0.1%) ⬆️
3.14 45.9% <96.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.

@MarekSzczypinski
Copy link
Copy Markdown
Contributor Author

I've done unit tests refactoring for my driver. Apart from that - bunch of updates to current master branch.

@MarekSzczypinski
Copy link
Copy Markdown
Contributor Author

Yay!! Happy anniversary to this PR! ;-)

@Emantor
Copy link
Copy Markdown
Member

Emantor commented Mar 19, 2026

Please do a clean rebase on top of master without the merge commits. Sorry for the wait.

@MarekSzczypinski MarekSzczypinski force-pushed the feature/add-tapo-support branch from cb34dd5 to 44f6bb1 Compare March 23, 2026 09:31
@MarekSzczypinski
Copy link
Copy Markdown
Contributor Author

MarekSzczypinski commented Mar 24, 2026

Please do a clean rebase on top of master without the merge commits. Sorry for the wait.

@Emantor Done. No worries :)

@Emantor
Copy link
Copy Markdown
Member

Emantor commented Mar 30, 2026

IMO the commits can also be squashed down into one commit or do you see value in keeping the individual commits?

@Emantor Emantor self-assigned this Mar 30, 2026
@MarekSzczypinski
Copy link
Copy Markdown
Contributor Author

MarekSzczypinski commented Mar 30, 2026

IMO the commits can also be squashed down into one commit or do you see value in keeping the individual commits?

For sure, but I've already rebased the branch anyways.

Edit:
@Emantor OMG, you didn't mean the update-to-main merge commits XD
Yes, my feature's commits can be squashed. I don't mind :)

@MarekSzczypinski MarekSzczypinski force-pushed the feature/add-tapo-support branch from 44f6bb1 to b72ca70 Compare March 31, 2026 10:45
Signed-off-by: Marek Szczypiński <markacy@gmail.com>
Signed-off-by: Marek Szczypiński <markacy@gmail.com>
Signed-off-by: Marek Szczypiński <markacy@gmail.com>
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 <markacy@gmail.com>
Signed-off-by: Marek Szczypiński <markacy@gmail.com>
@MarekSzczypinski MarekSzczypinski force-pushed the feature/add-tapo-support branch from b72ca70 to 1d2c4ac Compare April 1, 2026 22:21
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