Add discovery notify support and mysensors notify (#5219)

* Add mysensors notify platform

* Make add_devices optional in platform callback function.
* Use new argument structure for all existing mysensors platforms.
* Add notify platform.
* Update mysensors gateway.

* Refactor notify setup

* Enable discovery of notify platforms.
* Update and add tests for notify component and some platforms.
* 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.
* Use discovery to set up mysensors notify platform.

* Add discovery_info to get_service and update tests

* Add discovery_info as keyword argument to the get_service function
  signature and update all notify platforms.
* Update existing notify tests to check config validation using test
  helper.
* Add removed tests back in that checked config in apns, command_line
  and file platforms, but use config validation test helper to verify
  config.
* Add a test for notify file to increase coverage.
* Fix some PEP issues.

* Fix comments and use more constants

* Move apns notify service under notify domain
This commit is contained in:
Martin Hjelmare authored and GitHub committed 2017-01-15 03:53:14 +01:00
1 parent 3b9fb6ccf5
commit 9db1aa7629
51 files changed
+395 -255

No files matched your search

+32 -11
View File
@@ -14,7 +14,7 @@ import homeassistant.bootstrap as bootstrap
import homeassistant.helpers.config_validation as cv
from homeassistant.config import load_yaml_config_file
from homeassistant.const import CONF_NAME, CONF_PLATFORM
from homeassistant.helpers import config_per_platform
from homeassistant.helpers import config_per_platform, discovery
from homeassistant.util import slugify
_LOGGER = logging.getLogger(__name__)
@@ -66,27 +66,32 @@ def send_message(hass, message, title=None, data=None):
def setup(hass, config):
"""Setup the notify services."""
success = False
descriptions = load_yaml_config_file(
os.path.join(os.path.dirname(__file__), 'services.yaml'))
targets = {}
for platform, p_config in config_per_platform(config, DOMAIN):
def setup_notify_platform(platform, p_config=None, discovery_info=None):
"""Set up a notify platform."""
if p_config is None:
p_config = {}
if discovery_info is None:
discovery_info = {}
notify_implementation = bootstrap.prepare_setup_platform(
hass, config, DOMAIN, platform)
if notify_implementation is None:
_LOGGER.error("Unknown notification service specified")
continue
return False
notify_service = notify_implementation.get_service(hass, p_config)
notify_service = notify_implementation.get_service(
hass, p_config, discovery_info)
if notify_service is None:
_LOGGER.error("Failed to initialize notification service %s",
platform)
continue
return False
def notify_message(notify_service, call):
"""Handle sending notification message service calls."""
@@ -112,7 +117,9 @@ def setup(hass, config):
service_call_handler = partial(notify_message, notify_service)
if hasattr(notify_service, 'targets'):
platform_name = (p_config.get(CONF_NAME) or platform)
platform_name = (
p_config.get(CONF_NAME) or discovery_info.get(CONF_NAME) or
platform)
for name, target in notify_service.targets.items():
target_name = slugify('{}_{}'.format(platform_name, name))
targets[target_name] = target
@@ -121,15 +128,29 @@ def setup(hass, config):
descriptions.get(SERVICE_NOTIFY),
schema=NOTIFY_SERVICE_SCHEMA)
platform_name = (p_config.get(CONF_NAME) or SERVICE_NOTIFY)
platform_name = (
p_config.get(CONF_NAME) or discovery_info.get(CONF_NAME) or
SERVICE_NOTIFY)
platform_name_slug = slugify(platform_name)
hass.services.register(
DOMAIN, platform_name_slug, service_call_handler,
descriptions.get(SERVICE_NOTIFY), schema=NOTIFY_SERVICE_SCHEMA)
success = True
return success
return True
for platform, p_config in config_per_platform(config, DOMAIN):
if not setup_notify_platform(platform, p_config):
_LOGGER.error("Failed to set up platform %s", platform)
continue
def platform_discovered(platform, info):
"""Callback to load a platform."""
setup_notify_platform(platform, discovery_info=info)
discovery.listen_platform(hass, DOMAIN, platform_discovered)
return True
class BaseNotificationService(object):