GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Add device fixture for P316M(US) by TheLinuxGuy · Pull Request #1561 · python-kasa/python-kasa 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.
|
There was an error while loading. Please reload this page.
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 Harness. 🚀 New features to boost your workflow:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
energy module to avoid KeyError.
There was an error while loading. Please reload this page.
|
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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| """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.
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")) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| 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.
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?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if "protection_enabled" in protection_data: | ||
| params = { | ||
| "protection_enabled": True, | ||
| "protection_power": mocker.ANY, |
There was a problem 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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| 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.
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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # 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.
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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
New PR created as requested, with only the fixtures. #1568 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Requested changes must be addressed to merge this pull request.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.