Home Assistant Unofficial Reference 2024.12.1
notify.py
Go to the documentation of this file.
1 """Support for SMS notifications from the Dovado router."""
2 
3 from __future__ import annotations
4 
5 import logging
6 
7 from homeassistant.components.notify import ATTR_TARGET, BaseNotificationService
8 from homeassistant.core import HomeAssistant
9 from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
10 
11 from . import DOMAIN as DOVADO_DOMAIN
12 
13 _LOGGER = logging.getLogger(__name__)
14 
15 
17  hass: HomeAssistant,
18  config: ConfigType,
19  discovery_info: DiscoveryInfoType | None = None,
20 ) -> DovadoSMSNotificationService:
21  """Get the Dovado Router SMS notification service."""
22  return DovadoSMSNotificationService(hass.data[DOVADO_DOMAIN].client)
23 
24 
25 class DovadoSMSNotificationService(BaseNotificationService):
26  """Implement the notification service for the Dovado SMS component."""
27 
28  def __init__(self, client):
29  """Initialize the service."""
30  self._client_client = client
31 
32  def send_message(self, message, **kwargs):
33  """Send SMS to the specified target phone number."""
34  if not (target := kwargs.get(ATTR_TARGET)):
35  _LOGGER.error("One target is required")
36  return
37 
38  self._client_client.send_sms(target, message)
DovadoSMSNotificationService get_service(HomeAssistant hass, ConfigType config, DiscoveryInfoType|None discovery_info=None)
Definition: notify.py:20