Skip to content

Add event platform to templates #145408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

Petro31
Copy link
Contributor

@Petro31 Petro31 commented May 21, 2025

Breaking change

Proposed change

Add Event Entities to template integration.

template:
- event:
  - name: Joost Review This PR Status
    event_type: "{{ 'joost_avoided_reviewing' }}"
    event_types: "{{ ['review_needed', 'joost_avoided_reviewing', 'reviewed_by_other', 'reviewed_by_joost'] }}"

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

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

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

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hey there @PhracturedBlue, @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration (template) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of template can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign template Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

Comment on lines +269 to +270
self.async_set_context(self.coordinator.data["context"])
self.async_write_ha_state()
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this mean we always set the context before writing state?

I never worked with context so no clue how that works

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, for trigger based template entities, we update the context from whatever triggered. Kinda like automations. There was a "bug fix" awhile ago that added this because template entities didn't properly reflect the context according to some people.

"device_id": "[%key:common::config_flow::data::device%]",
"name": "[%key:common::config_flow::data::name%]",
"device_class": "[%key:component::template::config::step::sensor::data::device_class%]",
"event_type": "Event type template",
Copy link
Member

Choose a reason for hiding this comment

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

Current event type? Last fired event type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure, it's technically the last event type. But it will be the event that's current. I'm open to suggestions.

Copy link
Member

Choose a reason for hiding this comment

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

@NoRi2909, we're looking for a string that represents the current event, but this would be a template that compiles to the current event

Copy link
Contributor

Choose a reason for hiding this comment

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

In the Events section of the Frontend Developer tools the headline is "Fire an event on the event bus".

So "Fired event type" might fit here.

BTW: In German we currently have this translated as "Ein Ereignis im Ereignisbus auslösen" which would be "trigger an event" in English as an alternative.

Copy link
Member

Choose a reason for hiding this comment

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

But that's the event bus, while this is an event entity.

Screenshot_20250522-085532.png

Screenshot_20250522-085546.png

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, for such a button that "event_type" attribute is the (last) type of event that this entity has fired, right?

Thus "Last fired event type" sounds OK to me, but you are much more familiar with the overall concept than me, so I'm probably not of much help here …

@home-assistant home-assistant bot marked this pull request as draft May 21, 2025 20:07
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@Petro31 Petro31 force-pushed the add-event-template-entity branch from 7648ca7 to dfb54ae Compare May 22, 2025 12:10
@Petro31 Petro31 marked this pull request as ready for review May 22, 2025 12:41
@home-assistant home-assistant bot requested a review from joostlek May 22, 2025 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy