1 """clicksend_tts platform for notify component."""
3 from __future__
import annotations
5 from http
import HTTPStatus
10 import voluptuous
as vol
13 PLATFORM_SCHEMA
as NOTIFY_PLATFORM_SCHEMA,
14 BaseNotificationService,
27 _LOGGER = logging.getLogger(__name__)
29 BASE_API_URL =
"https://rest.clicksend.com/v3"
31 HEADERS = {
"Content-Type": CONTENT_TYPE_JSON}
33 CONF_LANGUAGE =
"language"
37 FEMALE_VOICE =
"female"
39 DEFAULT_NAME =
"clicksend_tts"
40 DEFAULT_LANGUAGE =
"en-us"
41 DEFAULT_VOICE = FEMALE_VOICE
44 PLATFORM_SCHEMA = NOTIFY_PLATFORM_SCHEMA.extend(
46 vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
47 vol.Required(CONF_USERNAME): cv.string,
48 vol.Required(CONF_API_KEY): cv.string,
49 vol.Required(CONF_RECIPIENT): vol.All(
50 cv.string, vol.Match(
r"^\+?[1-9]\d{1,14}$")
52 vol.Optional(CONF_LANGUAGE, default=DEFAULT_LANGUAGE): cv.string,
53 vol.Optional(CONF_VOICE, default=DEFAULT_VOICE): vol.In(
54 [MALE_VOICE, FEMALE_VOICE]
63 discovery_info: DiscoveryInfoType |
None =
None,
64 ) -> ClicksendNotificationService |
None:
65 """Get the ClickSend notification service."""
67 _LOGGER.error(
"You are not authorized to access ClickSend")
74 """Implementation of a notification service for the ClickSend service."""
77 """Initialize the service."""
79 self.
api_keyapi_key = config[CONF_API_KEY]
82 self.
voicevoice = config[CONF_VOICE]
85 """Send a voice call to a user."""
89 "source":
"hass.notify",
93 "voice": self.
voicevoice,
97 api_url = f
"{BASE_API_URL}/voice/send"
100 data=json.dumps(data),
106 if resp.status_code == HTTPStatus.OK:
108 obj = json.loads(resp.text)
109 response_msg = obj[
"response_msg"]
110 response_code = obj[
"response_code"]
112 "Error %s : %s (Code %s)", resp.status_code, response_msg, response_code
117 """Authenticate with ClickSend."""
118 api_url = f
"{BASE_API_URL}/account"
122 auth=(config.get(CONF_USERNAME), config.get(CONF_API_KEY)),
126 return resp.status_code == HTTPStatus.OK
def send_message(self, message="", **kwargs)
def __init__(self, config)
def _authenticate(config)
ClicksendNotificationService|None get_service(HomeAssistant hass, ConfigType config, DiscoveryInfoType|None discovery_info=None)