diff --git a/homeassistant/components/notify/__init__.py b/homeassistant/components/notify/__init__.py index a28a50d766f..d7ebfbbcd1f 100644 --- a/homeassistant/components/notify/__init__.py +++ b/homeassistant/components/notify/__init__.py @@ -41,7 +41,7 @@ PLATFORM_SCHEMA = vol.Schema({ NOTIFY_SERVICE_SCHEMA = vol.Schema({ vol.Required(ATTR_MESSAGE): cv.template, - vol.Optional(ATTR_TITLE, default=ATTR_TITLE_DEFAULT): cv.string, + vol.Optional(ATTR_TITLE): cv.string, vol.Optional(ATTR_TARGET): cv.string, vol.Optional(ATTR_DATA): dict, }) diff --git a/homeassistant/components/notify/aws_sns.py b/homeassistant/components/notify/aws_sns.py index dec72b18633..31cac90105c 100644 --- a/homeassistant/components/notify/aws_sns.py +++ b/homeassistant/components/notify/aws_sns.py @@ -11,7 +11,7 @@ import voluptuous as vol from homeassistant.const import ( CONF_PLATFORM, CONF_NAME) from homeassistant.components.notify import ( - ATTR_TITLE, ATTR_TARGET, BaseNotificationService) + ATTR_TITLE, ATTR_TITLE_DEFAULT, ATTR_TARGET, BaseNotificationService) _LOGGER = logging.getLogger(__name__) REQUIREMENTS = ["boto3==1.3.1"] @@ -76,5 +76,6 @@ class AWSSNS(BaseNotificationService): for k, v in kwargs.items() if v} for target in targets: self.client.publish(TargetArn=target, Message=message, - Subject=kwargs.get(ATTR_TITLE), + Subject=kwargs.get(ATTR_TITLE, + ATTR_TITLE_DEFAULT), MessageAttributes=message_attributes) diff --git a/homeassistant/components/notify/file.py b/homeassistant/components/notify/file.py index ec79cab59ea..82ec2420df8 100644 --- a/homeassistant/components/notify/file.py +++ b/homeassistant/components/notify/file.py @@ -11,7 +11,7 @@ import voluptuous as vol import homeassistant.util.dt as dt_util from homeassistant.components.notify import ( - ATTR_TITLE, PLATFORM_SCHEMA, BaseNotificationService) + ATTR_TITLE, ATTR_TITLE_DEFAULT, PLATFORM_SCHEMA, BaseNotificationService) from homeassistant.const import CONF_FILENAME import homeassistant.helpers.config_validation as cv @@ -47,7 +47,7 @@ class FileNotificationService(BaseNotificationService): with open(self.filepath, 'a') as file: if os.stat(self.filepath).st_size == 0: title = '{} notifications (Log started: {})\n{}\n'.format( - kwargs.get(ATTR_TITLE), + kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT), dt_util.utcnow().isoformat(), '-' * 80) file.write(title) diff --git a/homeassistant/components/notify/gntp.py b/homeassistant/components/notify/gntp.py index 5b5d377e1ea..64033f03125 100644 --- a/homeassistant/components/notify/gntp.py +++ b/homeassistant/components/notify/gntp.py @@ -8,7 +8,7 @@ import logging import os from homeassistant.components.notify import ( - ATTR_TITLE, BaseNotificationService) + ATTR_TITLE, ATTR_TITLE_DEFAULT, BaseNotificationService) REQUIREMENTS = ['gntp==1.0.3'] @@ -59,5 +59,6 @@ class GNTPNotificationService(BaseNotificationService): def send_message(self, message="", **kwargs): """Send a message to a user.""" - self.gntp.notify(noteType="Notification", title=kwargs.get(ATTR_TITLE), + self.gntp.notify(noteType="Notification", + title=kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT), description=message) diff --git a/homeassistant/components/notify/html5.py b/homeassistant/components/notify/html5.py index 54727a60d3f..103ccc7885b 100644 --- a/homeassistant/components/notify/html5.py +++ b/homeassistant/components/notify/html5.py @@ -18,8 +18,8 @@ from homeassistant.const import (HTTP_BAD_REQUEST, HTTP_INTERNAL_SERVER_ERROR, HTTP_UNAUTHORIZED, URL_ROOT) from homeassistant.util import ensure_unique_string from homeassistant.components.notify import ( - ATTR_TARGET, ATTR_TITLE, ATTR_DATA, BaseNotificationService, - PLATFORM_SCHEMA) + ATTR_TARGET, ATTR_TITLE, ATTR_TITLE_DEFAULT, ATTR_DATA, + BaseNotificationService, PLATFORM_SCHEMA) from homeassistant.components.http import HomeAssistantView from homeassistant.components.frontend import add_manifest_json_key from homeassistant.helpers import config_validation as cv @@ -332,7 +332,7 @@ class HTML5NotificationService(BaseNotificationService): 'icon': '/static/icons/favicon-192x192.png', ATTR_TAG: tag, 'timestamp': (timestamp*1000), # Javascript ms since epoch - ATTR_TITLE: kwargs.get(ATTR_TITLE) + ATTR_TITLE: kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT) } data = kwargs.get(ATTR_DATA) diff --git a/homeassistant/components/notify/instapush.py b/homeassistant/components/notify/instapush.py index 028afb32468..7dbbbfced35 100644 --- a/homeassistant/components/notify/instapush.py +++ b/homeassistant/components/notify/instapush.py @@ -10,7 +10,7 @@ import logging import requests from homeassistant.components.notify import ( - ATTR_TITLE, DOMAIN, BaseNotificationService) + ATTR_TITLE, ATTR_TITLE_DEFAULT, DOMAIN, BaseNotificationService) from homeassistant.const import CONF_API_KEY from homeassistant.helpers import validate_config @@ -70,7 +70,7 @@ class InstapushNotificationService(BaseNotificationService): def send_message(self, message="", **kwargs): """Send a message to a user.""" - title = kwargs.get(ATTR_TITLE) + title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT) data = {"event": self._event, "trackers": {self._tracker: title + " : " + message}} diff --git a/homeassistant/components/notify/joaoapps_join.py b/homeassistant/components/notify/joaoapps_join.py index 67ecd493a06..ca82b6bb934 100644 --- a/homeassistant/components/notify/joaoapps_join.py +++ b/homeassistant/components/notify/joaoapps_join.py @@ -7,7 +7,7 @@ https://home-assistant.io/components/notify.join/ import logging import voluptuous as vol from homeassistant.components.notify import ( - ATTR_DATA, ATTR_TITLE, BaseNotificationService) + ATTR_DATA, ATTR_TITLE, ATTR_TITLE_DEFAULT, BaseNotificationService) from homeassistant.const import CONF_PLATFORM, CONF_NAME, CONF_API_KEY import homeassistant.helpers.config_validation as cv @@ -52,7 +52,7 @@ class JoinNotificationService(BaseNotificationService): def send_message(self, message="", **kwargs): """Send a message to a user.""" from pyjoin import send_notification - title = kwargs.get(ATTR_TITLE) + title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT) data = kwargs.get(ATTR_DATA) or {} send_notification(device_id=self._device_id, text=message, diff --git a/homeassistant/components/notify/nma.py b/homeassistant/components/notify/nma.py index f37f5ca8bd0..ef75abb2fe4 100644 --- a/homeassistant/components/notify/nma.py +++ b/homeassistant/components/notify/nma.py @@ -10,7 +10,7 @@ import xml.etree.ElementTree as ET import requests from homeassistant.components.notify import ( - ATTR_TITLE, DOMAIN, BaseNotificationService) + ATTR_TITLE, ATTR_TITLE_DEFAULT, DOMAIN, BaseNotificationService) from homeassistant.const import CONF_API_KEY from homeassistant.helpers import validate_config @@ -49,7 +49,7 @@ class NmaNotificationService(BaseNotificationService): data = { "apikey": self._api_key, "application": 'home-assistant', - "event": kwargs.get(ATTR_TITLE), + "event": kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT), "description": message, "priority": 0, } diff --git a/homeassistant/components/notify/pushbullet.py b/homeassistant/components/notify/pushbullet.py index 20a6daebf05..7c924223ae1 100644 --- a/homeassistant/components/notify/pushbullet.py +++ b/homeassistant/components/notify/pushbullet.py @@ -7,7 +7,7 @@ https://home-assistant.io/components/notify.pushbullet/ import logging from homeassistant.components.notify import ( - ATTR_TARGET, ATTR_TITLE, BaseNotificationService) + ATTR_TARGET, ATTR_TITLE, ATTR_TITLE_DEFAULT, BaseNotificationService) from homeassistant.const import CONF_API_KEY _LOGGER = logging.getLogger(__name__) @@ -73,7 +73,7 @@ class PushBulletNotificationService(BaseNotificationService): call which doesn't require a push object. """ targets = kwargs.get(ATTR_TARGET) - title = kwargs.get(ATTR_TITLE) + title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT) refreshed = False if not targets: diff --git a/homeassistant/components/notify/pushetta.py b/homeassistant/components/notify/pushetta.py index 234c8978452..441379b2285 100644 --- a/homeassistant/components/notify/pushetta.py +++ b/homeassistant/components/notify/pushetta.py @@ -7,7 +7,7 @@ https://home-assistant.io/components/notify.pushetta/ import logging from homeassistant.components.notify import ( - ATTR_TITLE, DOMAIN, BaseNotificationService) + ATTR_TITLE, ATTR_TITLE_DEFAULT, DOMAIN, BaseNotificationService) from homeassistant.const import CONF_API_KEY from homeassistant.helpers import validate_config @@ -52,6 +52,6 @@ class PushettaNotificationService(BaseNotificationService): def send_message(self, message="", **kwargs): """Send a message to a user.""" - title = kwargs.get(ATTR_TITLE) + title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT) self.pushetta.pushMessage(self._channel_name, "{} {}".format(title, message)) diff --git a/homeassistant/components/notify/pushover.py b/homeassistant/components/notify/pushover.py index 5ded1ebe778..de82bb4e819 100644 --- a/homeassistant/components/notify/pushover.py +++ b/homeassistant/components/notify/pushover.py @@ -9,7 +9,8 @@ import logging import voluptuous as vol from homeassistant.components.notify import ( - ATTR_TITLE, ATTR_TARGET, ATTR_DATA, BaseNotificationService) + ATTR_TITLE, ATTR_TITLE_DEFAULT, ATTR_TARGET, ATTR_DATA, + BaseNotificationService) from homeassistant.const import CONF_API_KEY import homeassistant.helpers.config_validation as cv @@ -56,7 +57,7 @@ class PushoverNotificationService(BaseNotificationService): # Make a copy and use empty dict if necessary data = dict(kwargs.get(ATTR_DATA) or {}) - data['title'] = kwargs.get(ATTR_TITLE) + data['title'] = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT) target = kwargs.get(ATTR_TARGET) if target is not None: diff --git a/homeassistant/components/notify/rest.py b/homeassistant/components/notify/rest.py index 5cc556a1957..0a82b8d5d72 100644 --- a/homeassistant/components/notify/rest.py +++ b/homeassistant/components/notify/rest.py @@ -10,7 +10,8 @@ import requests import voluptuous as vol from homeassistant.components.notify import ( - ATTR_TARGET, ATTR_TITLE, BaseNotificationService, PLATFORM_SCHEMA) + ATTR_TARGET, ATTR_TITLE, ATTR_TITLE_DEFAULT, BaseNotificationService, + PLATFORM_SCHEMA) from homeassistant.const import (CONF_RESOURCE, CONF_METHOD, CONF_NAME) import homeassistant.helpers.config_validation as cv @@ -71,7 +72,8 @@ class RestNotificationService(BaseNotificationService): } if self._title_param_name is not None: - data[self._title_param_name] = kwargs.get(ATTR_TITLE) + data[self._title_param_name] = kwargs.get(ATTR_TITLE, + ATTR_TITLE_DEFAULT) if self._target_param_name is not None: data[self._target_param_name] = kwargs.get(ATTR_TARGET) diff --git a/homeassistant/components/notify/sendgrid.py b/homeassistant/components/notify/sendgrid.py index 894b35a85d4..b0805338844 100644 --- a/homeassistant/components/notify/sendgrid.py +++ b/homeassistant/components/notify/sendgrid.py @@ -7,7 +7,7 @@ https://home-assistant.io/components/notify.sendgrid/ import logging from homeassistant.components.notify import ( - ATTR_TITLE, DOMAIN, BaseNotificationService) + ATTR_TITLE, ATTR_TITLE_DEFAULT, DOMAIN, BaseNotificationService) from homeassistant.helpers import validate_config REQUIREMENTS = ['sendgrid==3.2.10'] @@ -44,7 +44,7 @@ class SendgridNotificationService(BaseNotificationService): def send_message(self, message='', **kwargs): """Send an email to a user via SendGrid.""" - subject = kwargs.get(ATTR_TITLE) + subject = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT) data = { "personalizations": [ diff --git a/homeassistant/components/notify/smtp.py b/homeassistant/components/notify/smtp.py index 60fccc0c510..694058a11ce 100644 --- a/homeassistant/components/notify/smtp.py +++ b/homeassistant/components/notify/smtp.py @@ -14,7 +14,8 @@ import voluptuous as vol import homeassistant.helpers.config_validation as cv from homeassistant.components.notify import ( - ATTR_TITLE, ATTR_DATA, PLATFORM_SCHEMA, BaseNotificationService) + ATTR_TITLE, ATTR_TITLE_DEFAULT, ATTR_DATA, PLATFORM_SCHEMA, + BaseNotificationService) from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD, CONF_PORT) _LOGGER = logging.getLogger(__name__) @@ -120,7 +121,7 @@ class MailNotificationService(BaseNotificationService): Will send plain text normally, or will build a multipart HTML message with inline image attachments if images config is defined. """ - subject = kwargs.get(ATTR_TITLE) + subject = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT) data = kwargs.get(ATTR_DATA) if data: diff --git a/homeassistant/components/notify/syslog.py b/homeassistant/components/notify/syslog.py index 381a92394c3..8b36f0ea858 100644 --- a/homeassistant/components/notify/syslog.py +++ b/homeassistant/components/notify/syslog.py @@ -7,7 +7,7 @@ https://home-assistant.io/components/notify.syslog/ import logging from homeassistant.components.notify import ( - ATTR_TITLE, DOMAIN, BaseNotificationService) + ATTR_TITLE, ATTR_TITLE_DEFAULT, DOMAIN, BaseNotificationService) from homeassistant.helpers import validate_config _LOGGER = logging.getLogger(__name__) @@ -80,7 +80,7 @@ class SyslogNotificationService(BaseNotificationService): """Send a message to a user.""" import syslog - title = kwargs.get(ATTR_TITLE) + title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT) syslog.openlog(title, self._option, self._facility) syslog.syslog(self._priority, message) diff --git a/homeassistant/components/notify/telegram.py b/homeassistant/components/notify/telegram.py index 8da916eb1f3..35d6a5a6977 100644 --- a/homeassistant/components/notify/telegram.py +++ b/homeassistant/components/notify/telegram.py @@ -106,10 +106,20 @@ class TelegramNotificationService(BaseNotificationService): elif data is not None and ATTR_DOCUMENT in data: return self.send_document(data.get(ATTR_DOCUMENT)) + text = '' + + if title: + text = '{} {}'.format(title, message) + else: + text = message + + parse_mode = telegram.parsemode.ParseMode.MARKDOWN + # send message try: self.bot.sendMessage(chat_id=self._chat_id, - text=title + " " + message) + text=text, + parse_mode=parse_mode) except telegram.error.TelegramError: _LOGGER.exception("Error sending message.") return diff --git a/homeassistant/components/notify/xmpp.py b/homeassistant/components/notify/xmpp.py index 68c0ce2979f..e5b7792776e 100644 --- a/homeassistant/components/notify/xmpp.py +++ b/homeassistant/components/notify/xmpp.py @@ -7,7 +7,7 @@ https://home-assistant.io/components/notify.xmpp/ import logging from homeassistant.components.notify import ( - ATTR_TITLE, DOMAIN, BaseNotificationService) + ATTR_TITLE, ATTR_TITLE_DEFAULT, DOMAIN, BaseNotificationService) from homeassistant.helpers import validate_config REQUIREMENTS = ['sleekxmpp==1.3.1', @@ -45,7 +45,7 @@ class XmppNotificationService(BaseNotificationService): def send_message(self, message="", **kwargs): """Send a message to a user.""" - title = kwargs.get(ATTR_TITLE) + title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT) data = "{}: {}".format(title, message) if title else message send_message(self._sender + '/home-assistant', self._password, diff --git a/tests/components/notify/test_smtp.py b/tests/components/notify/test_smtp.py index 7fa61fbdc24..bbaca71ee13 100644 --- a/tests/components/notify/test_smtp.py +++ b/tests/components/notify/test_smtp.py @@ -37,7 +37,7 @@ class TestNotifySmtp(unittest.TestCase): expected = ('Content-Type: text/plain; charset="us-ascii"\n' 'MIME-Version: 1.0\n' 'Content-Transfer-Encoding: 7bit\n' - 'Subject: \n' + 'Subject: Home Assistant\n' 'To: testrecip@test.com\n' 'From: test@test.com\n' 'X-Mailer: HomeAssistant\n'