Package it.freedomotic.reactions

Examples of it.freedomotic.reactions.Command


        //don't mind this method for now
        throw new UnsupportedOperationException("Not supported yet.");
    }

    private String manageMessage(String mess) {
        Command c;
        Trigger t = null;
        Reaction r;
        NaturalLanguageProcessor nlp2 = new NaturalLanguageProcessor();
        //  String sentenceMess[] = nlp.getSentenceDetector().sentDetect(mess);
        String tokenMess[] = mess.split(" "); //nlp.getTokenizer().tokenize(sentenceMess[0]);
        String triggername = "";
        int conditionSep = 0;
        if (tokenMess[0].equalsIgnoreCase(HELP)) {
            return help(tokenMess);
        }
        if (tokenMess[0].equalsIgnoreCase(LIST)) {
            return list(tokenMess);
        }

        if (tokenMess[0].equalsIgnoreCase(IF) || tokenMess[0].equalsIgnoreCase(WHEN)) {
            for (int i = 1; i < tokenMess.length; i++) {
                if (tokenMess[i].equalsIgnoreCase(THEN)) {
                    triggername = unsplit(tokenMess, 1, i - 1, " ");
                    conditionSep = i + 1;
                    break;
                }
            }
            t = TriggerPersistence.getTrigger(triggername);
        }

        String commandName = unsplit(tokenMess, conditionSep, tokenMess.length - conditionSep, " ");
        List<NaturalLanguageProcessor.Rank> mostSimilar = nlp2.getMostSimilarCommand(commandName, 10);
        // user is asking for help
        if (commandName.contains("*")) {
            String response = "";
            for (NaturalLanguageProcessor.Rank nlpr : mostSimilar) {
                response += "? " + nlpr.getCommand().getName() + "\n";
            }
            return response;
        }
        if (!mostSimilar.isEmpty() && mostSimilar.get(0).getSimilarity() > 0) {
            c = mostSimilar.get(0).getCommand();
        } else {
            return "No available commands similar to: " + commandName;
        }
        if (tokenMess[0].equalsIgnoreCase(IF)) {
            Trigger NEWt = t.clone();
            NEWt.setNumberOfExecutions(1);
            r = new Reaction(NEWt, c);
            ReactionPersistence.add(r);
        } else if (tokenMess[0].equalsIgnoreCase(WHEN)) {
            // do something
            r = new Reaction(t, c);
            ReactionPersistence.add(r);
        } else {
            send(c);
            return c.getName() + "\n DONE.";
        }
        return "DONE";
    }
View Full Code Here


        sensor.askSomething();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)    {//GEN-FIRST:event_jButton2ActionPerformed

        Command c = new Command();
        c.setName("Ask user test");
        c.setReceiver("app.actuators.plugins.controller.in");
        c.setProperty("plugin", "Automations Editor");
        c.setProperty("action", "show"); //the default choice

        Freedomotic.sendCommand(c);
        txtResult.setText("Command sent, the GUI should be visible now.");
    }//GEN-LAST:event_jButton2ActionPerformed
View Full Code Here

        txtResult.setText("Command sent, the GUI should be visible now.");
    }//GEN-LAST:event_jButton2ActionPerformed

    private void btnJoinDeviceActionPerformed(java.awt.event.ActionEvent evt)    {//GEN-FIRST:event_btnJoinDeviceActionPerformed

        Command c = new Command();
        c.setName("Join Custom Light Object");
        c.setReceiver("app.objects.create");
        c.setProperty("object.class", "Light");
        c.setProperty("object.name", "Created with JoinDevice");
        c.setProperty("object.protocol", "test");
        c.setProperty("object.address", "test");

        Freedomotic.sendCommand(c);
        txtResult.setText("Command sent, the new object should be on the map");
    }//GEN-LAST:event_btnJoinDeviceActionPerformed
