Материал из Module developer
Перейти к: навигация, поиск

SubDevice.addAction()

to add Action

Syntax

Module.getSubDevice(SubDeviceName).addAction(Action)

input sample description
Action type: object
the Action object
Action field: Name "MyAction" type: string
the action name
Action field: ActionType "Simple" type: string
the action typeː "Simple" or "Advanced"
Action field: Type "send_number" type: string
the type of the action command: "send_number", "send_text" or "script_call"
Action field: Param [{id_sub: 1, set: 100}] type: data
the data to be sent to the channel. For "script_call" an array of objects is sent (1 object - 1 parameter in the "Method" function)
Action field: ChannelName "Dimmer:channel1" type: string
the channel name, it is not used in the "script_call" action
Action field: Space this type: Object
the space for the function call
Action field: Method function type: function
the executed function, only for "script_call"
output
Оbject type: Object
объект Action


Example:

Module = B.getModule(ModuleID);
sub = Module.getSubDevice("MySub");
channelName1 = "GRPS:myChannel" // full channel name for device "GPRS" and his channel "myChannel"
sub.addAction({  // create "send_number" action                                                              
            ActionType: "Simple",  
            Type: "send_number",   
            Param: SMSnumber, 
            ChannelName: channelName1,
            Name: "Send " + SMSnumber    
         });
sub.addAction({ // create "script_call" action                                                          
             ActionType: "Simple", 
             Type: "script_call", 
             Param: [{id_sub: 1, set: 100}], 
             Space: this,
             Method: HUE_changeLight,
             Name: "Turn On"
          });