webui: use partial status polling

This commit is contained in:
2026-06-07 19:13:39 -06:00
parent 512a1aa302
commit e7965f4b99
2 changed files with 31 additions and 3 deletions
@@ -240,6 +240,22 @@ input{width:100%;border:1px solid var(--line);border-radius:12px;padding:12px;ba
<script>
const API_BASE="/api/v1";
function api(path){return API_BASE+path;}
const STATUS_FIELDS_OVERVIEW="battery,temps,relays,vehicle,network,alarms,system";
function isConfigTabActive(){
return $("configPage")?.classList.contains("active") || false;
}
function statusUrl(){
const needsFullStatus=isConfigTabActive() || !window.lastStatus?.config;
return needsFullStatus ? api("/status") : api("/status?fields="+STATUS_FIELDS_OVERVIEW);
}
function mergeStatus(previous,next){
if(!previous) return next;
return Object.assign({},previous,next);
}
const $=id=>document.getElementById(id);
function fmt(n,d=1){return typeof n==="number"?n.toFixed(d):"--"}
function temp(v){return typeof v==="number"?fmt(v,1)+"°F":"Offline"}
@@ -332,6 +348,7 @@ async function relay(id,on){
await load();
}
function render(data){
data=mergeStatus(window.lastStatus,data);
window.lastStatus=data;
$("conn").textContent="Live";
$("conn").className="pill good";
@@ -562,7 +579,7 @@ function renderConfigControls(data){
}
async function saveRelayConfig(){
const r=await fetch(api("/status"),{cache:"no-store"});
const r=await fetch(api("/status?fields=config"),{cache:"no-store"});
const data=await r.json();
const relays=data.config?.relays||[];
@@ -587,7 +604,7 @@ async function saveRelayConfig(){
}
async function saveTempConfig(){
const r=await fetch(api("/status"),{cache:"no-store"});
const r=await fetch(api("/status?fields=config"),{cache:"no-store"});
const data=await r.json();
const temps=data.config?.temperature_sensors||[];
@@ -649,7 +666,7 @@ async function connectWifi(){
}
async function load(){
try{
const r=await fetch(api("/status"),{cache:"no-store"});
const r=await fetch(statusUrl(),{cache:"no-store"});
render(await r.json());
}catch(e){
$("conn").textContent="Offline";