wifi trigger

This commit is contained in:
Jens 2024-01-06 11:49:49 +01:00
parent f3613f8eb0
commit 223cca442d
5 changed files with 69 additions and 9 deletions

View File

@ -226,7 +226,16 @@ public class Actions
Map<String,String> 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]);
}

View File

@ -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-");

View File

@ -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;

View File

@ -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<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);
}
}
@ -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;
}

View File

@ -61,6 +61,12 @@
android:layout_marginVertical="@dimen/default_margin"
android:text="@string/setVariableExplanation" />
<TextView
android:id="@+id/tvLegend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/urlLegend" />
<Button
android:id="@+id/bSaveVariable"
android:layout_marginTop="@dimen/default_margin"