Currently, I am developing a Web app to manage light control through the openHab API and utilizing SSE. However, an issue arises when the light is turned on as I receive three messages simultaneously.
One message contains the value 100, while the other two messages contain the current brightness level of the light (e.g., 45). This value corresponds to the percentage of brightness for the light.
eventSource.onmessage = (event: any) => {
this.val = JSON.parse(JSON.parse(event.data).payload).value;
console.log("new val " + this.val);
slid.value = this.val;
if(this.val >= 1){
this.light = true;
button.checked= true;
}
else{
this.light = false;
button.checked = false;
}
};
The issue lies in my progress bar displaying the light's position reaching 100% before adjusting to the actual value. Is there a way to prevent or update the value only for the most recent message received?
Thank you.