mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
Use voluptuous for gntp (#3237)
This commit is contained in:
parent
e00f9339d1
commit
22870d424a
@ -7,8 +7,12 @@ https://home-assistant.io/components/notify.gntp/
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.notify import (
|
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']
|
REQUIREMENTS = ['gntp==1.0.3']
|
||||||
|
|
||||||
@ -18,20 +22,37 @@ _GNTP_LOGGER = logging.getLogger('gntp')
|
|||||||
_GNTP_LOGGER.setLevel(logging.ERROR)
|
_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):
|
def get_service(hass, config):
|
||||||
"""Get the GNTP notification service."""
|
"""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",
|
icon_file = os.path.join(os.path.dirname(__file__), "..", "frontend",
|
||||||
"www_static", "icons", "favicon-192x192.png")
|
"www_static", "icons", "favicon-192x192.png")
|
||||||
app_icon = open(icon_file, 'rb').read()
|
app_icon = open(icon_file, 'rb').read()
|
||||||
else:
|
else:
|
||||||
app_icon = config.get('app_icon')
|
app_icon = config.get(CONF_APP_ICON)
|
||||||
|
|
||||||
return GNTPNotificationService(config.get('app_name', 'HomeAssistant'),
|
return GNTPNotificationService(config.get(CONF_APP_NAME),
|
||||||
config.get('app_icon', app_icon),
|
app_icon,
|
||||||
config.get('hostname', 'localhost'),
|
config.get(CONF_HOSTNAME),
|
||||||
config.get('password'),
|
config.get(CONF_PASSWORD),
|
||||||
config.get('port', 23053))
|
config.get(CONF_PORT))
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
|
Loading…
x
Reference in New Issue
Block a user