-
-
Notifications
You must be signed in to change notification settings - Fork 238
Add device fixture for P316M(US) #1561
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
Open
TheLinuxGuy
wants to merge
7
commits into
python-kasa:master
Choose a base branch
from
TheLinuxGuy:add-P316M
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0d98aa2
Update documentation and add new device fixture for P316M(US)
18ddad8
Update powerprotection.py to handle different key names for enabled s…
df15a91
Fix powerprotection tests to handle both enabled and protection_enabl…
29c2aa0
Fix whitespace.
72151f1
Add special handling for P316M powerstrip in
48b9262
Fix. kasa/smart/modules/energy.py:168:9: SIM102
a79f27a
Fix alignment.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled dif
8000
ferently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -57,7 +57,8 @@ def overloaded(self) -> bool: | |||||||||||||||
| @property | ||||||||||||||||
| def enabled(self) -> bool: | ||||||||||||||||
| """Return True if child protection is enabled.""" | ||||||||||||||||
| return self.data["get_protection_power"]["enabled"] | ||||||||||||||||
| gp = self.data["get_protection_power"] | ||||||||||||||||
| return gp.get("enabled") or gp.get("protection_enabled") | ||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
|
|
||||||||||||||||
| async def set_enabled(self, enabled: bool, *, threshold: int | None = None) -> dict: | ||||||||||||||||
| """Set power protection enabled. | ||||||||||||||||
|
|
@@ -74,6 +75,10 @@ async def set_enabled(self, enabled: bool, *, threshold: int | None = None) -> d | |||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| params = {**self.data["get_protection_power"], "enabled": enabled} | ||||||||||||||||
| # If "enabled" is not used by the device, use "protection_enabled" | ||||||||||||||||
| if "protection_enabled" in self.data["get_protection_power"]: | ||||||||||||||||
| params["protection_enabled"] = enabled | ||||||||||||||||
| params.pop("enabled", None) | ||||||||||||||||
|
Comment on lines
77
to
+81
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
How about something like this? |
||||||||||||||||
| if threshold is not None: | ||||||||||||||||
| params["protection_power"] = threshold | ||||||||||||||||
| return await self.call("set_protection_power", params) | ||||||||||||||||
|
|
||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
So this check is only done to avoid initializing energy module for the main device on P304M as it only reports this information on the child sockets. I think this was an easy solution as the main device cannot be switched on and off, but this check should to my understanding also work for your P316M.
Maybe it's just the cli that needs adjustment for devices that have individual sockets with emeter?
In any case, I would suggest that we get this PR first merged without changes to emeter & tackle that issue in a separate PR.