From 72d07f62fd45dcdada9654b2728ce128828a3e97 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Sat, 16 Jun 2018 18:50:29 +0200 Subject: [PATCH 1/5] Align unit (W) of the power consumption (load_power) --- miio/chuangmi_plug.py | 6 +++--- miio/tests/test_chuangmi_plug.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/miio/chuangmi_plug.py b/miio/chuangmi_plug.py index 3260c6a42..c2859146a 100644 --- a/miio/chuangmi_plug.py +++ b/miio/chuangmi_plug.py @@ -61,10 +61,10 @@ def usb_power(self) -> Optional[bool]: return None @property - def load_power(self) -> Optional[int]: + def load_power(self) -> Optional[float]: """Current power load, if available.""" if "load_power" in self.data and self.data["load_power"] is not None: - return self.data["load_power"] + return float(self.data["load_power"]) return None @property @@ -134,7 +134,7 @@ def status(self) -> ChuangmiPlugStatus: load_power = self.send("get_power", []) # Response: [300] if len(load_power) == 1: properties.append('load_power') - values.append(load_power[0]) + values.append(load_power[0] * 0.01) return ChuangmiPlugStatus( defaultdict(lambda: None, zip(properties, values))) diff --git a/miio/tests/test_chuangmi_plug.py b/miio/tests/test_chuangmi_plug.py index dd922ffc0..923061ff8 100644 --- a/miio/tests/test_chuangmi_plug.py +++ b/miio/tests/test_chuangmi_plug.py @@ -147,7 +147,7 @@ def test_status(self): load_power = self.device._get_load_power().pop(0) start_state_extended = self.device.start_state.copy() - start_state_extended['load_power'] = load_power + start_state_extended['load_power'] = float(load_power) assert repr(self.state()) == repr( ChuangmiPlugStatus(start_state_extended)) @@ -155,7 +155,7 @@ def test_status(self): assert self.state().usb_power is True assert self.state().temperature == self.device.start_state[ "temperature"] - assert self.state().load_power == load_power + assert self.state().load_power == float(load_power) def test_usb_on(self): self.device.usb_off() # ensure off From 902d76f34f59fef9b07ccf3c4ffee8c839c58061 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Sat, 16 Jun 2018 19:07:42 +0200 Subject: [PATCH 2/5] Fix type --- miio/tests/test_chuangmi_plug.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miio/tests/test_chuangmi_plug.py b/miio/tests/test_chuangmi_plug.py index 923061ff8..46fff13b1 100644 --- a/miio/tests/test_chuangmi_plug.py +++ b/miio/tests/test_chuangmi_plug.py @@ -147,7 +147,7 @@ def test_status(self): load_power = self.device._get_load_power().pop(0) start_state_extended = self.device.start_state.copy() - start_state_extended['load_power'] = float(load_power) + start_state_extended['load_power'] = load_power assert repr(self.state()) == repr( ChuangmiPlugStatus(start_state_extended)) From a24f1e8b7ccc5257fec28d0a24c2ae83d7be33fb Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Sat, 16 Jun 2018 19:08:28 +0200 Subject: [PATCH 3/5] Fix unit --- miio/tests/test_chuangmi_plug.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miio/tests/test_chuangmi_plug.py b/miio/tests/test_chuangmi_plug.py index 46fff13b1..d5414fca4 100644 --- a/miio/tests/test_chuangmi_plug.py +++ b/miio/tests/test_chuangmi_plug.py @@ -155,7 +155,7 @@ def test_status(self): assert self.state().usb_power is True assert self.state().temperature == self.device.start_state[ "temperature"] - assert self.state().load_power == float(load_power) + assert self.state().load_power == float(load_power * 0.01) def test_usb_on(self): self.device.usb_off() # ensure off From 86d729e7c8ccb24ba3e9f9c12c400f4af75a3047 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Sat, 16 Jun 2018 19:11:11 +0200 Subject: [PATCH 4/5] Remove needless cast --- miio/tests/test_chuangmi_plug.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miio/tests/test_chuangmi_plug.py b/miio/tests/test_chuangmi_plug.py index d5414fca4..660651920 100644 --- a/miio/tests/test_chuangmi_plug.py +++ b/miio/tests/test_chuangmi_plug.py @@ -155,7 +155,7 @@ def test_status(self): assert self.state().usb_power is True assert self.state().temperature == self.device.start_state[ "temperature"] - assert self.state().load_power == float(load_power * 0.01) + assert self.state().load_power == load_power * 0.01 def test_usb_on(self): self.device.usb_off() # ensure off From 4768a51d84f7b0b29d319a2d21a9a8d942010645 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Sat, 16 Jun 2018 19:19:40 +0200 Subject: [PATCH 5/5] Update extended state, too --- miio/tests/test_chuangmi_plug.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/miio/tests/test_chuangmi_plug.py b/miio/tests/test_chuangmi_plug.py index 660651920..84f4c4ff1 100644 --- a/miio/tests/test_chuangmi_plug.py +++ b/miio/tests/test_chuangmi_plug.py @@ -144,7 +144,7 @@ def test_off(self): def test_status(self): self.device._reset_state() - load_power = self.device._get_load_power().pop(0) + load_power = float(self.device._get_load_power().pop(0) * 0.01) start_state_extended = self.device.start_state.copy() start_state_extended['load_power'] = load_power @@ -155,7 +155,7 @@ def test_status(self): assert self.state().usb_power is True assert self.state().temperature == self.device.start_state[ "temperature"] - assert self.state().load_power == load_power * 0.01 + assert self.state().load_power == load_power def test_usb_on(self): self.device.usb_off() # ensure off