Skip to content

Conversation

gjohansson-ST
Copy link
Member

@gjohansson-ST gjohansson-ST commented Oct 9, 2024

Proposed change

Fix ManualTriggerEntity to not write state before calculating availability.

  • Test availability first
  • If available, render templates as normal
  • If not available, no further rendering (all other properties remains as before)

Fair share of tests added.

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:

@gjohansson-ST gjohansson-ST marked this pull request as draft October 9, 2024 19:41
@gjohansson-ST gjohansson-ST marked this pull request as ready for review October 9, 2024 20:11
@gjohansson-ST gjohansson-ST marked this pull request as draft October 9, 2024 20:38
@gjohansson-ST gjohansson-ST marked this pull request as ready for review October 11, 2024 17:37
@frenck frenck added this to the 2024.11.0b0 milestone Oct 11, 2024
@frenck frenck added the smash Indicator this PR is close to finish for merging or closing label Oct 18, 2024
@flo-wer
Copy link
Contributor

flo-wer commented Oct 26, 2024

Does this also fix #99942 and #119992? Also does this replace #100079? If yes, it might be a good idea to copy the integration test for the rest sensor from your old PR.

@gjohansson-ST
Copy link
Member Author

Does this also fix #99942 and #119992? Also does this replace #100079? If yes, it might be a good idea to copy the integration test for the rest sensor from your old PR.

Thanks @flo-wer I added those to be fixed by this PR and while this isn't specifically only for rest I guess including that test makes sense so I added it in.

@edenhaus edenhaus modified the milestones: 2024.11.0b0, 2024.11.0 Oct 30, 2024
@emontnemery emontnemery marked this pull request as draft November 6, 2024 10:48
Copy link
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

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

For non-trigger template entities, we added the concept of "super template" which is always the availability template and which:

  • Is rendered first
  • Suppresses rendering of other templates if it's false

Can we do something similar here?

Also, we should preferably add direct tests of ManualTriggerEntity.
The existing test is in tests/components/template/test_manual_trigger_entity.py, it should be moved to tests/helpers/test_trigger_template_entity.py

@emontnemery emontnemery removed this from the 2024.11.0 milestone Nov 6, 2024
@gjohansson-ST
Copy link
Member Author

Created #130134 #130135 #130136 as preliminary PR's for this one

@frenck frenck removed the smash Indicator this PR is close to finish for merging or closing label Nov 8, 2024
@gjohansson-ST gjohansson-ST force-pushed the manual_trigger_entity-fix-availability branch from d9eada0 to 2576e52 Compare December 8, 2024 16:42
@gjohansson-ST gjohansson-ST force-pushed the manual_trigger_entity-fix-availability branch from 1c03cde to 2e2c718 Compare January 7, 2025 21:18
Copy link
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

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

Looks pretty good, some questions though.

Also, we should make sure the way the availability template suppresses rendering of other templates is documented, both for the trigger case and for the state case.

Comment on lines +191 to +195
except TemplateError as err:
logging.getLogger(f"{__package__}.{self.entity_id.split('.')[0]}").error(
"Error rendering %s template for %s: %s", key, self.entity_id, err
)
self._render_error = True
Copy link
Member Author

Choose a reason for hiding this comment

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

Here is a significant difference between state and trigger based templates.
If a state availability template fails to render, it assumes it's available
If a trigger availability template fails to render, it will go unavailable.

This PR does not change this behavior from before, but it's a notable difference on behavior which should be addressed.

Copy link

github-actions bot commented May 1, 2025

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions bot added the stale label May 1, 2025
@emontnemery
Copy link
Contributor

emontnemery commented May 6, 2025

I think this PR is no longer needed thanks to the changes in #140660, and I suggest we close it

@github-actions github-actions bot removed the stale label May 6, 2025
@github-actions github-actions bot locked and limited conversation to collaborators May 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
7 participants