From b6c3a7c54b288efe712f27072ba1d3fe6136cb61 Mon Sep 17 00:00:00 2001 From: Andrew May Date: Sun, 12 Apr 2020 07:00:15 -0700 Subject: [PATCH] Move has_emeter to device level for multiple plug outlets (#41) --- kasa/smartdevice.py | 12 ++++++++---- kasa/smartplug.py | 12 ------------ kasa/smartstrip.py | 10 ---------- 3 files changed, 8 insertions(+), 26 deletions(-) diff --git a/kasa/smartdevice.py b/kasa/smartdevice.py index 593c035e..dfe97dae 100755 --- a/kasa/smartdevice.py +++ b/kasa/smartdevice.py @@ -155,13 +155,17 @@ class SmartDevice: return result + @property # type: ignore + @requires_update def has_emeter(self) -> bool: - """Return if device has an energy meter. + """Return whether device has an energy meter. - :return: True if energey meter is available - False if energymeter is missing + :return: True if energy meter is available + False otherwise """ - raise NotImplementedError() + sys_info = self.sys_info + features = sys_info["feature"].split(":") + return "ENE" in features async def get_sys_info(self) -> Dict[str, Any]: """Retrieve system information. diff --git a/kasa/smartplug.py b/kasa/smartplug.py index e21dda92..c4754a1e 100644 --- a/kasa/smartplug.py +++ b/kasa/smartplug.py @@ -92,18 +92,6 @@ class SmartPlug(SmartDevice): sys_info = self.sys_info return "brightness" in sys_info - @property # type: ignore - @requires_update - def has_emeter(self): - """Return whether device has an energy meter. - - :return: True if energy meter is available - False otherwise - """ - sys_info = self.sys_info - features = sys_info["feature"].split(":") - return "ENE" in features - @property # type: ignore @requires_update def is_on(self) -> bool: diff --git a/kasa/smartstrip.py b/kasa/smartstrip.py index b382629c..31cc262f 100755 --- a/kasa/smartstrip.py +++ b/kasa/smartstrip.py @@ -45,10 +45,6 @@ class SmartStrip(SmartDevice): and should be handled by the user of the library. """ - def has_emeter(self) -> bool: - """Return True as strips has always an emeter.""" - return True - def __init__(self, host: str, *, cache_ttl: int = 3) -> None: super().__init__(host=host) self.emeter_type = "emeter" @@ -281,12 +277,6 @@ class SmartStripPlug(SmartPlug): """ return f"{self.mac}_{self.child_id}" - @property # type: ignore - @requires_update - def has_emeter(self): - """Single sockets have always an emeter.""" - return True - @property # type: ignore @requires_update def alias(self) -> str: