Skip to content

Commit

Permalink
Merge pull request #8 from talss89/map-support
Browse files Browse the repository at this point in the history
Basic map support
  • Loading branch information
Jezza34000 authored Jan 22, 2023
2 parents bc2ac51 + d0578d5 commit 9338bab
Show file tree
Hide file tree
Showing 7 changed files with 520 additions and 5 deletions.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,47 @@ Go to WeBack app :
* Create a new account
* Add your robot to your new account
## Maps and Rooms
Maps are supported for `yw_ls` (LiDAR) vacuums. Others may work. Tested on:

- Electriq "Helga" iQlean-LR01

Integration with [PiotrMachowski/lovelace-xiaomi-vacuum-map-card](https://github.com/PiotrMachowski/lovelace-xiaomi-vacuum-map-card) supports automatic map calibration and room boundaries.

The vacuum entity has been modified to accept `send_command`s for room / segment cleaning.

### Example `lovelace-xiaomi-vacuum-map-card` card setup

To support automatic room boundaries, the Lovelace card needs to be templated. An example of this using [iantrich/config-template-card](https://github.com/iantrich/config-template-card)

*Please set both vacuum and camera entities appropriately. `camera.robot_map` and `vacuum.robot` in this example*


``` YAML
type: custom:config-template-card
variables:
ROOMS: states['camera.robot_map'].attributes.rooms
entities:
- camera.robot_map
card:
type: custom:xiaomi-vacuum-map-card
map_source:
camera: camera.robot_map
calibration_source:
camera: true
entity: vacuum.robot
vacuum_platform: send_command
title: Vacuum
preset_name: Live map
map_modes:
- template: vacuum_clean_zone
- template: vacuum_clean_segment
name: Rooms
icon: mdi:floor-plan
predefined_selections: ${ROOMS}
```

## Issues

Expand Down
36 changes: 36 additions & 0 deletions custom_components/weback_vacuum/VacDevice.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import logging
import io

from .WebackApi import WebackWssCtrl
from .VacMap import VacMap, VacMapDraw, VacMapRoom

_LOGGER = logging.getLogger(__name__)

Expand All @@ -13,6 +15,8 @@ def __init__(self, thing_name, thing_nickname, sub_type, thing_status,
self.name = thing_name
self.nickname = thing_nickname
self.sub_type = sub_type
self.map = None
self.map_image_buffer = None

# First init status from HTTP API
if self.robot_status is None:
Expand All @@ -29,6 +33,31 @@ async def watch_state(self):
except:
_LOGGER.exception('Error on watch_state starting refresh_handler')

async def load_maps(self):
"""Load the current reuse map"""
map_data = await self.get_reuse_map_by_id(self.robot_status["hismap_id"], self.sub_type, self.name)
if map_data is not []:
self.map = VacMap(map_data)
self.render_map()

def render_map(self):
if not self.map:
return False

vac_map_draw = VacMapDraw(self.map)
vac_map_draw.draw_charger_point()
vac_map_draw.draw_path()
vac_map_draw.draw_robot_position()

img = vac_map_draw.get_image()

img_byte_arr = io.BytesIO()
img.save(img_byte_arr, format='PNG')
img.close()
self.map_image_buffer = img_byte_arr.getvalue()

return True

# ==========================================================
# Vacuum Entity
# -> Properties
Expand Down Expand Up @@ -201,3 +230,10 @@ async def undisturb_mode(self, state: str):
else:
_LOGGER.error(f"Undisturb mode can't be set with value : {state}")
return

async def clean_room(self, room_ids: list):
room_data = list()
for id in room_ids:
room_data.append(dict(room_id = id))
working_payload = {self.ASK_STATUS: self.CLEAN_MODE_ROOMS, self.SELECTED_ZONE: room_data}
await self.send_command(self.name, self.sub_type, working_payload)
Loading

0 comments on commit 9338bab

Please sign in to comment.