Well, @thebells. I fiddled with this some tonight and I re-learned and remembered some of the reasons why this was setup the way it was. And we were both wrong sort of about how the switch behaves I think.
The way the firmware behaves without any motivation from the driver is:
- Single-tap up: Previous level
- Single-tap down: One step down (33% if 3 speed or 25% if 4 speed)
- All other taps nothing except send event but no action performed
So when we are seeing the switch go up AND down one level is because the switch was last turned off physically and the last level was really the lowest. However, if you setLevel(99) from the driver and then off() from the driver. Then single-tap up it will resume to 99. If you hit single-tap down it will go to 66 or 75 depending on what speed type you have set. If you were to off it at that point it would resume to 66/75 with a single tap up again. It's weird.
So... because of this we don't need a single tap up behavior change. The one preference we have to set to full on single-tap is enough because the default behavior is to go to last level.
What we need is a preference to single-tap down... and unfortunately, we are not going to be able to do it. With single-tap up to full we know the target because full is 100 (really 99). But going down we don't because the target depends on where we are. Here is an example of what happens. Let's say the switch is at 75%.
- Switch is on and level is 75
- Single tap down (physical)
- Firmware moves level to 50 internally
- Firmware sends the tap event and level event nearly simultaneously but no guarantee which comes first at least as far as I could tell from my logs. There may be an order but the way that driver instances start up I was seeing them switch orders
- From the level event I don't know if the tap event has come first and vice versa. I could put a bunch of logic in there to check but it would be error prone, complicated and not worth it. Since I don't know if the level has already moved or not I don't know what to save as the last level or what to return to since the internal level of the firmware will have been 50 but really in the software (driver) I need to tell it 75. But I wouldn't know if it was really 75 or 50 because I don't know when I look at the level if I'm seeing it set yet. I think that's what's happening anyway.
So, instead of messing around with that, I added more functionality to the double tap since it won't do anything to the level. I changed double tap down to have two options; one that goes to 25% as before and one that goes to off. I think that's the best we can do.
At this point it will be a small training exercise for your users. Single tap turns it on to previous level but to turn off they will have to learn to double-tap down.
What do you think? If we can't come up with anything better I'll push these changes once I get a question about the firmware not showing up correctly and another feature I want to implement.