Improve type hints in microsoft_face_identify (#145419)

This commit is contained in:
epenet 2025-05-22 10:36:12 +02:00 committed by GitHub
parent e410977e64
commit 7893eaa389
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -10,9 +10,10 @@ from homeassistant.components.image_processing import (
ATTR_CONFIDENCE, ATTR_CONFIDENCE,
CONF_CONFIDENCE, CONF_CONFIDENCE,
PLATFORM_SCHEMA as IMAGE_PROCESSING_PLATFORM_SCHEMA, PLATFORM_SCHEMA as IMAGE_PROCESSING_PLATFORM_SCHEMA,
FaceInformation,
ImageProcessingFaceEntity, ImageProcessingFaceEntity,
) )
from homeassistant.components.microsoft_face import DATA_MICROSOFT_FACE from homeassistant.components.microsoft_face import DATA_MICROSOFT_FACE, MicrosoftFace
from homeassistant.const import ATTR_NAME, CONF_ENTITY_ID, CONF_NAME, CONF_SOURCE from homeassistant.const import ATTR_NAME, CONF_ENTITY_ID, CONF_NAME, CONF_SOURCE
from homeassistant.core import HomeAssistant, split_entity_id from homeassistant.core import HomeAssistant, split_entity_id
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
@ -37,8 +38,9 @@ async def async_setup_platform(
) -> None: ) -> None:
"""Set up the Microsoft Face identify platform.""" """Set up the Microsoft Face identify platform."""
api = hass.data[DATA_MICROSOFT_FACE] api = hass.data[DATA_MICROSOFT_FACE]
face_group = config[CONF_GROUP] face_group: str = config[CONF_GROUP]
confidence = config[CONF_CONFIDENCE] confidence: float = config[CONF_CONFIDENCE]
source: list[dict[str, str]] = config[CONF_SOURCE]
async_add_entities( async_add_entities(
MicrosoftFaceIdentifyEntity( MicrosoftFaceIdentifyEntity(
@ -48,43 +50,35 @@ async def async_setup_platform(
confidence, confidence,
camera.get(CONF_NAME), camera.get(CONF_NAME),
) )
for camera in config[CONF_SOURCE] for camera in source
) )
class MicrosoftFaceIdentifyEntity(ImageProcessingFaceEntity): class MicrosoftFaceIdentifyEntity(ImageProcessingFaceEntity):
"""Representation of the Microsoft Face API entity for identify.""" """Representation of the Microsoft Face API entity for identify."""
def __init__(self, camera_entity, api, face_group, confidence, name=None): def __init__(
self,
camera_entity: str,
api: MicrosoftFace,
face_group: str,
confidence: float,
name: str | None,
) -> None:
"""Initialize the Microsoft Face API.""" """Initialize the Microsoft Face API."""
super().__init__() super().__init__()
self._api = api self._api = api
self._camera = camera_entity self._attr_camera_entity = camera_entity
self._confidence = confidence self._attr_confidence = confidence
self._face_group = face_group self._face_group = face_group
if name: if name:
self._name = name self._attr_name = name
else: else:
self._name = f"MicrosoftFace {split_entity_id(camera_entity)[1]}" self._attr_name = f"MicrosoftFace {split_entity_id(camera_entity)[1]}"
@property async def async_process_image(self, image: bytes) -> None:
def confidence(self):
"""Return minimum confidence for send events."""
return self._confidence
@property
def camera_entity(self):
"""Return camera entity id from process pictures."""
return self._camera
@property
def name(self):
"""Return the name of the entity."""
return self._name
async def async_process_image(self, image):
"""Process image. """Process image.
This method is a coroutine. This method is a coroutine.
@ -106,7 +100,7 @@ class MicrosoftFaceIdentifyEntity(ImageProcessingFaceEntity):
return return
# Parse data # Parse data
known_faces = [] known_faces: list[FaceInformation] = []
total = 0 total = 0
for face in detect: for face in detect:
total += 1 total += 1