For commands that I want to restrict completely, I override the COMMANDS attribute, to remove the command altogether. But I can see you wanting to restrict only in certain circumstances.
Are the instances that show this being used?
I assume this won't restrict the physical switch... Or is there code to immediately return the device to the restricted state, if the device changes states outside pytomation?