mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Pushbullet push an url note if an url is provided inside data (#3758)
This commit is contained in:
parent
6951b6f60b
commit
7697cdef0a
@ -9,14 +9,15 @@ import logging
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.notify import (
|
from homeassistant.components.notify import (
|
||||||
ATTR_TARGET, ATTR_TITLE, ATTR_TITLE_DEFAULT, PLATFORM_SCHEMA,
|
ATTR_DATA, ATTR_TARGET, ATTR_TITLE, ATTR_TITLE_DEFAULT,
|
||||||
BaseNotificationService)
|
PLATFORM_SCHEMA, BaseNotificationService)
|
||||||
from homeassistant.const import CONF_API_KEY
|
from homeassistant.const import CONF_API_KEY
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
REQUIREMENTS = ['pushbullet.py==0.10.0']
|
REQUIREMENTS = ['pushbullet.py==0.10.0']
|
||||||
|
|
||||||
|
ATTR_URL = 'url'
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Required(CONF_API_KEY): cv.string,
|
vol.Required(CONF_API_KEY): cv.string,
|
||||||
@ -40,7 +41,7 @@ def get_service(hass, config):
|
|||||||
return PushBulletNotificationService(pushbullet)
|
return PushBulletNotificationService(pushbullet)
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods, too-many-branches
|
||||||
class PushBulletNotificationService(BaseNotificationService):
|
class PushBulletNotificationService(BaseNotificationService):
|
||||||
"""Implement the notification service for Pushbullet."""
|
"""Implement the notification service for Pushbullet."""
|
||||||
|
|
||||||
@ -79,10 +80,17 @@ class PushBulletNotificationService(BaseNotificationService):
|
|||||||
"""
|
"""
|
||||||
targets = kwargs.get(ATTR_TARGET)
|
targets = kwargs.get(ATTR_TARGET)
|
||||||
title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
|
title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
|
||||||
|
data = kwargs.get(ATTR_DATA)
|
||||||
|
url = None
|
||||||
|
if data:
|
||||||
|
url = data.get(ATTR_URL, None)
|
||||||
refreshed = False
|
refreshed = False
|
||||||
|
|
||||||
if not targets:
|
if not targets:
|
||||||
# Backward compatebility, notify all devices in own account
|
# Backward compatebility, notify all devices in own account
|
||||||
|
if url:
|
||||||
|
self.pushbullet.push_link(title, url, body=message)
|
||||||
|
else:
|
||||||
self.pushbullet.push_note(title, message)
|
self.pushbullet.push_note(title, message)
|
||||||
_LOGGER.info('Sent notification to self')
|
_LOGGER.info('Sent notification to self')
|
||||||
return
|
return
|
||||||
@ -98,6 +106,10 @@ class PushBulletNotificationService(BaseNotificationService):
|
|||||||
# Target is email, send directly, don't use a target object
|
# Target is email, send directly, don't use a target object
|
||||||
# This also seems works to send to all devices in own account
|
# This also seems works to send to all devices in own account
|
||||||
if ttype == 'email':
|
if ttype == 'email':
|
||||||
|
if url:
|
||||||
|
self.pushbullet.push_link(title, url,
|
||||||
|
body=message, email=tname)
|
||||||
|
else:
|
||||||
self.pushbullet.push_note(title, message, email=tname)
|
self.pushbullet.push_note(title, message, email=tname)
|
||||||
_LOGGER.info('Sent notification to email %s', tname)
|
_LOGGER.info('Sent notification to email %s', tname)
|
||||||
continue
|
continue
|
||||||
@ -117,6 +129,10 @@ class PushBulletNotificationService(BaseNotificationService):
|
|||||||
# Attempt push_note on a dict value. Keys are types & target
|
# Attempt push_note on a dict value. Keys are types & target
|
||||||
# name. Dict pbtargets has all *actual* targets.
|
# name. Dict pbtargets has all *actual* targets.
|
||||||
try:
|
try:
|
||||||
|
if url:
|
||||||
|
self.pbtargets[ttype][tname].push_link(title, url,
|
||||||
|
body=message)
|
||||||
|
else:
|
||||||
self.pbtargets[ttype][tname].push_note(title, message)
|
self.pbtargets[ttype][tname].push_note(title, message)
|
||||||
_LOGGER.info('Sent notification to %s/%s', ttype, tname)
|
_LOGGER.info('Sent notification to %s/%s', ttype, tname)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user