mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Allow MS face detection to handle updating entities when no face is detected (#17593)
* Allow Microsoft face detection to handle updating entities when no face is detected * Remove microsoft_face_detect_no_face_detected.json and hard code in simple empty list into the tests
This commit is contained in:
parent
a4c0c34028
commit
cb7ae5cdf2
@ -102,7 +102,7 @@ class MicrosoftFaceDetectEntity(ImageProcessingFaceEntity):
|
||||
return
|
||||
|
||||
if not face_data:
|
||||
return
|
||||
face_data = []
|
||||
|
||||
faces = []
|
||||
for face in face_data:
|
||||
|
@ -83,18 +83,16 @@ class MicrosoftFaceIdentifyEntity(ImageProcessingFaceEntity):
|
||||
|
||||
This method is a coroutine.
|
||||
"""
|
||||
detect = None
|
||||
detect = []
|
||||
try:
|
||||
face_data = await self._api.call_api(
|
||||
'post', 'detect', image, binary=True)
|
||||
|
||||
if not face_data:
|
||||
return
|
||||
|
||||
face_ids = [data['faceId'] for data in face_data]
|
||||
detect = await self._api.call_api(
|
||||
'post', 'identify',
|
||||
{'faceIds': face_ids, 'personGroupId': self._face_group})
|
||||
if face_data:
|
||||
face_ids = [data['faceId'] for data in face_data]
|
||||
detect = await self._api.call_api(
|
||||
'post', 'identify',
|
||||
{'faceIds': face_ids, 'personGroupId': self._face_group})
|
||||
|
||||
except HomeAssistantError as err:
|
||||
_LOGGER.error("Can't process image on Microsoft face: %s", err)
|
||||
|
@ -160,3 +160,23 @@ class TestMicrosoftFaceDetect:
|
||||
assert face_events[0].data['gender'] == 'male'
|
||||
assert face_events[0].data['entity_id'] == \
|
||||
'image_processing.test_local'
|
||||
|
||||
# Test that later, if a request is made that results in no face
|
||||
# being detected, that this is reflected in the state object
|
||||
aioclient_mock.clear_requests()
|
||||
aioclient_mock.post(
|
||||
self.endpoint_url.format("detect"),
|
||||
text="[]",
|
||||
params={'returnFaceAttributes': "age,gender"}
|
||||
)
|
||||
|
||||
common.scan(self.hass, entity_id='image_processing.test_local')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('image_processing.test_local')
|
||||
|
||||
# No more face events were fired
|
||||
assert len(face_events) == 1
|
||||
# Total faces and actual qualified number of faces reset to zero
|
||||
assert state.attributes.get('total_faces') == 0
|
||||
assert state.state == '0'
|
||||
|
@ -2,7 +2,7 @@
|
||||
from unittest.mock import patch, PropertyMock
|
||||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.const import ATTR_ENTITY_PICTURE
|
||||
from homeassistant.const import ATTR_ENTITY_PICTURE, STATE_UNKNOWN
|
||||
from homeassistant.setup import setup_component
|
||||
import homeassistant.components.image_processing as ip
|
||||
import homeassistant.components.microsoft_face as mf
|
||||
@ -164,3 +164,22 @@ class TestMicrosoftFaceIdentify:
|
||||
assert face_events[0].data['confidence'] == float(92)
|
||||
assert face_events[0].data['entity_id'] == \
|
||||
'image_processing.test_local'
|
||||
|
||||
# Test that later, if a request is made that results in no face
|
||||
# being detected, that this is reflected in the state object
|
||||
aioclient_mock.clear_requests()
|
||||
aioclient_mock.post(
|
||||
self.endpoint_url.format("detect"),
|
||||
text="[]"
|
||||
)
|
||||
|
||||
common.scan(self.hass, entity_id='image_processing.test_local')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('image_processing.test_local')
|
||||
|
||||
# No more face events were fired
|
||||
assert len(face_events) == 1
|
||||
# Total faces and actual qualified number of faces reset to zero
|
||||
assert state.attributes.get('total_faces') == 0
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
Loading…
x
Reference in New Issue
Block a user