Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
e836674
Fix Gogogate2 'available' attribute (#13728)
dlbroadfoot Apr 7, 2018
0adb240
Fix so it is possible to ignore discovered config entry handlers (#13…
Kane610 Apr 7, 2018
26c76e3
Prevent vesync doing I/O in event loop (#13862)
balloob Apr 14, 2018
727ab95
Fix #13846 Double underscore in bluetooth address (#13884)
aav7fl Apr 15, 2018
663aeb1
Fix race condition for component loaded before listening (#13887)
balloob Apr 14, 2018
bcd8a69
Missing property decorator added (#13889)
syssi Apr 14, 2018
6520635
Fix call to parent broadlink switch (#13906)
Danielhiversen Apr 17, 2018
fadff18
Import operation modes from air humidifier (#13908)
syssi Apr 15, 2018
6fa60c4
Upgrade pyqwikswitch to 0.71 (#13920)
kellerza Apr 15, 2018
5350682
Upgrade somecomfort to 0.5.2 (#13940)
balloob Apr 17, 2018
e9b997d
Update pyhydroquebec to 2.2.2 (#13946)
titilambert Apr 17, 2018
6c456ad
Update pyfido to 2.1.1 (#13947)
titilambert Apr 17, 2018
24ec8c5
Bumped pypollencom to 1.1.2 (#13959)
bachya Apr 17, 2018
e7aea5c
Version bump to 0.67.1
balloob Apr 18, 2018
c076dbe
Revert "Upgrade pyqwikswitch to 0.71 (#13920)"
balloob Apr 18, 2018
2cb9e2d
Merge pull request #13975 from home-assistant/rc
balloob Apr 18, 2018
a566804
Merge branch 'dev' into rc
balloob Apr 20, 2018
2b53729
Version bump to 0.68.0b0
balloob Apr 20, 2018
8cb1e17
Bump frontend to 20180425.0
balloob Apr 25, 2018
44be801
Qwikswitch binary sensors (#14008)
kellerza Apr 21, 2018
2bc87bf
Order the output of the automation editor (#14019)
balloob Apr 23, 2018
cb839ef
HomeKit Alarm Control Panel Code Exception Fix (#14025)
schmittx Apr 21, 2018
fc1f6ee
Revert cast platform polling mode (#14027)
OttoWinter Apr 22, 2018
7566bb5
Handle HomeKit configuration failure more cleanly (#14041)
mjg59 Apr 22, 2018
2e3a27e
Update device classes for contact sensor HomeKit (#14051)
marthoc Apr 23, 2018
c497515
Version bump to 0.68.0b1
balloob Apr 25, 2018
1b71ce3
Bump frontend to 20180426
balloob Apr 26, 2018
833508f
Version bump to 0.68.0b2
balloob Apr 26, 2018
403a546
Upgrade broadlink lib (#14074)
Danielhiversen Apr 25, 2018
9d0251c
Fix timezone issue when calculating min/max values in tibber #14009 (…
Danielhiversen Apr 26, 2018
c42c668
Updated list of AWS regions for Amazon Polly (#14097)
GotoCode Apr 26, 2018
9fb2bf7
Version bump to 0.68.0
balloob Apr 27, 2018
7da1d75
Change Eufy brightness handling (#14111)
mjg59 Apr 27, 2018
9d34e8c
Merge pull request #14124 from home-assistant/rc
balloob Apr 28, 2018
a06f610
Fix color setting of tplink lights (#14108)
amelchio Apr 28, 2018
52a48b3
Improve precision of Hue color state (#14113)
amelchio Apr 27, 2018
b5bae17
Revert Hue color state to be xy-based (#14154)
amelchio Apr 29, 2018
f2a17a5
Fix Python 3.6 compatibility for HomeKit controller (#14160)
mjg59 Apr 29, 2018
03c3480
Added CONF_IP_ADDRESS to HomeKit (#14163)
cdce8p Apr 30, 2018
aba143a
Do not sync entities with an empty name (#14181)
balloob Apr 30, 2018
7f1b591
Improve chromecast disconnection logic (#14190)
OttoWinter Apr 30, 2018
daeccfe
Fix poorly formatted automations (#14196)
balloob Apr 30, 2018
c704cea
Version bump to 0.68.1
balloob Apr 30, 2018
c23cc0e
Disable eliqonline requirement (#14156)
balloob Apr 29, 2018
d1460de
Merge pull request #14199 from home-assistant/rc
balloob Apr 30, 2018
26f5eb1
Adds facebox face detect
robmarkcole May 4, 2018
fe92c1b
Remove ROUNDING_DECIMALS
robmarkcole May 4, 2018
9859840
Update issue templates
fabaff May 4, 2018
a7a3cff
Update issue templates
fabaff May 4, 2018
54ccbbc
Update issue templates
fabaff May 4, 2018
5f8f666
Update issue templates
fabaff May 4, 2018
b49d984
Remove feature request
fabaff May 4, 2018
fa0ad7b
Color fixes for Wink lights (#14263)
amelchio May 4, 2018
c80b752
fix check config not working after #14211 (#14259)
fanthos May 4, 2018
36cf212
Issue Template Fix CRLF (#14283)
OttoWinter May 4, 2018
f98525a
Upgrade attrs to 18.1.0 (#14281)
fabaff May 4, 2018
e37fd5b
Update HAP-python to 2.0.0 (#14278)
cdce8p May 4, 2018
7900ba3
Upgrade holidays to 0.9.5 (#14274)
fabaff May 4, 2018
bb76ba6
Homekit: Changed device_class requirement Humidity Sensor (#14277)
cdce8p May 4, 2018
255a85a
HomeKit: Support triggered state for alarm_control_panel (#14285)
schmittx May 4, 2018
3544704
Fix filter sensor missing window_size argument (#14252)
dgomes May 5, 2018
75bf483
Upgrade astral to 1.6.1 (#14297)
fabaff May 5, 2018
5ade84d
BOM Weather throttle fix (#14234)
nickw444 May 5, 2018
ec3ce4c
Publish attributes unconditionally (#14179)
blackwind May 5, 2018
95d27bd
Sensor device classes (#14282)
cdce8p May 5, 2018
af8cd63
Matrix Chatbot (#13355)
tinloaf May 5, 2018
8410b63
deCONZ add new device without restart (#14221)
Kane610 May 5, 2018
1a93622
Add alarmdotcom sensor status (#14254)
May 5, 2018
f6e29a6
Add domain to labels and count state changes to Prometheus (#14253)
May 5, 2018
4d08588
Add support for max_volume (#13822)
relvacode May 5, 2018
b9e8931
Refactor ImageProcessingFaceEntity (#14296)
robmarkcole May 5, 2018
ed7d790
Adds facebox face detect
robmarkcole May 4, 2018
2baaeed
Remove ROUNDING_DECIMALS
robmarkcole May 4, 2018
02bba10
Merge remote-tracking branch 'origin/facebox-detect' into facebox-detect
robmarkcole May 5, 2018
2e8eaf4
Onkyo: SUPPORT_VOLUME_STEP (#14299)
rsmeral May 5, 2018
64ba2c6
Add All-Linking capabilities (#14065)
teharris1 May 5, 2018
a4b6983
Update translations
balloob May 5, 2018
83e342d
Update frontend to 20180505.0
balloob May 5, 2018
2326312
Merge branch 'master' into dev
balloob May 5, 2018
f3411f8
Version bump to 0.70.0.dev0
balloob May 5, 2018
e623e87
Adds facebox face detect
robmarkcole May 4, 2018
eaf710f
Remove ROUNDING_DECIMALS
robmarkcole May 4, 2018
5cbf7c9
Adds facebox face detect
robmarkcole May 4, 2018
f5cf660
Address rebase
robmarkcole May 5, 2018
710f841
Merge remote-tracking branch 'origin/facebox-detect' into facebox-detect
robmarkcole May 5, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions homeassistant/components/image_processing/facebox_face_detect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
"""
Component that will perform facial detection via a local facebox instance.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/image_processing.facebox_face_detect
"""
import base64
import requests
import logging
import time
import voluptuous as vol

from homeassistant.core import split_entity_id
import homeassistant.helpers.config_validation as cv
from homeassistant.components.image_processing import (
PLATFORM_SCHEMA, CONF_SOURCE, CONF_ENTITY_ID,
CONF_NAME)
from homeassistant.const import (CONF_IP_ADDRESS, CONF_PORT)
from homeassistant.components.image_processing.microsoft_face_identify import (

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the base face entity class located in the microsoft platform? This is weird. @pvizeli do you know? Normally we should not rely on another platform in a platform. The base entity class should probably move to homeassistant.components.image_processing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MartinHjelmare I agree and propose a refactor

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MartinHjelmare that is correct. On my inital PR it was inside component but I need remove this. In a later discusion about this designe, paulus agree that I can move back the code. But I found never time for this.

@MartinHjelmare MartinHjelmare May 4, 2018

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robmarkcole if you have time, a refactor in a separate PR would be great.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor in #14296

ImageProcessingFaceEntity)

_LOGGER = logging.getLogger(__name__)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_IP_ADDRESS): cv.string,
vol.Required(CONF_PORT): cv.string,
})


def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the classifier."""
entities = []
for camera in config[CONF_SOURCE]:
entities.append(FaceboxFaceDetectEntity(
config[CONF_IP_ADDRESS],
config[CONF_PORT],
camera[CONF_ENTITY_ID],
camera.get(CONF_NAME)
))
add_devices(entities)


class FaceboxFaceDetectEntity(ImageProcessingFaceEntity):
"""Perform a classification via a Facebox."""

def __init__(self, ip, port, camera_entity, name=None):
"""Init with the API key and model id"""
super().__init__()
self._url = "http://{}:{}/facebox/check".format(ip, port)
self._camera = camera_entity
if name:
self._name = name
else:
self._name = "Facebox {0}".format(
split_entity_id(camera_entity)[1])
self._response_time = None
self.total_faces = 0
self.faces = []

def process_image(self, image):
"""Process an image."""
timer_start = time.perf_counter()
response = {}
try:
response = requests.post(
self._url,
json=self.encode_image(image),
timeout=30
).json()
except requests.exceptions.ConnectionError:
_LOGGER.error("ConnectionError: Is Facebox running?")
response['success'] = False

if response['success']:
elapsed_time = time.perf_counter() - timer_start
self._response_time = "{} seconds".format(

@pvizeli pvizeli May 4, 2018

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the time only if you find faces. Otherwise it flush the state database.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean if total_faces > zero?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. If there is no faces found, he should also not update time.

@robmarkcole robmarkcole May 5, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pvizeli That would mean that the response_time was for an earlier request that found > zero faces, and not for the last request that was successful but returned zero faces. I think the confusion that could cause outweighs any benefit from not updating? The only alternative I can think of is to drop response_time but it is useful for choosing a scan_interval and monitoring performance of the classifier under different loads

str(round(elapsed_time, 1)))
self.total_faces = response['facesCount']
self.faces = response['faces']

else:
self.total_faces = "Request_failed"
self.faces = []

def encode_image(self, image):
"""base64 encode an image stream."""
base64_img = base64.b64encode(image).decode('ascii')
return {"base64": base64_img}

@property
def camera_entity(self):
"""Return camera entity id from process pictures."""
return self._camera

@property
def name(self):
"""Return the name of the sensor."""
return self._name

@property
def device_state_attributes(self):
"""Return the other state attributes."""
return {
'response_time': self._response_time,
}
68 changes: 68 additions & 0 deletions tests/components/image_processing/test_facebox_face_detect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""The tests for the facebox component."""
import requests_mock

from homeassistant.const import (CONF_IP_ADDRESS, CONF_PORT)
from homeassistant.setup import setup_component
import homeassistant.components.image_processing as ip

from tests.common import (
get_test_home_assistant, assert_setup_component)

MOCK_IP = '192.168.0.1'
MOCK_PORT = '8080'

MOCK_RESPONSE = """
{"facesCount": 1,
"success": True,
"faces":['face_data']}
"""

VALID_ENTITY_ID = 'image_processing.facebox_demo_camera'
VALID_CONFIG = {
ip.DOMAIN: {
'platform': 'facebox_face_detect',
CONF_IP_ADDRESS: MOCK_IP,
CONF_PORT: MOCK_PORT,
ip.CONF_SOURCE: {
ip.CONF_ENTITY_ID: 'camera.demo_camera'}
},
'camera': {
'platform': 'demo'
}
}


class TestFaceboxSetup(object):
"""Test class for image processing."""

def setup_method(self):
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()

def test_setup_platform(self):
"""Setup platform with one entity."""

with assert_setup_component(1, ip.DOMAIN):
setup_component(self.hass, ip.DOMAIN, VALID_CONFIG)

assert self.hass.states.get(VALID_ENTITY_ID)

def test_process_image(self):
"""Test processing of an image."""

with assert_setup_component(1, ip.DOMAIN):
setup_component(self.hass, ip.DOMAIN, VALID_CONFIG)
assert self.hass.states.get(VALID_ENTITY_ID)

with requests_mock.Mocker() as mock_req:
url = "http://{}:{}/facebox/check".format(MOCK_IP, MOCK_PORT)
mock_req.get(url, text=MOCK_RESPONSE)
ip.scan(self.hass, entity_id=VALID_ENTITY_ID)
self.hass.block_till_done()

state = self.hass.states.get(VALID_ENTITY_ID)
assert state.state == '1'

def teardown_method(self):
"""Stop everything that was started."""
self.hass.stop()