cbitstech / Purple-Robot

Sensing and automation platform for Android.
Other
38 stars 19 forks source link

PurpleRobot.updateTrigger breaking on second parameter #185

Closed estory1 closed 11 years ago

estory1 commented 11 years ago

As a PR 1.2.1 user running scripts on PR via the /test.html page, when I use the script found in [1.s], I get the error in [1.e].

The same error occurs given the code sample in [2.s].

The PR JS documentation shows the updateTrigger function takes an object as the second parameter, so when I try [3.s], I get the error message in [3.e]

Thoughts? Mark and I both looked at this...

[1.s] (second parameter as JS string)

{
    "command": "execute_script",
    "script": " var trigger_initial_date = new Date();
      var trigger_array = [];
      trigger_array[0] = {};
      trigger_array[0].type = 'datetime';
      trigger_array[0].name = 'FOCUS Window #1 - 9a-1p';
      trigger_array[0].identifier = 'FOCUS1';
      trigger_array[0].datetime_start = trigger_initial_date.setHours(9);
      trigger_array[0].datetime_end = trigger_initial_date.setHours(13);
      trigger_array[0].action = \"'PurpleRobot.vibrate('blip'); PurpleRobot.playDefaultTone(); PurpleRobot.showNativeDialog('FOCUS', 'Can you check in with FOCUS right now?', 'YES', 'NO', 'var string_text =\\'loadPrompt\\';PurpleRobot.persistString(\\'load_prompt\\',string_text);PurpleRobot.launchApplication(\\'com.cbits.focus\\', {}, null);', 'PurpleRobot.emitToast(\\'Thanks, we will check in later!\\', true)');';\"
      trigger_array[0].datetime_repeat = 'FREQ=DAILY;INTERVAL=1';
PurpleRobot.updateTrigger(trigger_array[0].name, JSON.stringify(trigger_array[0]));
"
}

[1.e]

{
  "message": "org.mozilla.javascript.EvaluatorException: Can't find method edu.northwestern.cbits.purple_robot_manager.scripting.JavaScriptEngine.updateTrigger(string,string). (<engine>#11)",
  "command": "execute_script",
  "status": "error"
}

[2.s] (second parameter as JS string)

{
    "command": "execute_script",
    "script": "var t = { 'identifier': 'MedPrompt: medA at 09:00:00',
                            'type': 'datetime',
                            'name': 'MedPrompt: medA at 09:00:00',
                            'action': 'PurpleRobot.log(\"TAKE YOUR MEDS\");',
                            'datetime_start': '20130422T143018',
                            'datetime_end': '20130422T143118'
};
PurpleRobot.updateTrigger('MedPrompt: medA at 09:00:00', JSON.stringify(t));
"
}

[3.s] (second parameter as JS object)

{
    "command": "execute_script",
    "script": "var t = { 'identifier': 'MedPrompt: medA at 09:00:00',
                            'type': 'datetime',
                            'name': 'MedPrompt: medA at 09:00:00',
                            'action': 'PurpleRobot.log(\"TAKE YOUR MEDS\");',
                            'datetime_start': '20130422T143018',
                            'datetime_end': '20130422T143118'
};
PurpleRobot.updateTrigger('MedPrompt: medA at 09:00:00', t);
"
}

[3.e]

{
  "message": "org.mozilla.javascript.WrappedException: Wrapped java.lang.NullPointerException (<engine>#8)",
  "command": "execute_script",
  "status": "error"
}
audaciouscode commented 11 years ago

One initial note: The second param should always be an object. In the example file, I stringify the object because I'm building a script. Within the context of the script itself, the second argument should always be an object.

audaciouscode commented 11 years ago

Fixed in 1.2.2.