Clean up notifiy component
This commit is contained in:
parent
3947691347
commit
3b3f5fe6fe
13 changed files with 143 additions and 253 deletions
|
@ -8,41 +8,29 @@ https://home-assistant.io/components/notify.pushbullet.html
|
|||
"""
|
||||
import logging
|
||||
|
||||
from homeassistant.helpers import validate_config
|
||||
from homeassistant.components.notify import (
|
||||
DOMAIN, ATTR_TITLE, BaseNotificationService)
|
||||
from homeassistant.components.notify import ATTR_TITLE, BaseNotificationService
|
||||
from homeassistant.const import CONF_API_KEY
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
REQUIREMENTS = ['pushbullet.py==0.7.1']
|
||||
REQUIREMENTS = ['pushbullet.py==0.8.1']
|
||||
|
||||
|
||||
def get_service(hass, config):
|
||||
""" Get the PushBullet notification service. """
|
||||
from pushbullet import InvalidKeyError
|
||||
|
||||
if not validate_config(config,
|
||||
{DOMAIN: [CONF_API_KEY]},
|
||||
_LOGGER):
|
||||
if CONF_API_KEY not in config:
|
||||
_LOGGER.error("Unable to find config key '%s'", CONF_API_KEY)
|
||||
return None
|
||||
|
||||
try:
|
||||
# pylint: disable=unused-variable
|
||||
from pushbullet import PushBullet, InvalidKeyError # noqa
|
||||
|
||||
except ImportError:
|
||||
_LOGGER.exception(
|
||||
"Unable to import pushbullet. "
|
||||
"Did you maybe not install the 'pushbullet.py' package?")
|
||||
|
||||
return None
|
||||
|
||||
try:
|
||||
return PushBulletNotificationService(config[DOMAIN][CONF_API_KEY])
|
||||
return PushBulletNotificationService(config[CONF_API_KEY])
|
||||
|
||||
except InvalidKeyError:
|
||||
_LOGGER.error(
|
||||
"Wrong API key supplied. "
|
||||
"Get it at https://www.pushbullet.com/account")
|
||||
return None
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
|
@ -50,9 +38,9 @@ class PushBulletNotificationService(BaseNotificationService):
|
|||
""" Implements notification service for Pushbullet. """
|
||||
|
||||
def __init__(self, api_key):
|
||||
from pushbullet import PushBullet
|
||||
from pushbullet import Pushbullet
|
||||
|
||||
self.pushbullet = PushBullet(api_key)
|
||||
self.pushbullet = Pushbullet(api_key)
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
""" Send a message to a user. """
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue