Skip to content
Merged
Prev Previous commit
Next Next commit
more human-friendly properties
  • Loading branch information
ofen committed Nov 2, 2021
commit 23b0c01fd4242d0cf1cff934f84909fa5eea450c
54 changes: 28 additions & 26 deletions miio/pet_water_dispenser.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,15 @@ class PetWaterDispenserException(DeviceException):


class PetWaterDispenserStatus(DeviceStatus):
'''Container for status reports from the Pet Water Dispenser.'''
'''Container for status reports from the Pet Water Dispenser'''

def __init__(self, data: Dict[str, Any]) -> None:
''' Pet Waterer / Pet Drinking Fountain / Smart Pet Water Dispenser (mmgg.pet_waterer.s1):
'''
'''Pet Waterer / Pet Drinking Fountain / Smart Pet Water Dispenser (mmgg.pet_waterer.s1)'''
self.data = data

@property
def filter_left_time(self) -> int:
'''Filter life time remaining in days.'''
'''Filter life time remaining in days'''
return self.data['filter_left_time']

@property
Expand All @@ -68,43 +67,46 @@ def power(self) -> str:

@property
def is_on(self) -> bool:
'''Return True if device is on.'''
'''True if device is on'''
return self.data['on']

@property
def mode(self) -> int:
'''Return True if device is on.'''
return self.data['mode']
def mode(self) -> str:
'''OperatingMode'''
return OperatingMode(self.data['mode']).name

@property
def indicator_light(self) -> bool:
def indicator_light_enabled(self) -> bool:
'''True if enabled'''
return self.data['indicator_light']

@property
def cotton_left_time(self) -> int:
return self.data['cotton_left_time']

@property
def remain_clean_time(self) -> int:
def days_before_cleaning(self) -> int:
return self.data['remain_clean_time']

@property
def no_water(self) -> bool:
'''Return True if there is no water left'''
'''True if there is no water left'''
if self.data['no_water_flag']:
return False
return True

@property
def no_water_time(self) -> int:
def minutes_without_water(self) -> int:
return self.data['no_water_time']

@property
def pump_block_flag(self) -> bool:
def pump_is_blocked(self) -> bool:
'''True if pump is blocked'''
return self.data['pump_block_flag']

@property
def lid_up_flag(self) -> bool:
def lid_is_up(self) -> bool:
'''True if lid is up'''
return self.data['lid_up_flag']

@property
Expand All @@ -116,9 +118,9 @@ def location(self) -> str:
return self.data['location']

@property
def fault(self) -> int:
'''Return device fault status code (0 - no faults)'''
return self.data['fault']
def error_detected(self) -> bool:
'''True if fault detected'''
return self.data['fault'] > 0


class PetWaterDispenser(MiotDevice):
Expand All @@ -130,17 +132,17 @@ class PetWaterDispenser(MiotDevice):
default_output=format_output(
'',
'Cotton filter live: {result.cotton_left_time} day(s) left\n'
'Fault: {result.fault}\n'
'Days before cleaning: {result.days_before_cleaning} day(s)\n'
'Error detected: {result.error_detected}\n'
'Filter live: {result.filter_left_time} day(s) left\n'
'Indicator light enabled: {result.indicator_light}\n'
'Lid is up: {result.lid_up_flag}\n'
'Indicator light enabled: {result.indicator_light_enabled}\n'
'Lid is up: {result.lid_is_up}\n'
'Location: {result.location}\n'
'Mode: {result.mode}\n'
'No water time: {result.no_water_time} minute(s)\n'
'Minutes without water: {result.minutes_without_water} minute(s)\n'
'No water: {result.no_water}\n'
'Power: {result.power}\n'
'Pump is blocked: {result.pump_block_flag}\n'
'Cleaning time: {result.remain_clean_time} day(s) left\n'
'Pump is blocked: {result.pump_is_blocked}\n'
'Timezone: {result.timezone}\n'
)
)
Expand Down Expand Up @@ -179,7 +181,7 @@ def on(self) -> str:
def disable_indicator_light(self) -> str:
Comment thread
rytilahti marked this conversation as resolved.
Outdated
'''Turn off idicator light.'''
status = self.status()
if not status.indicator_light:
if not status.indicator_light_enabled:
return 'Already disabled'
resp = self.set_property('indicator_light', False)
if resp[0]['code'] != 0:
Expand All @@ -190,7 +192,7 @@ def disable_indicator_light(self) -> str:
def enable_indicator_light(self) -> str:
'''Turn off idicator light.'''
status = self.status()
if status.indicator_light:
if status.indicator_light_enabled:
return 'Already enabled'
resp = self.set_property('indicator_light', True)
if resp[0]['code'] != 0:
Expand All @@ -205,7 +207,7 @@ def set_mode(self, mode: OperatingMode) -> str:
'''Switch operation mode.'''
status = self.status()
if status.mode == mode.value:
return f'Already set to "{mode.name}"'
return f'Already set to "{status.mode}"'
resp = self.set_property('mode', mode.value)
if resp[0]['code'] != 0:
raise PetWaterDispenserException(resp)
Expand Down