Trying to fix HA

This commit is contained in:
2026-04-13 00:52:33 +02:00
parent dcd8bfda4c
commit f5d5c916b4

View File

@@ -312,8 +312,6 @@ status_led_green = [False for _ in range(num_gauges)]
_bl_dirty_since = None
_BL_SAVE_DELAY_MS = 5000
_disco_saved_color = [[0, 0, 0] for _ in range(num_gauges)]
def _publish(topic, payload, retain=False):
@@ -366,6 +364,30 @@ def on_message(topic, payload):
info("All gauges zeroed")
return
if topic == T_SET:
try:
data = ujson.loads(payload)
if isinstance(data, dict):
for i, val in enumerate(data.values()):
if i < len(gauges):
g = gauges[i]
gauge_targets[i] = max(g["min"], min(g["max"], float(val)))
info(f"Gauge {i} target → {gauge_targets[i]:.1f}")
else:
val = float(payload)
for i in range(len(gauges)):
gauge_targets[i] = max(gauges[i]["min"], min(gauges[i]["max"], val))
info(f"All gauges target → {val:.1f}")
except Exception:
try:
val = float(payload)
for i in range(len(gauges)):
gauge_targets[i] = max(gauges[i]["min"], min(gauges[i]["max"], val))
info(f"All gauges target → {val:.1f}")
except:
warn(f"Invalid set value: '{payload}'")
return
if topic == T_RESET_DISCOVERY:
info("Reset discovery triggered")
try:
@@ -619,25 +641,6 @@ def publish_discovery(client):
client.check_msg()
utime.sleep_ms(10)
client.publish(
gt["led_green_disc"],
ujson.dumps(
{
"name": f"{g['name']} Green LED",
"uniq_id": f"{MQTT_CLIENT_ID}_g{i}_green",
"cmd_t": gt["led_green"],
"stat_t": gt["led_green_state"],
"pl_on": "ON",
"pl_off": "OFF",
"icon": "mdi:led-on",
"dev": _dev_ref,
"ret": True,
}
),
retain=True,
)
info(f"Discovery: gauge {i} green LED")
client.publish(
gt["led_bl_disc"],
ujson.dumps(