Skip to content

Add ability to specify a sender in the clicksend notification#11046

Merged
fabaff merged 4 commits into
home-assistant:devfrom
heydonms:clicksend-addsender
Jan 15, 2018
Merged

Add ability to specify a sender in the clicksend notification#11046
fabaff merged 4 commits into
home-assistant:devfrom
heydonms:clicksend-addsender

Conversation

@heydonms
Copy link
Copy Markdown
Contributor

@heydonms heydonms commented Dec 9, 2017

Description:

Add the ability to specify a sender string to the notify.clicksend component (previous version used the recipient as the sender).

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#4422

Example entry for configuration.yaml (if applicable):

notify:
  - platform: clicksend
    name: ClickSend
    username: CLICKSEND_USERNAME
    api_key: CLICKSEND_API_KEY
    recipient: PHONE_NO
    sender: HomeAssistant

Checklist:

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass

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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (80 > 79 characters)

vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_API_KEY): cv.string,
vol.Required(CONF_RECIPIENT): cv.string,
vol.Optional(CONF_SENDER, default=""): cv.string,
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.

Set the default to CONF_RECIPIENT no need to check it later.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This doesn't seem to work for me, if I change it to this:

vol.Optional(CONF_SENDER, default=CONF_RECIPIENT): cv.string,

and don't set the sender in the config file, then sender is set to the string "recipient" rather than the actual value of the recipient variable. The config object isn't in scope so I can't use config.get(CONF_RECIPIENT) either.

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.

Right, then self.sender = config.get(CONF_SENDER, CONF_RECIPIENT) in setup().

@homeassistant
Copy link
Copy Markdown
Contributor

Hi @heydonms,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@fabaff
Copy link
Copy Markdown
Member

fabaff commented Jan 6, 2018

@heydonms, can you please fix the CLA issue that we can merge this PR? Thanks.

@heydonms
Copy link
Copy Markdown
Contributor Author

heydonms commented Jan 8, 2018

@fabaff, I filled in the form a couple of weeks ago. I did it again yesterday but it is still tagged cla-error. Is there something else that I need to do?

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

CLA checks out, thanks!

See below for an improvement.

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

@fabaff fabaff merged commit 079d403 into home-assistant:dev Jan 15, 2018
Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Nice! Just a leftover from testing below.


def get_service(hass, config, discovery_info=None):
"""Get the ClickSend notification service."""
print("#### ", config)
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.

This was left.

@balloob balloob mentioned this pull request Jan 26, 2018
@home-assistant home-assistant locked and limited conversation to collaborators May 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants