Use voluptuous for gntp (#3237)

This commit is contained in:
Pascal Vizeli 2016-09-07 00:16:21 +02:00 committed by Teagan Glenn
parent e00f9339d1
commit 22870d424a

View file

@ -7,8 +7,12 @@ https://home-assistant.io/components/notify.gntp/
import logging
import os
import voluptuous as vol
from homeassistant.components.notify import (
ATTR_TITLE, ATTR_TITLE_DEFAULT, BaseNotificationService)
ATTR_TITLE, ATTR_TITLE_DEFAULT, PLATFORM_SCHEMA, BaseNotificationService)
from homeassistant.const import CONF_PASSWORD, CONF_PORT
import homeassistant.helpers.config_validation as cv
REQUIREMENTS = ['gntp==1.0.3']
@ -18,20 +22,37 @@ _GNTP_LOGGER = logging.getLogger('gntp')
_GNTP_LOGGER.setLevel(logging.ERROR)
CONF_APP_NAME = 'app_name'
CONF_APP_ICON = 'app_icon'
CONF_HOSTNAME = 'hostname'
DEFAULT_APP_NAME = 'HomeAssistant'
DEFAULT_HOST = 'localhost'
DEFAULT_PORT = 23053
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_APP_NAME, default=DEFAULT_APP_NAME): cv.string,
vol.Optional(CONF_APP_ICON): vol.Url,
vol.Optional(CONF_HOSTNAME, default=DEFAULT_HOST): cv.string,
vol.Optional(CONF_PASSWORD): cv.string,
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
})
def get_service(hass, config):
"""Get the GNTP notification service."""
if config.get('app_icon') is None:
if config.get(CONF_APP_ICON) is None:
icon_file = os.path.join(os.path.dirname(__file__), "..", "frontend",
"www_static", "icons", "favicon-192x192.png")
app_icon = open(icon_file, 'rb').read()
else:
app_icon = config.get('app_icon')
app_icon = config.get(CONF_APP_ICON)
return GNTPNotificationService(config.get('app_name', 'HomeAssistant'),
config.get('app_icon', app_icon),
config.get('hostname', 'localhost'),
config.get('password'),
config.get('port', 23053))
return GNTPNotificationService(config.get(CONF_APP_NAME),
app_icon,
config.get(CONF_HOSTNAME),
config.get(CONF_PASSWORD),
config.get(CONF_PORT))
# pylint: disable=too-few-public-methods