As a learning experience, I'm coding a virtual shade driver (based on the existing one(s)) that will simulate a window shade. For example, when it receives an open command, it will set the windowShade attribute to "partially open", then go into a loop that will...
- Sleep for one second.
- Do a sendEvent to simulate the shade position changing.
The number of iterations is a preference. So if the iterations is 10, it will loop 10 times. Each time, it will update the position by 10%, e.g., 0%, 10%, 20%,...,100%. If iterations is 5, it will show 0%, 20%,...,100%. It also handles the scenario where an open command is simulated on a partially open shade. So if iterations is 10, and the shade is currently at 50%, the position will start at 50% instead of zero, and it will only iterate five times.
The driver does not actually try to control a shade. It is for simulation/testing only.
Open and close are basically working. I'm working on the "stop" command now. My idea is to check to see if there was a stop command issued from the same control device while the driver is in the loop. Is this possible with a HE driver? If so, what's the best design for doing this?
The simulated scenario needs to handle the possibility of multiple buttons each controlling a single shade. So, there may be three shades opening at the same time because three individual buttons were pressed at nearly the same time. If one of those is pressed again while it's shade is still "opening", I want to only stop the shade that the button is controlling.
For testing, I'm using either the driver detail page or the relay button on a ZEN30 double switch. For the latter, I have rules set up so that if the relay button is pressed while the shade is not opening and not closing, an open command is sent. If the shade is opening or closing, a stop command is sent. The rules seem to be working, I can see the open command and the stop command in the log. I just don't know how to make the stop command interrupt the "in progress" open command. I use a button 2x tap to send a close command.
I realize that the real shade drivers don't need to worry about this, e.g., they just send a stop command to the shade and it's done. But my driver is acting as the shade, so it's a different scenario.