labels and automatizations

This commit is contained in:
Mateusz Gruszczyński
2026-05-06 22:13:52 +02:00
parent e2017b8344
commit a72b6eb364
5 changed files with 70 additions and 34 deletions

View File

@@ -111,8 +111,11 @@ def _conditions_match(conn, rule: dict[str, Any], profile_id: int, t: dict[str,
if not h: return False
immediate_ok = True; delayed_ok = True; now = utcnow(); now_ts = _now_ts()
for cond in rule.get('conditions') or []:
ok = _condition_true(t, cond)
if cond.get('type') == 'no_seeds' and int(cond.get('minutes') or 0) > 0:
raw_ok = _condition_true(t, cond)
negated = bool(cond.get('negate'))
ok = (not raw_ok) if negated else raw_ok
# Note: Conditions can now be negated in automation rules. Timed no-seeds keeps its old delayed behavior only for the positive condition, so old rules do not change.
if cond.get('type') == 'no_seeds' and int(cond.get('minutes') or 0) > 0 and not negated:
row = conn.execute('SELECT condition_since_at FROM automation_rule_state WHERE rule_id=? AND profile_id=? AND torrent_hash=?', (rule['id'], profile_id, h)).fetchone()
if ok:
since = row['condition_since_at'] if row and row.get('condition_since_at') else now