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.
This commit is contained in:
fabtesta 2019-03-25 02:13:56 +01:00 committed by Robbie Trencheny
parent c59d45caa3
commit 324a7c7875

View file

@ -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)