mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 10:47:10 +00:00
Add pushetta notify platform
This commit is contained in:
parent
e8a0d54fdd
commit
8371b08676
63
homeassistant/components/notify/pushetta.py
Normal file
63
homeassistant/components/notify/pushetta.py
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
"""
|
||||||
|
homeassistant.components.notify.pushetta
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
Pushetta platform for notify component.
|
||||||
|
|
||||||
|
For more details about this platform, please refer to the documentation at
|
||||||
|
https://home-assistant.io/components/notify.pushetta/
|
||||||
|
"""
|
||||||
|
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__)
|
||||||
|
|
||||||
|
REQUIREMENTS = ['pushetta==1.0.15']
|
||||||
|
|
||||||
|
|
||||||
|
def get_service(hass, config):
|
||||||
|
""" Get the Pushetta notification service. """
|
||||||
|
|
||||||
|
from pushetta import Pushetta, exceptions
|
||||||
|
|
||||||
|
if not validate_config({DOMAIN: config},
|
||||||
|
{DOMAIN: [CONF_API_KEY, 'channel_name']},
|
||||||
|
_LOGGER):
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
pushetta = Pushetta(config[CONF_API_KEY])
|
||||||
|
pushetta.pushMessage(config['channel_name'], "Home Assistant started")
|
||||||
|
except exceptions.TokenValidationError:
|
||||||
|
_LOGGER.error("Please check your access token")
|
||||||
|
return None
|
||||||
|
except exceptions.ChannelNotFoundError:
|
||||||
|
_LOGGER.exception("Channel '%s' not found", config['channel_name'])
|
||||||
|
return None
|
||||||
|
|
||||||
|
return PushettaNotificationService(config[CONF_API_KEY],
|
||||||
|
config['channel_name'])
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=too-few-public-methods
|
||||||
|
class PushettaNotificationService(BaseNotificationService):
|
||||||
|
""" Implements notification service for Pushetta. """
|
||||||
|
|
||||||
|
def __init__(self, api_key, channel_name):
|
||||||
|
|
||||||
|
from pushetta import Pushetta
|
||||||
|
|
||||||
|
self._api_key = api_key
|
||||||
|
self._channel_name = channel_name
|
||||||
|
self.pushetta = Pushetta(self._api_key)
|
||||||
|
|
||||||
|
def send_message(self, message="", **kwargs):
|
||||||
|
""" Send a message to a user. """
|
||||||
|
|
||||||
|
title = kwargs.get(ATTR_TITLE)
|
||||||
|
|
||||||
|
self.pushetta.pushMessage(self._channel_name,
|
||||||
|
"{} {}".format(title, message))
|
Loading…
x
Reference in New Issue
Block a user