The Commands API lets you expose commands of your plugin to be used by other plugins or by other Qatium components, like Q, our digital assistant .
addCommand()
Allows the plugin to expose commands to be used by other components: Digital assistant (Q), other plugins, other Qatium components, etc.
Method signature
type CommandDescription = <
Receives extends Record < string , string >,
Returns extends Record < string , unknown >
returnType : Record < keyof Returns , string >;
type CommandAnswer< Returns extends Record < string , unknown >> = {
addCommand < Receives , Returns >(
description: CommandDescription < Receives, Returns > ,
fn: ( args : Record < keyof Receives , string > ) => Promise < CommandAnswer < Returns >>
class CommandDescription :
returnType: Dict[ str , str ]
data: Optional[Dict[ str , Any]] = None
add_command ( description: Dict [ str , Any ] , fn: CommandFn ) -> None
Parameters
description: CommandDescription<Receives, Returns>
:
name: The name of the command.
description: A description of the command.
aliases: A list of aliases for the command.
arguments: An object describing the arguments your command will receive.
returnType: An object describing the returned result type.
const commandDescription = {
description: " It closes valves from the network " ,
aliases: [ " shutdown valves " , " close TCV " , " close shut-off valves " ] ,
numOfValves: " number of valves to close "
valvesClosed: " how many valves the command was able to close "
description = CommandDescription (
description = ' It closes valves from the network ' ,
aliases = [ ' shutdown valves ' , ' close TCV ' , ' close shut-off valves ' ],
' numOfValves ' : ' number of valves to close '
' valvesClosed ' : ' how many valves the command was able to close '
fn: <Receives, Returns>(args: Record<keyof Receives, string>) => Promise<CommandAnswer<Returns>>
: It will perform the command and then return a Promise<CommandAnswer>
:
type CommandAnswer< Returns > = {
* The data returned by the command.
* It should match the keys in { @link CommandDescription.returnType }
* Whether or not to open the plugin panel after the command succeeds.
data: Optional[Dict[ str , Any]] = None
// A command that sets the demand of a junction
type Receives = { junctionId : string ; demand : string };
type Returns = { junctionId : string ; newDemand : string };
const setJunctionDemandCommand : CommandFn < Receives , Returns > = async ( args ) => {
const { junctionId , demand } = args ;
sdk . network . setDemand (junctionId , demand) ;
async def set_junction_demand ( args ) :
junction_id = args[ ' junction_id ' ]
sdk.network. set_demand ( junction_id , demand )
' junction_id ' : junction_id,
Example
name: " Set junction demand " ,
description: " sets the demand of a junction " ,
" increase flow in junction " ,
junctionId: " the id of the junction " ,
demand: " the new demand of the junction "
junctionId: " the id of the junction " ,
newDemand: " the new demand of the junction "
const { junctionId , demand } = args;
sdk . network . setDemand (junctionId, Number (demand));
" name " : " Set junction demand " ,
" description " : " sets the demand of a junction " ,
" increase flow in junction " ,
junctionId: " the id of the junction " ,
demand: " the new demand of the junction "
junctionId: " the id of the junction " ,
newDemand: " the new demand of the junction "
availableCommands()
Returns the available commands to call. You can use this method to connect your plugin with other plugins, or with other Qatium components.
Usually you would connect two plugins you own, so they can interact with each other.
Method signature
availableCommands () : Command[]
available_commands () -> List[Command]