Skip to content

Commit

Permalink
Improve firmware version parser of the Air Humidifier (Closes: #529) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
syssi authored Oct 6, 2019
1 parent 03d9e5f commit d4354e3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
13 changes: 8 additions & 5 deletions miio/airhumidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]:
Expand Down
10 changes: 8 additions & 2 deletions miio/tests/test_airhumidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit d4354e3

Please sign in to comment.