Skip to content

Commit

Permalink
Add support for vacuum's carpet mode, which requires a recent firmwar…
Browse files Browse the repository at this point in the history
…e versions (#299)
  • Loading branch information
rytilahti authored and syssi committed Apr 4, 2018
1 parent 09643c2 commit 91b05a1
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 4 deletions.
37 changes: 34 additions & 3 deletions docs/vacuum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,33 @@ To enable (dnd 22:00-0600):

mirobo dnd on 22 0 6 0

It is also possible to run raw commands for testing:
Carpet mode
~~~~~~~~~~~

Carpet mode increases the suction when encountering a carpet.
The optional parameters (when using miiocli) are unknown and set as
they were in the original firmware.

To enable:

::

mirobo carpet_mode 1 (or any other true-value, such as 'true')


To disable:

::

mirobo carpet_mode 0


Raw commands
~~~~~~~~~~~~

It is also possible to run raw commands, which can be useful
for testing new unknown commands or if you want to have full access
to what is being sent to the device:

::

Expand All @@ -216,8 +242,13 @@ or with parameters (same as above dnd on):

mirobo raw_command set_dnd_timer '[22,0,6,0]'

If you find a new command please let us know by creating a pull request
or an issue, if you do not want to implement it on your own!
The input is passed as it is to the device as the `params` value,
so it is also possible to pass dicts.

.. NOTE::

If you find a new command please let us know by creating a pull request
or an issue, if you do not want to implement it on your own!

.. _HelpOutput:

Expand Down
27 changes: 26 additions & 1 deletion miio/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from .device import Device, DeviceException
from .vacuumcontainers import (VacuumStatus, ConsumableStatus, DNDStatus,
CleaningSummary, CleaningDetails, Timer,
SoundStatus, SoundInstallStatus, )
SoundStatus, SoundInstallStatus, CarpetModeStatus)

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -342,6 +342,31 @@ def configure_wifi(self, ssid, password, uid=0, timezone=None):

return super().configure_wifi(ssid, password, uid, extra_params)

@command()
def carpet_mode(self):
"""Get carpet mode settings"""
return CarpetModeStatus(self.send("get_carpet_mode")[0])

@command(
click.argument("enabled", required=True, type=bool),
click.argument("stall_time", required=False, default=10, type=int),
click.argument("low", required=False, default=400, type=int),
click.argument("high", required=False, default=500, type=int),
click.argument("integral", required=False, default=450, type=int)
)
def set_carpet_mode(self, enabled: bool, stall_time: int = 10,
low: int = 400, high: int = 500, integral: int = 450):
"""Set the carpet mode."""
click.echo("Setting carpet mode: %s" % enabled)
data = {
'enable': int(enabled),
'stall_time': stall_time,
'current_low': low,
'current_high': high,
'current_integral': integral,
}
return self.send("set_carpet_mode", [data])[0] == 'ok'

@classmethod
def get_device_group(cls):

Expand Down
10 changes: 10 additions & 0 deletions miio/vacuum_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,16 @@ def timezone(vac: miio.Vacuum, tz=None):
click.echo("Timezone: %s" % vac.timezone())


@cli.command()
@click.argument('enabled', required=False, type=bool)
@pass_dev
def carpet_mode(vac: miio.Vacuum, enabled=None):
"""Query or set the carpet mode."""
if enabled is None:
click.echo(vac.carpet_mode())
else:
click.echo(vac.set_carpet_mode(enabled))

@cli.command()
@click.argument('ssid', required=True)
@click.argument('password', required=True)
Expand Down
41 changes: 41 additions & 0 deletions miio/vacuumcontainers.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,3 +475,44 @@ def __repr__(self) -> str:

def __json__(self):
return self.data


class CarpetModeStatus:
"""Container for carpet mode status."""
def __init__(self, data):
# {'current_high': 500, 'enable': 1, 'current_integral': 450,
# 'current_low': 400, 'stall_time': 10}
self.data = data

@property
def enabled(self) -> bool:
"""True if carpet mode is enabled."""
return self.data['enable'] == 1

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

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

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

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

def __repr__(self):
return "<CarpetModeStatus enabled=%s, " \
"stall_time: %s, " \
"current (low, high, integral): (%s, %s, %s)>" % (self.enabled,
self.stall_time,
self.current_low,
self.current_high,
self.current_integral)

def __json__(self):
return self.data

0 comments on commit 91b05a1

Please sign in to comment.