Rachio webhooks#15111
Conversation
There was a problem hiding this comment.
Please rename the DOMAIN import: DOMAIN as DOMAIN_RACHIO
There was a problem hiding this comment.
Also, instead of \ you can wrap all values in (…)
MartinHjelmare
left a comment
There was a problem hiding this comment.
Set should_poll property to False.
homeassistant/components/rachio.py
Outdated
There was a problem hiding this comment.
Use our dispatch helper instead of the event bus to communicate between component and platforms.
There was a problem hiding this comment.
Please do not use the event bus for this. Use the dispatcher instead.
There was a problem hiding this comment.
This is weird. Why not control this by passing True as second parameter to add_devices instead. This will cause the update() method to be called, which is meant for polling an update
There was a problem hiding this comment.
With _poll_update in the constructor, I can pass data that I already fetched in an earlier call. When HA calls update, it would have to fetch that data and use an API call (which now have a rate limit). After instantiation, updates are provided via webhooks only.
There was a problem hiding this comment.
Please have this entity set should_poll to False to avoid having Home Assistant try to update it regularly.
homeassistant/components/rachio.py
Outdated
There was a problem hiding this comment.
I'm not sure exactly what "this" is (and I'm not even writing JS...)
- The custom URL can be set in the config.
- If set, it overrides the base_url. If not, it stores the base_url.
- (Now replaced with
generate_secret.) This is passed to the Rachio API and then provided with incoming webhooks to authenticate the connections. - This assembles the hostname and path. The combine URL is then given to the Rachio API to call when events occur.
homeassistant/components/rachio.py
Outdated
There was a problem hiding this comment.
We should under no circumstance send our API password to Rachio. Instead, generate a random token and have your web view implement that as authentication.
You can generate a token by using homeassistant.auth.generate_secret
homeassistant/components/rachio.py
Outdated
There was a problem hiding this comment.
When would a custom url be necessary ?
There was a problem hiding this comment.
For cases where the base_url will not be accessible by Rachio's server, or is incorrect. I don't know how commonly this will happen, but I figured it should be possible after there were similar issues with another component.
homeassistant/components/rachio.py
Outdated
There was a problem hiding this comment.
These are kinda overkill. Just make the instance name self.username ?
homeassistant/components/rachio.py
Outdated
homeassistant/components/rachio.py
Outdated
There was a problem hiding this comment.
How does this work. How long will it send things over this webhook? Are we registering on each restart of Home Assistant ?
There was a problem hiding this comment.
It will send things over this webhook until it is deleted on shutdown. Yes, a new webhook is created on each restart, as this accounts for port/hostname changes.
homeassistant/components/rachio.py
Outdated
There was a problem hiding this comment.
What happens if this callback does not get called? Is there a way we can query existing webhooks and make sure there is only 1 configured?
There was a problem hiding this comment.
I have added a line to remove all existing HA webhooks on startup. It should only be 1 extra startup API call if they were removed correctly on shutdown. In my testing, they have always been removed correctly at shutdown (even sending a series of ^C!)
homeassistant/components/rachio.py
Outdated
There was a problem hiding this comment.
No, 204. The page is blank.
There was a problem hiding this comment.
Remove the polling option and send True as second param to add_devices so it will call the update method.
There was a problem hiding this comment.
Doesn't every controller have 3 switches?
There was a problem hiding this comment.
For now, yes. But I want it to be easy to add more switchable options in the future.
|
Awesome. |
* Make fewer requests to the Rachio API * BREAKING: Rewrite Rachio component
| else: | ||
| self._state = None | ||
|
|
||
| dispatcher_connect(hass, SIGNAL_RACHIO_CONTROLLER_UPDATE, |
There was a problem hiding this comment.
It's safer to connect the state update handler in async_added_to_hass which will be scheduled after the device has been added to home assistant. If the signal is sent before the entity has been added to home assistant the handler will error since we connect before the entity has been added to home assistant.
| name = url[1:].replace('/', ':') | ||
|
|
||
| # pylint: disable=no-self-use | ||
| @asyncio.coroutine |
There was a problem hiding this comment.
Remove what, specifically?
Description:
switchcomponent, is now broken up into arachiocomponent as well asswitchandbinary_sensorcomponents.rachioto the configuration and moving theaccess_tokenoption (renamed toapi_key) to the new section, leavingmanual_run_minsin the switch section. You may also need to specifyhass_url_overrideif yoru instance is unaware of its actual web location (base_url). Port-forwarding or proxying may be needed in order for the Rachio API to be able to call[your instance]:8123/api/rachio.Related issue (if applicable): fixes #12639
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#5589
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..coveragerc.