Use voluptuous for instapush (#3132)
This commit is contained in:
parent
b8b1fadc6d
commit
000832a82c
1 changed files with 21 additions and 14 deletions
|
@ -8,11 +8,25 @@ import json
|
|||
import logging
|
||||
|
||||
import requests
|
||||
import voluptuous as vol
|
||||
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.components.notify import (
|
||||
ATTR_TITLE, ATTR_TITLE_DEFAULT, DOMAIN, BaseNotificationService)
|
||||
ATTR_TITLE, ATTR_TITLE_DEFAULT, PLATFORM_SCHEMA, BaseNotificationService)
|
||||
from homeassistant.const import CONF_API_KEY
|
||||
from homeassistant.helpers import validate_config
|
||||
|
||||
|
||||
CONF_APP_SECRET = 'app_secret'
|
||||
CONF_EVENT = 'event'
|
||||
CONF_TRACKER = 'tracker'
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_API_KEY): cv.string,
|
||||
vol.Required(CONF_APP_SECRET): cv.string,
|
||||
vol.Required(CONF_EVENT): cv.string,
|
||||
vol.Required(CONF_TRACKER): cv.string,
|
||||
})
|
||||
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
_RESOURCE = 'https://api.instapush.im/v1/'
|
||||
|
@ -20,16 +34,8 @@ _RESOURCE = 'https://api.instapush.im/v1/'
|
|||
|
||||
def get_service(hass, config):
|
||||
"""Get the instapush notification service."""
|
||||
if not validate_config({DOMAIN: config},
|
||||
{DOMAIN: [CONF_API_KEY,
|
||||
'app_secret',
|
||||
'event',
|
||||
'tracker']},
|
||||
_LOGGER):
|
||||
return None
|
||||
|
||||
headers = {'x-instapush-appid': config[CONF_API_KEY],
|
||||
'x-instapush-appsecret': config['app_secret']}
|
||||
'x-instapush-appsecret': config[CONF_APP_SECRET]}
|
||||
|
||||
try:
|
||||
response = requests.get(_RESOURCE + 'events/list',
|
||||
|
@ -42,15 +48,16 @@ def get_service(hass, config):
|
|||
_LOGGER.error(response['msg'])
|
||||
return None
|
||||
|
||||
if len([app for app in response if app['title'] == config['event']]) == 0:
|
||||
if len([app for app in response
|
||||
if app['title'] == config[CONF_EVENT]]) == 0:
|
||||
_LOGGER.error(
|
||||
"No app match your given value. "
|
||||
"Please create an app at https://instapush.im")
|
||||
return None
|
||||
|
||||
return InstapushNotificationService(
|
||||
config[CONF_API_KEY], config['app_secret'], config['event'],
|
||||
config['tracker'])
|
||||
config[CONF_API_KEY], config[CONF_APP_SECRET], config[CONF_EVENT],
|
||||
config[CONF_TRACKER])
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
|
|
Loading…
Add table
Reference in a new issue