View Full Code Here

    protected void onShowGui() {
        bindGuiToPlugin(new VariousSensorsGui(this));
    }

    public void askSomething() {
        final Command c = new Command();
        c.setName("Ask something silly to user");
        c.setDelay(0);
        c.setExecuted(true);
        c.setEditable(false);
        c.setReceiver("app.actuators.frontend.javadesktop.in");
        c.setProperty("question", "<html><h1>Do you like Freedomotic?</h1></html>");
        c.setProperty("options", "Yes, it's good; No, it sucks; I don't know");
        c.setReplyTimeout(10000); //10 seconds

        new Thread(new Runnable() {
            public void run() {
                VariousSensorsGui guiHook = (VariousSensorsGui) gui;
                Command reply = send(c);

                if (reply != null) {
                    String userInput = reply.getProperty("result");

                    if (userInput != null) {
                        guiHook.updateDescription("The reply to the test question is " + userInput);
                    } else {
                        guiHook.updateDescription("The user has not responded to the question within the given time");
View Full Code Here

        ipCamera = configuration.getStringProperty("camera-url", "http://194.218.96.93/axis-cgi/mjpg/video.cgi?resolution=320x240");
    }

    public void displayVideo() {
        //sends a message to a video player to visualize the stream
        Command playMedia = new Command();
        playMedia.setName("Media Player Request");
        playMedia.setDescription("request to play a media file or web stream");
        playMedia.setReceiver("app.actuators.media.player.in");
        playMedia.setProperty("url", ipCamera);
        playMedia.setProperty("fullscreen", "false");
        playMedia.setProperty("dimension", "from source");
    }
View Full Code Here

                for (EnvironmentLogic env : EnvironmentPersistence.getEnvironments()) {
                    for (Zone z : env.getPojo().getZones()) {
                        if (z.getName().equals(target)) {
                            for (EnvObject obj : z.getObjects()) {
                                if (obj.getType().startsWith(c.getProperty("devType"))) {
                                    Command c2 = CommandPersistence.getCommand("Turn off " + obj.getName());
                                    if (c2 != null) {
                                        send(c2);
                                    }
                                }
                            }
                        }
                    }
                }

            } else if (command.equals("Turn off area devices")) {
                for (EnvironmentLogic env : EnvironmentPersistence.getEnvironments()) {
                    if (env.getPojo().getName().equals(target)) {
                        for (EnvObjectLogic obj : EnvObjectPersistence.getObjectByEnvironment(env.getPojo().getUUID())) {
                            if (obj.getPojo().getType().startsWith(c.getProperty("devType"))) {
                                Command c2 = CommandPersistence.getCommand("Turn off " + obj.getPojo().getName());
                                if (c2 != null) {
                                    send(c2);
                                }
                            }
                        }
View Full Code Here

        String cmdName;
        for (EnvironmentLogic env : EnvironmentPersistence.getEnvironments()) {
            for (Zone z : env.getPojo().getZones()) {
                if (z.isRoom()) {
                    cmdName = "Turn off devices inside room " + z.getName();
                    Command c = CommandPersistence.getCommand(cmdName);
                    if (c != null) {
                        CommandPersistence.remove(c);
                    }
                    c = new Command();
                    c.setReceiver("app.actuators.logging.roomevents.in");
                    c.setName(cmdName);
                    c.setDescription(cmdName);
                    c.setProperty("target", z.getName());
                    c.setProperty("command", "Turn off room devices");
                    c.setProperty("devType", "EnvObject.ElectricDevice");
                    HashSet<String> tags = new HashSet<String>();
                    tags.add("turn");
                    tags.add("off");
                    tags.add("room");
                    tags.add("devices");
                    tags.add(z.getName());
                    c.setTags(tags);
                    CommandPersistence.add(c);
                }
            }
        }
    }
View Full Code Here

        }
    }

    private void logUser() {
        // send command to restart java frontend
        Command c = new Command();
        c.setName("Restart Java frontend");
        c.setReceiver("app.actuators.plugins.controller.in");
        c.setProperty("plugin", master.getName());
        c.setProperty("action", "restart"); //the default choice

        Freedomotic.sendCommand(c);
    }
View Full Code Here

        }
    }//GEN-LAST:event_mnuObjectEditModeActionPerformed

    private void mnuAutomationsActionPerformed(java.awt.event.ActionEvent evt)    {//GEN-FIRST:event_mnuAutomationsActionPerformed

        Command c = new Command();
        c.setName("Popup Automation Editor Gui");
        c.setReceiver("app.actuators.plugins.controller.in");
        c.setProperty("plugin", "Automations Editor");
        c.setProperty("action", "show"); //the default choice

        Freedomotic.sendCommand(c);
    }//GEN-LAST:event_mnuAutomationsActionPerformed
View Full Code Here

        clicked.setPersistence(false);
    }

    @Override
    protected void createCommands() {
                Command setOn = new Command();
        setOn.setName("Update " + getPojo().getName() + "data");
        setOn.setDescription(getPojo().getName() + " requests data update");
        setOn.setReceiver("app.events.sensors.behavior.request.objects");
        setOn.setProperty("object",
                getPojo().getName());
        setOn.setProperty("behavior", BEHAVIOR_DATA);
        setOn.setProperty("value", BooleanBehavior.VALUE_TRUE);
    }
View Full Code Here

TOP

Related Classes of it.freedomotic.reactions.Command

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.