-
-
Notifications
You must be signed in to change notification settings - Fork 226
Extend smartcam detection support #1552
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
base: master
Are you sure you want to change the base?
Conversation
Those file have linecrossingDetection in app_component_list; this fix tests
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1552 +/- ##
==========================================
+ Coverage 92.66% 92.74% +0.08%
==========================================
Files 150 155 +5
Lines 9538 9648 +110
Branches 974 974
==========================================
+ Hits 8838 8948 +110
Misses 499 499
Partials 201 201 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This avoid typos when defining entity keys in Home Assistant that must be same as Feature ID.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all, thanks for the PR and looking into this, I'm sure many will find this useful in the future! Just a quick initial review, with a couple of points:
- I think we should generalize the togglables/enablables under a "TogglableFeature" or something similar to avoid copy&pasting boilerplate for both the implementation and the tests. We could also leverage this for other features in the future.
- This PR should be kept as small as possible, so please avoid adding the feature identifier class as a part of this. We can discuss having such later, but it's better to keep PRs contained and clean for the future maintainers' sake.
kasa/feature.py
Outdated
@@ -81,6 +81,44 @@ | |||
_LOGGER = logging.getLogger(__name__) | |||
|
|||
|
|||
class FeatureIdentifier(StrEnum): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not add this, at least not yet, to keep the PR as small as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I've added it after looking at home assistant code, where I've found that feature's id must be the same as the home assistant entity's key, and this can be easily mistyped.
I could revert those changes and create a different PR after this will be merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class BarkDetection(SmartCamModule): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering all detection modules follow the same format, only with a different section and method names, I'm wondering if we could generalize this to avoid boilerplate? Maybe the generic detection module could read the available components and create the entities, having an enum defining the available detection types that could also be passed to a generic "set_enabled".
This will allow keeping the codebase easier to maintain, and also the tests much simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll work on this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactored with a common class for all the detections
@@ -506,6 +506,22 @@ | |||
} | |||
} | |||
}, | |||
"getLinecrossingDetectionConfig": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have all these devices that have new fixtures including this information? If yes, I would suggest only including one fixture update alongside the dump_devinfo updates in this initial PR, and creating a new PR to update the rest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no I haven't, I've put those blocks to have test passed.
code looks at this dict when fixture has
{
"name": "linecrossingDetection",
"version": 2
},
let me know if you prefer having failure tests or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as example of why I did this change, with commit add LineCrossingDetectionRegion on dump_devinfo I've added a new section about linedetection region and then dumped the C220 webcam I have: the tests now fail for other webcams that have declared the linecrossingDetection feature but they have no "region_info" block.
To fix this, there are two ways:
- remove the change on devtools/helpers/smartcamrequests.py
- add missing block on all the fixture files
let me know which is the way to do, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a dictionary in one of the fake protocol implementation files containing dummy payloads where none is available, that's the place to add one so that the fixtures remain intact. I'll try to review other changes now on the train or latest later this weekend :)
edit: https://github.com/python-kasa/python-kasa/blob/master/tests%2Ffakeprotocol_smart.py#L91
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a dictionary in one of the fake protocol implementation files containing dummy payloads where none is available, that's the place to add one so that the fixtures remain intact. I'll try to review other changes now on the train or latest later this weekend :)
edit: https://github.com/python-kasa/python-kasa/blob/master/tests%2Ffakeprotocol_smart.py#L91
tryied to use that file, and also fakeprotocol_smartcam, but none working as you can see by all the failing pipeline.
This reverts commit 2ab846c.
QUERY_SECTION_NAMES can be list, so mypy returns error.
@@ -0,0 +1,45 @@ | |||
"""Tests for smartcam bark detection module.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should also parameterize the tests to avoid code duplication for these similar modules? Just an idea 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted to multiple SmartCamModule with repeated code, it's the only version that passes tests.
I've tried parametrize_combine but I cannot get it to work; same end also using @pytest.mark.parametrize .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late response, but let's rather fix the tests to avoid code duplication to keep it more maintainable.
If you want to bring your generalized revision back to this PR, I will try to find some time soon to look into fixing the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @rytilahti , sorry for this late response, I've pushed the branch with detectionmodule
common class, all the detections inherits from it.
I've tried some test changes but I've no idea actually on how to fix it, thanks.
b695653
to
745342a
Compare
New detection added with tests:
those module should be ready for home assistant, a change is needed into core repo adding more entity like this one .
closes #1551