diff --git a/services.yaml b/services.yaml new file mode 100644 index 0000000..c068ede --- /dev/null +++ b/services.yaml @@ -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]" diff --git a/vacuum.py b/vacuum.py index 79ea9bf..dd0c69a 100644 --- a/vacuum.py +++ b/vacuum.py @@ -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( { @@ -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( @@ -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, @@ -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