New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add sighthound integration #28824
Add sighthound integration #28824
Conversation
OK CI is failing because simplehound has |
We currently still support 3.6, so that requires an integration to work with Python 3.6 as well. However, we are in the process of moving away from 3.6, now Python 3.8 has become stable. IMHO, there are 2 options. Either make it Python 3.6 compatible or hold off a bit until we've officially dropped Python 3.6. |
Made python 3.6 compatible |
The commit history is a bit of a mess now, does this matter? |
History looks ok. 👍 |
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
EVENT_PERSON_DETECTED = "image_processing.person_detected" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should prefix the event with the integration name. Replace image_processing
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
DEV = "dev" | ||
PROD = "prod" | ||
|
||
SCAN_INTERVAL = timedelta(days=365) # NEVER SCAN. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set should_poll
property to False
instead in the entity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
) | ||
|
||
|
||
def setup_platform(hass, config, add_devices, discovery_info=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename add_devices
to add_entities
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
entities = [] | ||
for camera in config[CONF_SOURCE]: | ||
sighthound = SighthoundEntity( | ||
config.get(CONF_API_KEY), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use dict[key]
for required config keys and keys with default config schema values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
|
||
def __init__(self, api_key, account_type, camera_entity, name): | ||
"""Init.""" | ||
super().__init__() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove call to parent. It doesn't have an init method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
def __init__(self, api_key, account_type, camera_entity, name): | ||
"""Init.""" | ||
super().__init__() | ||
self._api = hound.cloud(api_key, account_type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this have side effects? We don't want side effects in init method.
We should check that the api key is ok before creating the entity.
Probably create the api instance before creating the entity and pass the api to the entity.
Don't we want to create a single api instance and pass the same instance to all entities?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately the API doesn't have an endpoint to validate credentials, so the integration will raise an exception if invalid credentials only when processing is performed. One option is to perform processing of a test image to see if credentials are valid? Any other suggestions? In the meantime I will raise this with the API provider
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Processing a mock image would be ok, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
if name: | ||
self._name = name | ||
else: | ||
self._camera_name = split_entity_id(camera_entity)[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Camera name doesn't have to be an instance attribute since it's only used in this method. Just make it a local variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
If we add a test for the api test failure case, coverage should be enough. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Are PR merged automatically? |
No, it's done manually. Thanks for the ping. 👍 |
Description:
Adds integration for person detection with Sighthound cloud. The Sighthound Developer tier (free for non-commercial use) allows 5000 requests per month. If you need more requests per month you will need to sign up for a production account (i.e. Basic or Pro account).
This integration adds an image processing entity where the state of the entity is the number of people detected in an image. For each person detected, an image_processing.person_detected event is fired. The event data includes the entity_id of the image processing entity firing the event, and the bounding box around the detected person. Note that in order to prevent accidentally using up your requets to Sighthound, by default the component will not automatically scan images, but requires you to call the image_processing.scan service e.g. using an automation triggered by motion. Alternativley, periodic scanning can be enabled by configuring a scan_interval.
Pull request with documentation for home-assistant.io (if applicable): home-assistant/home-assistant.io#11203
Example entry for
configuration.yaml
(if applicable):Checklist:
tox
. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
python3 -m script.hassfest
.requirements_all.txt
by runningpython3 -m script.gen_requirements_all
..coveragerc
.