Debounce setToCurrentColor to avoid random/unexpected final color #34
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
Should address:
Overview
@sahilchaddha @sahilchaddha93
Add
LightBulb#debouncedSetToCurrentColor
method on 250ms delay as the light bulb service receives possibly 3 set events in succession (hue, saturation, brightness).LightBulb#setHue
,LightBulb#setSaturation
, andLightBulb#setBrightness
now callLightBulb#debouncedSetToCurrentColor
. Prior to this change, I found the service would clobber the device with flux_led.py command invocations. What we want is the 1-3 successiveset*
events to updateLightBulb#color
, and a singleLightBulb#sendCommand
invocation. Debouncing addresses this.In my specific case, this fixed a scene that changed the light's brightness/color. I observed 3
flux_led.py
commands with the same timestamp, and after looking through source code, realized it's probably 3-successive calls tosetToCurrentColor
caused by hue, saturation, brightness changes. We still want those 3 methods to mutate theLightBulb#color
state. But want to debounce the actualLightBulb#sendCommand
/LightBulb#executeCommand
invocation as to not clobber the device, resulting in a random color depending on which of the 3 successive events wins the race condition.