From 460794339ec4e8485bf1a38d488da8065f9025eb Mon Sep 17 00:00:00 2001 From: Roman Chernyatchik Date: Sat, 28 Mar 2020 17:48:10 +0300 Subject: [PATCH] Code cleanup, removed hardware/firmware properties from status, use device.info() for them (#642) --- miio/airhumidifier_jsq.py | 33 +++++----------------------- miio/tests/test_airhumidifier_jsq.py | 8 +------ 2 files changed, 6 insertions(+), 35 deletions(-) diff --git a/miio/airhumidifier_jsq.py b/miio/airhumidifier_jsq.py index fb9beaff5..1b7bceb91 100644 --- a/miio/airhumidifier_jsq.py +++ b/miio/airhumidifier_jsq.py @@ -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__) @@ -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] @@ -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: @@ -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 = ( " 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, @@ -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 @@ -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( @@ -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): @@ -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): diff --git a/miio/tests/test_airhumidifier_jsq.py b/miio/tests/test_airhumidifier_jsq.py index a94038179..4857def2a 100644 --- a/miio/tests/test_airhumidifier_jsq.py +++ b/miio/tests/test_airhumidifier_jsq.py @@ -11,7 +11,6 @@ LedBrightness, OperationMode, ) -from miio.device import DeviceInfo from .dummies import DummyDevice @@ -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"] @@ -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():