1 """Component that will help set the Microsoft face for verify processing."""
3 from __future__
import annotations
7 import voluptuous
as vol
12 PLATFORM_SCHEMA
as IMAGE_PROCESSING_PLATFORM_SCHEMA,
13 ImageProcessingFaceEntity,
23 _LOGGER = logging.getLogger(__name__)
27 PLATFORM_SCHEMA = IMAGE_PROCESSING_PLATFORM_SCHEMA.extend(
28 {vol.Required(CONF_GROUP): cv.slugify}
35 async_add_entities: AddEntitiesCallback,
36 discovery_info: DiscoveryInfoType |
None =
None,
38 """Set up the Microsoft Face identify platform."""
39 api = hass.data[DATA_MICROSOFT_FACE]
40 face_group = config[CONF_GROUP]
41 confidence = config[CONF_CONFIDENCE]
45 camera[CONF_ENTITY_ID],
49 camera.get(CONF_NAME),
51 for camera
in config[CONF_SOURCE]
56 """Representation of the Microsoft Face API entity for identify."""
58 def __init__(self, camera_entity, api, face_group, confidence, name=None):
59 """Initialize the Microsoft Face API."""
70 self.
_name_name = f
"MicrosoftFace {split_entity_id(camera_entity)[1]}"
74 """Return minimum confidence for send events."""
79 """Return camera entity id from process pictures."""
84 """Return the name of the entity."""
85 return self.
_name_name
90 This method is a coroutine.
94 face_data = await self.
_api_api.call_api(
"post",
"detect", image, binary=
True)
97 face_ids = [data[
"faceId"]
for data
in face_data]
98 detect = await self.
_api_api.call_api(
101 {
"faceIds": face_ids,
"personGroupId": self.
_face_group_face_group},
104 except HomeAssistantError
as err:
105 _LOGGER.error(
"Can't process image on Microsoft face: %s", err)
113 if not face[
"candidates"]:
116 data = face[
"candidates"][0]
118 for s_name, s_id
in self.
_api_api.store[self.
_face_group_face_group].items():
119 if data[
"personId"] == s_id:
124 {ATTR_NAME: name, ATTR_CONFIDENCE: data[
"confidence"] * 100}
None async_process_faces(self, list[FaceInformation] faces, int total)
def async_process_image(self, image)
def __init__(self, camera_entity, api, face_group, confidence, name=None)
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None discovery_info=None)