Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhaus authored May 30, 2024
1 parent de7a37e commit d6463b5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
10 changes: 3 additions & 7 deletions deebot_client/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,7 @@ def _get_svg_positions(
for position in sorted(positions, key=lambda x: _POSITIONS_SVG[x.type].order):
pos = _calc_point_in_viewbox(position.x, position.y, viewbox)
svg_positions.append(
svg.Use(
href=f"#{_POSITIONS_SVG[position.type].svg_id}",
x=pos.x,
y=pos.y,
)
svg.Use(href=f"#{_POSITIONS_SVG[position.type].svg_id}", x=pos.x, y=pos.y)
)

return svg_positions
Expand Down Expand Up @@ -385,7 +381,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 = util.decompress_7z_base64_data(data)
trace_points = decompress_7z_base64_data(data)

for i in range(0, len(trace_points), 5):
position_x, position_y = struct.unpack("<hh", trace_points[i : i + 4])
Expand Down Expand Up @@ -612,7 +608,7 @@ def image(self) -> Image.Image:

def update_points(self, base64_data: str) -> None:
"""Add map piece points."""
decoded = util.decompress_7z_base64_data(base64_data)
decoded = decompress_7z_base64_data(base64_data)
old_crc32 = self._crc32
self._crc32 = zlib.crc32(decoded)

Expand Down
20 changes: 7 additions & 13 deletions tests/test_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,27 +280,27 @@ def test_get_svg_subset(subset: MapSubsetEvent, expected: Path | Polygon) -> Non

_test_get_svg_positions_data = [
(
[Position(PositionType.CHARGER, 5000, -55000)],
[Position(PositionType.CHARGER, 5000, -55000, 0)],
ViewBoxSpec(-500, -500, 1000, 1000),
[Use(href="#c", x=100, y=500)],
),
(
[Position(PositionType.DEEBOT, 15000, 15000)],
[Position(PositionType.DEEBOT, 15000, 15000, 0)],
ViewBoxSpec(-500, -500, 1000, 1000),
[Use(href="#d", x=300, y=-300)],
),
(
[
Position(PositionType.CHARGER, 25000, 55000),
Position(PositionType.DEEBOT, -5000, -50000),
Position(PositionType.CHARGER, 25000, 55000, 0),
Position(PositionType.DEEBOT, -5000, -50000, 0),
],
ViewBoxSpec(-500, -500, 1000, 1000),
[Use(href="#d", x=-100, y=500), Use(href="#c", x=500, y=-500)],
),
(
[
Position(PositionType.DEEBOT, -10000, 10000),
Position(PositionType.CHARGER, 50000, 5000),
Position(PositionType.DEEBOT, -10000, 10000, 0),
Position(PositionType.CHARGER, 50000, 5000, 0),
],
ViewBoxSpec(-500, -500, 1000, 1000),
[Use(href="#d", x=-200, y=-200), Use(href="#c", x=500, y=-100)],
Expand All @@ -317,10 +317,4 @@ def test_get_svg_positions(
expected: list[Use],
) -> None:
result = _get_svg_positions(positions, viewbox)
assert len(result) == len(expected)
for result_item, expected_item in zip(result, expected, strict=True):
assert type(result_item) == Use
assert result_item.href == expected_item.href
assert result_item.x == expected_item.x
assert result_item.y == expected_item.y
assert result_item == expected_item
assert result == expected

0 comments on commit d6463b5

Please sign in to comment.