Remove deprecated hass.components from image_processing platform (#113613)

* Remove deprecated `hass.components` from image_processing platform

* Add test and change log

* D'oh.. use updated error text
This commit is contained in:
Jan-Philipp Benecke 2024-03-17 15:59:29 +01:00 committed by GitHub
parent 0643ff1cfe
commit b8e1862746
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 7 deletions

View File

@ -10,7 +10,7 @@ from typing import Any, Final, TypedDict, final
import voluptuous as vol
from homeassistant.components.camera import Image
from homeassistant.components.camera import async_get_image
from homeassistant.const import (
ATTR_ENTITY_ID,
ATTR_NAME,
@ -176,13 +176,16 @@ class ImageProcessingEntity(Entity):
This method is a coroutine.
"""
camera = self.hass.components.camera
if self.camera_entity is None:
_LOGGER.error(
"No camera entity id was set by the image processing entity",
)
return
try:
image: Image = await camera.async_get_image(
self.camera_entity, timeout=self.timeout
image = await async_get_image(
self.hass, self.camera_entity, timeout=self.timeout
)
except HomeAssistantError as err:
_LOGGER.error("Error on receive image from entity: %s", err)
return

View File

@ -1,5 +1,4 @@
"""The tests for the image_processing component."""
from unittest.mock import PropertyMock, patch
import pytest
@ -103,7 +102,7 @@ async def test_get_image_from_camera(
@patch(
"homeassistant.components.camera.async_get_image",
"homeassistant.components.image_processing.async_get_image",
side_effect=HomeAssistantError(),
)
async def test_get_image_without_exists_camera(
@ -180,3 +179,22 @@ async def test_face_event_call_no_confidence(
assert event_data[0]["confidence"] == 98.34
assert event_data[0]["gender"] == "male"
assert event_data[0]["entity_id"] == "image_processing.demo_face"
async def test_update_missing_camera(
hass: HomeAssistant,
aiohttp_unused_port_factory,
enable_custom_integrations: None,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test when entity does not set camera."""
await setup_image_processing(hass, aiohttp_unused_port_factory)
with patch(
"custom_components.test.image_processing.TestImageProcessing.camera_entity",
new_callable=PropertyMock(return_value=None),
):
common.async_scan(hass, entity_id="image_processing.test")
await hass.async_block_till_done()
assert "No camera entity id was set by the image processing entity" in caplog.text