tplink: add support for kasa smart plugs
Description
- Extend the
tplinkresource definition to support smart plug devices like the HS103, in addition to the existing IotStrip functionality. - Since these only have one port, make the
indexargument forNetworkPowerPortoptional and default to0if not provided. - Also update the docs to indicate that
indexis now optional.
Tested locally using both a KP303 strip (already supported) and an HS103. Here's the latter's kasa discover data:
(labgrid-venv) tgamblin@ecogrid:~/labgrid$ kasa discover
Discovering devices on 255.255.255.255 for 10 seconds
== workspace - HS103 ==
Host: 192.168.40.218
Port: 9999
Device state: True
Time: 2025-07-11 13:26:06-05:00 (tz: EST)
Hardware: 5.0 (US)
Firmware: 1.0.13 Build 240117 Rel.162355
MAC (rssi): 98:25:4A:08:63:35 (-60)
== Primary features ==
State (state): True
== Information ==
On since (on_since): 2025-07-11 13:13:31-05:00
Cloud connection (cloud_connection): True
== Configuration ==
LED (led): True
== Debug ==
RSSI (rssi): -60 dBm
Reboot (reboot): <Action>
And here is the sample exporter config:
thinkcentre:
location: ecogrid
thinkcentre-kasa-plug:
cls: 'NetworkPowerPort'
model: 'tplink'
host: '192.168.40.218'
Checklist
- [X] Documentation for the feature
- [X] Tests for the feature - I think the existing tests may be adequate, but review would be good.
- [X] The arguments and description in doc/configuration.rst have been updated
- [X] PR has been tested
Pushed an update because I realized that the doc update didn't clarify that tplink now works for smart plugs too.
Codecov Report
:x: Patch coverage is 13.79310% with 25 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 45.2%. Comparing base (38d41d5) to head (fcae346).
:white_check_mark: All tests successful. No failed tests found.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| labgrid/driver/power/tplink.py | 10.7% | 25 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## master #1693 +/- ##
========================================
- Coverage 45.2% 45.2% -0.1%
========================================
Files 174 174
Lines 13747 13763 +16
========================================
+ Hits 6221 6223 +2
- Misses 7526 7540 +14
| Flag | Coverage Δ | |
|---|---|---|
| 3.10 | 45.2% <13.7%> (-0.1%) |
:arrow_down: |
| 3.11 | 45.2% <13.7%> (-0.1%) |
:arrow_down: |
| 3.12 | 45.2% <13.7%> (-0.1%) |
:arrow_down: |
| 3.13 | 45.1% <13.7%> (-0.1%) |
:arrow_down: |
| 3.14 | 45.1% <13.7%> (-0.1%) |
:arrow_down: |
| 3.9 | 45.2% <13.7%> (-0.1%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Added a new test case in TestNetworkPowerDriver to test the index and make sure that the NetworkPowerDriver object still gets created OK if no index is provided.
A few rebases recently, no changes to the logic.
@Bastian-Krause @jluebbe anything holding this one back?
Just rebasing again, no new additions.
Rebased again.
Rebased again.
Just another rebase to keep the branch current.
Last force push was just a rebase on master.
I took a look and it looked reasonable. Can you rebase and test again?
I took a look and it looked reasonable. Can you rebase and test again?
Sorry for the wait. Fixed it up and did another test with my HS103 smart plug just now. I had to fix the default for the index parameter so it was provided as a string instead of int.