8000 Fallback to get_current_power if get_energy_usage does not provide current_power by Fulch36 · Pull Request #1186 · python-kasa/python-kasa · GitHub
[go: up one dir, main page]

Skip to content

Fallback to get_current_power if get_energy_usage does not provide current_power #1186

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

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions kasa/smart/modules/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
"""Current power in watts."""
if (power := self.energy.get("current_power")) is not None:
return power / 1_000
# Fallback if get_energy_usage does not provide current_power,
# which can happen on some newer devices (e.g. P304M).
elif (
power := self.data.get("get_current_power").get("current_power")
) is not None:
return power

Check warning on line 36 in kasa/smart/modules/energy.py

View check run for this annotation

Codecov / codecov/patch

kasa/smart/modules/energy.py#L36

Added line #L36 was not covered by tests
return None

@property
Expand Down Expand Up @@ -105,3 +111,8 @@
async def get_monthly_stats(self, *, year=None, kwh=True) -> dict:
"""Return monthly stats for the given year."""
raise KasaException("Device does not support periodic statistics")

async def _check_supported(self):
"""Additional check to see if the module is supported by the device."""
# Energy module is not supported on P304M parent device
return "device_on" in self._device.sys_info
Loading
0