mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Only warn once per entity when the async_camera_image signature needs to be updated (#55238)
This commit is contained in:
parent
b3e84c6ee8
commit
fbcf21412d
@ -165,10 +165,7 @@ async def _async_get_image(
|
|||||||
width=width, height=height
|
width=width, height=height
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
_LOGGER.warning(
|
camera.async_warn_old_async_camera_image_signature()
|
||||||
"The camera entity %s does not support requesting width and height, please open an issue with the integration author",
|
|
||||||
camera.entity_id,
|
|
||||||
)
|
|
||||||
image_bytes = await camera.async_camera_image()
|
image_bytes = await camera.async_camera_image()
|
||||||
|
|
||||||
if image_bytes:
|
if image_bytes:
|
||||||
@ -381,6 +378,7 @@ class Camera(Entity):
|
|||||||
self.stream_options: dict[str, str] = {}
|
self.stream_options: dict[str, str] = {}
|
||||||
self.content_type: str = DEFAULT_CONTENT_TYPE
|
self.content_type: str = DEFAULT_CONTENT_TYPE
|
||||||
self.access_tokens: collections.deque = collections.deque([], 2)
|
self.access_tokens: collections.deque = collections.deque([], 2)
|
||||||
|
self._warned_old_signature = False
|
||||||
self.async_update_token()
|
self.async_update_token()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -455,11 +453,20 @@ class Camera(Entity):
|
|||||||
return await self.hass.async_add_executor_job(
|
return await self.hass.async_add_executor_job(
|
||||||
partial(self.camera_image, width=width, height=height)
|
partial(self.camera_image, width=width, height=height)
|
||||||
)
|
)
|
||||||
|
self.async_warn_old_async_camera_image_signature()
|
||||||
|
return await self.hass.async_add_executor_job(self.camera_image)
|
||||||
|
|
||||||
|
# Remove in 2022.1 after all custom components have had a chance to change their signature
|
||||||
|
@callback
|
||||||
|
def async_warn_old_async_camera_image_signature(self) -> None:
|
||||||
|
"""Warn once when calling async_camera_image with the function old signature."""
|
||||||
|
if self._warned_old_signature:
|
||||||
|
return
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"The camera entity %s does not support requesting width and height, please open an issue with the integration author",
|
"The camera entity %s does not support requesting width and height, please open an issue with the integration author",
|
||||||
self.entity_id,
|
self.entity_id,
|
||||||
)
|
)
|
||||||
return await self.hass.async_add_executor_job(self.camera_image)
|
self._warned_old_signature = True
|
||||||
|
|
||||||
async def handle_async_still_stream(
|
async def handle_async_still_stream(
|
||||||
self, request: web.Request, interval: float
|
self, request: web.Request, interval: float
|
||||||
|
@ -77,6 +77,28 @@ async def test_get_image_from_camera(hass, image_mock_url):
|
|||||||
assert image.content == b"Test"
|
assert image.content == b"Test"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_legacy_async_get_image_signature_warns_only_once(
|
||||||
|
hass, image_mock_url, caplog
|
||||||
|
):
|
||||||
|
"""Test that we only warn once when we encounter a legacy async_get_image function signature."""
|
||||||
|
|
||||||
|
async def _legacy_async_camera_image(self):
|
||||||
|
return b"Image"
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.demo.camera.DemoCamera.async_camera_image",
|
||||||
|
new=_legacy_async_camera_image,
|
||||||
|
):
|
||||||
|
image = await camera.async_get_image(hass, "camera.demo_camera")
|
||||||
|
assert image.content == b"Image"
|
||||||
|
assert "does not support requesting width and height" in caplog.text
|
||||||
|
caplog.clear()
|
||||||
|
|
||||||
|
image = await camera.async_get_image(hass, "camera.demo_camera")
|
||||||
|
assert image.content == b"Image"
|
||||||
|
assert "does not support requesting width and height" not in caplog.text
|
||||||
|
|
||||||
|
|
||||||
async def test_get_image_from_camera_with_width_height(hass, image_mock_url):
|
async def test_get_image_from_camera_with_width_height(hass, image_mock_url):
|
||||||
"""Grab an image from camera entity with width and height."""
|
"""Grab an image from camera entity with width and height."""
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user