1 """Clicksend platform for notify component."""
3 from __future__
import annotations
5 from http
import HTTPStatus
11 import voluptuous
as vol
14 PLATFORM_SCHEMA
as NOTIFY_PLATFORM_SCHEMA,
15 BaseNotificationService,
28 _LOGGER = logging.getLogger(__name__)
30 BASE_API_URL =
"https://rest.clicksend.com/v3"
31 DEFAULT_SENDER =
"hass"
34 HEADERS = {
"Content-Type": CONTENT_TYPE_JSON}
37 PLATFORM_SCHEMA = NOTIFY_PLATFORM_SCHEMA.extend(
39 vol.Required(CONF_USERNAME): cv.string,
40 vol.Required(CONF_API_KEY): cv.string,
41 vol.Required(CONF_RECIPIENT, default=[]): vol.All(cv.ensure_list, [cv.string]),
42 vol.Optional(CONF_SENDER, default=DEFAULT_SENDER): cv.string,
50 discovery_info: DiscoveryInfoType |
None =
None,
51 ) -> ClicksendNotificationService |
None:
52 """Get the ClickSend notification service."""
54 _LOGGER.error(
"You are not authorized to access ClickSend")
60 """Implementation of a notification service for the ClickSend service."""
62 def __init__(self, config: ConfigType) ->
None:
63 """Initialize the service."""
64 self.username: str = config[CONF_USERNAME]
65 self.api_key: str = config[CONF_API_KEY]
66 self.recipients: list[str] = config[CONF_RECIPIENT]
67 self.sender: str = config[CONF_SENDER]
70 """Send a message to a user."""
71 data: dict[str, Any] = {
"messages": []}
72 for recipient
in self.recipients:
73 data[
"messages"].append(
75 "source":
"hass.notify",
82 api_url = f
"{BASE_API_URL}/sms/send"
85 data=json.dumps(data),
87 auth=(self.username, self.api_key),
90 if resp.status_code == HTTPStatus.OK:
93 obj = json.loads(resp.text)
94 response_msg = obj.get(
"response_msg")
95 response_code = obj.get(
"response_code")
97 "Error %s : %s (Code %s)", resp.status_code, response_msg, response_code
102 """Authenticate with ClickSend."""
103 api_url = f
"{BASE_API_URL}/account"
107 auth=(config[CONF_USERNAME], config[CONF_API_KEY]),
110 return resp.status_code == HTTPStatus.OK
None __init__(self, ConfigType config)
None send_message(self, str message="", **Any kwargs)
bool _authenticate(ConfigType config)
ClicksendNotificationService|None get_service(HomeAssistant hass, ConfigType config, DiscoveryInfoType|None discovery_info=None)