8000 Fix reading current consumption for P304M · python-kasa/python-kasa@3dcc9e8 · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3dcc9e8

Browse files
committed
Fix reading current consumption for P304M
1 parent e3610cf commit 3dcc9e8

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

kasa/smart/modules/energy.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ def current_consumption(self) -> float | None:
2828
"""Current power in watts."""
2929
if (power := self.energy.get("current_power")) is not None:
3030
return power / 1_000
31+
# Fallback if get_energy_usage does not provide current_power,
32+
# which can happen on some newer devices (e.g. P304M).
33+
elif (
34+
power := self.data.get("get_current_power").get("current_power")
35+
) is not None:
36+
return power
3137
return None
3238

3339
@property
@@ -105,3 +111,8 @@ async def get_daily_stats(self, *, year=None, month=None, kwh=True) -> dict:
105111
async def get_monthly_stats(self, *, year=None, kwh=True) -> dict:
106112
"""Return monthly stats for the given year."""
107113
raise KasaException("Device does not support periodic statistics")
114+
115+
async def _check_supported(self):
116+
"""Additional check to see if the module is supported by the device."""
117+
# Energy module is not supported on P304M parent device
118+
return "device_on" in self._device.sys_info

0 commit comments

Comments
 (0)
0