-
-
Notifications
You must be signed in to change notification settings - Fork 236
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
base: master
Are you sure you want to change the base?
Conversation
…ed keys The P316M device uses 'protection_enabled' instead of 'enabled' in the protection power configuration. Update tests to check which key is used by each device and assert the correct parameters in test calls.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1561 +/- ##
=======================================
Coverage 92.66% 92.66%
=======================================
Files 150 150
Lines 9538 9544 +6
Branches 974 976 +2
=======================================
+ Hits 8838 8844 +6
Misses 499 499
Partials 201 201 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I'm a bit stuck and could use some guidance. Shouldn't this device report its power emeter metrics via CLI? I have tried both these commands and they seem to fail. I don't know what needs to be changed.
Error
Error |
energy module to avoid KeyError.
|
While I think I may have found and fixed the bug about root@kasapi:~/try2/python-kasa# uv run kasa --username xx --password x --host 192.168.66.240 energy
Discovering device 192.168.66.240 for 10 seconds
== Energy ==
Current: 0.0 A
Voltage: 122.359 V
Power: 0.0 W
Total consumption: None kWh
Today: 0.0 kWh
This month: 0.0 kWh |
Use a single `if` statement instead of nested `if` statements
|
@rytilahti Hi I know you are busy, do you think you could help share a few pointers on what code may need to be changed to make this device work? My PR has the fixture files, but IOT powerstrip which has e-meter is not reporting Energy() and usage of each independent power outlet of the powerstrip. I believe this is a new function that may need to be added, perhaps I am wrong and this exists but I do not have any older allegedly supported HS300 power strip to see how it reports emeter data. |
rytilahti
left a comment
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.
Thanks for the PR, @TheLinuxGuy! I added some comments inline, but it is generally looking good. I would suggest that we try to keep this PR as minimum (as it's about adding a fixture) & tackle other issues (like the cli emeter support) in separate PRs.
| """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") |
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.
| return gp.get("enabled") or gp.get("protection_enabled") | |
| return gp.get("enabled", gp.get("protection_enabled")) |
| 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) |
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.
| 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) | |
| enabled_key = next(k for k in self.data["get_protection_power"].keys() if "enabled" in k) | |
| params = {**self.data["get_protection_power"], enabled_key: enabled} |
How about something like this?
| if "protection_enabled" in protection_data: | ||
| params = { | ||
| "protection_enabled": True, | ||
| "protection_power": mocker.ANY, |
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'd do similar trick here as above in the implementation to make it cleaner.
| if "protection_enabled" in protection_data: | ||
| params = { | ||
| "protection_enabled": True, | ||
| "protection_power": int(powerprot._max_power / 2), | ||
| } | ||
| else: | ||
| params = { | ||
| "enabled": True, | ||
| "protection_power": int(powerprot._max_power / 2), |
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.
See my comment above about extracting the key & re-using it to avoid branching here and below.
| # Energy module is not supported on P304M parent device | ||
| # P316M powerstrip does not have 'device_on' key in sys_info. | ||
| if ( | ||
| "device_on" not in self._device.sys_info | ||
| and self._device.sys_info.get("model") == "P316M" | ||
| ): | ||
| return True | ||
| return "device_on" in self._device.sys_info |
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.
IOT powerstrips are structured very differently, so it does not make much sense to take example for them. The emeter support for devices like P304M and P316M should already be there (using the If you execute |
|
New PR created as requested, with only the fixtures. #1568 |
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
Add P316M support to python-kasa.