Putting local declaration at top of function will remove the const. Should we allow this type of declaration where variable is closest to the location it is being used?
Basically, you're calling waitForObjectExists on a component that will always exist. It will be visible and enabled too, so waitForObject wouldn't help you. What would help you is to wait for the object to exist that distinguishes it from the object being waited for in previous calls to test_state. The dictionary, names.o_treatmentStart_HeparinSection, is not unique with each call, but if you set the buttonText property of that dictionary on each call, then it will be unique. So that property needs to be part of the object you're waiting for in order for repeated calls to waitForObjectExists to be useful. Using the helper function is up to you. I'm just letting you know of its existence and purpose should you choose to use it in the future once it's merged. Hope this clarifies things
I think condition should stay. Flag name is confusing. hasTurnOnBeenRequested sounds like it only relates to turning UV reactor on but it's not. Setting to FALSE indicates we want UV reactor turned off. Recommend renaming this flag.