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

Change the service API to match Xiaomi Miio and add segment cleaning #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
vacuum_clean_zone:
description: Start the cleaning operation in the selected areas for the number of repeats indicated.
fields:
entity_id:
description: Name of the vacuum entity.
example: "vacuum.xiaomi_vacuum_cleaner"
zone:
description: Array of zones. Each zone is an array of 4 float values. The values are in meters, where (0, 0) is the robot attached to the docking station.
example: "[[-1,-1,2,2]]"
repeats:
description: Number of cleaning repeats for each zone between 1 and 3.
example: "1"

vacuum_goto:
description: Start cleaning around the specified coordinate (spot cleaning).
fields:
entity_id:
description: Name of the vacuum entity.
example: "vacuum.xiaomi_vacuum_cleaner"
x_coord:
description: x-coordinate.
example: "-1"
y_coord:
description: y-coordinate.
example: 2

vacuum_clean_segment:
description: Start cleaning of the specified segment(s).
fields:
entity_id:
description: Name of the vacuum entity.
example: "vacuum.xiaomi_vacuum_cleaner"
segments:
description: Segments.
example: "[10,11]"

xiaomi_clean_zone:
description: Obsoleted, see vacuum_clean_zone.
fields:
entity_id:
description: Name of the vacuum entity.
example: "vacuum.xiaomi_vacuum_cleaner"
zone:
description: Array of zones. Each zone is an array of 4 float values. The values are in meters, where (0, 0) is the robot attached to the docking station.
example: "[[-1,-1,2,2]]"
repeats:
description: Number of cleaning repeats for each zone between 1 and 3.
example: "1"

xiaomi_clean_point:
description: Obsoleted, see vacuum_goto.
fields:
entity_id:
description: Name of the vacuum entity.
example: "vacuum.xiaomi_vacuum_cleaner"
point:
description: An array specifying a coordinate pair.
example: "[-1,2]"
48 changes: 47 additions & 1 deletion vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,16 @@
)

VACUUM_SERVICE_SCHEMA = vol.Schema({vol.Optional(ATTR_ENTITY_ID): cv.comp_entity_ids})
SERVICE_CLEAN_ZONE = "xiaomi_clean_zone"
SERVICE_CLEAN_ZONE = "vacuum_clean_zone"
SERVICE_GOTO = "vacuum_goto"
SERVICE_CLEAN_SEGMENT = "vacuum_clean_segment"
SERVICE_OBS_CLEAN_ZONE = "xiaomi_clean_zone"
SERVICE_CLEAN_POINT = "xiaomi_clean_point"
ATTR_ZONE_ARRAY = "zone"
ATTR_ZONE_REPEATER = "repeats"
ATTR_X_COORD = "x_coord"
ATTR_Y_COORD = "y_coord"
ATTR_SEGMENTS = "segments"
ATTR_POINT = "point"
SERVICE_SCHEMA_CLEAN_ZONE = VACUUM_SERVICE_SCHEMA.extend(
{
Expand All @@ -72,6 +78,20 @@
),
}
)
SERVICE_SCHEMA_GOTO = VACUUM_SERVICE_SCHEMA.extend(
{
vol.Required(ATTR_X_COORD): vol.Coerce(float),
vol.Required(ATTR_Y_COORD): vol.Coerce(float),
}
)
SERVICE_SCHEMA_CLEAN_SEGMENT = VACUUM_SERVICE_SCHEMA.extend(
{
vol.Required(ATTR_SEGMENTS): vol.Any(
vol.Coerce(int),
[vol.Coerce(int)]
),
}
)
SERVICE_SCHEMA_CLEAN_POINT = VACUUM_SERVICE_SCHEMA.extend(
{
vol.Required(ATTR_POINT): vol.All(
Expand All @@ -86,6 +106,18 @@
"method": "async_clean_zone",
"schema": SERVICE_SCHEMA_CLEAN_ZONE,
},
SERVICE_GOTO: {
"method": "async_goto",
"schema": SERVICE_SCHEMA_GOTO,
},
SERVICE_CLEAN_SEGMENT: {
"method": "async_clean_segment",
"schema": SERVICE_SCHEMA_CLEAN_SEGMENT,
},
SERVICE_OBS_CLEAN_ZONE: {
"method": "async_clean_zone",
"schema": SERVICE_SCHEMA_CLEAN_ZONE,
},
SERVICE_CLEAN_POINT: {
"method": "async_clean_point",
"schema": SERVICE_SCHEMA_CLEAN_POINT,
Expand Down Expand Up @@ -405,6 +437,20 @@ async def async_clean_zone(self, zone, repeats=1):
and await self._try_command("Unable to clean zone: %s", self._vacuum.raw_command, 'set_zone', result) \
and await self._try_command("Unable to clean zone: %s", self._vacuum.raw_command, 'set_mode', [3, 1])

async def async_goto(self, x_coord, y_coord):
"""Clean area around the specified coordinates"""
self._last_clean_point = [x_coord, y_coord]
await self._try_command("Unable to goto: %s", self._vacuum.raw_command, 'set_uploadmap', [0]) \
and await self._try_command("Unable to goto: %s", self._vacuum.raw_command, 'set_pointclean', [1, x_coord, y_coord])

async def async_clean_segment(self, segments):
"""Clean selected segment(s) (rooms)"""
if isinstance(segments, int):
segments = [segments]

await self._try_command("Unable to clean segments: %s", self._vacuum.raw_command, 'set_uploadmap', [1]) \
and await self._try_command("Unable to clean segments: %s", self._vacuum.raw_command, 'set_mode_withroom', [0, 1, len(segments)] + segments)

async def async_clean_point(self, point):
"""Clean selected area"""
x, y = point
Expand Down