Keep record of number of times a rule was applied

This commit is contained in:
M66B
2019-10-19 16:02:28 +02:00
parent e392447a5f
commit 8d760b2acd
6 changed files with 1979 additions and 4 deletions

View File

@@ -85,6 +85,8 @@ public class EntityRule {
public String condition;
@NonNull
public String action;
@NonNull
public Integer applied = 0;
static final int TYPE_SEEN = 1;
static final int TYPE_UNSEEN = 2;
@@ -276,6 +278,15 @@ public class EntityRule {
}
boolean execute(Context context, EntityMessage message) throws JSONException, IOException {
boolean executed = _execute(context, message);
if (executed) {
DB db = DB.getInstance(context);
db.rule().applyRule(id);
}
return executed;
}
private boolean _execute(Context context, EntityMessage message) throws JSONException, IOException {
JSONObject jaction = new JSONObject(action);
int type = jaction.getInt("type");
Log.i("Executing rule=" + type + ":" + name + " message=" + message.id);
@@ -524,7 +535,8 @@ public class EntityRule {
this.enabled == other.enabled &&
this.stop == other.stop &&
this.condition.equals(other.condition) &&
this.action.equals(other.action);
this.action.equals(other.action) &&
this.applied.equals(other.applied);
} else
return false;
}