Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make get_module return typed module #892

Merged
merged 7 commits into from
May 3, 2024
Merged

Make get_module return typed module #892

merged 7 commits into from
May 3, 2024

Conversation

sdb9696
Copy link
Collaborator

@sdb9696 sdb9696 commented May 1, 2024

Passing in a string still works and returns either IotModule or SmartModule type when called on IotDevice or SmartDevice respectively. When calling on Device will return Module type.

Passing in a module type is then typed to that module, i.e.:

smartdev.get_module(FanModule)  # type is FanModule
smartdev.get_module("FanModule")  # type is SmartModule

Only thing this doesn't do is check that you can't pass an IotModule to a SmartDevice.get_module(). However there is a runtime check which will return null if the passed ModuleType is not a subclass of SmartModule.

Many thanks to @cdce8p for helping with this.

Copy link

codecov bot commented May 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.48%. Comparing base (5b48607) to head (bb1492b).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #892      +/-   ##
==========================================
+ Coverage   90.31%   90.48%   +0.16%     
==========================================
  Files          70       70              
  Lines        4917     4937      +20     
  Branches     1214     1218       +4     
==========================================
+ Hits         4441     4467      +26     
+ Misses        386      380       -6     
  Partials       90       90              

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

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.

Looking good and this is much nicer than casting & string access! It'd be great to have tests for the corner cases (i.e., passing invalid module name, passing invalid class, ..) and adding tests to fix those codecov warnings.

kasa/smart/smartdevice.py Show resolved Hide resolved
kasa/smart/smartdevice.py Show resolved Hide resolved
@rytilahti rytilahti added the enhancement New feature or request label May 3, 2024
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, let's get it merged! 🥇

@rytilahti rytilahti merged commit c5d65b6 into master May 3, 2024
27 checks passed
@rytilahti rytilahti deleted the feat/module_typing branch May 3, 2024 15:01
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.

None yet

2 participants