mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Voluptuous for pushover (#3000)
This commit is contained in:
parent
37048919bf
commit
4aad83d60b
@ -6,23 +6,26 @@ https://home-assistant.io/components/notify.pushover/
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.notify import (
|
from homeassistant.components.notify import (
|
||||||
ATTR_TITLE, ATTR_TARGET, ATTR_DATA, DOMAIN, BaseNotificationService)
|
ATTR_TITLE, ATTR_TARGET, ATTR_DATA, 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
|
||||||
|
|
||||||
REQUIREMENTS = ['python-pushover==0.2']
|
REQUIREMENTS = ['python-pushover==0.2']
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
||||||
|
vol.Required('user_key'): cv.string,
|
||||||
|
vol.Required(CONF_API_KEY): cv.string,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=unused-variable
|
# pylint: disable=unused-variable
|
||||||
def get_service(hass, config):
|
def get_service(hass, config):
|
||||||
"""Get the Pushover notification service."""
|
"""Get the Pushover notification service."""
|
||||||
if not validate_config({DOMAIN: config},
|
|
||||||
{DOMAIN: ['user_key', CONF_API_KEY]},
|
|
||||||
_LOGGER):
|
|
||||||
return None
|
|
||||||
|
|
||||||
from pushover import InitError
|
from pushover import InitError
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -30,8 +33,7 @@ def get_service(hass, config):
|
|||||||
config[CONF_API_KEY])
|
config[CONF_API_KEY])
|
||||||
except InitError:
|
except InitError:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"Wrong API key supplied. "
|
'Wrong API key supplied. Get it at https://pushover.net')
|
||||||
"Get it at https://pushover.net")
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@ -47,7 +49,7 @@ class PushoverNotificationService(BaseNotificationService):
|
|||||||
self.pushover = Client(
|
self.pushover = Client(
|
||||||
self._user_key, api_token=self._api_token)
|
self._user_key, api_token=self._api_token)
|
||||||
|
|
||||||
def send_message(self, message="", **kwargs):
|
def send_message(self, message='', **kwargs):
|
||||||
"""Send a message to a user."""
|
"""Send a message to a user."""
|
||||||
from pushover import RequestError
|
from pushover import RequestError
|
||||||
|
|
||||||
@ -65,4 +67,4 @@ class PushoverNotificationService(BaseNotificationService):
|
|||||||
except ValueError as val_err:
|
except ValueError as val_err:
|
||||||
_LOGGER.error(str(val_err))
|
_LOGGER.error(str(val_err))
|
||||||
except RequestError:
|
except RequestError:
|
||||||
_LOGGER.exception("Could not send pushover notification")
|
_LOGGER.exception('Could not send pushover notification')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user