From 9e61c7ec49dd47dc3f7b8744c40739af0f2348c6 Mon Sep 17 00:00:00 2001 From: elBoz73 <26686772+elBoz73@users.noreply.github.com> Date: Tue, 28 Jun 2022 22:57:47 +0200 Subject: [PATCH] Add target management for the service call (#73332) --- homeassistant/components/sms/notify.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/sms/notify.py b/homeassistant/components/sms/notify.py index 1bd3c60b9b9..433144773f7 100644 --- a/homeassistant/components/sms/notify.py +++ b/homeassistant/components/sms/notify.py @@ -5,7 +5,7 @@ import gammu # pylint: disable=import-error import voluptuous as vol from homeassistant.components.notify import PLATFORM_SCHEMA, BaseNotificationService -from homeassistant.const import CONF_NAME, CONF_RECIPIENT +from homeassistant.const import CONF_NAME, CONF_RECIPIENT, CONF_TARGET import homeassistant.helpers.config_validation as cv from .const import DOMAIN, SMS_GATEWAY @@ -44,6 +44,8 @@ class SMSNotificationService(BaseNotificationService): async def async_send_message(self, message="", **kwargs): """Send SMS message.""" + + targets = kwargs.get(CONF_TARGET, [self.number]) smsinfo = { "Class": -1, "Unicode": True, @@ -60,9 +62,11 @@ class SMSNotificationService(BaseNotificationService): for encoded_message in encoded: # Fill in numbers encoded_message["SMSC"] = {"Location": 1} - encoded_message["Number"] = self.number - try: - # Actually send the message - await self.gateway.send_sms_async(encoded_message) - except gammu.GSMError as exc: - _LOGGER.error("Sending to %s failed: %s", self.number, exc) + + for target in targets: + encoded_message["Number"] = target + try: + # Actually send the message + await self.gateway.send_sms_async(encoded_message) + except gammu.GSMError as exc: + _LOGGER.error("Sending to %s failed: %s", target, exc)