1 """Twilio SMS platform for notify component."""
3 from __future__
import annotations
7 import voluptuous
as vol
12 PLATFORM_SCHEMA
as NOTIFY_PLATFORM_SCHEMA,
13 BaseNotificationService,
20 _LOGGER = logging.getLogger(__name__)
22 CONF_FROM_NUMBER =
"from_number"
23 ATTR_MEDIAURL =
"media_url"
25 PLATFORM_SCHEMA = NOTIFY_PLATFORM_SCHEMA.extend(
27 vol.Required(CONF_FROM_NUMBER): vol.All(
30 r"^\+?[1-9]\d{1,14}$|"
31 r"^(?=.{1,11}$)[a-zA-Z0-9\s]*"
32 r"[a-zA-Z][a-zA-Z0-9\s]*$"
33 r"^(?:[a-zA-Z]+)\:?\+?[1-9]\d{1,14}$|"
43 discovery_info: DiscoveryInfoType |
None =
None,
44 ) -> TwilioSMSNotificationService |
None:
45 """Get the Twilio SMS notification service."""
47 hass.data[DATA_TWILIO], config[CONF_FROM_NUMBER]
52 """Implement the notification service for the Twilio SMS service."""
54 def __init__(self, twilio_client, from_number):
55 """Initialize the service."""
60 """Send SMS to specified target user cell."""
61 targets = kwargs.get(ATTR_TARGET)
62 data = kwargs.get(ATTR_DATA)
or {}
63 twilio_args = {
"body": message,
"from_": self.
from_numberfrom_number}
65 if ATTR_MEDIAURL
in data:
66 twilio_args[ATTR_MEDIAURL] = data[ATTR_MEDIAURL]
69 _LOGGER.warning(
"At least 1 target is required")
72 for target
in targets:
73 self.
clientclient.messages.create(to=target, **twilio_args)
def send_message(self, message="", **kwargs)
def __init__(self, twilio_client, from_number)
TwilioSMSNotificationService|None get_service(HomeAssistant hass, ConfigType config, DiscoveryInfoType|None discovery_info=None)