core/homeassistant/components/notify/pushbullet.py

51 lines
1.4 KiB
Python
Raw Normal View History

"""
2015-05-13 17:18:30 +00:00
homeassistant.components.notify.pushbullet
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PushBullet platform for notify component.
2015-05-13 17:18:30 +00:00
2015-10-13 20:30:21 +00:00
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/notify.pushbullet.html
"""
import logging
2015-11-09 06:15:34 +00:00
from homeassistant.components.notify import ATTR_TITLE, BaseNotificationService
from homeassistant.const import CONF_API_KEY
_LOGGER = logging.getLogger(__name__)
2015-11-09 06:15:34 +00:00
REQUIREMENTS = ['pushbullet.py==0.8.1']
def get_service(hass, config):
""" Get the PushBullet notification service. """
2015-11-09 06:15:34 +00:00
from pushbullet import InvalidKeyError
2015-11-09 06:15:34 +00:00
if CONF_API_KEY not in config:
_LOGGER.error("Unable to find config key '%s'", CONF_API_KEY)
return None
try:
2015-11-09 06:15:34 +00:00
return PushBulletNotificationService(config[CONF_API_KEY])
2015-01-11 16:09:25 +00:00
except InvalidKeyError:
_LOGGER.error(
"Wrong API key supplied. "
"Get it at https://www.pushbullet.com/account")
2015-11-09 06:15:34 +00:00
return None
# pylint: disable=too-few-public-methods
class PushBulletNotificationService(BaseNotificationService):
""" Implements notification service for Pushbullet. """
def __init__(self, api_key):
2015-11-09 06:15:34 +00:00
from pushbullet import Pushbullet
2015-11-09 06:15:34 +00:00
self.pushbullet = Pushbullet(api_key)
def send_message(self, message="", **kwargs):
""" Send a message to a user. """
title = kwargs.get(ATTR_TITLE)
self.pushbullet.push_note(title, message)