diff --git a/miio/airhumidifier.py b/miio/airhumidifier.py index 8ebf08c35..2c7f7395b 100644 --- a/miio/airhumidifier.py +++ b/miio/airhumidifier.py @@ -136,7 +136,7 @@ def strong_mode_enabled(self) -> bool: if self.trans_level == 90: return True - elif self.firmware_version_minor > 25: + elif self.firmware_version_minor > 25 or self.firmware_version_minor == 0: return self.mode.value == "strong" return False @@ -148,13 +148,16 @@ def firmware_version(self) -> str: @property def firmware_version_major(self) -> str: - major, _ = self.firmware_version.rsplit('_', 1) - return major + parts = self.firmware_version.rsplit('_', 1) + return parts[0] @property def firmware_version_minor(self) -> int: - _, minor = self.firmware_version.rsplit('_', 1) - return int(minor) + parts = self.firmware_version.rsplit('_', 1) + try: + return int(parts[1]) + except IndexError: + return 0 @property def motor_speed(self) -> Optional[int]: diff --git a/miio/tests/test_airhumidifier.py b/miio/tests/test_airhumidifier.py index d9baa265d..23f2001ea 100644 --- a/miio/tests/test_airhumidifier.py +++ b/miio/tests/test_airhumidifier.py @@ -217,7 +217,7 @@ class DummyAirHumidifierCA1(DummyDevice, AirHumidifier): def __init__(self, *args, **kwargs): self.model = MODEL_HUMIDIFIER_CA1 self.dummy_device_info = { - 'fw_ver': '1.2.9_5033', + 'fw_ver': '1.6.6', 'token': '68ffffffffffffffffffffffffffffff', 'otu_stat': [101, 74, 5343, 0, 5327, 407], 'mmfree': 228248, @@ -324,7 +324,13 @@ def test_status(self): assert self.state().firmware_version == device_info.firmware_version assert self.state().firmware_version_major == device_info.firmware_version.rsplit('_', 1)[0] - assert self.state().firmware_version_minor == int(device_info.firmware_version.rsplit('_', 1)[1]) + + try: + version_minor = int(device_info.firmware_version.rsplit('_', 1)[1]) + except IndexError: + version_minor = 0 + + assert self.state().firmware_version_minor == version_minor assert self.state().strong_mode_enabled is False def test_set_mode(self):