1 """MessageBird platform for notify component."""
3 from __future__
import annotations
8 from messagebird.client
import ErrorException
9 import voluptuous
as vol
13 PLATFORM_SCHEMA
as NOTIFY_PLATFORM_SCHEMA,
14 BaseNotificationService,
21 _LOGGER = logging.getLogger(__name__)
23 PLATFORM_SCHEMA = NOTIFY_PLATFORM_SCHEMA.extend(
25 vol.Required(CONF_API_KEY): cv.string,
26 vol.Optional(CONF_SENDER, default=
"HA"): vol.All(
27 cv.string, vol.Match(
r"^(\+?[1-9]\d{1,14}|\w{1,11})$")
36 discovery_info: DiscoveryInfoType |
None =
None,
37 ) -> MessageBirdNotificationService |
None:
38 """Get the MessageBird notification service."""
39 client = messagebird.Client(config[CONF_API_KEY])
43 except messagebird.client.ErrorException:
44 _LOGGER.error(
"The specified MessageBird API key is invalid")
51 """Implement the notification service for MessageBird."""
54 """Initialize the service."""
59 """Send a message to a specified target."""
60 if not (targets := kwargs.get(ATTR_TARGET)):
61 _LOGGER.error(
"No target specified")
64 for target
in targets:
66 self.
clientclient.message_create(
67 self.
sendersender, target, message, {
"reference":
"HA"}
69 except ErrorException
as exception:
70 _LOGGER.error(
"Failed to notify %s: %s", target, exception)
def send_message(self, message=None, **kwargs)
def __init__(self, sender, client)
MessageBirdNotificationService|None get_service(HomeAssistant hass, ConfigType config, DiscoveryInfoType|None discovery_info=None)