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:
Neil Crosby
2018-11-02 09:50:43 +00:00
committed by Pascal Vizeli
parent a4c0c34028
commit cb7ae5cdf2
4 changed files with 47 additions and 10 deletions

View File

@@ -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'

View File

@@ -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