dashboard: refresh relay status immediately after command

This commit is contained in:
2026-06-09 23:03:05 -06:00
parent 8daba01bbb
commit cc4495c1fa
@@ -10,7 +10,7 @@
using namespace esp_panel::drivers; using namespace esp_panel::drivers;
using namespace esp_panel::board; using namespace esp_panel::board;
static const char *DASHBOARD_VERSION = "0.0.5-relay-control"; static const char *DASHBOARD_VERSION = "0.0.6-immediate-relay-refresh";
// Update these if your Cargo ESP AP credentials are different. // Update these if your Cargo ESP AP credentials are different.
static const char *CARGO_WIFI_SSID = "OverlandController"; static const char *CARGO_WIFI_SSID = "OverlandController";
@@ -72,7 +72,7 @@ static String on_off(bool value)
return value ? "ON" : "OFF"; return value ? "ON" : "OFF";
} }
static void force_status_poll_soon() static void force_status_poll_now()
{ {
last_status_poll_ms = 0; last_status_poll_ms = 0;
} }
@@ -137,10 +137,22 @@ static void relay_button_event_cb(lv_event_t *event)
bool ok = post_relay_state(relay_id, next_state); bool ok = post_relay_state(relay_id, next_state);
String result_text = ok ? "Relay command sent\nRefreshing status..." : "Relay command failed"; if (ok) {
set_label_text_if_changed(system_label, last_system_text, result_text); relay_states[index] = next_state;
update_relay_buttons();
force_status_poll_soon(); String optimistic_text = "Relay command sent\n";
optimistic_text += relay_id;
optimistic_text += " -> ";
optimistic_text += on_off(next_state);
optimistic_text += "\nRefreshing status...";
set_label_text_if_changed(system_label, last_system_text, optimistic_text);
force_status_poll_now();
poll_status_api();
} else {
set_label_text_if_changed(system_label, last_system_text, "Relay command failed");
}
} }
static void update_relay_buttons() static void update_relay_buttons()