Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Voluptuous for pushover #3000

Merged
merged 1 commit into from
Aug 27, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions homeassistant/components/notify/pushover.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,34 @@
"""
import logging

import voluptuous as vol

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.helpers import validate_config
import homeassistant.helpers.config_validation as cv

REQUIREMENTS = ['python-pushover==0.2']
_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
def get_service(hass, config):
"""Get the Pushover notification service."""
if not validate_config({DOMAIN: config},
{DOMAIN: ['user_key', CONF_API_KEY]},
_LOGGER):
return None

from pushover import InitError

try:
return PushoverNotificationService(config['user_key'],
config[CONF_API_KEY])
except InitError:
_LOGGER.error(
"Wrong API key supplied. "
"Get it at https://pushover.net")
'Wrong API key supplied. Get it at https://pushover.net')
return None


Expand All @@ -47,7 +49,7 @@ def __init__(self, user_key, api_token):
self.pushover = Client(
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."""
from pushover import RequestError

Expand All @@ -65,4 +67,4 @@ def send_message(self, message="", **kwargs):
except ValueError as val_err:
_LOGGER.error(str(val_err))
except RequestError:
_LOGGER.exception("Could not send pushover notification")
_LOGGER.exception('Could not send pushover notification')