Skip to content
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

Fix an infinite loop in automation numeric_state #22429

Merged
merged 1 commit into from
Oct 29, 2024

Conversation

karwosts
Copy link
Contributor

Proposed change

Address issues from #22403

As best I can tell what was happening was (on changing template field from empty to e.g. a)

  • On change of template field, valueChanged was called for the first time
  • inputAbove and inputBelow mode variables changed from undefined to true/false in valueChanged, as well as firing a valueChanged event with the new template condition.
  • the change in the input mode variables triggered a local update due to change in @state.
  • on this update from @state change, template field is still undefined because the valueChanged event hasn't propogated up and back down yet.
  • because we rerender the form with template as undefined, the codemirror block fires this as a valueChanged, this time with template as "". This seems unique to codemirror/template blocks, and is not how e.g. a text field behaves. not sure if that's an issue.
  • numeric_state condition gets a second valueChanged event, this time with template as "", and fires another value-changed with template as "".
  • Now from a single change in template, we have fired two events, first one with template: a, and second one with template: "".
  • These two events propogate back down as two condition changes, and just spin in an infinite loop changing the template field from "" -> "a" -> "" -> "a".

This is mitigated by setting the inputMode variables to true/false before the first time valueChanged event is received, so they don't trigger updates from unrelated change in other fields.

Type of change

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

Example configuration

Additional information

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

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

@piitaya piitaya merged commit 9fff3ad into home-assistant:dev Oct 29, 2024
17 checks passed
@karwosts karwosts deleted the numeric_state_hang branch October 29, 2024 14:28
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.

Infinite loop/UI freeze when editing template in nested binary_sensor condition
2 participants