Update ordering and sync logger messages (#4615)

This commit is contained in:
Fabian Affolter 2016-11-28 20:50:42 +01:00 committed by GitHub
parent 4bc37bd661
commit e8367f245a

View File

@ -4,35 +4,37 @@ Provides functionality to notify people.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/notify/ https://home-assistant.io/components/notify/
""" """
from functools import partial
import logging import logging
import os import os
from functools import partial
import voluptuous as vol import voluptuous as vol
import homeassistant.bootstrap as bootstrap import homeassistant.bootstrap as bootstrap
from homeassistant.config import load_yaml_config_file
from homeassistant.helpers import config_per_platform
import homeassistant.helpers.config_validation as cv 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.const import CONF_NAME, CONF_PLATFORM
from homeassistant.helpers import config_per_platform
from homeassistant.util import slugify from homeassistant.util import slugify
DOMAIN = "notify" _LOGGER = logging.getLogger(__name__)
# Title of notification
ATTR_TITLE = "title"
ATTR_TITLE_DEFAULT = "Home Assistant"
# Target of the notification (user, device, etc)
ATTR_TARGET = 'target'
# Text to notify user of
ATTR_MESSAGE = "message"
# Platform specific data # Platform specific data
ATTR_DATA = 'data' ATTR_DATA = 'data'
SERVICE_NOTIFY = "notify" # Text to notify user of
ATTR_MESSAGE = 'message'
# Target of the notification (user, device, etc)
ATTR_TARGET = 'target'
# Title of notification
ATTR_TITLE = 'title'
ATTR_TITLE_DEFAULT = "Home Assistant"
DOMAIN = 'notify'
SERVICE_NOTIFY = 'notify'
PLATFORM_SCHEMA = vol.Schema({ PLATFORM_SCHEMA = vol.Schema({
vol.Required(CONF_PLATFORM): cv.string, vol.Required(CONF_PLATFORM): cv.string,
@ -46,8 +48,6 @@ NOTIFY_SERVICE_SCHEMA = vol.Schema({
vol.Optional(ATTR_DATA): dict, vol.Optional(ATTR_DATA): dict,
}) })
_LOGGER = logging.getLogger(__name__)
def send_message(hass, message, title=None, data=None): def send_message(hass, message, title=None, data=None):
"""Send a notification message.""" """Send a notification message."""
@ -78,7 +78,7 @@ def setup(hass, config):
hass, config, DOMAIN, platform) hass, config, DOMAIN, platform)
if notify_implementation is None: if notify_implementation is None:
_LOGGER.error("Unknown notification service specified.") _LOGGER.error("Unknown notification service specified")
continue continue
notify_service = notify_implementation.get_service(hass, p_config) notify_service = notify_implementation.get_service(hass, p_config)
@ -114,7 +114,7 @@ def setup(hass, config):
if hasattr(notify_service, 'targets'): if hasattr(notify_service, 'targets'):
platform_name = (p_config.get(CONF_NAME) or platform) platform_name = (p_config.get(CONF_NAME) or platform)
for name, target in notify_service.targets.items(): for name, target in notify_service.targets.items():
target_name = slugify("{}_{}".format(platform_name, name)) target_name = slugify('{}_{}'.format(platform_name, name))
targets[target_name] = target targets[target_name] = target
hass.services.register(DOMAIN, target_name, hass.services.register(DOMAIN, target_name,
service_call_handler, service_call_handler,
@ -124,10 +124,9 @@ def setup(hass, config):
platform_name = (p_config.get(CONF_NAME) or SERVICE_NOTIFY) platform_name = (p_config.get(CONF_NAME) or SERVICE_NOTIFY)
platform_name_slug = slugify(platform_name) platform_name_slug = slugify(platform_name)
hass.services.register(DOMAIN, platform_name_slug, hass.services.register(
service_call_handler, DOMAIN, platform_name_slug, service_call_handler,
descriptions.get(SERVICE_NOTIFY), descriptions.get(SERVICE_NOTIFY), schema=NOTIFY_SERVICE_SCHEMA)
schema=NOTIFY_SERVICE_SCHEMA)
success = True success = True
return success return success