Skip to content

Conversation

threexc
Copy link
Contributor

@threexc threexc commented Jul 11, 2025

Description

  • Extend the tplink resource definition to support smart plug devices like the HS103, in addition to the existing IotStrip functionality.
  • Since these only have one port, make the index argument for NetworkPowerPort optional and default to 0 if not provided.
  • Also update the docs to indicate that index is 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

  • Documentation for the feature
  • Tests for the feature - I think the existing tests may be adequate, but review would be good.
  • The arguments and description in doc/configuration.rst have been updated
  • PR has been tested

@threexc threexc force-pushed the tgamblin/kasa-driver branch from e17fbb1 to 4edf37e Compare July 11, 2025 17:38
@threexc
Copy link
Contributor Author

threexc commented Jul 11, 2025

Pushed an update because I realized that the doc update didn't clarify that tplink now works for smart plugs too.

Copy link

codecov bot commented Jul 11, 2025

Codecov Report

❌ Patch coverage is 14.81481% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.3%. Comparing base (2daa13d) to head (f4f2fc1).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
labgrid/driver/power/tplink.py 11.5% 23 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #1693     +/-   ##
========================================
- Coverage    45.4%   45.3%   -0.1%     
========================================
  Files         172     172             
  Lines       13503   13517     +14     
========================================
+ Hits         6131    6133      +2     
- Misses       7372    7384     +12     
Flag Coverage Δ
3.10 45.3% <14.8%> (-0.1%) ⬇️
3.11 45.3% <14.8%> (-0.1%) ⬇️
3.12 45.3% <14.8%> (-0.1%) ⬇️
3.13 45.3% <14.8%> (-0.1%) ⬇️
3.9 45.4% <14.8%> (-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.

@threexc
Copy link
Contributor Author

threexc commented Jul 11, 2025

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.

@threexc threexc force-pushed the tgamblin/kasa-driver branch 3 times, most recently from 5c21895 to a48b9a0 Compare July 16, 2025 14:49
@threexc threexc force-pushed the tgamblin/kasa-driver branch from a48b9a0 to d945598 Compare July 21, 2025 16:53
@threexc threexc force-pushed the tgamblin/kasa-driver branch 2 times, most recently from 15d1f49 to e78a072 Compare July 22, 2025 13:21
Copy link
Contributor

@sjg20 sjg20 left a comment

Choose a reason for hiding this comment

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

I'm not sure what can be done about testing, but otherwise this LGTM

@threexc threexc force-pushed the tgamblin/kasa-driver branch 3 times, most recently from 25fd909 to ff6fd02 Compare July 28, 2025 16:05
@threexc
Copy link
Contributor Author

threexc commented Jul 28, 2025

A few rebases recently, no changes to the logic.

@threexc threexc force-pushed the tgamblin/kasa-driver branch from ff6fd02 to 64eef0a Compare August 11, 2025 13:23
@threexc threexc force-pushed the tgamblin/kasa-driver branch from 64eef0a to 7704779 Compare August 22, 2025 18:58
@threexc
Copy link
Contributor Author

threexc commented Aug 22, 2025

@Bastian-Krause @jluebbe anything holding this one back?

@threexc threexc force-pushed the tgamblin/kasa-driver branch from 7704779 to ea77529 Compare September 3, 2025 13:50
@threexc threexc force-pushed the tgamblin/kasa-driver branch from ea77529 to 7e04d60 Compare September 15, 2025 01:02
@threexc
Copy link
Contributor Author

threexc commented Sep 15, 2025

Just rebasing again, no new additions.

@threexc threexc force-pushed the tgamblin/kasa-driver branch from 7e04d60 to c976530 Compare September 22, 2025 16:37
@threexc
Copy link
Contributor Author

threexc commented Sep 22, 2025

Rebased again.

- differentiate between 'strip' and 'plug' devices, using simpler logic
  for controlling power on the latter
- create new _power_get() async function to match _power_set()

Signed-off-by: Trevor Gamblin <[email protected]>
Smart plugs and similar single-port network-controlled devices shouldn't
require the exporter config to include the 'index' argument. Make it
optional by including a default of 0 in NetworkPowerPort.

Signed-off-by: Trevor Gamblin <[email protected]>
- Document that 'index' is now optional
- Change 'tplink' section to indicate it controls both smart plugs and
  power strips

Signed-off-by: Trevor Gamblin <[email protected]>
This is similar test_create, but it doesn't pass an index value, testing
that the default index of the NetworkPowerPort object is '0' and also
that the NetworkPowerDriver can still be instantiated correctly.

Signed-off-by: Trevor Gamblin <[email protected]>
@threexc threexc force-pushed the tgamblin/kasa-driver branch from c976530 to f4f2fc1 Compare September 24, 2025 16:20
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