mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Use voluptuous for pushbullet, pushetta and pushover (#3240)
This commit is contained in:
parent
22870d424a
commit
9eacde0005
@ -6,24 +6,29 @@ https://home-assistant.io/components/notify.pushbullet/
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.notify import (
|
from homeassistant.components.notify import (
|
||||||
ATTR_TARGET, ATTR_TITLE, ATTR_TITLE_DEFAULT, BaseNotificationService)
|
ATTR_TARGET, ATTR_TITLE, ATTR_TITLE_DEFAULT, PLATFORM_SCHEMA,
|
||||||
|
BaseNotificationService)
|
||||||
from homeassistant.const import CONF_API_KEY
|
from homeassistant.const import CONF_API_KEY
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
REQUIREMENTS = ['pushbullet.py==0.10.0']
|
REQUIREMENTS = ['pushbullet.py==0.10.0']
|
||||||
|
|
||||||
|
|
||||||
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
vol.Required(CONF_API_KEY): cv.string,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def get_service(hass, config):
|
def get_service(hass, config):
|
||||||
"""Get the PushBullet notification service."""
|
"""Get the PushBullet notification service."""
|
||||||
from pushbullet import PushBullet
|
from pushbullet import PushBullet
|
||||||
from pushbullet import InvalidKeyError
|
from pushbullet import InvalidKeyError
|
||||||
|
|
||||||
if CONF_API_KEY not in config:
|
|
||||||
_LOGGER.error("Unable to find config key '%s'", CONF_API_KEY)
|
|
||||||
return None
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pushbullet = PushBullet(config[CONF_API_KEY])
|
pushbullet = PushBullet(config[CONF_API_KEY])
|
||||||
except InvalidKeyError:
|
except InvalidKeyError:
|
||||||
|
@ -6,37 +6,42 @@ https://home-assistant.io/components/notify.pushetta/
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.notify import (
|
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.const import CONF_API_KEY
|
||||||
from homeassistant.helpers import validate_config
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
REQUIREMENTS = ['pushetta==1.0.15']
|
REQUIREMENTS = ['pushetta==1.0.15']
|
||||||
|
|
||||||
|
|
||||||
|
CONF_CHANNEL_NAME = 'channel_name'
|
||||||
|
|
||||||
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
vol.Required(CONF_API_KEY): cv.string,
|
||||||
|
vol.Required(CONF_CHANNEL_NAME): cv.string,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
def get_service(hass, config):
|
def get_service(hass, config):
|
||||||
"""Get the Pushetta notification service."""
|
"""Get the Pushetta notification service."""
|
||||||
from pushetta import Pushetta, exceptions
|
from pushetta import Pushetta, exceptions
|
||||||
|
|
||||||
if not validate_config({DOMAIN: config},
|
|
||||||
{DOMAIN: [CONF_API_KEY, 'channel_name']},
|
|
||||||
_LOGGER):
|
|
||||||
return None
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pushetta = Pushetta(config[CONF_API_KEY])
|
pushetta = Pushetta(config[CONF_API_KEY])
|
||||||
pushetta.pushMessage(config['channel_name'], "Home Assistant started")
|
pushetta.pushMessage(config[CONF_CHANNEL_NAME],
|
||||||
|
"Home Assistant started")
|
||||||
except exceptions.TokenValidationError:
|
except exceptions.TokenValidationError:
|
||||||
_LOGGER.error("Please check your access token")
|
_LOGGER.error("Please check your access token")
|
||||||
return None
|
return None
|
||||||
except exceptions.ChannelNotFoundError:
|
except exceptions.ChannelNotFoundError:
|
||||||
_LOGGER.error("Channel '%s' not found", config['channel_name'])
|
_LOGGER.error("Channel '%s' not found", config[CONF_CHANNEL_NAME])
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return PushettaNotificationService(config[CONF_API_KEY],
|
return PushettaNotificationService(config[CONF_API_KEY],
|
||||||
config['channel_name'])
|
config[CONF_CHANNEL_NAME])
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
|
@ -18,8 +18,10 @@ REQUIREMENTS = ['python-pushover==0.2']
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
CONF_USER_KEY = 'user_key'
|
||||||
|
|
||||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
||||||
vol.Required('user_key'): cv.string,
|
vol.Required(CONF_USER_KEY): cv.string,
|
||||||
vol.Required(CONF_API_KEY): cv.string,
|
vol.Required(CONF_API_KEY): cv.string,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -30,7 +32,7 @@ def get_service(hass, config):
|
|||||||
from pushover import InitError
|
from pushover import InitError
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return PushoverNotificationService(config['user_key'],
|
return PushoverNotificationService(config[CONF_USER_KEY],
|
||||||
config[CONF_API_KEY])
|
config[CONF_API_KEY])
|
||||||
except InitError:
|
except InitError:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user