mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Use voluptuous for message_bird, sendgrid (#3136)
This commit is contained in:
parent
7bab4055a5
commit
e460d8f637
@ -6,26 +6,22 @@ https://home-assistant.io/components/notify.message_bird/
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.components.notify import (
|
import voluptuous as vol
|
||||||
ATTR_TARGET, DOMAIN, BaseNotificationService)
|
|
||||||
from homeassistant.const import CONF_API_KEY
|
|
||||||
from homeassistant.helpers import validate_config
|
|
||||||
|
|
||||||
CONF_SENDER = 'sender'
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.components.notify import (
|
||||||
|
ATTR_TARGET, PLATFORM_SCHEMA, BaseNotificationService)
|
||||||
|
from homeassistant.const import CONF_API_KEY, CONF_SENDER
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
REQUIREMENTS = ['messagebird==1.2.0']
|
REQUIREMENTS = ['messagebird==1.2.0']
|
||||||
|
|
||||||
|
|
||||||
def is_valid_sender(sender):
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
"""Test if the sender config option is valid."""
|
vol.Required(CONF_API_KEY): cv.string,
|
||||||
length = len(sender)
|
vol.Optional(CONF_SENDER, default='HA'):
|
||||||
if length > 1:
|
vol.Match(r"^(\+?[1-9]\d{1,14}|\w{1,11})$"),
|
||||||
if sender[0] == '+':
|
})
|
||||||
return sender[1:].isdigit()
|
|
||||||
elif length <= 11:
|
|
||||||
return sender.isalpha()
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
@ -33,17 +29,6 @@ def get_service(hass, config):
|
|||||||
"""Get the MessageBird notification service."""
|
"""Get the MessageBird notification service."""
|
||||||
import messagebird
|
import messagebird
|
||||||
|
|
||||||
if not validate_config({DOMAIN: config},
|
|
||||||
{DOMAIN: [CONF_API_KEY]},
|
|
||||||
_LOGGER):
|
|
||||||
return None
|
|
||||||
|
|
||||||
sender = config.get(CONF_SENDER, 'HA')
|
|
||||||
if not is_valid_sender(sender):
|
|
||||||
_LOGGER.error('Sender is invalid: It must be a phone number or '
|
|
||||||
'a string not longer than 11 characters.')
|
|
||||||
return None
|
|
||||||
|
|
||||||
client = messagebird.Client(config[CONF_API_KEY])
|
client = messagebird.Client(config[CONF_API_KEY])
|
||||||
try:
|
try:
|
||||||
# validates the api key
|
# validates the api key
|
||||||
@ -52,7 +37,7 @@ def get_service(hass, config):
|
|||||||
_LOGGER.error('The specified MessageBird API key is invalid.')
|
_LOGGER.error('The specified MessageBird API key is invalid.')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return MessageBirdNotificationService(sender, client)
|
return MessageBirdNotificationService(config.get(CONF_SENDER), client)
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
|
@ -6,24 +6,29 @@ https://home-assistant.io/components/notify.sendgrid/
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
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.helpers import validate_config
|
from homeassistant.const import CONF_API_KEY, CONF_SENDER, CONF_RECIPIENT
|
||||||
|
|
||||||
REQUIREMENTS = ['sendgrid==3.2.10']
|
REQUIREMENTS = ['sendgrid==3.2.10']
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
vol.Required(CONF_API_KEY): cv.string,
|
||||||
|
vol.Required(CONF_SENDER): vol.Email,
|
||||||
|
vol.Required(CONF_RECIPIENT): cv.string,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
def get_service(hass, config):
|
def get_service(hass, config):
|
||||||
"""Get the SendGrid notification service."""
|
"""Get the SendGrid notification service."""
|
||||||
if not validate_config({DOMAIN: config},
|
api_key = config[CONF_API_KEY]
|
||||||
{DOMAIN: ['api_key', 'sender', 'recipient']},
|
sender = config[CONF_SENDER]
|
||||||
_LOGGER):
|
recipient = config[CONF_RECIPIENT]
|
||||||
return None
|
|
||||||
|
|
||||||
api_key = config['api_key']
|
|
||||||
sender = config['sender']
|
|
||||||
recipient = config['recipient']
|
|
||||||
|
|
||||||
return SendgridNotificationService(api_key, sender, recipient)
|
return SendgridNotificationService(api_key, sender, recipient)
|
||||||
|
|
||||||
|
@ -16,15 +16,14 @@ import homeassistant.helpers.config_validation as cv
|
|||||||
from homeassistant.components.notify import (
|
from homeassistant.components.notify import (
|
||||||
ATTR_TITLE, ATTR_TITLE_DEFAULT, ATTR_DATA, PLATFORM_SCHEMA,
|
ATTR_TITLE, ATTR_TITLE_DEFAULT, ATTR_DATA, PLATFORM_SCHEMA,
|
||||||
BaseNotificationService)
|
BaseNotificationService)
|
||||||
from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD, CONF_PORT)
|
from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD, CONF_PORT,
|
||||||
|
CONF_SENDER, CONF_RECIPIENT)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
ATTR_IMAGES = 'images' # optional embedded image file attachments
|
ATTR_IMAGES = 'images' # optional embedded image file attachments
|
||||||
|
|
||||||
CONF_STARTTLS = 'starttls'
|
CONF_STARTTLS = 'starttls'
|
||||||
CONF_SENDER = 'sender'
|
|
||||||
CONF_RECIPIENT = 'recipient'
|
|
||||||
CONF_DEBUG = 'debug'
|
CONF_DEBUG = 'debug'
|
||||||
CONF_SERVER = 'server'
|
CONF_SERVER = 'server'
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ import voluptuous as vol
|
|||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.components.notify import (
|
from homeassistant.components.notify import (
|
||||||
ATTR_TITLE, ATTR_TITLE_DEFAULT, PLATFORM_SCHEMA, BaseNotificationService)
|
ATTR_TITLE, ATTR_TITLE_DEFAULT, PLATFORM_SCHEMA, BaseNotificationService)
|
||||||
from homeassistant.const import CONF_PASSWORD
|
from homeassistant.const import CONF_PASSWORD, CONF_SENDER, CONF_RECIPIENT
|
||||||
|
|
||||||
REQUIREMENTS = ['sleekxmpp==1.3.1',
|
REQUIREMENTS = ['sleekxmpp==1.3.1',
|
||||||
'dnspython3==1.12.0',
|
'dnspython3==1.12.0',
|
||||||
@ -19,8 +19,6 @@ REQUIREMENTS = ['sleekxmpp==1.3.1',
|
|||||||
'pyasn1-modules==0.0.8']
|
'pyasn1-modules==0.0.8']
|
||||||
|
|
||||||
|
|
||||||
CONF_SENDER = 'sender'
|
|
||||||
CONF_RECIPIENT = 'recipient'
|
|
||||||
CONF_TLS = 'tls'
|
CONF_TLS = 'tls'
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
@ -73,9 +73,11 @@ CONF_PIN = 'pin'
|
|||||||
CONF_PLATFORM = 'platform'
|
CONF_PLATFORM = 'platform'
|
||||||
CONF_PORT = 'port'
|
CONF_PORT = 'port'
|
||||||
CONF_PREFIX = 'prefix'
|
CONF_PREFIX = 'prefix'
|
||||||
|
CONF_RECIPIENT = 'recipient'
|
||||||
CONF_RESOURCE = 'resource'
|
CONF_RESOURCE = 'resource'
|
||||||
CONF_RESOURCES = 'resources'
|
CONF_RESOURCES = 'resources'
|
||||||
CONF_SCAN_INTERVAL = 'scan_interval'
|
CONF_SCAN_INTERVAL = 'scan_interval'
|
||||||
|
CONF_SENDER = 'sender'
|
||||||
CONF_SENSOR_CLASS = 'sensor_class'
|
CONF_SENSOR_CLASS = 'sensor_class'
|
||||||
CONF_SENSORS = 'sensors'
|
CONF_SENSORS = 'sensors'
|
||||||
CONF_SSL = 'ssl'
|
CONF_SSL = 'ssl'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user