Skip to content

Commit

Permalink
Merge pull request #2 from FrancYescO/patch-1
Browse files Browse the repository at this point in the history
fix cleaning while no mop attached
  • Loading branch information
tykarol authored May 10, 2021
2 parents adfd445 + 4e6bbd7 commit 536565d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion custom_components/viomi_vacuum_v8/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "viomi_vacuum_v8",
"name": "Viomi Vacuum V8",
"version": "1.2.1",
"version": "1.2.2",
"documentation": "https://github.com/tykarol/home-assistant-viomi-vacuum-v8",
"requirements": [
"construct>=2.10.59",
Expand Down
39 changes: 28 additions & 11 deletions custom_components/viomi_vacuum_v8/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,20 +424,37 @@ def update(self):

self._available = True

# Automatically set mop based on box_type
is_mop = int(self.vacuum_state['is_mop'])
# Current state of the vacuum
# 2: mop only, 1: dust&mop, 0: only vacuum
current_mode = int(self.vacuum_state['is_mop'])

# 3: 2 in 1, 2: water only, 1: dust only, 0: no box
box_type = int(self.vacuum_state['box_type'])

update_mop = None
if box_type == 2 and is_mop != 2:
update_mop = 2
elif box_type == 3 and is_mop != 1:
update_mop = 1
elif box_type == 1 and is_mop != 0:
update_mop = 0
# True: has the mop attachment, False: no attachment
has_mop = bool(self.vacuum_state['mop_type'])

if update_mop is not None:
self._vacuum.raw_command('set_mop', [update_mop])
# Automatically set mop based on box_type
new_mode = None

if box_type == 3:
# 2 in 1 box
if has_mop:
# Vacuum and mop if we have the attachment
new_mode = 1
else:
# Just vacuum if we have no mop
new_mode = 0
elif box_type == 2:
# We only have water, so let's mop.
# (Vacuum will error out if we have no mop attachment)
new_mode = 2
elif box_type == 1:
# We only have dust box, mopping not possible
new_mode = 0

if new_mode is not None and new_mode != current_mode:
self._vacuum.raw_command('set_mop', [new_mode])
self.update()
except OSError as exc:
_LOGGER.error("Got OSError while fetching the state: %s", exc)
Expand Down

0 comments on commit 536565d

Please sign in to comment.