From 6b6d34ba51a509cb979d421a0af656587c686c5f Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Fri, 2 Sep 2016 06:27:28 +0200 Subject: [PATCH] Use voluptuous for xmpp (#3127) --- homeassistant/components/notify/xmpp.py | 27 +++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/notify/xmpp.py b/homeassistant/components/notify/xmpp.py index e5b7792776e..35157a9bd46 100644 --- a/homeassistant/components/notify/xmpp.py +++ b/homeassistant/components/notify/xmpp.py @@ -6,30 +6,41 @@ https://home-assistant.io/components/notify.xmpp/ """ import logging +import voluptuous as vol + +import homeassistant.helpers.config_validation as cv from homeassistant.components.notify import ( - ATTR_TITLE, ATTR_TITLE_DEFAULT, DOMAIN, BaseNotificationService) -from homeassistant.helpers import validate_config + ATTR_TITLE, ATTR_TITLE_DEFAULT, PLATFORM_SCHEMA, BaseNotificationService) +from homeassistant.const import CONF_PASSWORD REQUIREMENTS = ['sleekxmpp==1.3.1', 'dnspython3==1.12.0', 'pyasn1==0.1.9', 'pyasn1-modules==0.0.8'] + +CONF_SENDER = 'sender' +CONF_RECIPIENT = 'recipient' +CONF_TLS = 'tls' + +PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ + vol.Required(CONF_SENDER): cv.string, + vol.Required(CONF_PASSWORD): cv.string, + vol.Required(CONF_RECIPIENT): cv.string, + vol.Optional(CONF_TLS, default=True): cv.boolean, +}) + + _LOGGER = logging.getLogger(__name__) def get_service(hass, config): """Get the Jabber (XMPP) notification service.""" - if not validate_config({DOMAIN: config}, - {DOMAIN: ['sender', 'password', 'recipient']}, - _LOGGER): - return None - return XmppNotificationService( config.get('sender'), config.get('password'), config.get('recipient'), - config.get('tls', True)) + config.get('tls')) # pylint: disable=too-few-public-methods