mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +00:00
Service validation for notify component.
This commit is contained in:
parent
40e36126bc
commit
7ffc254a87
@ -8,11 +8,13 @@ from functools import partial
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
import homeassistant.bootstrap as bootstrap
|
import homeassistant.bootstrap as bootstrap
|
||||||
from homeassistant.config import load_yaml_config_file
|
from homeassistant.config import load_yaml_config_file
|
||||||
from homeassistant.helpers import config_per_platform, template
|
from homeassistant.helpers import config_per_platform, template
|
||||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.const import CONF_NAME
|
from homeassistant.const import CONF_NAME
|
||||||
|
|
||||||
DOMAIN = "notify"
|
DOMAIN = "notify"
|
||||||
@ -32,6 +34,13 @@ ATTR_DATA = 'data'
|
|||||||
|
|
||||||
SERVICE_NOTIFY = "notify"
|
SERVICE_NOTIFY = "notify"
|
||||||
|
|
||||||
|
NOTIFY_SERVICE_SCHEMA = vol.Schema({
|
||||||
|
vol.Required(ATTR_MESSAGE): cv.template,
|
||||||
|
vol.Optional(ATTR_TITLE, default=ATTR_TITLE_DEFAULT): cv.string,
|
||||||
|
vol.Optional(ATTR_TARGET): cv.string,
|
||||||
|
vol.Optional(ATTR_DATA): dict, # nobody seems to be using this (yet)
|
||||||
|
})
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -71,13 +80,7 @@ def setup(hass, config):
|
|||||||
|
|
||||||
def notify_message(notify_service, call):
|
def notify_message(notify_service, call):
|
||||||
"""Handle sending notification message service calls."""
|
"""Handle sending notification message service calls."""
|
||||||
message = call.data.get(ATTR_MESSAGE)
|
message = call.data[ATTR_MESSAGE]
|
||||||
|
|
||||||
if message is None:
|
|
||||||
_LOGGER.error(
|
|
||||||
'Received call to %s without attribute %s',
|
|
||||||
call.service, ATTR_MESSAGE)
|
|
||||||
return
|
|
||||||
|
|
||||||
title = template.render(
|
title = template.render(
|
||||||
hass, call.data.get(ATTR_TITLE, ATTR_TITLE_DEFAULT))
|
hass, call.data.get(ATTR_TITLE, ATTR_TITLE_DEFAULT))
|
||||||
@ -91,7 +94,8 @@ def setup(hass, config):
|
|||||||
service_call_handler = partial(notify_message, notify_service)
|
service_call_handler = partial(notify_message, notify_service)
|
||||||
service_notify = p_config.get(CONF_NAME, SERVICE_NOTIFY)
|
service_notify = p_config.get(CONF_NAME, SERVICE_NOTIFY)
|
||||||
hass.services.register(DOMAIN, service_notify, service_call_handler,
|
hass.services.register(DOMAIN, service_notify, service_call_handler,
|
||||||
descriptions.get(SERVICE_NOTIFY))
|
descriptions.get(SERVICE_NOTIFY),
|
||||||
|
schema=NOTIFY_SERVICE_SCHEMA)
|
||||||
success = True
|
success = True
|
||||||
|
|
||||||
return success
|
return success
|
||||||
|
Loading…
x
Reference in New Issue
Block a user