Skip to content

Conversation

ZeliardM
Copy link
Contributor

Wrote a iot styled module based on the existing smart HomeKit module. I may have missed some things and there may be some style or code changes that you may want to consider, but I think it should work. I got the commands from a user with an older, iot device that supports HomeKit and had him manually test them through the CLI and it worked.

Let me know if there's anything else or anything you'd like to have changed or updated.

Also, this is in conjunction with the following issue:
#1523

Once this is approved, would it be possible to get a new version of the library published so that I would be able to use this in my Homebridge plug-in?

@Copilot Copilot AI review requested due to automatic review settings August 12, 2025 21:38
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds HomeKit support for IoT devices by implementing a new HomeKit module that can retrieve setup information (setup codes and payloads) from devices that natively support HomeKit functionality.

  • Adds a new HomeKit module for IoT devices to query HomeKit setup information
  • Implements proper data masking for sensitive HomeKit credentials in protocol handling
  • Includes comprehensive test coverage for the new HomeKit module functionality

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
kasa/iot/modules/homekit.py New HomeKit module implementation with setup info retrieval
tests/iot/modules/test_homekit.py Complete test suite for HomeKit module functionality
kasa/iot/modules/init.py Exports the new HomeKit module
kasa/module.py Registers the IoT HomeKit module name
kasa/protocols/iotprotocol.py Adds data masking for HomeKit sensitive fields
tests/fakeprotocol_iot.py Mock HomeKit module data for testing
devtools/dump_devinfo.py Includes HomeKit setup info in device discovery

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

codecov bot commented Aug 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.73%. Comparing base (2b881cf) to head (19b38cb).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1566      +/-   ##
==========================================
+ Coverage   92.70%   92.73%   +0.02%     
==========================================
  Files         156      157       +1     
  Lines        9602     9630      +28     
  Branches      974      976       +2     
==========================================
+ Hits         8902     8930      +28     
  Misses        499      499              
  Partials      201      201              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ZeliardM
Copy link
Contributor Author

@rytilahti Let me know your thoughts here. I finally found someone who could help get the correct commands and modules so I could set it up. I created this module based on the older iot modules but with the same barebones functionality as the newer smart homekit module.

Unfortunately, I have not been able to test its functionality because I don't have an older iot device with homekit.

Copy link
Member

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

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

LGTM, I'm a bit worried if this can cause some issues with devices that do not support the module, but everything works fine on my only kasa test device so let's merge this :-)

@rytilahti rytilahti added the enhancement New feature or request label Aug 30, 2025
@rytilahti rytilahti changed the title Add bare bones homekit module iot devices Add bare bones homekit module for iot devices Aug 30, 2025
@rytilahti
Copy link
Member

Looks like the test coverage is failing, as we have no fixture containing this data. Do you have a fixture file from a real device that has this module? It would be great to add it to our collection!

@ZeliardM
Copy link
Contributor Author

I don't, how would I be able to use my branch to get one? I don't have a device but I could get the user that has one to test with my branch, if that's possible?

@ZeliardM
Copy link
Contributor Author

I messaged the user with the instructions for pulling my repo with the updated code so they can get us a fixture, will let you know. Then I can update everything.

@rytilahti
Copy link
Member

Okay, awesome! I usually use the github cli tool to fetch a PR (e.g., gh pr checkout 1566) & then just use the regular dumping script. Let me know how it goes!

@ZeliardM
Copy link
Contributor Author

@rytilahti ok, got the fixture, added it and updated everything here. Let me know if you need anything else.

@rytilahti
Copy link
Member

Nice, can be merged as soon as the tests pass!

@ZeliardM
Copy link
Contributor Author

@rytilahti ok, everything looks good except the codecov checks.

@ZeliardM
Copy link
Contributor Author

@rytilahti Will we be able to get a new release published after this? I'm hoping to get this implemented into my plugin, but would need a published version in Homebridge.

@sdb9696
Copy link
Collaborator

sdb9696 commented Aug 30, 2025

I am around tomorrow to cut a release if that helps

@ZeliardM
Copy link
Contributor Author

That would be fantastic. Good to hear from you and glad you're doing ok!

@rytilahti
Copy link
Member

Looks like the code paths are not covered for some reason, I can try to take a look and fix it if I find some time tomorrow.

As for the next release, I would like to include a fix to one issue that's been pending on my todo. I will try to handle that and create a release probably by the end of the next week.

@ZeliardM
Copy link
Contributor Author

Ok, sounds good. I have some MAC Address inclusion and exclusion features in the plugin that are used for right now so next week should be fine. I appreciate both of your hard work.

@rytilahti
Copy link
Member

@ZeliardM I added a commit fixing the initialization and the tests. There were several issues, but now your user should be able to see the feature getting initialized correctly.

The commit adds homekit module for all iot devices, but I don't think it should be an issue. In any case, it would be a good idea to test this PR against devices that do not support the module. @sdb9696 what do you think about this approach?

Btw, for future PRs, it's a good idea to use feature branches instead of master in your own repository, just in case :-)

@ZeliardM
Copy link
Contributor Author

I gotcha. Yea, I will take that approach in the future. Thanks.

I can test it against iot devices without HomeKit as I have several. And with child devices. What would I be looking for?

@rytilahti rytilahti added this to the 0.11 milestone Aug 31, 2025
@rytilahti
Copy link
Member

Yeah, just try the cli tool against your devices to see that everything is still working as expected. If you enable debug logging with --debug, you should also see that it tried to query the new module, but reports that it is not supported.

@ZeliardM
Copy link
Contributor Author

iotstrip.py does not call the super for the modules from IoTDevice so it will need to be added manually there. But everything for my plugs is working great. I see it called, but it comes up as not supported and moves on, no errors or hiccups. I can push out a commit for the iotstrip if you would like?

@ZeliardM
Copy link
Contributor Author

ZeliardM commented Sep 3, 2025

I pushed changes for adding the HomeKit module to the iotstrip devices as well as the rest of the code coverages for the testing of the module. I made changes so that when checking against the fixtures that if the data wasn't in the fixture it was skipped or said that it didn't exist instead of force adding the data to the fake protocol.

@ZeliardM
Copy link
Contributor Author

ZeliardM commented Sep 3, 2025

Had to fix the docstring checks. The way the module and tests are now for coverage, they actually test against the existing fixture files instead of blindly adding data to the fake protocol. This allowed for coverage tests of not actually having any data in the setup_info_get but therefore causes the homekit_setup_code to not be in the features. Fixed that and modified the docstring with an ellipsis to handle if devices have the code or not, but the homekit module is still always added as default, but the code may or may not be added as a feature, if that makes sense. Is this ok done this way?

@ZeliardM
Copy link
Contributor Author

ZeliardM commented Sep 3, 2025

Ok, coverage looks good, everything is still working for iot devices on my end that don't have homekit, it just flags it as not supported and moves on. The module being added is fine since every device could have it and there's no real way to test from the discovery of the older iot devices if they have homekit before adding the module and we add the module and just have it flagged as not supported, works for me. If y'all are good?

@ZeliardM
Copy link
Contributor Author

@rytilahti @sdb9696 I wanted to check and see if things were still progressing for this to be released?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants