Skip to content

Conversation

@MarekSzczypinski
Copy link

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
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
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
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
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
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
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)

@MarekSzczypinski
Copy link
Author

No changes - just updating to the master branch

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

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