Skip to content

driver/power: Add support for TAPO devices#1630

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

driver/power: Add support for TAPO devices#1630
MarekSzczypinski wants to merge 5 commits into
labgrid-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
Comment thread labgrid/driver/power/tapo.py Outdated
# 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

codecov Bot commented Jan 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 46.1%. Comparing base (0507604) to head (eb6f6f5).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff            @@
##           master   #1630     +/-   ##
========================================
+ Coverage    46.0%   46.1%   +0.1%     
========================================
  Files         180     181      +1     
  Lines       14464   14514     +50     
========================================
+ Hits         6654    6704     +50     
  Misses       7810    7810             
Flag Coverage Δ
3.10 46.1% <96.0%> (+0.1%) ⬆️
3.11 46.1% <96.0%> (+0.1%) ⬆️
3.12 46.1% <96.0%> (+0.1%) ⬆️
3.13 46.1% <96.0%> (+0.1%) ⬆️
3.14 46.1% <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 Harness.
📢 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

Emantor commented Mar 19, 2026

Copy link
Copy Markdown
Member

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

MarekSzczypinski commented Mar 24, 2026

Copy link
Copy Markdown
Contributor Author

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

@Emantor Done. No worries :)

@Emantor

Emantor commented Mar 30, 2026

Copy link
Copy Markdown
Member

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

MarekSzczypinski commented Mar 30, 2026

Copy link
Copy Markdown
Contributor Author

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 2 times, most recently from b72ca70 to 1d2c4ac Compare April 1, 2026 22:21
@MarekSzczypinski MarekSzczypinski force-pushed the feature/add-tapo-support branch from 1d2c4ac to a3df1cc Compare April 8, 2026 08:20
@threexc

threexc commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

Hi,

Following the community call, I've been looking this over and trying to compare it to my own PR to extend the tplink driver support: #1693

I don't think that the functionality added here overlaps with #1693, as despite the devices being similar I believe there are different protocols at play.

To test, I used the same HS103 I'd used previously with my PR, and the following exporter config:

smartplug-1:
  location: shelf
  kasa-smartplug-1:
    cls: 'NetworkPowerPort'
    model: 'tplink'
    host: '192.168.40.5'

and I see this error after changing to model: tapo with your branch, re-exporting, and running labgrid-client -p smartplug-test pw on:

labgrid-client: error: failed to create NetworkPowerPort for target 'Target(name='smartplug-test', env=None)' using {'host': '192.168.40.5', 'model': 'tapo'}
This is likely caused by an error in the environment configuration or invalid
resource information provided by the coordinator.

We may be able to combine some of the logic in both PRs, but it is worth noting too that they don't follow exactly the same flow - for example, the existing tplink driver makes async Discover.discover_single() calls as part of the set/get methods, while I don't see that here.

Maybe we need to align the two sets of code and implement a tplink_common module? Alternatively, we combine them into a single kasa module to avoid duplication at all? There is some appeal to making them distinct so that users can find them by product name, but maybe not for maintenance :)

@jluebbe @Emantor thoughts?

@MarekSzczypinski MarekSzczypinski force-pushed the feature/add-tapo-support branch from a3df1cc to 766e8f5 Compare May 5, 2026 20:03
@MarekSzczypinski MarekSzczypinski force-pushed the feature/add-tapo-support branch from 130ca1d to eb6f6f5 Compare June 8, 2026 08:17
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 eb6f6f5 to 051e0f5 Compare June 15, 2026 06:56
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.

3 participants