mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Add notification component and PushBullet platform
This commit is contained in:
parent
a6ec071244
commit
4fec2dcb28
@ -36,6 +36,10 @@ platform=wemo
|
|||||||
[downloader]
|
[downloader]
|
||||||
download_dir=downloads
|
download_dir=downloads
|
||||||
|
|
||||||
|
[notify]
|
||||||
|
platform=pushbullet
|
||||||
|
api_key=ABCDEFGHJKLMNOPQRSTUVXYZ
|
||||||
|
|
||||||
[device_sun_light_trigger]
|
[device_sun_light_trigger]
|
||||||
# Optional: specify a specific light/group of lights that has to be turned on
|
# Optional: specify a specific light/group of lights that has to be turned on
|
||||||
light_group=group.living_room
|
light_group=group.living_room
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
""" DO NOT MODIFY. Auto-generated by build_frontend script """
|
""" DO NOT MODIFY. Auto-generated by build_frontend script """
|
||||||
VERSION = "e90cfdadc67bce88083a4af5b653bed5"
|
VERSION = "7a143577b779f68ff8b23e8aff04aa9b"
|
||||||
|
File diff suppressed because one or more lines are too long
@ -51,6 +51,9 @@
|
|||||||
case "simple_alarm":
|
case "simple_alarm":
|
||||||
return "social:notifications";
|
return "social:notifications";
|
||||||
|
|
||||||
|
case "notify":
|
||||||
|
return "announcement";
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return "bookmark-outline";
|
return "bookmark-outline";
|
||||||
}
|
}
|
||||||
|
83
homeassistant/components/notify/__init__.py
Normal file
83
homeassistant/components/notify/__init__.py
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
"""
|
||||||
|
homeassistant.components.notify
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Provides functionality to notify people.
|
||||||
|
"""
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from homeassistant.loader import get_component
|
||||||
|
from homeassistant.helpers import validate_config
|
||||||
|
|
||||||
|
from homeassistant.const import CONF_PLATFORM
|
||||||
|
|
||||||
|
DOMAIN = "notify"
|
||||||
|
DEPENDENCIES = []
|
||||||
|
|
||||||
|
# Title of notification
|
||||||
|
ATTR_TITLE = "title"
|
||||||
|
ATTR_TITLE_DEFAULT = "Message from Home Assistant"
|
||||||
|
|
||||||
|
# Text to notify user of
|
||||||
|
ATTR_MESSAGE = "message"
|
||||||
|
|
||||||
|
SERVICE_NOTIFY = "notify"
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def send_message(hass, message):
|
||||||
|
""" Send a notification message. """
|
||||||
|
hass.services.call(DOMAIN, SERVICE_NOTIFY, {ATTR_MESSAGE: message})
|
||||||
|
|
||||||
|
|
||||||
|
def setup(hass, config):
|
||||||
|
""" Sets up notify services. """
|
||||||
|
|
||||||
|
if not validate_config(config, {DOMAIN: [CONF_PLATFORM]}, _LOGGER):
|
||||||
|
return False
|
||||||
|
|
||||||
|
platform = config[DOMAIN].get(CONF_PLATFORM)
|
||||||
|
|
||||||
|
notify_implementation = get_component(
|
||||||
|
'notify.{}'.format(platform))
|
||||||
|
|
||||||
|
if notify_implementation is None:
|
||||||
|
_LOGGER.error("Unknown notification service specified.")
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
notify_service = notify_implementation.get_service(hass, config)
|
||||||
|
|
||||||
|
if notify_service is None:
|
||||||
|
_LOGGER.error("Failed to initialize notificatino service %s",
|
||||||
|
platform)
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
def notify_message(call):
|
||||||
|
""" Handle sending notification message service calls. """
|
||||||
|
message = call.data.get(ATTR_MESSAGE)
|
||||||
|
|
||||||
|
if message is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
title = call.data.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
|
||||||
|
|
||||||
|
notify_service.send_message(message, title=title)
|
||||||
|
|
||||||
|
hass.services.register(DOMAIN, SERVICE_NOTIFY, notify_message)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=too-few-public-methods
|
||||||
|
class BaseNotificationService(object):
|
||||||
|
""" Provides an ABC for notifcation services. """
|
||||||
|
|
||||||
|
def send_message(self, message, **kwargs):
|
||||||
|
"""
|
||||||
|
Send a message.
|
||||||
|
kwargs can contain ATTR_TITLE to specify a title.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError
|
51
homeassistant/components/notify/pushbullet.py
Normal file
51
homeassistant/components/notify/pushbullet.py
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
"""
|
||||||
|
PushBullet platform for notify component.
|
||||||
|
"""
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from homeassistant.helpers import validate_config
|
||||||
|
from homeassistant.components.notify import (
|
||||||
|
DOMAIN, ATTR_TITLE, BaseNotificationService)
|
||||||
|
from homeassistant.const import CONF_API_KEY
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def get_service(hass, config):
|
||||||
|
""" Get the pushbullet notification service. """
|
||||||
|
|
||||||
|
if not validate_config(config,
|
||||||
|
{DOMAIN: [CONF_API_KEY]},
|
||||||
|
_LOGGER):
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
# pylint: disable=unused-variable
|
||||||
|
from pushbullet import PushBullet # noqa
|
||||||
|
|
||||||
|
except ImportError:
|
||||||
|
_LOGGER.exception(
|
||||||
|
"Unable to import pushbullet. "
|
||||||
|
"Did you maybe not install the 'pushbullet' package?")
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
return PushBulletNotificationService(config[DOMAIN][CONF_API_KEY])
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=too-few-public-methods
|
||||||
|
class PushBulletNotificationService(BaseNotificationService):
|
||||||
|
""" Implements notification service for Pushbullet. """
|
||||||
|
|
||||||
|
def __init__(self, api_key):
|
||||||
|
from pushbullet import PushBullet
|
||||||
|
|
||||||
|
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)
|
@ -14,6 +14,7 @@ CONF_HOST = "host"
|
|||||||
CONF_HOSTS = "hosts"
|
CONF_HOSTS = "hosts"
|
||||||
CONF_USERNAME = "username"
|
CONF_USERNAME = "username"
|
||||||
CONF_PASSWORD = "password"
|
CONF_PASSWORD = "password"
|
||||||
|
CONF_API_KEY = "api_key"
|
||||||
|
|
||||||
# #### EVENTS ####
|
# #### EVENTS ####
|
||||||
EVENT_HOMEASSISTANT_START = "homeassistant_start"
|
EVENT_HOMEASSISTANT_START = "homeassistant_start"
|
||||||
|
4
pylintrc
4
pylintrc
@ -6,12 +6,12 @@ reports=no
|
|||||||
# locally-disabled - it spams too much
|
# locally-disabled - it spams too much
|
||||||
# duplicate-code - unavoidable
|
# duplicate-code - unavoidable
|
||||||
# cyclic-import - doesn't test if both import on load
|
# cyclic-import - doesn't test if both import on load
|
||||||
# file-ignored - we ignore a file to work around a pylint bug
|
# abstract-class-little-used - Prevents from setting right foundation
|
||||||
disable=
|
disable=
|
||||||
locally-disabled,
|
locally-disabled,
|
||||||
duplicate-code,
|
duplicate-code,
|
||||||
cyclic-import,
|
cyclic-import,
|
||||||
file-ignored
|
abstract-class-little-used
|
||||||
|
|
||||||
[EXCEPTIONS]
|
[EXCEPTIONS]
|
||||||
overgeneral-exceptions=Exception,HomeAssistantError
|
overgeneral-exceptions=Exception,HomeAssistantError
|
||||||
|
@ -20,3 +20,6 @@ tellcore-py>=1.0.4
|
|||||||
|
|
||||||
# namp_tracker plugin
|
# namp_tracker plugin
|
||||||
python-libnmap
|
python-libnmap
|
||||||
|
|
||||||
|
# pushbullet
|
||||||
|
pushbullet.py>=0.5.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user