Whilst I do agree this is weird, especially on the different options for display, why don’t you simply use system.perspective.closeDock and system.perspective.openDock ?
system.perspective.toggleDock also exists in case you do not keep track of the state of the dock.
Unless obviously you want to change more parameters, but this is also doable using the functions I mentioned above.
The options for display are the push/cover/auto. Unless it's missing from the documentation I don't know if you can change ondemand to visible during runtime.
I noticed yesterday myself that the documentation for system.perspective.alterDock is wrong for the display settings. I was making a lock/unlock feature for a dock with similar logic to @deon.korb’s script. See the end of this post: