Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions homeassistant/components/notify/clicksend.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
from homeassistant.components.notify import (
PLATFORM_SCHEMA, BaseNotificationService)
from homeassistant.const import (
CONF_API_KEY, CONF_USERNAME, CONF_RECIPIENT, CONTENT_TYPE_JSON)
CONF_API_KEY, CONF_USERNAME, CONF_RECIPIENT, CONF_SENDER,
CONTENT_TYPE_JSON)
import homeassistant.helpers.config_validation as cv

_LOGGER = logging.getLogger(__name__)
Expand All @@ -27,6 +28,7 @@
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_API_KEY): cv.string,
vol.Required(CONF_RECIPIENT): cv.string,
vol.Optional(CONF_SENDER): cv.string,
})


Expand All @@ -47,10 +49,11 @@ def __init__(self, config):
self.username = config.get(CONF_USERNAME)
self.api_key = config.get(CONF_API_KEY)
self.recipient = config.get(CONF_RECIPIENT)
self.sender = config.get(CONF_SENDER, CONF_RECIPIENT)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to add a schema validator that sets the default value during config validation.

def validate_sender(config):
    if CONF_SENDER in config:
        return config
    config[CONF_SENDER] = config[CONF_RECIPIENT]
    return config

Then use this validator like this in the schema:

PLATFORM_SCHEMA = vol.Schema(
    vol.All(PLATFORM_SCHEMA.extend({...}), validate_sender))


def send_message(self, message="", **kwargs):
"""Send a message to a user."""
data = ({'messages': [{'source': 'hass.notify', 'from': self.recipient,
data = ({'messages': [{'source': 'hass.notify', 'from': self.sender,
'to': self.recipient, 'body': message}]})

api_url = "{}/sms/send".format(BASE_API_URL)
Expand Down