Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a service for zoned cleaning for Xiaomi Miio vacuum #15932

Closed
wants to merge 1 commit into from

Conversation

tenfire
Copy link

@tenfire tenfire commented Aug 11, 2018

Added a service for zoned cleaning after some help from pnbruckner (thanks!). Tested with my Xiaomi Roborock 2.

Description:

Related issue (if applicable): fixes #

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.github.io#<home-assistant.github.io PR number goes here>

Example entry for configuration.yaml (if applicable):

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New or updated dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

@homeassistant
Copy link
Contributor

Hi @tenfire,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@homeassistant homeassistant added cla-needed merging-to-master This PR is merging into the master branch and should probably change the branch to `dev`. platform: vacuum.xiaomi_miio labels Aug 11, 2018
@ghost ghost added the in progress label Aug 11, 2018
y1: int = 25500,
x2: int = 25500,
y2: int = 25500,
repetitions: int = 1):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line over-indented for visual indent

x1: int = 25500,
y1: int = 25500,
x2: int = 25500,
y2: int = 25500,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line over-indented for visual indent

def async_clean_zone(self,
x1: int = 25500,
y1: int = 25500,
x2: int = 25500,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line over-indented for visual indent

@asyncio.coroutine
def async_clean_zone(self,
x1: int = 25500,
y1: int = 25500,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line over-indented for visual indent

@@ -318,6 +340,20 @@ def async_send_command(self, command, params=None, **kwargs):
"Unable to send command to the vacuum: %s",
self._vacuum.raw_command, command, params)

@asyncio.coroutine
def async_clean_zone(self,
x1: int = 25500,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line over-indented for visual indent

@awarecan
Copy link
Contributor

Thanks for your contribution, please change your pull request's target to dev branch

params = [[x1, y1, x2, y2, repetitions]]
yield from self._try_command(
"Unable to start zoned cleaning: %s",
self._vacuum.raw_command,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proper way to do this would be to fix the python-miio instead of using raw_command, see rytilahti/python-miio#311 . It could be also useful to add a service for "goto" for the purpose of emptying the bin :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rytilahti rytilahti changed the title Added a service for zoned cleaning vacuum.xiaomi_miio: Add a service for zoned cleaning Aug 11, 2018
@tenfire tenfire changed the base branch from master to dev August 12, 2018 07:35
@fabaff fabaff changed the title vacuum.xiaomi_miio: Add a service for zoned cleaning Add a service for zoned cleaning for Xiaomi Miio vacuum Aug 12, 2018
@cnrd
Copy link
Contributor

cnrd commented Aug 12, 2018

We should probably also have some documentation that shows how the x1, x2, y1, and y2 coordinates relates to the real world, as I have personally seen the map change orientation on different runs of the vacuum. (Would changing the orientation of the map also change the coordinates, such that an automation to clean up the kitchen floor after I'm done cooking would make the vacuum clean a different area?) and how do we extract the correct x and y coordinates?

@fabaff fabaff removed the merging-to-master This PR is merging into the master branch and should probably change the branch to `dev`. label Aug 13, 2018
@syssi
Copy link
Member

syssi commented Aug 21, 2018

Please rebase your PR and use the new "goto" method of python-miio 0.4.1: https://github.com/rytilahti/python-miio/blob/master/miio/vacuum.py#L80

@asyncio.coroutine
def async_goto(self,
x: int = 25500,
y: int = 25500):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line over-indented for visual indent


@asyncio.coroutine
def async_goto(self,
x: int = 25500,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line over-indented for visual indent

"""Clean a specific zone."""
zoneList = []
for zone in zones:
zoneList.append([int(zone["x1"]), int(zone["y1"]), int(zone["x2"]), int(zone["y2"]), int(zone["iterations"])])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (122 > 79 characters)

y1: int = 25500,
x2: int = 25500,
y2: int = 25500,
iterations: int = 1):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line over-indented for visual indent

x1: int = 25500,
y1: int = 25500,
x2: int = 25500,
y2: int = 25500,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line over-indented for visual indent

def async_clean_zone(self,
x1: int = 25500,
y1: int = 25500,
x2: int = 25500,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line over-indented for visual indent

@asyncio.coroutine
def async_clean_zone(self,
x1: int = 25500,
y1: int = 25500,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line over-indented for visual indent

@@ -318,6 +371,38 @@ def async_send_command(self, command, params=None, **kwargs):
"Unable to send command to the vacuum: %s",
self._vacuum.raw_command, command, params)

@asyncio.coroutine
def async_clean_zone(self,
x1: int = 25500,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line over-indented for visual indent

@tenfire
Copy link
Author

tenfire commented Aug 22, 2018

I have tested all three services with my roborock 2 and it seems to be working.
According to this the xiaomi is using x=25500, y=25500 as origin (docking station). I have found that it sometimes changes origin and orientation if you start the zoned cleanup when the vacuum isn't docked.
I created two separate services for zoned cleanup, the first one only support a single zone, but is easier to use (and probably more common), and the other one has support for a list of zones.

NOTE: From the docking station point of view facing away from the wall it is placed against the X-axis is positive towards the right and the Y-axis is positive forward.

@cybe
Copy link
Contributor

cybe commented Aug 22, 2018

@tenfire Do you know of any limit regarding the maximum number of zones to be cleaned per API call? If I recall correctly, the MiHome app has a limit of 5.

@tenfire
Copy link
Author

tenfire commented Aug 22, 2018

@tenfire Do you know of any limit regarding the maximum number of zones to be cleaned per API call? If I recall correctly, the MiHome app has a limit of 5.

The app is limited to 3 iterations, but it worked with 5 using python-miio. I did not test with a higher number
EDIT
Did not read your question carefully enough, missed that you asked about number of zones and not number of iterations. I tried with more that 5 zones now. The vacuum still cleans the first 5 zones, but returns to the dock without cleaning the remaining zones.

@cybe
Copy link
Contributor

cybe commented Aug 24, 2018

Did not read your question carefully enough, missed that you asked about number of zones and not number of iterations. I tried with more that 5 zones now. The vacuum still cleans the first 5 zones, but returns to the dock without cleaning the remaining zones.

Thanks for testing and clearing that up :) So if I want to use more than 5 zones I need to wrap it in some kind of automation.

@tamasv
Copy link
Contributor

tamasv commented Sep 13, 2018

I have found that it sometimes changes origin and orientation if you start the zoned cleanup when the vacuum isn't docked.

Yes, but you can "reset" the map and orientation with the following method.
1, call start ( cleaning )
2, let it run for ~20 sec
3, send back to dock
4, call stop
I'm using this for months now with my scripts for zoned cleanup and works like a charm.


SERVICE_SCHEMA_CLEAN_ZONES = VACUUM_SERVICE_SCHEMA.extend({
vol.Required(ATTR_ZONE_ZONES):
vol.All(vol.Coerce(list)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be more than just list. Also, use cv.ensure_list.

@@ -69,7 +80,41 @@
vol.Optional(ATTR_RC_DURATION): cv.positive_int,
})

SERVICE_SCHEMA_CLEAN_ZONE = VACUUM_SERVICE_SCHEMA.extend({
Copy link
Member

@balloob balloob Sep 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should be removed, clean_zones should be able to handle the cleaning of 1 zone.

vol.All(vol.Coerce(list)),
})

SERVICE_SCHEMA_GOTO = VACUUM_SERVICE_SCHEMA.extend({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please limit PRs to 1 service at a time.

"""Clean a specific zone."""
zoneList = []
for zone in zones:
zoneList.append([int(zone["x1"]), int(zone["y1"]), int(zone["x2"]), int(zone["y2"]), int(zone["iterations"])])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conversion of variables has to happen in voluptuous schema.

@balloob
Copy link
Member

balloob commented Sep 21, 2018

You will also need to fix the linting erros.

@balloob balloob self-assigned this Sep 21, 2018
@pvizeli pvizeli closed this Dec 7, 2018
@ghost ghost removed the in progress label Dec 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.