fix: let thresholds suppress force refresh
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user