forked from jens/Automation
wifi trigger
This commit is contained in:
parent
f3613f8eb0
commit
223cca442d
@ -226,7 +226,16 @@ public class Actions
|
|||||||
Map<String,String> map = AutomationService.getInstance().getVariableMap();
|
Map<String,String> map = AutomationService.getInstance().getVariableMap();
|
||||||
|
|
||||||
if(parts.length > 1)
|
if(parts.length > 1)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
map.put(parts[0], Miscellaneous.replaceVariablesInText(parts[1], Miscellaneous.getAnyContext()));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
map.put(parts[0], parts[1]);
|
map.put(parts[0], parts[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
map.remove(parts[0]);
|
map.remove(parts[0]);
|
||||||
}
|
}
|
||||||
|
@ -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-"))
|
while(source.contains("[variable-"))
|
||||||
{
|
{
|
||||||
int pos1 = source.indexOf("[variable-");
|
int pos1 = source.indexOf("[variable-");
|
||||||
|
@ -17,6 +17,8 @@ import com.jens.automation2.Rule;
|
|||||||
import com.jens.automation2.Settings;
|
import com.jens.automation2.Settings;
|
||||||
import com.jens.automation2.Trigger;
|
import com.jens.automation2.Trigger;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class WifiBroadcastReceiver extends BroadcastReceiver
|
public class WifiBroadcastReceiver extends BroadcastReceiver
|
||||||
@ -45,14 +47,14 @@ public class WifiBroadcastReceiver extends BroadcastReceiver
|
|||||||
|
|
||||||
public static void setLastWifiSsid(String newWifiSsid)
|
public static void setLastWifiSsid(String newWifiSsid)
|
||||||
{
|
{
|
||||||
// Remove double quotes
|
// Remove double quotes that sometimes come
|
||||||
if(newWifiSsid.startsWith("\"") && newWifiSsid.endsWith("\""))
|
if(newWifiSsid.startsWith("\"") && newWifiSsid.endsWith("\""))
|
||||||
newWifiSsid = newWifiSsid.substring(1, newWifiSsid.length()-1);
|
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 it's a real name, not an empty string, it's stored as the last ssid
|
||||||
if(newWifiSsid.length() > 0)
|
if(newWifiSsid.length() > 0)
|
||||||
{
|
{
|
||||||
if(newWifiSsid.equals(unknownSsidName))
|
if(!newWifiSsid.equals(unknownSsidName))
|
||||||
WifiBroadcastReceiver.lastWifiSsidReal = lastWifiSsid;
|
WifiBroadcastReceiver.lastWifiSsidReal = lastWifiSsid;
|
||||||
|
|
||||||
WifiBroadcastReceiver.lastWifiSsid = newWifiSsid;
|
WifiBroadcastReceiver.lastWifiSsid = newWifiSsid;
|
||||||
@ -74,6 +76,11 @@ public class WifiBroadcastReceiver extends BroadcastReceiver
|
|||||||
{
|
{
|
||||||
try
|
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;
|
NetworkInfo myWifi = null;
|
||||||
|
|
||||||
if(intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) // fired upon disconnection
|
if(intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) // fired upon disconnection
|
||||||
@ -98,8 +105,8 @@ public class WifiBroadcastReceiver extends BroadcastReceiver
|
|||||||
CellLocationChangedReceiver.stopCellLocationChangedReceiver();
|
CellLocationChangedReceiver.stopCellLocationChangedReceiver();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO: Every time the screen is turned on, we receiver a "wifi has been connected"-event.
|
TODO: Every time the screen is turned on, we receive a "wifi has been connected"-event.
|
||||||
This is technically wrong and not really any changed to when the screen was off. It has
|
This is technically wrong and not really any change to when the screen was off. It has
|
||||||
to be filtered.
|
to be filtered.
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
@ -130,7 +137,7 @@ public class WifiBroadcastReceiver extends BroadcastReceiver
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
wasConnected = false;
|
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;
|
mayCellLocationChangedReceiverBeActivatedFromWifiPointOfView = true;
|
||||||
CellLocationChangedReceiver.startCellLocationChangedReceiver();
|
CellLocationChangedReceiver.startCellLocationChangedReceiver();
|
||||||
lastConnectedState = false;
|
lastConnectedState = false;
|
||||||
|
@ -75,10 +75,12 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis
|
|||||||
|
|
||||||
private static void checkForRules(Context context)
|
private static void checkForRules(Context context)
|
||||||
{
|
{
|
||||||
|
//TODO: Overwrite notification
|
||||||
|
//TODO: Second appointment directly one after another or overlapping won't get executed
|
||||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.calendarEvent);
|
ArrayList<Rule> 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);
|
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);
|
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, nextWakeup.getTimeInMillis(), pi);
|
||||||
wakeupNeedsToBeScheduled = false;
|
wakeupNeedsToBeScheduled = false;
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,12 @@
|
|||||||
android:layout_marginVertical="@dimen/default_margin"
|
android:layout_marginVertical="@dimen/default_margin"
|
||||||
android:text="@string/setVariableExplanation" />
|
android:text="@string/setVariableExplanation" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvLegend"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/urlLegend" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/bSaveVariable"
|
android:id="@+id/bSaveVariable"
|
||||||
android:layout_marginTop="@dimen/default_margin"
|
android:layout_marginTop="@dimen/default_margin"
|
||||||
|
Loading…
Reference in New Issue
Block a user