Two Challenges & Solutions
Issue: We are once again feeling confident and hopeful about our plugin. We have successfully learned about Repeated Timers and redesigned our code. The main issue that we were having before we found out about our while loop fiasco was that we were initiating all of our functions in the on_after_startup() function and once it had ran once, we were unsure of how to get it to run again.
Solution: We have found that the solution to this is to create a repeated timer in the startup function. This repeated timer will call a function called condition every second. The condition function will check to see if the time has been set above 0, and if the temperature is set. If both of these conditions are not met, then there is not a need for the plugin. Once the condition is met, we essentially “pause*” the original timer and create a new timer that is set with the time that we have grabbed from the user interface in OctoPrint. Once the second timer has finished it’s job, we “pause” the second timer and once again start the original timer.
Issue: The second challenge is that we have to update the time if someone changes it underneath the settings tab. We had a really hard time conceptualizing where to do this in our old while loop code. However, we came together as a group and began designing our new plugin.
(Possible) Solution: Since the repeated timer plays nice with other functions, our plugin is able to respond to the on_settings_save() function. All we have to do was change a variable from True to False if the grabbed time was different from the original time. This variable will be returned as the Repeated Timer condition, so that if it is false, the repeated timer will not carry out it’s duty. The struggle is that once the new time is set, we want our plugin to go through the method of checking conditions and setting a new timer, however, we have to change the variable back, and if it is before the time is up, then both timers are going to try to kill the temperatures. We are still working through this.
*Pause: There is a way to cancel a Repeated Timer, but no way to pause one. The issue with cancelling the repeated timer is that once you cancel, you can no longer start the timer (it can only be started once). We are using the condition to tell it whether or not it can fire, which is not exactly pausing it but temporarily disabling it from doing it’s job.