2015-01-04 09:01:49 +00:00
|
|
|
"""
|
2015-05-13 17:18:30 +00:00
|
|
|
homeassistant.components.notify.pushbullet
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2015-01-04 09:01:49 +00:00
|
|
|
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
|
2015-01-04 09:01:49 +00:00
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
|
2015-11-09 06:15:34 +00:00
|
|
|
from homeassistant.components.notify import ATTR_TITLE, BaseNotificationService
|
2015-01-04 09:01:49 +00:00
|
|
|
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']
|
2015-01-04 09:01:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_service(hass, config):
|
2015-09-07 16:26:20 +00:00
|
|
|
""" Get the PushBullet notification service. """
|
2015-11-09 06:15:34 +00:00
|
|
|
from pushbullet import InvalidKeyError
|
2015-01-04 09:01:49 +00:00
|
|
|
|
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)
|
2015-01-04 09:01:49 +00:00
|
|
|
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
|
2015-01-04 09:01:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
# 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-01-04 09:01:49 +00:00
|
|
|
|
2015-11-09 06:15:34 +00:00
|
|
|
self.pushbullet = Pushbullet(api_key)
|
2015-01-04 09:01:49 +00:00
|
|
|
|
|
|
|
def send_message(self, message="", **kwargs):
|
|
|
|
""" Send a message to a user. """
|
|
|
|
|
|
|
|
title = kwargs.get(ATTR_TITLE)
|
|
|
|
|
|
|
|
self.pushbullet.push_note(title, message)
|