In the command provider, implement the following methods for handling commands, which are used by the Home Automation Manager:
If you are using the basic implementation of command provider, proceed in the following way:
You don't need to implement the getCommands() method - it is already implemented in the base command provider.
The following example shows a command provider for the DemoCommand command type, which prints in the system output the value of its only configuration property:
package demo.command.impl;
import java.util.Map;
import com.prosyst.mbs.services.configtree.CftException;
import com.prosyst.mbs.services.configtree.ConfigNode;
import com.prosyst.mbs.services.ham.Command;
import com.prosyst.mbs.services.ham.spi.CommandProvider;
import com.prosyst.mbs.services.ham.util.BaseCommand;
import com.prosyst.mbs.services.ham.util.BaseHAObject;
import com.prosyst.mbs.services.ham.util.BaseCommandProvider;
import com.prosyst.util.ref.Log;
import demo.command.serv.DemoCommandInt;
public class DemoCommandProvider extends BaseCommandProvider implements
CommandProvider {
static Log log = new Log(Activator.getContext());
// The command provider constructor
public DemoCommandProvider() {
super(DemoCommandInt.TYPE, log);
}
// Creates a new command instance, by calling the first constructor of the Command class.
public Command createCommand() {
DemoCommand comm = new DemoCommand(this);
return comm;
}
// Provides a command by specified ID by retrieving the node that contains the command's configuration...
public synchronized final Command getCommand(String id) {
ConfigNode cmdNode = getHAObjectConfig(id);
DemoCommand cmd = null;
if (cmdNode != null) {
try {
// ...and creates a new command object from that node..
cmd = new DemoCommand(this, cmdNode);
} catch (CftException e) {
}
}
return cmd;
}
//Executes the command (prints the value of its property) and returns an OK status.
protected String runCommand(BaseCommand command, Map params)
throws Exception {
DemoCommand commandCast = ((DemoCommand) command);
System.out.println("The value of " + commandCast.PROP_1 + " is "+ commandCast.getProp());
return command.STATUS_OK;
}
}