mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add target management for the service call (#73332)
This commit is contained in:
parent
146ff83a16
commit
9e61c7ec49
@ -5,7 +5,7 @@ import gammu # pylint: disable=import-error
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.notify import PLATFORM_SCHEMA, BaseNotificationService
|
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
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
from .const import DOMAIN, SMS_GATEWAY
|
from .const import DOMAIN, SMS_GATEWAY
|
||||||
@ -44,6 +44,8 @@ class SMSNotificationService(BaseNotificationService):
|
|||||||
|
|
||||||
async def async_send_message(self, message="", **kwargs):
|
async def async_send_message(self, message="", **kwargs):
|
||||||
"""Send SMS message."""
|
"""Send SMS message."""
|
||||||
|
|
||||||
|
targets = kwargs.get(CONF_TARGET, [self.number])
|
||||||
smsinfo = {
|
smsinfo = {
|
||||||
"Class": -1,
|
"Class": -1,
|
||||||
"Unicode": True,
|
"Unicode": True,
|
||||||
@ -60,9 +62,11 @@ class SMSNotificationService(BaseNotificationService):
|
|||||||
for encoded_message in encoded:
|
for encoded_message in encoded:
|
||||||
# Fill in numbers
|
# Fill in numbers
|
||||||
encoded_message["SMSC"] = {"Location": 1}
|
encoded_message["SMSC"] = {"Location": 1}
|
||||||
encoded_message["Number"] = self.number
|
|
||||||
try:
|
for target in targets:
|
||||||
# Actually send the message
|
encoded_message["Number"] = target
|
||||||
await self.gateway.send_sms_async(encoded_message)
|
try:
|
||||||
except gammu.GSMError as exc:
|
# Actually send the message
|
||||||
_LOGGER.error("Sending to %s failed: %s", self.number, exc)
|
await self.gateway.send_sms_async(encoded_message)
|
||||||
|
except gammu.GSMError as exc:
|
||||||
|
_LOGGER.error("Sending to %s failed: %s", target, exc)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user