1 """Component that will help set the Microsoft face detect processing."""
3 from __future__
import annotations
7 import voluptuous
as vol
13 PLATFORM_SCHEMA
as IMAGE_PROCESSING_PLATFORM_SCHEMA,
14 ImageProcessingFaceEntity,
24 _LOGGER = logging.getLogger(__name__)
26 SUPPORTED_ATTRIBUTES = [ATTR_AGE, ATTR_GENDER, ATTR_GLASSES]
28 CONF_ATTRIBUTES =
"attributes"
29 DEFAULT_ATTRIBUTES = [ATTR_AGE, ATTR_GENDER]
33 """Validate face attributes."""
34 for attr
in list_attributes:
35 if attr
not in SUPPORTED_ATTRIBUTES:
36 raise vol.Invalid(f
"Invalid attribute {attr}")
37 return list_attributes
40 PLATFORM_SCHEMA = IMAGE_PROCESSING_PLATFORM_SCHEMA.extend(
42 vol.Optional(CONF_ATTRIBUTES, default=DEFAULT_ATTRIBUTES): vol.All(
43 cv.ensure_list, validate_attributes
52 async_add_entities: AddEntitiesCallback,
53 discovery_info: DiscoveryInfoType |
None =
None,
55 """Set up the Microsoft Face detection platform."""
56 api = hass.data[DATA_MICROSOFT_FACE]
57 attributes = config[CONF_ATTRIBUTES]
61 camera[CONF_ENTITY_ID], api, attributes, camera.get(CONF_NAME)
63 for camera
in config[CONF_SOURCE]
68 """Microsoft Face API entity for identify."""
70 def __init__(self, camera_entity, api, attributes, name=None):
71 """Initialize Microsoft Face."""
81 self.
_name_name = f
"MicrosoftFace {split_entity_id(camera_entity)[1]}"
85 """Return camera entity id from process pictures."""
90 """Return the name of the entity."""
91 return self.
_name_name
96 This method is a coroutine.
100 face_data = await self.
_api_api.call_api(
105 params={
"returnFaceAttributes":
",".join(self.
_attributes_attributes)},
108 except HomeAssistantError
as err:
109 _LOGGER.error(
"Can't process image on microsoft face: %s", err)
116 for face
in face_data:
119 if attr
in face[
"faceAttributes"]:
120 face_attr[attr] = face[
"faceAttributes"][attr]
123 faces.append(face_attr)
None async_process_faces(self, list[FaceInformation] faces, int total)
def async_process_image(self, image)
def __init__(self, camera_entity, api, attributes, name=None)
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None discovery_info=None)
def validate_attributes(list_attributes)