diff --git a/app/src/main/java/com/jens/automation2/Actions.java b/app/src/main/java/com/jens/automation2/Actions.java index b2dd833..b9fa566 100644 --- a/app/src/main/java/com/jens/automation2/Actions.java +++ b/app/src/main/java/com/jens/automation2/Actions.java @@ -226,7 +226,16 @@ public class Actions Map map = AutomationService.getInstance().getVariableMap(); if(parts.length > 1) - map.put(parts[0], parts[1]); + { + try + { + map.put(parts[0], Miscellaneous.replaceVariablesInText(parts[1], Miscellaneous.getAnyContext())); + } + catch (Exception e) + { + map.put(parts[0], parts[1]); + } + } else map.remove(parts[0]); } diff --git a/app/src/main/java/com/jens/automation2/Miscellaneous.java b/app/src/main/java/com/jens/automation2/Miscellaneous.java index 1c83882..652973d 100644 --- a/app/src/main/java/com/jens/automation2/Miscellaneous.java +++ b/app/src/main/java/com/jens/automation2/Miscellaneous.java @@ -807,6 +807,42 @@ public class Miscellaneous extends Service } } + if(source.contains("[last_trigger_url_result]")) + { + try + { + source = source.replace("[last_trigger_url_result]", AutomationService.getInstance().getVariableMap().get("last_trigger_url_result")); + } + catch (Exception e) + { + Miscellaneous.logEvent("w", "Variable replacement", "Error replacing variable last_trigger_url_result.", 3); + } + } + + if(source.contains("[last_run_executable_exit_code]")) + { + try + { + source = source.replace("[last_run_executable_exit_code]", AutomationService.getInstance().getVariableMap().get("last_run_executable_exit_code")); + } + catch (Exception e) + { + Miscellaneous.logEvent("w", "Variable replacement", "Error replacing variable last_run_executable_exit_code.", 3); + } + } + + if(source.contains("[last_run_executable_output]")) + { + try + { + source = source.replace("[last_run_executable_output]", AutomationService.getInstance().getVariableMap().get("last_run_executable_output")); + } + catch (Exception e) + { + Miscellaneous.logEvent("w", "Variable replacement", "Error replacing variable last_run_executable_output.", 3); + } + } + while(source.contains("[variable-")) { int pos1 = source.indexOf("[variable-"); diff --git a/app/src/main/java/com/jens/automation2/location/WifiBroadcastReceiver.java b/app/src/main/java/com/jens/automation2/location/WifiBroadcastReceiver.java index 7366009..1a81d04 100644 --- a/app/src/main/java/com/jens/automation2/location/WifiBroadcastReceiver.java +++ b/app/src/main/java/com/jens/automation2/location/WifiBroadcastReceiver.java @@ -17,6 +17,8 @@ import com.jens.automation2.Rule; import com.jens.automation2.Settings; import com.jens.automation2.Trigger; +import org.apache.commons.lang3.StringUtils; + import java.util.ArrayList; public class WifiBroadcastReceiver extends BroadcastReceiver @@ -45,14 +47,14 @@ public class WifiBroadcastReceiver extends BroadcastReceiver public static void setLastWifiSsid(String newWifiSsid) { - // Remove double quotes + // Remove double quotes that sometimes come if(newWifiSsid.startsWith("\"") && newWifiSsid.endsWith("\"")) newWifiSsid = newWifiSsid.substring(1, newWifiSsid.length()-1); // If it's a real name, not an empty string, it's stored as the last ssid if(newWifiSsid.length() > 0) { - if(newWifiSsid.equals(unknownSsidName)) + if(!newWifiSsid.equals(unknownSsidName)) WifiBroadcastReceiver.lastWifiSsidReal = lastWifiSsid; WifiBroadcastReceiver.lastWifiSsid = newWifiSsid; @@ -74,6 +76,11 @@ public class WifiBroadcastReceiver extends BroadcastReceiver { try { + if(!StringUtils.isEmpty(intent.getAction())) + Miscellaneous.logEvent("i", "WifiReceiver", "Received signal with action \""+ intent.getAction() + "\".", 4); + else + Miscellaneous.logEvent("i", "WifiReceiver", "Received signal with empty action.", 4); + NetworkInfo myWifi = null; if(intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) // fired upon disconnection @@ -98,8 +105,8 @@ public class WifiBroadcastReceiver extends BroadcastReceiver CellLocationChangedReceiver.stopCellLocationChangedReceiver(); /* - TODO: Every time the screen is turned on, we receiver a "wifi has been connected"-event. - This is technically wrong and not really any changed to when the screen was off. It has + TODO: Every time the screen is turned on, we receive a "wifi has been connected"-event. + This is technically wrong and not really any change to when the screen was off. It has to be filtered. */ } @@ -130,7 +137,7 @@ public class WifiBroadcastReceiver extends BroadcastReceiver try { wasConnected = false; - Miscellaneous.logEvent("i", "WifiReceiver", String.format(context.getResources().getString(R.string.disconnectedFromWifi), getLastWifiSsid()) + " Switching to CellLocationChangedReceiver.", 3); + Miscellaneous.logEvent("i", "WifiReceiver", "Disconnected from wifi \"" + getLastWifiSsid() + "\". Switching to CellLocationChangedReceiver.", 3); mayCellLocationChangedReceiverBeActivatedFromWifiPointOfView = true; CellLocationChangedReceiver.startCellLocationChangedReceiver(); lastConnectedState = false; diff --git a/app/src/main/java/com/jens/automation2/receivers/CalendarReceiver.java b/app/src/main/java/com/jens/automation2/receivers/CalendarReceiver.java index f73832a..1c251ec 100644 --- a/app/src/main/java/com/jens/automation2/receivers/CalendarReceiver.java +++ b/app/src/main/java/com/jens/automation2/receivers/CalendarReceiver.java @@ -75,10 +75,12 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis private static void checkForRules(Context context) { + //TODO: Overwrite notification + //TODO: Second appointment directly one after another or overlapping won't get executed ArrayList ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.calendarEvent); - for(int i = 0; i < ruleCandidates.size(); i++) + for (int i = 0; i < ruleCandidates.size(); i++) { - if(ruleCandidates.get(i).getsGreenLight(context)) + if (ruleCandidates.get(i).getsGreenLight(context)) ruleCandidates.get(i).activate(AutomationService.getInstance(), false); } } @@ -340,7 +342,7 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis { } - Miscellaneous.logEvent("i", "armOrRearmTimer()", "Scheduling wakeup for calendar at " + Miscellaneous.formatDate(nextWakeup.getTime()), 5); + Miscellaneous.logEvent("i", "armOrRearmTimer()", "Scheduling wakeup for calendar at " + Miscellaneous.formatDate(nextWakeup.getTime()), 4); alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, nextWakeup.getTimeInMillis(), pi); wakeupNeedsToBeScheduled = false; } diff --git a/app/src/main/res/layout/activity_manage_action_set_variable.xml b/app/src/main/res/layout/activity_manage_action_set_variable.xml index 30f00bf..22ae7c3 100644 --- a/app/src/main/res/layout/activity_manage_action_set_variable.xml +++ b/app/src/main/res/layout/activity_manage_action_set_variable.xml @@ -61,6 +61,12 @@ android:layout_marginVertical="@dimen/default_margin" android:text="@string/setVariableExplanation" /> + +