Add message template support for alert component#17516
Add message template support for alert component#17516balloob merged 12 commits intohome-assistant:devfrom
Conversation
homeassistant/components/alert.py
Outdated
| if self._message_template is not None: | ||
| message = self._message_template.async_render() | ||
| else: | ||
| message = '{0}'.format(self._name) |
There was a problem hiding this comment.
No reason to format, just message = self._name will do.
|
Looks good! Ok to merge when a test has been added. |
tests/components/test_alert.py
Outdated
| self._setup_notify() | ||
|
|
||
| config = deepcopy(TEST_CONFIG) | ||
| config[alert.DOMAIN][NAME][alert.CONF_MESSAGE_TEMPLATE] = "{{ states.sensor.test.entity_id }}" |
There was a problem hiding this comment.
line too long (102 > 79 characters)
tests/components/test_alert.py
Outdated
| self.hass.services.register( | ||
| notify.DOMAIN, NOTIFIER, record_event) | ||
|
|
||
| return events |
There was a problem hiding this comment.
indentation contains tabs
unexpected indentation
TabError: inconsistent use of tabs and spaces in indentation
tests/components/test_alert.py
Outdated
|
|
||
| self.hass.services.register( | ||
| notify.DOMAIN, NOTIFIER, record_event) | ||
|
|
There was a problem hiding this comment.
indentation contains tabs
indentation contains mixed spaces and tabs
blank line contains whitespace
| """Stop everything that was started.""" | ||
| self.hass.stop() | ||
|
|
||
| def _setup_notify(self): |
There was a problem hiding this comment.
indentation contains mixed spaces and tabs
tests/components/test_alert.py
Outdated
| def tearDown(self): | ||
| """Stop everything that was started.""" | ||
| self.hass.stop() | ||
|
|
There was a problem hiding this comment.
indentation contains tabs
indentation contains mixed spaces and tabs
blank line contains whitespace
a6634f4 to
b4ad138
Compare
tests/components/test_alert.py
Outdated
| self.hass.add_job(entity.end_alerting) | ||
| self.hass.block_till_done() | ||
| assert entity._send_done_message is False | ||
| assert entity._send_done_message is False No newline at end of file |
| _LOGGER.info("Alerting: %s", self._done_message_template) | ||
| self._send_done_message = False | ||
|
|
||
| if self._done_message_template is None: |
There was a problem hiding this comment.
indentation contains mixed spaces and tabs
homeassistant/components/alert.py
Outdated
| _LOGGER.info("Alerting: %s", self._done_message) | ||
| _LOGGER.info("Alerting: %s", self._done_message_template) | ||
| self._send_done_message = False | ||
|
|
There was a problem hiding this comment.
blank line contains whitespace
indentation contains mixed spaces and tabs
indentation contains tabs
homeassistant/components/alert.py
Outdated
| self._done_message_template = done_message_template | ||
| if self._done_message_template is not None: | ||
| self._done_message_template.hass = hass | ||
|
|
There was a problem hiding this comment.
blank line contains whitespace
indentation contains mixed spaces and tabs
indentation contains tabs
homeassistant/components/alert.py
Outdated
| state, repeat, skip_first, notifiers, can_ack): | ||
| def __init__(self, hass, entity_id, name, watched_entity_id, | ||
| state, repeat, skip_first, message_template, | ||
| done_message_template, notifiers, can_ack): |
There was a problem hiding this comment.
continuation line under-indented for visual indent
indentation contains mixed spaces and tabs
indentation contains tabs
homeassistant/components/alert.py
Outdated
| def __init__(self, hass, entity_id, name, done_message, watched_entity_id, | ||
| state, repeat, skip_first, notifiers, can_ack): | ||
| def __init__(self, hass, entity_id, name, watched_entity_id, | ||
| state, repeat, skip_first, message_template, |
| watched_entity_id, alert_state, repeat, | ||
| skip_first, message_template, | ||
| done_message_template, notifiers, | ||
| can_ack)) |
There was a problem hiding this comment.
indentation contains mixed spaces and tabs
homeassistant/components/alert.py
Outdated
| entities.append(Alert(hass, object_id, name, | ||
| watched_entity_id, alert_state, repeat, | ||
| skip_first, message_template, | ||
| done_message_template, notifiers, |
There was a problem hiding this comment.
continuation line under-indented for visual indent
indentation contains mixed spaces and tabs
indentation contains tabs
homeassistant/components/alert.py
Outdated
|
|
||
| entities.append(Alert(hass, object_id, name, | ||
| watched_entity_id, alert_state, repeat, | ||
| skip_first, message_template, |
homeassistant/components/alert.py
Outdated
| notifiers = cfg.get(CONF_NOTIFIERS) | ||
| can_ack = cfg.get(CONF_CAN_ACK) | ||
|
|
||
| entities.append(Alert(hass, object_id, name, |
This reverts commit 7be519b.
|
I updated the component to support templates for both, message and done_message. For legacy support, the message is optional and the name taken instead, like it was before. |
|
Is this PR clashing with #17616? |
Description:
Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#6859
Example entry for
configuration.yaml(if applicable):Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed: