mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 13:47:35 +00:00
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:
parent
0643ff1cfe
commit
b8e1862746
@ -10,7 +10,7 @@ from typing import Any, Final, TypedDict, final
|
|||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.camera import Image
|
from homeassistant.components.camera import async_get_image
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ENTITY_ID,
|
ATTR_ENTITY_ID,
|
||||||
ATTR_NAME,
|
ATTR_NAME,
|
||||||
@ -176,13 +176,16 @@ class ImageProcessingEntity(Entity):
|
|||||||
|
|
||||||
This method is a coroutine.
|
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:
|
try:
|
||||||
image: Image = await camera.async_get_image(
|
image = await async_get_image(
|
||||||
self.camera_entity, timeout=self.timeout
|
self.hass, self.camera_entity, timeout=self.timeout
|
||||||
)
|
)
|
||||||
|
|
||||||
except HomeAssistantError as err:
|
except HomeAssistantError as err:
|
||||||
_LOGGER.error("Error on receive image from entity: %s", err)
|
_LOGGER.error("Error on receive image from entity: %s", err)
|
||||||
return
|
return
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""The tests for the image_processing component."""
|
"""The tests for the image_processing component."""
|
||||||
|
|
||||||
from unittest.mock import PropertyMock, patch
|
from unittest.mock import PropertyMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@ -103,7 +102,7 @@ async def test_get_image_from_camera(
|
|||||||
|
|
||||||
|
|
||||||
@patch(
|
@patch(
|
||||||
"homeassistant.components.camera.async_get_image",
|
"homeassistant.components.image_processing.async_get_image",
|
||||||
side_effect=HomeAssistantError(),
|
side_effect=HomeAssistantError(),
|
||||||
)
|
)
|
||||||
async def test_get_image_without_exists_camera(
|
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]["confidence"] == 98.34
|
||||||
assert event_data[0]["gender"] == "male"
|
assert event_data[0]["gender"] == "male"
|
||||||
assert event_data[0]["entity_id"] == "image_processing.demo_face"
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user