1 """Support for SMS notification services."""
3 from __future__
import annotations
14 from .const
import CONF_UNICODE, DOMAIN, GATEWAY, SMS_GATEWAY
16 _LOGGER = logging.getLogger(__name__)
22 discovery_info: DiscoveryInfoType |
None =
None,
23 ) -> SMSNotificationService |
None:
24 """Get the SMS notification service."""
26 if discovery_info
is None:
33 """Implement the notification service for SMS."""
36 """Initialize the service."""
41 """Send SMS message."""
43 if SMS_GATEWAY
not in self.
hasshass.data[DOMAIN]:
44 _LOGGER.error(
"SMS gateway not found, cannot send message")
47 gateway = self.
hasshass.data[DOMAIN][SMS_GATEWAY][GATEWAY]
49 targets = kwargs.get(CONF_TARGET)
51 _LOGGER.error(
"No target number specified, cannot send message")
54 extended_data = kwargs.get(ATTR_DATA)
55 _LOGGER.debug(
"Extended data:%s", extended_data)
57 if extended_data
is None:
60 is_unicode = extended_data.get(CONF_UNICODE,
True)
64 "Unicode": is_unicode,
65 "Entries": [{
"ID":
"ConcatenatedTextLong",
"Buffer": message}],
69 encoded = gammu.EncodeSMS(smsinfo)
70 except gammu.GSMError
as exc:
71 _LOGGER.error(
"Encoding message %s failed: %s", message, exc)
75 for encoded_message
in encoded:
77 encoded_message[
"SMSC"] = {
"Location": 1}
79 for target
in targets:
80 encoded_message[
"Number"] = target
83 await gateway.send_sms_async(encoded_message)
84 except gammu.GSMError
as exc:
85 _LOGGER.error(
"Sending to %s failed: %s", target, exc)
def async_send_message(self, message="", **kwargs)
SMSNotificationService|None async_get_service(HomeAssistant hass, ConfigType config, DiscoveryInfoType|None discovery_info=None)