Skip to content

Commit

Permalink
Code cleanup, removed hardware/firmware properties from status, use d…
Browse files Browse the repository at this point in the history
…evice.info() for them (rytilahti#642)
  • Loading branch information
iromeo committed Mar 28, 2020
1 parent f23130b commit 4607943
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 35 deletions.
33 changes: 5 additions & 28 deletions miio/airhumidifier_jsq.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from .airhumidifier import AirHumidifierException
from .click_common import EnumType, command, format_output
from .device import Device, DeviceInfo, Optional
from .device import Device

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -46,7 +46,7 @@ class LedBrightness(enum.Enum):
class AirHumidifierStatus:
"""Container for status reports from the air humidifier jsq."""

def __init__(self, data: Dict[str, Any], device_info: DeviceInfo) -> None:
def __init__(self, data: Dict[str, Any]) -> None:
"""
Status of an Air Humidifier (shuii.humidifier.jsq001):
[24, 30, 1, 1, 0, 2, 0, 0, 0]
Expand All @@ -57,7 +57,6 @@ def __init__(self, data: Dict[str, Any], device_info: DeviceInfo) -> None:
'lid_opened': 0}
"""
self.data = data
self.device_info = device_info

@property
def power(self) -> str:
Expand Down Expand Up @@ -127,16 +126,6 @@ def lid_opened(self) -> bool:
"""True if the water tank is detached."""
return self.data["lid_opened"] == 1

@property
def firmware_version(self) -> str:
"""Returns the fw_ver of miIO.info. For example 1.3.9."""
return self.device_info.firmware_version

@property
def hardware_version(self) -> Optional[str]:
"""The hardware version."""
return self.device_info.hardware_version

def __repr__(self) -> str:
s = (
"<AirHumidiferStatus power=%s, "
Expand All @@ -147,9 +136,7 @@ def __repr__(self) -> str:
"buzzer=%s, "
"child_lock=%s, "
"no_water=%s, "
"lid_opened=%s, "
"hardware_version=%s, "
"firmware_version=%s>"
"lid_opened=%s>"
% (
self.power,
self.mode,
Expand All @@ -160,8 +147,6 @@ def __repr__(self) -> str:
self.child_lock,
self.no_water,
self.lid_opened,
self.firmware_version,
self.hardware_version,
)
)
return s
Expand All @@ -187,7 +172,6 @@ def __init__(
super().__init__(ip, token, start_id, debug, lazy_discover)

self.model = model if model in AVAILABLE_PROPERTIES else MODEL_HUMIDIFIER_JSQ001
self.device_info = None

@command(
default_output=format_output(
Expand All @@ -200,17 +184,12 @@ def __init__(
"LED brightness: {result.led_brightness}\n"
"Child lock: {result.child_lock}\n"
"No water: {result.no_water}\n"
"Lid opened: {result.lid_opened}\n"
"Firmware version: {result.firmware_version}\n"
"Hardware version: {result.hardware_version}\n",
"Lid opened: {result.lid_opened}\n",
)
)
def status(self) -> AirHumidifierStatus:
"""Retrieve properties."""

if self.device_info is None:
self.device_info = self.info()

values = self.send("get_props")

# Response of an Air Humidifier (shuii.humidifier.jsq001):
Expand All @@ -237,9 +216,7 @@ def status(self) -> AirHumidifierStatus:
values,
)

return AirHumidifierStatus(
{k: v for k, v in zip(properties, values)}, self.device_info
)
return AirHumidifierStatus({k: v for k, v in zip(properties, values)})

@command(default_output=format_output("Powering on"))
def on(self):
Expand Down
8 changes: 1 addition & 7 deletions miio/tests/test_airhumidifier_jsq.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
LedBrightness,
OperationMode,
)
from miio.device import DeviceInfo

from .dummies import DummyDevice

Expand Down Expand Up @@ -113,10 +112,7 @@ def test_off(self):
def test_status(self):
self.device._reset_state()

device_info = DeviceInfo(self.device.dummy_device_info)
assert repr(self.state()) == repr(
AirHumidifierStatus(self.device.start_state, device_info)
)
assert repr(self.state()) == repr(AirHumidifierStatus(self.device.start_state))

assert self.state().temperature == self.device.start_state["temperature"]
assert self.state().humidity == self.device.start_state["humidity"]
Expand All @@ -129,8 +125,6 @@ def test_status(self):
assert self.is_on() is True
assert self.state().no_water == (self.device.start_state["no_water"] == 1)
assert self.state().lid_opened == (self.device.start_state["lid_opened"] == 1)
assert self.state().hardware_version == self.device.dummy_device_info["hw_ver"]
assert self.state().firmware_version == self.device.dummy_device_info["fw_ver"]

def test_status_wrong_input(self):
def mode():
Expand Down

0 comments on commit 4607943

Please sign in to comment.