Hass-Custom-Alarm icon indicating copy to clipboard operation
Hass-Custom-Alarm copied to clipboard

Add optional beeping on device while arming/warning

Open TJPoorman opened this issue 4 years ago • 2 comments

TJPoorman avatar Aug 29 '20 19:08 TJPoorman

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);

akasma74 avatar Aug 29 '20 21:08 akasma74

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.

TJPoorman avatar Aug 31 '20 15:08 TJPoorman