Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #520 from Thomas55555/do-not-update-image-to-often
Browse files Browse the repository at this point in the history
avoid duplicates in position history
  • Loading branch information
Thomas55555 committed Aug 4, 2023
2 parents 1490821 + 59d20e4 commit e9296d5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 37 deletions.
9 changes: 2 additions & 7 deletions custom_components/husqvarna_automower/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,8 @@ def _generate_image_img(
position_history[0]["latitude"],
position_history[0]["longitude"],
)
if len(position_history) == 1:
self._position_history[
mower_id
] = position_history + self._position_history.get(mower_id, [])
position_history = self._position_history[mower_id]
else:
self._position_history[mower_id] = position_history

self._position_history[mower_id] = position_history

# pylint: disable=invalid-name
x1, y1 = self._scale_to_img(location, (map_image.size[0], map_image.size[1]))
Expand Down
30 changes: 0 additions & 30 deletions custom_components/husqvarna_automower/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,37 +145,7 @@ async def test_load_image_enabled(hass: HomeAssistant):
# Mower, no home location
image_one.home_location = None
await asyncio.to_thread(image_one._generate_image, {})

# Single position history
exp_result = [
automower_coordinator_mock.session.data["data"][MWR_ONE_IDX]["attributes"][
"positions"
][0]
] + automower_coordinator_mock.session.data["data"][MWR_ONE_IDX]["attributes"][
"positions"
]
automower_coordinator_mock.session.data["data"][MWR_ONE_IDX]["attributes"][
"positions"
] = [
automower_coordinator_mock.session.data["data"][MWR_ONE_IDX]["attributes"][
"positions"
][0]
]
await asyncio.to_thread(image_one._generate_image, {})
assert image_one._position_history[MWR_ONE_ID] == exp_result

# Single position history, but it's the first position update
exp_result = [
automower_coordinator_mock.session.data["data"][MWR_ONE_IDX]["attributes"][
"positions"
][0]
]
automower_coordinator_mock.session.data["data"][MWR_ONE_IDX]["attributes"][
"positions"
] = exp_result
image_one._position_history = {}
await asyncio.to_thread(image_one._generate_image, {})
assert image_one._position_history[MWR_ONE_ID] == exp_result


@pytest.mark.asyncio
Expand Down

0 comments on commit e9296d5

Please sign in to comment.