mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 11:13:34 +00:00
Kasa KP125M basic emeter support (#560)
* Add KP125M basic emeter support. * Reduce diff. * PR Comments
This commit is contained in:
parent
a6b7d73d79
commit
bfd1d6ae0a
@ -137,6 +137,7 @@ If your device is unlisted but working, please open a pull request to update the
|
||||
* KP105
|
||||
* KP115
|
||||
* KP125
|
||||
* KP125M
|
||||
* KP401
|
||||
* EP10
|
||||
|
||||
|
@ -5,7 +5,8 @@ from typing import Any, Dict, Optional, cast
|
||||
|
||||
from ..credentials import Credentials
|
||||
from ..emeterstatus import EmeterStatus
|
||||
from ..smartdevice import DeviceType
|
||||
from ..modules import Emeter
|
||||
from ..smartdevice import DeviceType, requires_update
|
||||
from .tapodevice import TapoDevice
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -24,6 +25,15 @@ class TapoPlug(TapoDevice):
|
||||
) -> None:
|
||||
super().__init__(host, port=port, credentials=credentials, timeout=timeout)
|
||||
self._device_type = DeviceType.Plug
|
||||
self.modules: Dict[str, Any] = {}
|
||||
self.emeter_type = "emeter"
|
||||
self.modules["emeter"] = Emeter(self, self.emeter_type)
|
||||
|
||||
@property # type: ignore
|
||||
@requires_update
|
||||
def has_emeter(self) -> bool:
|
||||
"""Return that the plug has an emeter."""
|
||||
return True
|
||||
|
||||
async def update(self, update_children: bool = True):
|
||||
"""Call the device endpoint and update the device data."""
|
||||
@ -52,17 +62,24 @@ class TapoPlug(TapoDevice):
|
||||
@property
|
||||
def emeter_realtime(self) -> EmeterStatus:
|
||||
"""Get the emeter status."""
|
||||
return EmeterStatus({"power_mw": self._energy.get("current_power")})
|
||||
return EmeterStatus(
|
||||
{
|
||||
"power_mw": self._energy.get("current_power"),
|
||||
"total": self._convert_energy_data(
|
||||
self._energy.get("today_energy"), 1 / 1000
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
@property
|
||||
def emeter_today(self) -> Optional[float]:
|
||||
"""Get the emeter value for today."""
|
||||
return None
|
||||
return self._convert_energy_data(self._energy.get("today_energy"), 1 / 1000)
|
||||
|
||||
@property
|
||||
def emeter_this_month(self) -> Optional[float]:
|
||||
"""Get the emeter value for this month."""
|
||||
return None
|
||||
return self._convert_energy_data(self._energy.get("month_energy"), 1 / 1000)
|
||||
|
||||
@property
|
||||
def on_since(self) -> Optional[datetime]:
|
||||
@ -71,3 +88,7 @@ class TapoPlug(TapoDevice):
|
||||
return None
|
||||
on_time = cast(float, self._info.get("on_time"))
|
||||
return datetime.now().replace(microsecond=0) - timedelta(seconds=on_time)
|
||||
|
||||
def _convert_energy_data(self, data, scale) -> Optional[float]:
|
||||
"""Return adjusted emeter information."""
|
||||
return data if not data else data * scale
|
||||
|
Loading…
Reference in New Issue
Block a user