Fix PEP257 issues
parent
cf7c2c492a
commit
652f059d6a
|
@ -45,7 +45,7 @@ def send_message(hass, message, title=None):
|
|||
|
||||
|
||||
def setup(hass, config):
|
||||
"""Sets up notify services."""
|
||||
"""Setup the notify services."""
|
||||
success = False
|
||||
|
||||
descriptions = load_yaml_config_file(
|
||||
|
@ -91,11 +91,11 @@ def setup(hass, config):
|
|||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class BaseNotificationService(object):
|
||||
"""Provides an ABC for notification services."""
|
||||
"""An abstract class for notification services."""
|
||||
|
||||
def send_message(self, message, **kwargs):
|
||||
"""
|
||||
Send a message.
|
||||
"""Send a message.
|
||||
|
||||
kwargs can contain ATTR_TITLE to specify a title.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
"""
|
||||
homeassistant.components.notify.command_line
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
command_line notification service.
|
||||
Support for command line notification services.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/notify.command_line/
|
||||
|
@ -16,8 +14,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||
|
||||
|
||||
def get_service(hass, config):
|
||||
""" Get the Command Line notification service. """
|
||||
|
||||
"""Get the Command Line notification service."""
|
||||
if not validate_config({DOMAIN: config},
|
||||
{DOMAIN: ['command']},
|
||||
_LOGGER):
|
||||
|
@ -30,14 +27,14 @@ def get_service(hass, config):
|
|||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class CommandLineNotificationService(BaseNotificationService):
|
||||
""" Implements notification service for the Command Line service. """
|
||||
"""Implement the notification service for the Command Line service."""
|
||||
|
||||
def __init__(self, command):
|
||||
"""Initialize the service."""
|
||||
self.command = command
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
""" Send a message to a command_line. """
|
||||
|
||||
"""Send a message to a command line."""
|
||||
try:
|
||||
proc = subprocess.Popen(self.command, universal_newlines=True,
|
||||
stdin=subprocess.PIPE, shell=True)
|
||||
|
|
|
@ -16,13 +16,13 @@ def get_service(hass, config):
|
|||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class DemoNotificationService(BaseNotificationService):
|
||||
"""Implements demo notification service."""
|
||||
"""Implement demo notification service."""
|
||||
|
||||
def __init__(self, hass):
|
||||
"""Initialize the service."""
|
||||
self.hass = hass
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
""" Send a message to a user. """
|
||||
|
||||
"""Send a message to a user."""
|
||||
title = kwargs.get(ATTR_TITLE)
|
||||
|
||||
self.hass.bus.fire(EVENT_NOTIFY, {"title": title, "message": message})
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
"""
|
||||
homeassistant.components.notify.file
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
File notification service.
|
||||
Support for file notification.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/notify.file/
|
||||
|
@ -18,8 +16,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||
|
||||
|
||||
def get_service(hass, config):
|
||||
""" Get the file notification service. """
|
||||
|
||||
"""Get the file notification service."""
|
||||
if not validate_config({DOMAIN: config},
|
||||
{DOMAIN: ['filename',
|
||||
'timestamp']},
|
||||
|
@ -34,15 +31,15 @@ def get_service(hass, config):
|
|||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class FileNotificationService(BaseNotificationService):
|
||||
""" Implements notification service for the File service. """
|
||||
"""Implement the notification service for the File service."""
|
||||
|
||||
def __init__(self, hass, filename, add_timestamp):
|
||||
"""Initialize the service."""
|
||||
self.filepath = os.path.join(hass.config.config_dir, filename)
|
||||
self.add_timestamp = add_timestamp
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
""" Send a message to a file. """
|
||||
|
||||
"""Send a message to a file."""
|
||||
with open(self.filepath, 'a') as file:
|
||||
if os.stat(self.filepath).st_size == 0:
|
||||
title = '{} notifications (Log started: {})\n{}\n'.format(
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
"""
|
||||
homeassistant.components.notify.free_mobile
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Free Mobile SMS platform for notify component.
|
||||
Support for thr Free Mobile SMS platform.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/notify.free_mobile/
|
||||
|
@ -17,8 +15,7 @@ REQUIREMENTS = ['freesms==0.1.0']
|
|||
|
||||
|
||||
def get_service(hass, config):
|
||||
""" Get the Free Mobile SMS notification service. """
|
||||
|
||||
"""Get the Free Mobile SMS notification service."""
|
||||
if not validate_config({DOMAIN: config},
|
||||
{DOMAIN: [CONF_USERNAME,
|
||||
CONF_ACCESS_TOKEN]},
|
||||
|
@ -31,14 +28,15 @@ def get_service(hass, config):
|
|||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class FreeSMSNotificationService(BaseNotificationService):
|
||||
""" Implements notification service for the Free Mobile SMS service. """
|
||||
"""Implement a notification service for the Free Mobile SMS service."""
|
||||
|
||||
def __init__(self, username, access_token):
|
||||
"""Initialize the service."""
|
||||
from freesms import FreeClient
|
||||
self.free_client = FreeClient(username, access_token)
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
""" Send a message to the Free Mobile user cell. """
|
||||
"""Send a message to the Free Mobile user cell."""
|
||||
resp = self.free_client.send_sms(message)
|
||||
|
||||
if resp.status_code == 400:
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
"""
|
||||
homeassistant.components.notify.googlevoice
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Google Voice SMS platform for notify component.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
|
@ -20,8 +18,7 @@ REQUIREMENTS = ['https://github.com/w1ll1am23/pygooglevoice-sms/archive/'
|
|||
|
||||
|
||||
def get_service(hass, config):
|
||||
""" Get the Google Voice SMS notification service. """
|
||||
|
||||
"""Get the Google Voice SMS notification service."""
|
||||
if not validate_config({DOMAIN: config},
|
||||
{DOMAIN: [CONF_USERNAME,
|
||||
CONF_PASSWORD]},
|
||||
|
@ -34,17 +31,17 @@ def get_service(hass, config):
|
|||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class GoogleVoiceSMSNotificationService(BaseNotificationService):
|
||||
""" Implements notification service for the Google Voice SMS service. """
|
||||
"""Implement the notification service for the Google Voice SMS service."""
|
||||
|
||||
def __init__(self, username, password):
|
||||
"""Initialize the service."""
|
||||
from googlevoicesms import Voice
|
||||
self.voice = Voice()
|
||||
self.username = username
|
||||
self.password = password
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
""" Send SMS to specified target user cell. """
|
||||
|
||||
"""Send SMS to specified target user cell."""
|
||||
targets = kwargs.get(ATTR_TARGET)
|
||||
|
||||
if not targets:
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
"""
|
||||
homeassistant.components.notify.instapush
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Instapush notification service.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
|
@ -21,8 +19,7 @@ _RESOURCE = 'https://api.instapush.im/v1/'
|
|||
|
||||
|
||||
def get_service(hass, config):
|
||||
""" Get the instapush notification service. """
|
||||
|
||||
"""Get the instapush notification service."""
|
||||
if not validate_config({DOMAIN: config},
|
||||
{DOMAIN: [CONF_API_KEY,
|
||||
'app_secret',
|
||||
|
@ -58,9 +55,10 @@ def get_service(hass, config):
|
|||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class InstapushNotificationService(BaseNotificationService):
|
||||
""" Implements notification service for Instapush. """
|
||||
"""Implement the notification service for Instapush."""
|
||||
|
||||
def __init__(self, api_key, app_secret, event, tracker):
|
||||
"""Initialize the service."""
|
||||
self._api_key = api_key
|
||||
self._app_secret = app_secret
|
||||
self._event = event
|
||||
|
@ -71,10 +69,8 @@ class InstapushNotificationService(BaseNotificationService):
|
|||
'Content-Type': 'application/json'}
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
""" Send a message to a user. """
|
||||
|
||||
"""Send a message to a user."""
|
||||
title = kwargs.get(ATTR_TITLE)
|
||||
|
||||
data = {"event": self._event,
|
||||
"trackers": {self._tracker: title + " : " + message}}
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
"""
|
||||
homeassistant.components.notify.nma
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
NMA (Notify My Android) notification service.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
|
@ -21,8 +19,7 @@ _RESOURCE = 'https://www.notifymyandroid.com/publicapi/'
|
|||
|
||||
|
||||
def get_service(hass, config):
|
||||
""" Get the NMA notification service. """
|
||||
|
||||
"""Get the NMA notification service."""
|
||||
if not validate_config({DOMAIN: config},
|
||||
{DOMAIN: [CONF_API_KEY]},
|
||||
_LOGGER):
|
||||
|
@ -41,14 +38,14 @@ def get_service(hass, config):
|
|||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class NmaNotificationService(BaseNotificationService):
|
||||
""" Implements notification service for NMA. """
|
||||
"""Implement the notification service for NMA."""
|
||||
|
||||
def __init__(self, api_key):
|
||||
"""Initialize the service."""
|
||||
self._api_key = api_key
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
""" Send a message to a user. """
|
||||
|
||||
"""Send a message to a user."""
|
||||
data = {
|
||||
"apikey": self._api_key,
|
||||
"application": 'home-assistant',
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
"""
|
||||
homeassistant.components.notify.pushbullet
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
PushBullet platform for notify component.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
|
@ -18,7 +16,7 @@ REQUIREMENTS = ['pushbullet.py==0.9.0']
|
|||
|
||||
# pylint: disable=unused-argument
|
||||
def get_service(hass, config):
|
||||
""" Get the PushBullet notification service. """
|
||||
"""Get the PushBullet notification service."""
|
||||
from pushbullet import PushBullet
|
||||
from pushbullet import InvalidKeyError
|
||||
|
||||
|
@ -39,16 +37,16 @@ def get_service(hass, config):
|
|||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class PushBulletNotificationService(BaseNotificationService):
|
||||
""" Implements notification service for Pushbullet. """
|
||||
"""Implement the notification service for Pushbullet."""
|
||||
|
||||
def __init__(self, pb):
|
||||
"""Initialize the service."""
|
||||
self.pushbullet = pb
|
||||
self.pbtargets = {}
|
||||
self.refresh()
|
||||
|
||||
def refresh(self):
|
||||
"""
|
||||
Refresh devices, contacts, etc
|
||||
"""Refresh devices, contacts, etc.
|
||||
|
||||
pbtargets stores all targets available from this pushbullet instance
|
||||
into a dict. These are PB objects!. It sacrifices a bit of memory
|
||||
|
@ -67,8 +65,8 @@ class PushBulletNotificationService(BaseNotificationService):
|
|||
}
|
||||
|
||||
def send_message(self, message=None, **kwargs):
|
||||
"""
|
||||
Send a message to a specified target.
|
||||
"""Send a message to a specified target.
|
||||
|
||||
If no target specified, a 'normal' push will be sent to all devices
|
||||
linked to the PB account.
|
||||
Email is special, these are assumed to always exist. We use a special
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
"""
|
||||
homeassistant.components.notify.pushetta
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Pushetta platform for notify component.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
|
@ -19,8 +17,7 @@ REQUIREMENTS = ['pushetta==1.0.15']
|
|||
|
||||
|
||||
def get_service(hass, config):
|
||||
""" Get the Pushetta notification service. """
|
||||
|
||||
"""Get the Pushetta notification service."""
|
||||
from pushetta import Pushetta, exceptions
|
||||
|
||||
if not validate_config({DOMAIN: config},
|
||||
|
@ -44,20 +41,17 @@ def get_service(hass, config):
|
|||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class PushettaNotificationService(BaseNotificationService):
|
||||
""" Implements notification service for Pushetta. """
|
||||
"""Implement the notification service for Pushetta."""
|
||||
|
||||
def __init__(self, api_key, channel_name):
|
||||
|
||||
"""Initialize the service."""
|
||||
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. """
|
||||
|
||||
"""Send a message to a user."""
|
||||
title = kwargs.get(ATTR_TITLE)
|
||||
|
||||
self.pushetta.pushMessage(self._channel_name,
|
||||
"{} {}".format(title, message))
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
"""
|
||||
homeassistant.components.notify.pushover
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Pushover platform for notify component.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
|
@ -19,8 +17,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||
|
||||
# pylint: disable=unused-variable
|
||||
def get_service(hass, config):
|
||||
""" Get the pushover notification service. """
|
||||
|
||||
"""Get the Pushover notification service."""
|
||||
if not validate_config({DOMAIN: config},
|
||||
{DOMAIN: ['user_key', CONF_API_KEY]},
|
||||
_LOGGER):
|
||||
|
@ -40,9 +37,10 @@ def get_service(hass, config):
|
|||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class PushoverNotificationService(BaseNotificationService):
|
||||
""" Implements notification service for Pushover. """
|
||||
"""Implement the notification service for Pushover."""
|
||||
|
||||
def __init__(self, user_key, api_token):
|
||||
"""Initialize the service."""
|
||||
from pushover import Client
|
||||
self._user_key = user_key
|
||||
self._api_token = api_token
|
||||
|
@ -50,7 +48,7 @@ class PushoverNotificationService(BaseNotificationService):
|
|||
self._user_key, api_token=self._api_token)
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
""" Send a message to a user. """
|
||||
"""Send a message to a user."""
|
||||
from pushover import RequestError
|
||||
|
||||
try:
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
"""
|
||||
homeassistant.components.notify.rest
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
REST platform for notify component.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
|
@ -23,8 +21,7 @@ DEFAULT_TARGET_PARAM_NAME = None
|
|||
|
||||
|
||||
def get_service(hass, config):
|
||||
""" Get the REST notification service. """
|
||||
|
||||
"""Get the REST notification service."""
|
||||
if not validate_config({DOMAIN: config},
|
||||
{DOMAIN: ['resource', ]},
|
||||
_LOGGER):
|
||||
|
@ -45,10 +42,11 @@ def get_service(hass, config):
|
|||
|
||||
# pylint: disable=too-few-public-methods, too-many-arguments
|
||||
class RestNotificationService(BaseNotificationService):
|
||||
""" Implements notification service for REST. """
|
||||
"""Implement the notification service for REST."""
|
||||
|
||||
def __init__(self, resource, method, message_param_name,
|
||||
title_param_name, target_param_name):
|
||||
"""Initialize the service."""
|
||||
self._resource = resource
|
||||
self._method = method.upper()
|
||||
self._message_param_name = message_param_name
|
||||
|
@ -56,8 +54,7 @@ class RestNotificationService(BaseNotificationService):
|
|||
self._target_param_name = target_param_name
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
""" Send a message to a user. """
|
||||
|
||||
"""Send a message to a user."""
|
||||
data = {
|
||||
self._message_param_name: message
|
||||
}
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
"""
|
||||
homeassistant.components.notify.sendgrid
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
SendGrid notification service.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
|
@ -17,7 +15,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||
|
||||
|
||||
def get_service(hass, config):
|
||||
""" Get the SendGrid notification service """
|
||||
"""Get the SendGrid notification service."""
|
||||
if not validate_config({DOMAIN: config},
|
||||
{DOMAIN: ['api_key', 'sender', 'recipient']},
|
||||
_LOGGER):
|
||||
|
@ -31,9 +29,10 @@ def get_service(hass, config):
|
|||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class SendgridNotificationService(BaseNotificationService):
|
||||
""" Implements the notification service for email via Sendgrid. """
|
||||
"""Implement the notification service for email via Sendgrid."""
|
||||
|
||||
def __init__(self, api_key, sender, recipient):
|
||||
"""Initialize the service."""
|
||||
self.api_key = api_key
|
||||
self.sender = sender
|
||||
self.recipient = recipient
|
||||
|
@ -42,7 +41,7 @@ class SendgridNotificationService(BaseNotificationService):
|
|||
self._sg = SendGridClient(self.api_key)
|
||||
|
||||
def send_message(self, message='', **kwargs):
|
||||
""" Send an email to a user via SendGrid. """
|
||||
"""Send an email to a user via SendGrid."""
|
||||
subject = kwargs.get(ATTR_TITLE)
|
||||
|
||||
from sendgrid import Mail
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
"""
|
||||
homeassistant.components.notify.slack
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Slack platform for notify component.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
|
@ -18,7 +16,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||
|
||||
# pylint: disable=unused-variable
|
||||
def get_service(hass, config):
|
||||
""" Get the slack notification service. """
|
||||
"""Get the Slack notification service."""
|
||||
import slacker
|
||||
|
||||
if not validate_config({DOMAIN: config},
|
||||
|
@ -39,22 +37,21 @@ def get_service(hass, config):
|
|||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class SlackNotificationService(BaseNotificationService):
|
||||
""" Implements notification service for Slack. """
|
||||
"""Implement the notification service for Slack."""
|
||||
|
||||
def __init__(self, default_channel, api_token):
|
||||
"""Initialize the service."""
|
||||
from slacker import Slacker
|
||||
|
||||
self._default_channel = default_channel
|
||||
self._api_token = api_token
|
||||
self.slack = Slacker(self._api_token)
|
||||
self.slack.auth.test()
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
""" Send a message to a user. """
|
||||
"""Send a message to a user."""
|
||||
import slacker
|
||||
|
||||
channel = kwargs.get('channel', self._default_channel)
|
||||
|
||||
try:
|
||||
self.slack.chat.post_message(channel, message)
|
||||
except slacker.Error:
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
"""
|
||||
homeassistant.components.notify.smtp
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Mail (SMTP) notification service.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
|
@ -18,8 +16,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||
|
||||
|
||||
def get_service(hass, config):
|
||||
""" Get the mail notification service. """
|
||||
|
||||
"""Get the mail notification service."""
|
||||
if not validate_config({DOMAIN: config},
|
||||
{DOMAIN: ['recipient']},
|
||||
_LOGGER):
|
||||
|
@ -74,11 +71,12 @@ def get_service(hass, config):
|
|||
|
||||
# pylint: disable=too-few-public-methods, too-many-instance-attributes
|
||||
class MailNotificationService(BaseNotificationService):
|
||||
""" Implements notification service for E-Mail messages. """
|
||||
"""Implement the notification service for E-Mail messages."""
|
||||
|
||||
# pylint: disable=too-many-arguments
|
||||
def __init__(self, server, port, sender, starttls, username,
|
||||
password, recipient, debug):
|
||||
"""Initialize the service."""
|
||||
self._server = server
|
||||
self._port = port
|
||||
self._sender = sender
|
||||
|
@ -90,8 +88,7 @@ class MailNotificationService(BaseNotificationService):
|
|||
self.tries = 2
|
||||
|
||||
def connect(self):
|
||||
""" Connect/Authenticate to SMTP Server """
|
||||
|
||||
"""Connect/authenticate to SMTP Server."""
|
||||
mail = smtplib.SMTP(self._server, self._port, timeout=5)
|
||||
mail.set_debuglevel(self.debug)
|
||||
mail.ehlo_or_helo_if_needed()
|
||||
|
@ -103,8 +100,7 @@ class MailNotificationService(BaseNotificationService):
|
|||
return mail
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
""" Send a message to a user. """
|
||||
|
||||
"""Send a message to a user."""
|
||||
mail = self.connect()
|
||||
subject = kwargs.get(ATTR_TITLE)
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
"""
|
||||
homeassistant.components.notify.syslog
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Syslog notification service.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
|
@ -69,16 +67,17 @@ def get_service(hass, config):
|
|||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class SyslogNotificationService(BaseNotificationService):
|
||||
""" Implements syslog notification service. """
|
||||
"""Implement the syslog notification service."""
|
||||
|
||||
# pylint: disable=too-many-arguments
|
||||
def __init__(self, facility, option, priority):
|
||||
"""Initialize the service."""
|
||||
self._facility = facility
|
||||
self._option = option
|
||||
self._priority = priority
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
""" Send a message to a user. """
|
||||
"""Send a message to a user."""
|
||||
import syslog
|
||||
|
||||
title = kwargs.get(ATTR_TITLE)
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
"""
|
||||
homeassistant.components.notify.telegram
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Telegram platform for notify component.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
|
@ -20,7 +18,7 @@ REQUIREMENTS = ['python-telegram-bot==3.2.0']
|
|||
|
||||
|
||||
def get_service(hass, config):
|
||||
""" Get the Telegram notification service. """
|
||||
"""Get the Telegram notification service."""
|
||||
import telegram
|
||||
|
||||
if not validate_config({DOMAIN: config},
|
||||
|
@ -41,9 +39,10 @@ def get_service(hass, config):
|
|||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class TelegramNotificationService(BaseNotificationService):
|
||||
""" Implements notification service for Telegram. """
|
||||
"""Implement the notification service for Telegram."""
|
||||
|
||||
def __init__(self, api_key, chat_id):
|
||||
"""Initialize the service."""
|
||||
import telegram
|
||||
|
||||
self._api_key = api_key
|
||||
|
@ -51,7 +50,7 @@ class TelegramNotificationService(BaseNotificationService):
|
|||
self.bot = telegram.Bot(token=self._api_key)
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
""" Send a message to a user. """
|
||||
"""Send a message to a user."""
|
||||
import telegram
|
||||
|
||||
title = kwargs.get(ATTR_TITLE)
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
"""
|
||||
homeassistant.components.notify.twitter
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Twitter platform for notify component.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
|
@ -21,8 +19,7 @@ CONF_ACCESS_TOKEN_SECRET = "access_token_secret"
|
|||
|
||||
|
||||
def get_service(hass, config):
|
||||
""" Get the Twitter notification service. """
|
||||
|
||||
"""Get the Twitter notification service."""
|
||||
if not validate_config({DOMAIN: config},
|
||||
{DOMAIN: [CONF_CONSUMER_KEY, CONF_CONSUMER_SECRET,
|
||||
CONF_ACCESS_TOKEN,
|
||||
|
@ -38,16 +35,17 @@ def get_service(hass, config):
|
|||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class TwitterNotificationService(BaseNotificationService):
|
||||
""" Implements notification service for the Twitter service. """
|
||||
"""Implement notification service for the Twitter service."""
|
||||
|
||||
def __init__(self, consumer_key, consumer_secret, access_token_key,
|
||||
access_token_secret):
|
||||
"""Initialize the service."""
|
||||
from TwitterAPI import TwitterAPI
|
||||
self.api = TwitterAPI(consumer_key, consumer_secret, access_token_key,
|
||||
access_token_secret)
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
""" Tweet some message. """
|
||||
"""Tweet some message."""
|
||||
resp = self.api.request('statuses/update', {'status': message})
|
||||
if resp.status_code != 200:
|
||||
import json
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
"""
|
||||
homeassistant.components.notify.xmpp
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Jabber (XMPP) notification service.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
|
@ -18,8 +16,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||
|
||||
|
||||
def get_service(hass, config):
|
||||
""" Get the Jabber (XMPP) notification service. """
|
||||
|
||||
"""Get the Jabber (XMPP) notification service."""
|
||||
if not validate_config({DOMAIN: config},
|
||||
{DOMAIN: ['sender', 'password', 'recipient']},
|
||||
_LOGGER):
|
||||
|
@ -32,16 +29,16 @@ def get_service(hass, config):
|
|||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class XmppNotificationService(BaseNotificationService):
|
||||
""" Implements notification service for Jabber (XMPP). """
|
||||
"""Implement the notification service for Jabber (XMPP)."""
|
||||
|
||||
def __init__(self, sender, password, recipient):
|
||||
"""Initialize the service."""
|
||||
self._sender = sender
|
||||
self._password = password
|
||||
self._recipient = recipient
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
""" Send a message to a user. """
|
||||
|
||||
"""Send a message to a user."""
|
||||
title = kwargs.get(ATTR_TITLE)
|
||||
data = "{}: {}".format(title, message) if title else message
|
||||
|
||||
|
@ -50,13 +47,14 @@ class XmppNotificationService(BaseNotificationService):
|
|||
|
||||
|
||||
def send_message(sender, password, recipient, message):
|
||||
""" Send a message over XMPP. """
|
||||
"""Send a message over XMPP."""
|
||||
import sleekxmpp
|
||||
|
||||
class SendNotificationBot(sleekxmpp.ClientXMPP):
|
||||
""" Service for sending Jabber (XMPP) messages. """
|
||||
"""Service for sending Jabber (XMPP) messages."""
|
||||
|
||||
def __init__(self):
|
||||
"""Initialize the Jabber Bot."""
|
||||
super(SendNotificationBot, self).__init__(sender, password)
|
||||
|
||||
logging.basicConfig(level=logging.ERROR)
|
||||
|
@ -69,14 +67,14 @@ def send_message(sender, password, recipient, message):
|
|||
self.process()
|
||||
|
||||
def start(self, event):
|
||||
""" Starts the communication and sends the message. """
|
||||
"""Start the communication and sends the message."""
|
||||
self.send_presence()
|
||||
self.get_roster()
|
||||
self.send_message(mto=recipient, mbody=message, mtype='chat')
|
||||
self.disconnect(wait=True)
|
||||
|
||||
def check_credentials(self, event):
|
||||
"""" Disconnect from the server if credentials are invalid. """
|
||||
""""Disconnect from the server if credentials are invalid."""
|
||||
self.disconnect()
|
||||
|
||||
SendNotificationBot()
|
||||
|
|
Loading…
Reference in New Issue