diff --git a/deebot_client/map.py b/deebot_client/map.py index 21be6361..41fa1734 100644 --- a/deebot_client/map.py +++ b/deebot_client/map.py @@ -17,6 +17,7 @@ from PIL import Image, ImageColor, ImageOps, ImagePalette import svg +from deebot_client import util from deebot_client.events.map import CachedMapInfoEvent, MapChangedEvent from .commands.json import GetMinorMap @@ -38,7 +39,6 @@ from .util import ( OnChangedDict, OnChangedList, - decompress_7z_base64_data, ) if TYPE_CHECKING: @@ -385,7 +385,7 @@ async def on_map_subset(event: MapSubsetEvent) -> None: def _update_trace_points(self, data: str) -> None: _LOGGER.debug("[_update_trace_points] Begin") - trace_points = decompress_7z_base64_data(data) + trace_points = util.decompress_7z_base64_data(data) for i in range(0, len(trace_points), 5): position_x, position_y = struct.unpack(" Image.Image: def update_points(self, base64_data: str) -> None: """Add map piece points.""" - decoded = decompress_7z_base64_data(base64_data) + decoded = util.decompress_7z_base64_data(base64_data) old_crc32 = self._crc32 self._crc32 = zlib.crc32(decoded) diff --git a/tests/test_map.py b/tests/test_map.py index 1f44cf05..59d9288a 100644 --- a/tests/test_map.py +++ b/tests/test_map.py @@ -2,7 +2,7 @@ import asyncio from typing import TYPE_CHECKING -from unittest.mock import ANY, AsyncMock, Mock, call +from unittest.mock import ANY, AsyncMock, Mock, call, patch import pytest import svg @@ -141,6 +141,34 @@ async def on_change() -> None: assert not map._unsubscribers +@patch( + "deebot_client.util.decompress_7z_base64_data", + Mock(return_value=b"\x10\x00\x00\x01\x00"), +) +async def test_Map_svg_traces_path( + execute_mock: AsyncMock, event_bus_mock: Mock +) -> None: + map = Map(execute_mock, event_bus_mock) + + path = map._get_svg_traces_path() + assert path is None + + map._update_trace_points("") + path = map._get_svg_traces_path() + + assert path == Path( + fill="none", + stroke="#fff", + stroke_width=1.5, + stroke_linejoin="round", + vector_effect="non-scaling-stroke", + transform=[ + svg.Scale(0.2, -0.2), + ], + d=[svg.MoveTo(x=16, y=256)], + ) + + def test_compact_path() -> None: """Test that the path is compacted correctly.""" path = Path(