Skip to content

Commit

Permalink
Manage empty space in file name (#308)
Browse files Browse the repository at this point in the history
* add replace for URL with space

* add tests
  • Loading branch information
marcolivierarsenault authored Apr 6, 2024
1 parent 0d8f2fc commit 868324e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
7 changes: 3 additions & 4 deletions custom_components/moonraker/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ async def async_camera_image(
del width, height

new_path = self.coordinator.data["thumbnails_path"]

_LOGGER.debug(f"Thumbnail new_path: {new_path}")
if self._current_path == new_path and self._current_pic is not None:
_LOGGER.debug("no change in thumbnail, returning cached")
Expand All @@ -159,6 +160,8 @@ async def async_camera_image(
_LOGGER.debug("Empty path, no thumbnail")
return None

new_path = new_path.replace(" ", "%20")

_LOGGER.debug(
f"Fetching new thumbnail: http://{self.url}/server/files/gcodes/{new_path}"
)
Expand All @@ -169,8 +172,4 @@ async def async_camera_image(
self._current_path = new_path
self._current_pic = await response.read()

_LOGGER.debug(
f"Size of thumbnail: {self._current_pic.width} x {self._current_pic.height}"
)

return self._current_pic
19 changes: 19 additions & 0 deletions tests/test_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,25 @@ async def test_thumbnail_on_subfolder(hass, get_data, aioclient_mock):
await camera.async_get_image(hass, "camera.mainsail_thumbnail")


async def test_thumbnail_space_in_path(hass, get_data, aioclient_mock):
"""Test thumbnail with space in URL."""

get_data["thumbnails"][1][
"relative_path"
] = ".thumbs/CE3E3V2_picture frame_holder-32x32.png"

config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test")
config_entry.add_to_hass(hass)
assert await async_setup_entry(hass, config_entry)
await hass.async_block_till_done()

test_path = "http://1.2.3.4/server/files/gcodes/.thumbs/CE3E3V2_picture%20frame_holder-32x32.png"

aioclient_mock.get(test_path, content=Image.new("RGB", (30, 30)))

await camera.async_get_image(hass, "camera.mainsail_thumbnail")


async def test_option_config_camera_services(hass, caplog):
"""Test camera services."""

Expand Down

0 comments on commit 868324e

Please sign in to comment.