Schedule not working

I"m facing a wierd issue. I’ve written a simple thermostat app that schedules the next thermostat change.

Here’s the function that schedules - initialize() for anyone interested. The bug? I’m seeing is that in the scheduling function initialize() if I don’t call unschedule() the scheduler stops working (events not fired) after about 2-3 schedules.

The function only schedules the next timer, so at any point there is only one active schedule. E.g. it schedules for 11am , when the event is fired at 11am it then schedules the next change say 11:05am, when the event is fired at 11:05am it schedules for 11:10am etc.

In this initialize() function if remove the unschedule() function it stops working after 2-3 schedules even though there is only one scheduled event. Don’t scheduled events expire after they are fired?

I don’t understand why should I have to call unschedule after each schedule. Is this a bug or a feature?

@bflorian FYI please, can you comments from a platform perspective?