diff --git a/homeassistant/components/camera/__init__.py b/homeassistant/components/camera/__init__.py index b955f1a0249..f3258681b52 100644 --- a/homeassistant/components/camera/__init__.py +++ b/homeassistant/components/camera/__init__.py @@ -10,7 +10,6 @@ from dataclasses import dataclass from datetime import datetime, timedelta from functools import partial import hashlib -import inspect import logging import os from random import SystemRandom @@ -161,18 +160,9 @@ async def _async_get_image( """ with suppress(asyncio.CancelledError, asyncio.TimeoutError): async with async_timeout.timeout(timeout): - # Calling inspect will be removed in 2022.1 after all - # custom components have had a chance to change their signature - sig = inspect.signature(camera.async_camera_image) - if "height" in sig.parameters and "width" in sig.parameters: - image_bytes = await camera.async_camera_image( - width=width, height=height - ) - else: - camera.async_warn_old_async_camera_image_signature() - image_bytes = await camera.async_camera_image() - - if image_bytes: + if image_bytes := await camera.async_camera_image( + width=width, height=height + ): content_type = camera.content_type image = Image(content_type, image_bytes) if ( @@ -576,27 +566,9 @@ class Camera(Entity): self, width: int | None = None, height: int | None = None ) -> bytes | None: """Return bytes of camera image.""" - sig = inspect.signature(self.camera_image) - # Calling inspect will be removed in 2022.1 after all - # custom components have had a chance to change their signature - if "height" in sig.parameters and "width" in sig.parameters: - return await self.hass.async_add_executor_job( - 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( - "The camera entity %s does not support requesting width and height, please open an issue with the integration author", - self.entity_id, + return await self.hass.async_add_executor_job( + partial(self.camera_image, width=width, height=height) ) - self._warned_old_signature = True async def handle_async_still_stream( self, request: web.Request, interval: float diff --git a/tests/components/camera/test_init.py b/tests/components/camera/test_init.py index 0e53e163404..e72941ef488 100644 --- a/tests/components/camera/test_init.py +++ b/tests/components/camera/test_init.py @@ -108,28 +108,6 @@ async def test_get_image_from_camera(hass, image_mock_url): 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): """Grab an image from camera entity with width and height."""