mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 19:23:34 +00:00
Fallback to get_current_power if get_energy_usage does not provide current_power (#1186)
This commit is contained in:
parent
1e0ca799bc
commit
8b95b7d557
@ -28,6 +28,12 @@ class Energy(SmartModule, EnergyInterface):
|
|||||||
"""Current power in watts."""
|
"""Current power in watts."""
|
||||||
if (power := self.energy.get("current_power")) is not None:
|
if (power := self.energy.get("current_power")) is not None:
|
||||||
return power / 1_000
|
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
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -105,3 +111,8 @@ class Energy(SmartModule, EnergyInterface):
|
|||||||
async def get_monthly_stats(self, *, year=None, kwh=True) -> dict:
|
async def get_monthly_stats(self, *, year=None, kwh=True) -> dict:
|
||||||
"""Return monthly stats for the given year."""
|
"""Return monthly stats for the given year."""
|
||||||
raise KasaException("Device does not support periodic statistics")
|
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…
Reference in New Issue
Block a user