Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chuangmi Plug V3: Fix measurement unit (W) of the power consumption (load_power) #338

Merged
merged 5 commits into from
Jun 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions miio/chuangmi_plug.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))
Expand Down
2 changes: 1 addition & 1 deletion miio/tests/test_chuangmi_plug.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down