diff --git a/custom_components/moonraker/camera.py b/custom_components/moonraker/camera.py index 55990a7..47b493f 100755 --- a/custom_components/moonraker/camera.py +++ b/custom_components/moonraker/camera.py @@ -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") @@ -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}" ) @@ -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 diff --git a/tests/test_camera.py b/tests/test_camera.py index 71f963a..da8a8e9 100755 --- a/tests/test_camera.py +++ b/tests/test_camera.py @@ -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."""