Only preview notifications for rules that would act

This commit is contained in:
Sterling Archer committed 2026-08-12 09:54:23 -07:00
1 parent d66cc59244
commit 2a9e9cda4c
1 file changed
+24 -11
+24 -11
View File
@@ -969,6 +969,9 @@ def _print_rule_table(
states = engine.states if engine else None states = engine.states if engine else None
for index, rule in enumerate(profile.active_rules()): for index, rule in enumerate(profile.active_rules()):
acting = False
errored = False
if states: if states:
state = states[index] state = states[index]
satisfied = state.last_value satisfied = state.last_value
@@ -976,36 +979,46 @@ def _print_rule_table(
ripe = state.ripe(now) if now else False ripe = state.ripe(now) if now else False
if state.error: if state.error:
verdict = f"ERROR {state.error}" verdict = f"ERROR {state.error}"
errored = True
elif not satisfied: elif not satisfied:
verdict = "false" verdict = "no"
elif ripe: elif ripe:
verdict = f"TRUE and ripe -> would {rule.action}" verdict = f"YES, ready now -> would {rule.action}"
acting = True
else: else:
remaining = (rule.dwell or 0) - held remaining = (rule.dwell or 0) - held
verdict = f"true, waiting {format_duration(remaining)} of dwell" verdict = (
f"YES, holding {format_duration(remaining)} more before acting"
)
acting = True
else: else:
try: try:
satisfied = rule.evaluate(variables) satisfied = rule.evaluate(variables)
verdict = ( if satisfied:
f"true -> would {rule.action} after {format_duration(rule.dwell)}" verdict = (
if satisfied f"YES -> would {rule.action} after "
else "false" f"{format_duration(rule.dwell)}"
) )
acting = True
else:
verdict = "no"
except Exception as err: except Exception as err:
verdict = f"ERROR {type(err).__name__}: {err}" verdict = f"ERROR {type(err).__name__}: {err}"
errored = True
print(f" [{rule.priority:>3}] {rule.name}") marker = " *" if acting else (" " if not errored else " !")
print(f" {marker} [{rule.priority:>3}] {rule.name}")
print(f" when {rule.when_source}") print(f" when {rule.when_source}")
print(f" {verdict}") print(f" {verdict}")
desired = rule.desired_state() desired = rule.desired_state()
if desired is not None: if acting and desired is not None:
if engine: if engine:
message = _render_live_notification(engine, rule, variables, desired) message = _render_live_notification(engine, rule, variables, desired)
else: else:
message = _preview_notification(profile, rule, variables, desired) message = _preview_notification(profile, rule, variables, desired)
if message: if message:
print(f" notify: {message}") print(f" would notify: {message}")
def _render_live_notification(engine, rule, variables, desired): def _render_live_notification(engine, rule, variables, desired):