Skip to content

Add message template support for alert component#17516

Merged
balloob merged 12 commits intohome-assistant:devfrom
thoscut:dev
Nov 1, 2018
Merged

Add message template support for alert component#17516
balloob merged 12 commits intohome-assistant:devfrom
thoscut:dev

Conversation

@thoscut
Copy link
Copy Markdown
Contributor

@thoscut thoscut commented Oct 16, 2018

Description:

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

Example entry for configuration.yaml (if applicable):

  plant_office:
    name: Plant in office needs help
    entity_id: plant.plant_office
    state: 'problem'
    repeat:
      - 60
      - 720
    message: "{{ states.plant.plant_office }} ({{ state_attr('plant.plant_office', 'problem') }})"
    notifiers:
      - telegram_receiver

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

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

if self._message_template is not None:
message = self._message_template.async_render()
else:
message = '{0}'.format(self._name)
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.

No reason to format, just message = self._name will do.

@balloob
Copy link
Copy Markdown
Member

balloob commented Oct 17, 2018

Looks good! Ok to merge when a test has been added.

self._setup_notify()

config = deepcopy(TEST_CONFIG)
config[alert.DOMAIN][NAME][alert.CONF_MESSAGE_TEMPLATE] = "{{ states.sensor.test.entity_id }}"
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 (102 > 79 characters)

self.hass.services.register(
notify.DOMAIN, NOTIFIER, record_event)

return events
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

indentation contains tabs
unexpected indentation
TabError: inconsistent use of tabs and spaces in indentation


self.hass.services.register(
notify.DOMAIN, NOTIFIER, record_event)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

indentation contains mixed spaces and tabs

def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

indentation contains tabs
indentation contains mixed spaces and tabs
blank line contains whitespace

@thoscut thoscut force-pushed the dev branch 4 times, most recently from a6634f4 to b4ad138 Compare October 18, 2018 21:09
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
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

indentation contains mixed spaces and tabs

_LOGGER.info("Alerting: %s", self._done_message)
_LOGGER.info("Alerting: %s", self._done_message_template)
self._send_done_message = False

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

blank line contains whitespace
indentation contains mixed spaces and tabs
indentation contains tabs

self._done_message_template = done_message_template
if self._done_message_template is not None:
self._done_message_template.hass = hass

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

blank line contains whitespace
indentation contains mixed spaces and tabs
indentation contains tabs

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

Choose a reason for hiding this comment

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

continuation line under-indented for visual indent
indentation contains mixed spaces and tabs
indentation contains tabs

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

Choose a reason for hiding this comment

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

trailing whitespace

watched_entity_id, alert_state, repeat,
skip_first, message_template,
done_message_template, notifiers,
can_ack))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

indentation contains mixed spaces and tabs

entities.append(Alert(hass, object_id, name,
watched_entity_id, alert_state, repeat,
skip_first, message_template,
done_message_template, notifiers,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

continuation line under-indented for visual indent
indentation contains mixed spaces and tabs
indentation contains tabs


entities.append(Alert(hass, object_id, name,
watched_entity_id, alert_state, repeat,
skip_first, message_template,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

trailing whitespace

notifiers = cfg.get(CONF_NOTIFIERS)
can_ack = cfg.get(CONF_CAN_ACK)

entities.append(Alert(hass, object_id, name,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

trailing whitespace

@thoscut
Copy link
Copy Markdown
Contributor Author

thoscut commented Oct 31, 2018

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 there a common practice for marking this legacy support for removal/deprecated in a later release?

@MartinHjelmare
Copy link
Copy Markdown
Member

Is this PR clashing with #17616?

@balloob balloob merged commit bfa86b8 into home-assistant:dev Nov 1, 2018
@ghost ghost removed the in progress label Nov 1, 2018
@balloob balloob mentioned this pull request Nov 9, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Feb 5, 2019
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.

6 participants