Hass-Custom-Alarm
Hass-Custom-Alarm copied to clipboard
Add optional beeping on device while arming/warning
Thanks for the PR.
So basically it defines playSound
and invokes it when required (and also adds that option to Settings), is that correct?
Could you explain me what this thing does (I know it's some JS trickery but I'm not a web developer and can only guess, which is not the right thing in this situation)?
this.countdownTimerId = setInterval(() => this.playSound(), 1000);
Yes that's correct. setInterval is a JS function that creates a timer to run in the background that will execute the function (the first argument) every X milliseconds (the second argument). The "() =>" part is an ES6 arrow function which allows the binding of "this" which makes it a cleaner shorter syntax. setInterval optionally returns a unique ID for the timer that is created, that is what is being stored in the "this.countdownTimerId" variable. That is used when the timer is finished counting down that it removes it so it does not continue to beep.