Add webhook support for Netatmo Cameras#20755
Conversation
|
I'll probably also change the types of events that are being fired. They should be different depending on what type of event actually happened in my opinion because that also affects what data is available. |
|
This will only support the Welcome camera event types, Presence will send event types of |
|
Sure, that would be great. |
|
@andersonshatch
Except from the
For
The |
|
I have now also added services to add and drop the webhooks. Adding webhooks is particulary useful because they can get banned. Being able to (re)add the webhook via service removes the need to restart Home Assistant in case the webhook has been banned. |
|
@andersonshatch What I thought would work (but does not): - alias: "Daniel Welcome"
trigger:
platform: event
event_type: netatmo_person
event_data:
name: DanielI do get the matching event. But for some reason the automation won't fire. 😕 EDIT: This did work: - alias: "Welcome Movement"
trigger:
platform: event
event_type: netatmo_movement |
|
Other than the one set of changes I annotated, it seems to work okay, though I only tested so far with a dummy event of one type. Is it expected that the webhook is not registered until the service is called? So I would need to create an automation to call this service after hass startup? |
|
No, you don't need to call the service. I first added it to be able add and drop during runtime while testing this. In practice it will be irrelevant for me, except if the webhook got banned. In that case you have to go to the dev-panel from Netatmo and unban the app. Afterwards you would need to restart Home Assistant to subscribe again. Using the service lets you do that without restarting Home Assistant. I'll take care of the documentation now. |
|
Could you please give me a description of what |
|
Sure! |
|
@balloob |
MartinHjelmare
left a comment
There was a problem hiding this comment.
Please open a new PR where we can address the comments.
| discovery.load_platform(hass, component, DOMAIN, {}, config) | ||
|
|
||
| if config[DOMAIN][CONF_WEBHOOKS]: | ||
| webhook_id = hass.components.webhook.async_generate_id() |
There was a problem hiding this comment.
We shouldn't call an async function from a sync context. Probably use hass.add_job to schedule the async function.
|
|
||
| if config[DOMAIN][CONF_WEBHOOKS]: | ||
| webhook_id = hass.components.webhook.async_generate_id() | ||
| NETATMO_WEBHOOK_URL = hass.components.webhook.async_generate_url( |
| webhook_id = hass.components.webhook.async_generate_id() | ||
| NETATMO_WEBHOOK_URL = hass.components.webhook.async_generate_url( | ||
| webhook_id) | ||
| hass.components.webhook.async_register( |
| """Handle webhook callback.""" | ||
| body = await request.text() | ||
| try: | ||
| data = json.loads(body) if body else {} |
There was a problem hiding this comment.
Why not use:
data = await request.json()| import pyatmo | ||
|
|
||
| global NETATMO_AUTH | ||
| global NETATMO_AUTH, NETATMO_WEBHOOK_URL |
There was a problem hiding this comment.
We should not use global. If this needs to be accessed from another module, use hass.data to store it.
|
|
||
| def get_persons(self): | ||
| """Gather person data for webhooks.""" | ||
| global NETATMO_PERSONS |
Description:
This PR updates the netatmo dependency (pyatmo) to version 1.8. I actually don't know what else has been changed, but I added helper methods to allow support for using webhooks for cameras.Update to 1.8 has already been done here. Webhook support is also what I have added in the component.In its current form the webhook support only fires events on the bus like such:
Movement:
Person:
I chose not to interact with the sensors this component (optionally) generates because there are no off-events for when motion stops or a person hat not been seen for a while. Besides that we also need periodic updates for the required refresh token to be refreshed (pyatmo does that on every update).
I have tested this with a Netatmo Welcome camera, and the existing functionality has not been broken. I also have the weather station with it's various sensors, and they seem to keep working like before as well. For other device types I can't make any statements. If anything breaks, that's due to changes in pyatmo I'm not aware of. But I doubt that there will be any trouble.
I'll take care of the documentation as soon as this PR generally gets accepted.
Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#8463
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:
REQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py.