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: address race condition and consider transition time when using debounce #167

Merged

Conversation

cayossarian
Copy link
Contributor

@cayossarian cayossarian commented Dec 28, 2024

Fixes issuse #166 race condition

This pull request does a few things to address the race condition:

  • Moves the handling of debounce time to the device level (stateful scene) instead of per entity
  • Substitutes HA scheduling routines for the use of sleep
  • Combines the transition time to the debounce time in such a way that the transition occurs and then debounce is added as a delay before evaluation of the scene

The UI switch remains responsive so the user can turn the scene on/off at will. When the user changes the stateful scene during a period where the transition or debounce is in play the scene changes state as would be expected and resets any pending delay in evaluation.

If an external source changes one of the entities that the scene controls during the transition/debounce the final evaluation will occur and set the stateful scene accordingly.

@cayossarian cayossarian force-pushed the fix/state_change_race_condition branch 3 times, most recently from 98eac5d to e48986e Compare December 29, 2024 02:18
Fix race condidtiion in state change.
Rapid state changes caused a race condition due to the
use of sleep methods which should not be used
in HA.  This change uses the HA event loop to
schedule the state change and ensures that the
debounce time follows any transition time.
@cayossarian cayossarian force-pushed the fix/state_change_race_condition branch from e48986e to 1791d4b Compare December 29, 2024 02:21
@hugobloem
Copy link
Owner

Brilliant, thank you.

@hugobloem hugobloem merged commit efd0423 into hugobloem:main Dec 29, 2024
4 checks passed
@cayossarian cayossarian deleted the fix/state_change_race_condition branch December 31, 2024 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants