Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
* expose repeat cleaning as a setting
* report error string only on real errors, the error code remains still available
* cleanup naming of some properties and methods
  • Loading branch information
rytilahti committed Oct 25, 2022
1 parent 10e037d commit 857c2ee
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions miio/integrations/vacuum/viomi/viomivacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,9 @@ def edge_state(self) -> ViomiEdgeState:
return ViomiEdgeState(self.data["mode"])

@property
@sensor("Mop installed")
def mop_installed(self) -> bool:
"""True if the mop is installed."""
@sensor("Mop attached")
def mop_attached(self) -> bool:
"""True if the mop is attached."""
return bool(self.data["mop_type"])

@property
Expand All @@ -367,7 +367,7 @@ def error_code(self) -> int:
@sensor("Error")
def error(self) -> Optional[str]:
"""String presentation for the error code."""
if self.error_code is None:
if self.vacuum_state != VacuumState.Error:
return None

return ERROR_CODES.get(self.error_code, f"Unknown error {self.error_code}")
Expand Down Expand Up @@ -428,7 +428,7 @@ def has_new_map(self) -> bool:

@property
@setting("Cleaning mode", choices=ViomiMode, setter_name="clean_mode")
def mop_mode(self) -> ViomiMode:
def clean_mode(self) -> ViomiMode:
"""Whether mopping is enabled and if so which mode."""
return ViomiMode(self.data["is_mop"])

Expand Down Expand Up @@ -460,7 +460,7 @@ def is_on(self) -> bool:

@property
@switch("LED state", setter_name="led")
def light_state(self) -> bool:
def led_state(self) -> bool:
"""Led state.
This seems doing nothing on STYJ02YM
Expand All @@ -475,7 +475,7 @@ def map_number(self) -> int:

@property
@setting("Mop pattern", choices=ViomiRoutePattern, setter_name="set_route_pattern")
def mop_route(self) -> Optional[ViomiRoutePattern]:
def route_pattern(self) -> Optional[ViomiRoutePattern]:
"""Pattern mode."""
route = self.data["mop_route"]
if route is None:
Expand All @@ -490,7 +490,7 @@ def order_time(self) -> int:
return self.data["order_time"]

@property
@sensor("Repeat cleaning active")
@switch("Repeat cleaning active", setter_name="set_repeat_cleaning")
def repeat_cleaning(self) -> bool:
"""Secondary clean up state.
Expand Down Expand Up @@ -599,7 +599,7 @@ def __init__(
"Fan speed: {result.fanspeed}\n"
"Water grade: {result.water_grade}\n"
"Mop mode: {result.mop_mode}\n"
"Mop installed: {result.mop_installed}\n"
"Mop attached: {result.mop_attached}\n"
"Vacuum along the edges: {result.edge_state}\n"
"Mop route pattern: {result.mop_route}\n"
"Secondary Cleanup: {result.repeat_cleaning}\n"
Expand Down Expand Up @@ -656,14 +656,15 @@ def status(self) -> ViomiVacuumStatus:
]
}

# fallback properties
all_properties = [
"battary_life",
"box_type",
"cur_mapid",
"err_state",
"has_map",
"has_newmap",
# "hw_info", # TODO: expose separately
"hw_info",
"is_charge",
"is_mop",
"is_work",
Expand All @@ -680,21 +681,19 @@ def status(self) -> ViomiVacuumStatus:
"suction_grade",
"v_state",
"water_grade",
# The following list of properties existing but
# there are not used in the code
# "order_time",
# "start_time",
# "water_percent",
# "zone_data",
# "sw_info",
# "main_brush_hours",
# "main_brush_life",
# "side_brush_hours",
# "side_brush_life",
# "mop_hours",
# "mop_life",
# "hypa_hours",
# "hypa_life",
"order_time",
"start_time",
"water_percent",
"zone_data",
"sw_info",
"main_brush_hours",
"main_brush_life",
"side_brush_hours",
"side_brush_life",
"mop_hours",
"mop_life",
"hypa_hours",
"hypa_life",
]

properties = device_props.get(self.model, all_properties)
Expand All @@ -703,6 +702,7 @@ def status(self) -> ViomiVacuumStatus:

status = ViomiVacuumStatus(defaultdict(lambda: None, zip(properties, values)))
status.embed(self.consumable_status())

return status

@command()
Expand All @@ -711,6 +711,7 @@ def home(self):
self.send("set_charge", [1])

def set_power(self, on: bool):
"""Set power on or off."""
if on:
return self.start()
else:
Expand Down Expand Up @@ -876,7 +877,7 @@ def set_edge(self, state: ViomiEdgeState):
return self.send("set_mode", [state.value])

@command(click.argument("state", type=bool))
def set_repeat(self, state: bool):
def set_repeat_cleaning(self, state: bool):
"""Set or Unset repeat mode (Secondary cleanup)."""
return self.send("set_repeat", [int(state)])

Expand Down

0 comments on commit 857c2ee

Please sign in to comment.