Skip to content

Commit

Permalink
New features for robots with self-wash base
Browse files Browse the repository at this point in the history
  • Loading branch information
Yiğit Topcu committed Oct 18, 2022
1 parent 4b2c786 commit b46af8b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 16 deletions.
14 changes: 6 additions & 8 deletions custom_components/dreame_vacuum/dreame/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -1102,8 +1102,8 @@ def set_cleaning_mode(self, cleaning_mode: int) -> bool:
"Cannot set cleaning mode while vacuum is running"
)

if not self.status.self_wash_base_available:
if cleaning_mode is DreameVacuumCleaningMode.SWEEPING:
if not self.status.sweeping_with_mop_pad_available:
if cleaning_mode is DreameVacuumCleaningMode.SWEEPING.value:
if self.status.water_tank_installed:
if self.status.self_wash_base_available:
raise InvalidActionException(
Expand Down Expand Up @@ -2328,6 +2328,10 @@ def robot_status(self) -> int: # TODO: Convert to enum
"""Device status for robot icon rendering."""
if self.running and not self.returning and not self.fast_mapping:
return 1
elif self.self_wash_base_available and (self.washing or self.drying or self.washing_paused):
if self.has_error or self.has_warning:
return 6
return 7
elif self.charging:
return 2
elif self.has_error or self.has_warning:
Expand All @@ -2336,12 +2340,6 @@ def robot_status(self) -> int: # TODO: Convert to enum
else:
return 3
elif self.sleeping:
if self.self_wash_base_available and (
self.washing
or self.drying
or self.washing_paused
):
return 0
return 4
return 0

Expand Down
46 changes: 42 additions & 4 deletions custom_components/dreame_vacuum/dreame/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -3006,6 +3006,7 @@ def __init__(self, color_scheme: int = 0) -> None:
self._robot_cleaning_icon = None
self._robot_warning_icon = None
self._robot_sleeping_icon = None
self._robot_washing_icon = None

default_map_image = Image.open(
BytesIO(base64.b64decode(DEFAULT_MAP_IMAGE))
Expand Down Expand Up @@ -3242,6 +3243,7 @@ def render_map(self, map_data: MapData, robot_status: int = 0, robot_shape: int
self._robot_charging_icon = None
self._robot_cleaning_icon = None
self._robot_warning_icon = None
self._robot_washing_icon = None

if (
self._map_data is None
Expand Down Expand Up @@ -3473,10 +3475,12 @@ def render_objects(
self._map_data is None
or self._map_data.charger_position != map_data.charger_position
or self._map_data.rotation != map_data.rotation
or bool(self._robot_status > 5) != bool(robot_status > 5)
or not self._layers.get(MapRendererLayer.CHARGER)
):
self._layers[MapRendererLayer.CHARGER] = self.render_charger(
map_data.charger_position,
robot_status,
layer,
map_data.dimensions,
int((7 * map_data.dimensions.scale * scale) * 1.2),
Expand Down Expand Up @@ -3561,7 +3565,7 @@ def render_path(self, path, color, layer, dimensions, width, scale):
return new_layer

def render_charger(
self, charger_position, layer, dimensions, size, map_rotation, scale
self, charger_position, robot_status, layer, dimensions, size, map_rotation, scale
):
new_layer = Image.new("RGBA", layer.size, MAP_COLOR_TRANSPARENT)
if self._charger_icon is None:
Expand All @@ -3582,6 +3586,39 @@ def render_charger(
int((point.y * scale) - (size / 2))),
self._charger_icon,
)

if robot_status > 5:
if self._robot_washing_icon is None:
self._robot_washing_icon = (
Image.open(BytesIO(base64.b64decode(MAP_ROBOT_WASHING_IMAGE)))
.convert("RGBA")
.resize((int(size * 1.25), int(size * 1.25)))
.rotate(-map_rotation)
)
enhancer = ImageEnhance.Brightness(self._robot_washing_icon)
if self.color_scheme is not 0:
self._robot_washing_icon = enhancer.enhance(0.65)

icon = self._robot_washing_icon

icon_x = point.x * scale
icon_y = point.y * scale
offset = (size * 1.5)
if map_rotation == 90:
icon_x = icon_x + offset
elif map_rotation == 180:
icon_y = icon_y + offset
elif map_rotation == 270:
icon_x = icon_x - offset
else:
icon_y = icon_y - offset

new_layer.paste(
icon,
(int(icon_x - (icon.size[0] / 2)),
int(icon_y - (icon.size[1] / 2))),
icon,
)
return new_layer

def render_vacuum(
Expand Down Expand Up @@ -3629,7 +3666,7 @@ def render_vacuum(
.resize(((int(size * 1.3), int(size * 1.3))))
)
status_icon = self._robot_charging_icon
elif robot_status == 3 or robot_status == 5:
elif robot_status == 3 or robot_status == 5 or robot_status == 6:
if self._robot_warning_icon is None:
self._robot_warning_icon = (
Image.open(
Expand Down Expand Up @@ -3677,8 +3714,6 @@ def render_vacuum(

for k in [[19, 10, 0], [24, 24, 1]]:
status_icon = self._robot_sleeping_icon[k[2]]
x = point.x + k[0]
y = point.y - k[1]
if map_rotation == 90:
x = point.x + k[1]
y = point.y + k[0]
Expand All @@ -3688,6 +3723,9 @@ def render_vacuum(
elif map_rotation == 270:
x = point.x - k[1]
y = point.y - k[0]
else:
x = point.x + k[0]
y = point.y - k[1]

new_layer.paste(
status_icon,
Expand Down
Loading

0 comments on commit b46af8b

Please sign in to comment.