8000 Add discovery notify support and mysensors notify by MartinHjelmare · Pull Request #4014 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add discovery notify support and mysensors notify #4014

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

Closed

Conversation

MartinHjelmare
Copy link
Member
@MartinHjelmare MartinHjelmare commented Oct 23, 2016

Description:

  • Add support for discovery setup for notify component platforms.
  • Make add_devices optional in mysensors platform callback function.
  • Use new argument structure for all existing mysensors platforms.
  • Add mysensors notify platform.

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.github.io#<home-assistant.github.io PR number goes here>

Example entry for configuration.yaml (if applicable):

mysensors:
  gateways:
    - device: '/dev/ttyACM0'
  version: 2.0

Checklist:
If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass

@mention-bot
Copy link

@MartinHjelmare, thanks for your PR! By analyzing the history of the files in this pull request, we identified @kaustubhphatak, @OttoWinter and @mxtra to be potential reviewers.

@MartinHjelmare
Copy link
Member Author

Don't merge! Need to rebase this when #4013 is merged.

@balloob
Copy link
Member
balloob commented Nov 2, 2016

Code looks fine with me 🐬 . You can merge this when you are ready.

@MartinHjelmare
Copy link
Member Author

I'll postpone merging this until after 0.32 release. If possible I'd like to setup the platform via discovery, but I haven't looked into what that would take yet.

@balloob
Copy link
Member
balloob commented Nov 11, 2016

Bump

@MartinHjelmare MartinHjelmare changed the title Add mysensors notify platform RFC: Add mysensors notify platform Nov 15, 2016
@MartinHjelmare
Copy link
Member Author

I've added possibility of using discovery for notify platforms. I'd like @balloob to look at this, if it's viable.

As discussed in gitter, I've been experiencing occasional, 1/3 - 1/5 of every start, race conditions with this branch where the notify component is setup more than once. We don't want this to happen!

https://gitter.im/home-assistant/home-assistant/devs?at=58289aecdf5ae966454fe218
https://gitter.im/home-assistant/home-assistant/devs?at=58289fe831c5cbef43eec10b

From how I'm reading the code and from my testing it looks like this is due to how the _async_setup_component coroutine in bootstrap.py is written. It doesn't enforce a lock from the beginning of the function and only if the lock is not already locked will a run be required to acquire the lock. Discovery setup is required to acquire the lock if the lock is locked, before entering the coroutine, but will be allowed to run the coroutine as soon as the lock is released, since the next config component setup does not acquire the lock again immediately. Also, the check for if a component is already added, is done in the beginning of the function, and not after the lock is acquired, so it's more or less a lame duck.

With that said, I'd love to be proven wrong, or that we find a better way to implement discovery for notify platforms.

@balloob
Copy link
Member
balloob commented Nov 19, 2016

Sorry for not getting back to you earlier.

You are right here about the locking not being correct. I think an easy fix for this is to acquire the lock inside async_from_config_file. That way, no discovery will ever run while we are setting up from a config file.

@balloob
Copy link
Member
balloob commented Nov 19, 2016

I have resolved the discovery issue in #4463

@MartinHjelmare MartinHjelmare changed the title RFC: Add mysensors notify platform Add discovery notify support and mysensors notify platform Nov 19, 2016
@MartinHjelmare MartinHjelmare changed the title Add discovery notify support and mysensors notify platform Add discovery notify support and mysensors notify Nov 19, 2016
}))
# Platform should not be set up, but component should be set up.
with assert_setup_component(0):
self.assertTrue(setup_component(self.hass, notify.DOMAIN, {
Copy link
Member Author

Choose a reason for hiding this comment

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

With the change to notify component this test doesn't add value anymore, I think. The notify component will be set up even with bad config, due to config validation removing the bad parts.

with assert_setup_component(0):
assert not setup_component(self.hass, notify.DOMAIN, {
assert setup_component(self.hass, notify.DOMAIN, {
Copy link
Member Author

Choose a reason for hiding this comment

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

With the change to notify component this test doesn't add value anymore, I think. The notify component will be set up even with bad config, due to config validation removing the bad parts.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, strip it.

if p_config is None:
p_config = {}
if discovery_info is not None:
p_config = discovery_info
Copy link
Member Author

Choose a reason for hiding this comment

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

Is this a good idea, using the passed discovery info directly as config for the platform?

Copy link
Member

Choose a reason for hiding this comment

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

Yes.

@balloob
Copy link
Member
balloob commented Nov 23, 2016

I have made another fix for the discovery today #4529


for platform, p_config in config_per_platform(config, DOMAIN):
if not setup_notify_platform(platform, p_config):
return False
Copy link
Member

Choose a reason for hiding this comment

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

The logic in bootstrap will actually continue setting up platforms after it finds invalid platforms. So let's mimic that behavior here.

@balloob balloob self-assigned this Nov 23, 2016
@balloob
Copy link
Member
balloob commented Dec 2, 2016

Bump

* Make add_devices optional in platform callback function.
* Use new argument structure for all existing mysensors platforms.
* Add notify platform.
* Enable discovery of notify platforms.
* Use discovery to set up mysensors notify platform.
* Continue setup of notify platforms if a platform fails setup.
* Remove notify tests that check platform config. These tests are not
  needed when config validation is used.
* Add config validation to APNS notify platform.
@@ -6,7 +6,7 @@

from homeassistant.bootstrap import setup_component
import homeassistant.components.notify as notify
from tests.common import get_test_home_assistant
from tests.common import assert_setup_component, get_test_home_assistant

Choose a reason for hiding this comment

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

'assert_setup_component' imported but unused

@MartinHjelmare
Copy link
Member Author

One lint violation and some tests for notify component is still missing. I'll fix that asap.

@balloob
Copy link
Member
balloob commented Dec 27, 2016

This PR seems to have gone stale. Closing it. You can reopen it when you're ready to finish it.

@balloob balloob closed this Dec 27, 2016
@home-assistant home-assistant locked and limited conversation to collaborators Mar 30, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0