From 324a7c7875d0d1bb79df16205526886d8a1382db Mon Sep 17 00:00:00 2001 From: fabtesta Date: Mon, 25 Mar 2019 02:13:56 +0100 Subject: [PATCH] Add ClickSend "caller" option (#20780) * removed "from" parameter from ClickSend API call Removed "from" parameter from API call to let ClickSend choose a random number and be more compliant with some cellular networks that do not allow incoming calls from the same recipient number. * fixed "line too long (94 > 79 characters)" houndci code review fixed "line too long (94 > 79 characters)" houndci code review * Added new component optional parameter "caller". If defined is used to override default logic that uses recipient phone number in "from" API call parameter * Removed default value for CALLER parameter. If not defined then will take the RECIPIENT value. --- homeassistant/components/notify/clicksend_tts.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/notify/clicksend_tts.py b/homeassistant/components/notify/clicksend_tts.py index 1481fea1783..2a7730c4a27 100644 --- a/homeassistant/components/notify/clicksend_tts.py +++ b/homeassistant/components/notify/clicksend_tts.py @@ -27,6 +27,7 @@ HEADERS = {CONTENT_TYPE: CONTENT_TYPE_JSON} CONF_LANGUAGE = 'language' CONF_VOICE = 'voice' +CONF_CALLER = 'caller' DEFAULT_LANGUAGE = 'en-us' DEFAULT_VOICE = 'female' @@ -38,6 +39,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_RECIPIENT): cv.string, vol.Optional(CONF_LANGUAGE, default=DEFAULT_LANGUAGE): cv.string, vol.Optional(CONF_VOICE, default=DEFAULT_VOICE): cv.string, + vol.Optional(CONF_CALLER): cv.string, }) @@ -60,10 +62,13 @@ class ClicksendNotificationService(BaseNotificationService): self.recipient = config.get(CONF_RECIPIENT) self.language = config.get(CONF_LANGUAGE) self.voice = config.get(CONF_VOICE) + self.caller = config.get(CONF_CALLER) + if self.caller is None: + self.caller = self.recipient def send_message(self, message="", **kwargs): """Send a voice call to a user.""" - data = ({'messages': [{'source': 'hass.notify', 'from': self.recipient, + data = ({'messages': [{'source': 'hass.notify', 'from': self.caller, 'to': self.recipient, 'body': message, 'lang': self.language, 'voice': self.voice}]}) api_url = "{}/voice/send".format(BASE_API_URL)