From 6d3e81307c53744cee0c996fce6a0f3e8451850b Mon Sep 17 00:00:00 2001 From: Giovanni Harting <539@idlegandalf.com> Date: Sun, 9 Nov 2025 02:56:12 +0100 Subject: [PATCH] fix: let thresholds suppress force refresh --- scripts/ac-power.lua | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/scripts/ac-power.lua b/scripts/ac-power.lua index 5c2281d..f28cc3b 100644 --- a/scripts/ac-power.lua +++ b/scripts/ac-power.lua @@ -18,6 +18,7 @@ local CONFIG = { min_delta_watts = 5, -- only show when change ≥ delta min_delta_percent = 0, -- optional % change relative to last reading force_refresh_interval = 30, -- seconds, even if delta small + force_refresh_obeys_threshold = true, -- skip force refresh when thresholds active display_label = "AC Power", units_label = "W", use_sensor_unit = true, -- prefer HA provided unit if any @@ -154,6 +155,10 @@ local function meets_delta_threshold(value) return false end +local function thresholds_enabled() + return (CONFIG.min_delta_watts or 0) > 0 or (CONFIG.min_delta_percent or 0) > 0 +end + local function handle_success(value, payload) backoff_failures = 0 local now = mp.get_time() @@ -163,7 +168,18 @@ local function handle_success(value, payload) and (now - last_display_ts) >= CONFIG.force_refresh_interval local significant_change = meets_delta_threshold(value) - if significant_change or force_due or last_watts == nil then + local should_render = significant_change or last_watts == nil + if not should_render and force_due then + local allow_force = true + if thresholds_enabled() and CONFIG.force_refresh_obeys_threshold then + allow_force = false + end + if allow_force then + should_render = true + end + end + + if should_render then show_value(printable, unit) last_unit = unit last_watts = value