Backlight retention re-added
This commit is contained in:
@@ -397,6 +397,36 @@ def set_status_led(gauge_idx, led_type, state):
|
|||||||
leds_bl.write()
|
leds_bl.write()
|
||||||
|
|
||||||
|
|
||||||
|
def publish_backlight_states(client):
|
||||||
|
"""Publish current backlight state for all gauges as retained MQTT messages."""
|
||||||
|
for i in range(num_gauges):
|
||||||
|
gt = gauge_topics[i]
|
||||||
|
r, g, b = backlight_color[i]
|
||||||
|
brightness = backlight_brightness[i]
|
||||||
|
state = {
|
||||||
|
"state": "ON" if backlight_on[i] else "OFF",
|
||||||
|
"color_mode": "rgb",
|
||||||
|
"brightness": int(brightness * 2.55),
|
||||||
|
"color": {"r": r, "g": g, "b": b},
|
||||||
|
}
|
||||||
|
try:
|
||||||
|
client.publish(gt["led_bl_state"], ujson.dumps(state), retain=True)
|
||||||
|
except Exception as e:
|
||||||
|
log_err(f"Backlight state publish failed for gauge {i}: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
def _flush_backlight_state():
|
||||||
|
global _bl_dirty_since
|
||||||
|
if _bl_dirty_since is None:
|
||||||
|
return
|
||||||
|
if utime.ticks_diff(utime.ticks_ms(), _bl_dirty_since) < _BL_SAVE_DELAY_MS:
|
||||||
|
return
|
||||||
|
if client_ref is None:
|
||||||
|
return
|
||||||
|
publish_backlight_states(client_ref)
|
||||||
|
_bl_dirty_since = None
|
||||||
|
info("Backlight state flushed to MQTT")
|
||||||
|
|
||||||
|
|
||||||
def _publish(topic, payload, retain=False):
|
def _publish(topic, payload, retain=False):
|
||||||
"""Safely publish MQTT message, returning True on success."""
|
"""Safely publish MQTT message, returning True on success."""
|
||||||
|
|||||||
Reference in New Issue
Block a user