ACtl.switchState
Gets or sets the state of a switch that was created in the
user configuration page.
ACtl.switchState(switchName[,newState]) switchName Type: string
The name of a switch as it appears in the configuration page. The name matching is done ignoring letter case and redundant white spaces.
i.e. My first switch is equivalent to mY FirST SwiTCh
newState Type: boolean | number Default: undefined
If this argument is omitted, the function does nothing; it just returns the switch's current state.
Otherwise, the argument can be:
true: The switch will be turned ON.
false: The switch will be turned OFF.
-1: The switch will be toggled to its opposite state.
Returns Type: Promise Resolves to: boolean | undefined
Returns immediately. The Promise will resolve with the new state of the switch (true or false).
If no switch matches the name given by switchName, undefined is returned.
Example
let switchName = 'My switch 1' ;
//Get the switch's current state
let switchState = await ACtl.switchState(switchName) ;
//If the switch doesn't exist
if( switchState===undefined ){
//Alert and terminate
alert(`'${switchName}' doesn't exist!`) ;
}else{
//Show its current state
alert(`'${switchName}' is currently ${switchState ? 'ON' : 'OFF'}`) ;
//Toggle it to its opposite state
switchState = await ACtl.switchState(switchName, -1) ;
//Show the new state
alert(`'${switchName}' is now ${switchState ? 'ON' : 'OFF'}`) ;
}