diff --git a/homeassistant/components/notify/__init__.py b/homeassistant/components/notify/__init__.py index 5bd99678f80..e56dfa5586d 100644 --- a/homeassistant/components/notify/__init__.py +++ b/homeassistant/components/notify/__init__.py @@ -42,7 +42,7 @@ PLATFORM_SCHEMA = vol.Schema({ NOTIFY_SERVICE_SCHEMA = vol.Schema({ vol.Required(ATTR_MESSAGE): cv.template, vol.Optional(ATTR_TITLE): cv.template, - vol.Optional(ATTR_TARGET): cv.string, + vol.Optional(ATTR_TARGET): vol.All(cv.ensure_list, [cv.string]), vol.Optional(ATTR_DATA): dict, }) diff --git a/homeassistant/components/notify/aws_lambda.py b/homeassistant/components/notify/aws_lambda.py index 3e3003763ea..9ac9c4cbc18 100644 --- a/homeassistant/components/notify/aws_lambda.py +++ b/homeassistant/components/notify/aws_lambda.py @@ -79,9 +79,6 @@ class AWSLambda(BaseNotificationService): _LOGGER.info("At least 1 target is required") return - if not isinstance(targets, list): - targets = [targets] - for target in targets: cleaned_kwargs = dict((k, v) for k, v in kwargs.items() if v) payload = {"message": message} diff --git a/homeassistant/components/notify/aws_sns.py b/homeassistant/components/notify/aws_sns.py index 88233234eca..fb6ae8984c6 100644 --- a/homeassistant/components/notify/aws_sns.py +++ b/homeassistant/components/notify/aws_sns.py @@ -70,9 +70,6 @@ class AWSSNS(BaseNotificationService): _LOGGER.info("At least 1 target is required") return - if not isinstance(targets, list): - targets = [targets] - message_attributes = {k: {"StringValue": json.dumps(v), "DataType": "String"} for k, v in kwargs.items() if v} diff --git a/homeassistant/components/notify/aws_sqs.py b/homeassistant/components/notify/aws_sqs.py index a1ddbcea3dd..edd8c4bec69 100644 --- a/homeassistant/components/notify/aws_sqs.py +++ b/homeassistant/components/notify/aws_sqs.py @@ -69,9 +69,6 @@ class AWSSQS(BaseNotificationService): _LOGGER.info("At least 1 target is required") return - if not isinstance(targets, list): - targets = [targets] - for target in targets: cleaned_kwargs = dict((k, v) for k, v in kwargs.items() if v) message_body = {"message": message} diff --git a/homeassistant/components/notify/html5.py b/homeassistant/components/notify/html5.py index 0cf7028351b..a868552d051 100644 --- a/homeassistant/components/notify/html5.py +++ b/homeassistant/components/notify/html5.py @@ -359,8 +359,6 @@ class HTML5NotificationService(BaseNotificationService): if not targets: targets = self.registrations.keys() - elif not isinstance(targets, list): - targets = [targets] for target in targets: info = self.registrations.get(target) diff --git a/homeassistant/components/notify/message_bird.py b/homeassistant/components/notify/message_bird.py index 3a2770a65b5..5e7cc9eaf17 100644 --- a/homeassistant/components/notify/message_bird.py +++ b/homeassistant/components/notify/message_bird.py @@ -58,9 +58,6 @@ class MessageBirdNotificationService(BaseNotificationService): _LOGGER.error('No target specified.') return - if not isinstance(targets, list): - targets = [targets] - for target in targets: try: self.client.message_create(self.sender, diff --git a/homeassistant/components/notify/pushbullet.py b/homeassistant/components/notify/pushbullet.py index d5402548508..71b3f227e9b 100644 --- a/homeassistant/components/notify/pushbullet.py +++ b/homeassistant/components/notify/pushbullet.py @@ -87,10 +87,6 @@ class PushBulletNotificationService(BaseNotificationService): _LOGGER.info('Sent notification to self') return - # Make list if not so - if not isinstance(targets, list): - targets = [targets] - # Main loop, Process all targets specified for target in targets: try: diff --git a/homeassistant/components/notify/pushover.py b/homeassistant/components/notify/pushover.py index c0a067fe918..bd7542c21cd 100644 --- a/homeassistant/components/notify/pushover.py +++ b/homeassistant/components/notify/pushover.py @@ -61,13 +61,15 @@ class PushoverNotificationService(BaseNotificationService): data['title'] = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT) - target = kwargs.get(ATTR_TARGET) - if target is not None: - data['device'] = target + targets = kwargs.get(ATTR_TARGET) - try: - self.pushover.send_message(message, **data) - except ValueError as val_err: - _LOGGER.error(str(val_err)) - except RequestError: - _LOGGER.exception('Could not send pushover notification') + for target in targets: + if target is not None: + data['device'] = target + + try: + self.pushover.send_message(message, **data) + except ValueError as val_err: + _LOGGER.error(str(val_err)) + except RequestError: + _LOGGER.exception('Could not send pushover notification') diff --git a/homeassistant/components/notify/rest.py b/homeassistant/components/notify/rest.py index 0a82b8d5d72..a7d31593ce3 100644 --- a/homeassistant/components/notify/rest.py +++ b/homeassistant/components/notify/rest.py @@ -75,8 +75,10 @@ class RestNotificationService(BaseNotificationService): 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) + if self._target_param_name is not None and ATTR_TARGET in kwargs: + # Target is a list as of 0.29 and we don't want to break existing + # integrations, so just return the first target in the list. + data[self._target_param_name] = kwargs[ATTR_TARGET][0] if self._method == 'POST': response = requests.post(self._resource, data=data, timeout=10) diff --git a/homeassistant/components/notify/services.yaml b/homeassistant/components/notify/services.yaml index 419a796199a..a3980f658ea 100644 --- a/homeassistant/components/notify/services.yaml +++ b/homeassistant/components/notify/services.yaml @@ -11,9 +11,9 @@ notify: example: 'Your Garage Door Friend' target: - description: Target of the notification. Optional depending on the platform + description: An array of targets to send the notification to. Optional depending on the platform. example: platform specific data: - description: Extended information for notification. Optional depending on the platform + description: Extended information for notification. Optional depending on the platform. example: platform specific diff --git a/homeassistant/components/notify/slack.py b/homeassistant/components/notify/slack.py index aded8cd56a9..75ebb9b26fe 100644 --- a/homeassistant/components/notify/slack.py +++ b/homeassistant/components/notify/slack.py @@ -9,7 +9,7 @@ import logging import voluptuous as vol from homeassistant.components.notify import ( - PLATFORM_SCHEMA, BaseNotificationService) + ATTR_TARGET, PLATFORM_SCHEMA, BaseNotificationService) from homeassistant.const import ( CONF_API_KEY, CONF_USERNAME, CONF_ICON) import homeassistant.helpers.config_validation as cv @@ -68,16 +68,19 @@ class SlackNotificationService(BaseNotificationService): """Send a message to a user.""" import slacker - channel = kwargs.get('target') or self._default_channel + targets = kwargs.get(ATTR_TARGET, [self._default_channel]) + data = kwargs.get('data') attachments = data.get('attachments') if data else None - try: - self.slack.chat.post_message(channel, message, - as_user=self._as_user, - username=self._username, - icon_emoji=self._icon, - attachments=attachments, - link_names=True) - except slacker.Error as err: - _LOGGER.error("Could not send slack notification. Error: %s", err) + for target in targets: + try: + self.slack.chat.post_message(target, message, + as_user=self._as_user, + username=self._username, + icon_emoji=self._icon, + attachments=attachments, + link_names=True) + except slacker.Error as err: + _LOGGER.error("Could not send slack notification. Error: %s", + err) diff --git a/homeassistant/components/notify/twilio_sms.py b/homeassistant/components/notify/twilio_sms.py index 8e59cf6d20c..d7e78ac7d1a 100644 --- a/homeassistant/components/notify/twilio_sms.py +++ b/homeassistant/components/notify/twilio_sms.py @@ -57,9 +57,6 @@ class TwilioSMSNotificationService(BaseNotificationService): _LOGGER.info("At least 1 target is required") return - if not isinstance(targets, list): - targets = [targets] - for target in targets: self.client.messages.create(to=target, body=message, from_=self.from_number) diff --git a/tests/components/notify/test_group.py b/tests/components/notify/test_group.py index f1289a3dec1..e1c6d9f5bd4 100644 --- a/tests/components/notify/test_group.py +++ b/tests/components/notify/test_group.py @@ -74,7 +74,7 @@ class TestNotifyGroup(unittest.TestCase): data = self.events[-1].data assert { 'message': 'Hello', - 'target': 'unnamed device', + 'target': ['unnamed device'], 'title': 'Test notification', 'data': {'hello': 'world', 'test': 'message'} } == data