mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 19:57:07 +00:00
Merge pull request #271 from rmkraus/notifier_update
Updated notifier component.
This commit is contained in:
commit
b418907598
@ -4,12 +4,13 @@ homeassistant.components.notify
|
|||||||
|
|
||||||
Provides functionality to notify people.
|
Provides functionality to notify people.
|
||||||
"""
|
"""
|
||||||
|
from functools import partial
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.loader import get_component
|
from homeassistant.loader import get_component
|
||||||
from homeassistant.helpers import validate_config
|
from homeassistant.helpers import config_per_platform
|
||||||
|
|
||||||
from homeassistant.const import CONF_PLATFORM
|
from homeassistant.const import CONF_NAME
|
||||||
|
|
||||||
DOMAIN = "notify"
|
DOMAIN = "notify"
|
||||||
DEPENDENCIES = []
|
DEPENDENCIES = []
|
||||||
@ -33,42 +34,45 @@ def send_message(hass, message):
|
|||||||
|
|
||||||
def setup(hass, config):
|
def setup(hass, config):
|
||||||
""" Sets up notify services. """
|
""" Sets up notify services. """
|
||||||
|
success = False
|
||||||
|
|
||||||
if not validate_config(config, {DOMAIN: [CONF_PLATFORM]}, _LOGGER):
|
for platform, p_config in config_per_platform(config, DOMAIN, _LOGGER):
|
||||||
return False
|
# get platform
|
||||||
|
notify_implementation = get_component(
|
||||||
|
'notify.{}'.format(platform))
|
||||||
|
|
||||||
platform = config[DOMAIN].get(CONF_PLATFORM)
|
if notify_implementation is None:
|
||||||
|
_LOGGER.error("Unknown notification service specified.")
|
||||||
|
continue
|
||||||
|
|
||||||
notify_implementation = get_component(
|
# create platform service
|
||||||
'notify.{}'.format(platform))
|
notify_service = notify_implementation.get_service(
|
||||||
|
hass, {DOMAIN: p_config})
|
||||||
|
|
||||||
if notify_implementation is None:
|
if notify_service is None:
|
||||||
_LOGGER.error("Unknown notification service specified.")
|
_LOGGER.error("Failed to initialize notification service %s",
|
||||||
|
platform)
|
||||||
|
continue
|
||||||
|
|
||||||
return False
|
# create service handler
|
||||||
|
def notify_message(notify_service, call):
|
||||||
|
""" Handle sending notification message service calls. """
|
||||||
|
message = call.data.get(ATTR_MESSAGE)
|
||||||
|
|
||||||
notify_service = notify_implementation.get_service(hass, config)
|
if message is None:
|
||||||
|
return
|
||||||
|
|
||||||
if notify_service is None:
|
title = call.data.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
|
||||||
_LOGGER.error("Failed to initialize notification service %s",
|
|
||||||
platform)
|
|
||||||
|
|
||||||
return False
|
notify_service.send_message(message, title=title)
|
||||||
|
|
||||||
def notify_message(call):
|
# register service
|
||||||
""" Handle sending notification message service calls. """
|
service_call_handler = partial(notify_message, notify_service)
|
||||||
message = call.data.get(ATTR_MESSAGE)
|
service_notify = p_config.get(CONF_NAME, SERVICE_NOTIFY)
|
||||||
|
hass.services.register(DOMAIN, service_notify, service_call_handler)
|
||||||
|
success = True
|
||||||
|
|
||||||
if message is None:
|
return success
|
||||||
return
|
|
||||||
|
|
||||||
title = call.data.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
|
|
||||||
|
|
||||||
notify_service.send_message(message, title=title)
|
|
||||||
|
|
||||||
hass.services.register(DOMAIN, SERVICE_NOTIFY, notify_message)
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
|
Loading…
x
Reference in New Issue
Block a user