dashboard: add temperature group priority
This commit is contained in:
@@ -39,7 +39,8 @@ void loadDefaultConfig() {
|
||||
"",
|
||||
i < appConfig.tempSensorCount,
|
||||
false,
|
||||
"cabin"
|
||||
"cabin",
|
||||
i + 1
|
||||
};
|
||||
}
|
||||
|
||||
@@ -106,6 +107,10 @@ void loadConfig() {
|
||||
(prefix + "group").c_str(),
|
||||
appConfig.tempSensors[i].group
|
||||
);
|
||||
appConfig.tempSensors[i].priority = preferences.getInt(
|
||||
(prefix + "priority").c_str(),
|
||||
appConfig.tempSensors[i].priority
|
||||
);
|
||||
}
|
||||
|
||||
appConfig.bms.enabled = preferences.getBool("bms_enabled", appConfig.bms.enabled);
|
||||
@@ -142,6 +147,7 @@ void saveConfig() {
|
||||
preferences.putBool((prefix + "enabled").c_str(), appConfig.tempSensors[i].enabled);
|
||||
preferences.putBool((prefix + "weather").c_str(), appConfig.tempSensors[i].weather);
|
||||
preferences.putString((prefix + "group").c_str(), appConfig.tempSensors[i].group);
|
||||
preferences.putInt((prefix + "priority").c_str(), appConfig.tempSensors[i].priority);
|
||||
}
|
||||
|
||||
preferences.putBool("bms_enabled", appConfig.bms.enabled);
|
||||
@@ -195,7 +201,9 @@ void printConfig() {
|
||||
Serial.print(" / address ");
|
||||
Serial.print(appConfig.tempSensors[i].address);
|
||||
Serial.print(" / group ");
|
||||
Serial.println(appConfig.tempSensors[i].group);
|
||||
Serial.print(appConfig.tempSensors[i].group);
|
||||
Serial.print(" / priority ");
|
||||
Serial.println(appConfig.tempSensors[i].priority);
|
||||
}
|
||||
|
||||
Serial.println(" BMS:");
|
||||
|
||||
@@ -23,6 +23,7 @@ struct TempSensorConfig {
|
||||
bool enabled;
|
||||
bool weather;
|
||||
String group;
|
||||
int priority;
|
||||
};
|
||||
|
||||
struct BmsConfig {
|
||||
|
||||
@@ -1192,6 +1192,9 @@ function renderConfigControls(data){
|
||||
<option value="other">Other</option>
|
||||
</select>
|
||||
|
||||
<label class="inputHelp" for="tempPriority${i}">Priority</label>
|
||||
<input id="tempPriority${i}" type="number" min="1" max="99" step="1" placeholder="1" oninput="markConfigFieldTouched('tempPriority${i}')">
|
||||
|
||||
<div class="tempConfigControls">
|
||||
<label class="tempCheck">
|
||||
<input id="tempEnabled${i}" type="checkbox" onchange="markConfigFieldTouched('tempEnabled${i}'); saveTempConfig()">
|
||||
@@ -1225,6 +1228,11 @@ function renderConfigControls(data){
|
||||
if(group && !configTouched["tempGroup"+i] && document.activeElement!==group){
|
||||
group.value=t.group||"cabin";
|
||||
}
|
||||
|
||||
const priority=$("tempPriority"+i);
|
||||
if(priority && !configTouched["tempPriority"+i] && document.activeElement!==priority){
|
||||
priority.value=t.priority||i+1;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1268,6 +1276,7 @@ async function saveTempConfig(){
|
||||
const enabled=$("tempEnabled"+i)?.checked || false;
|
||||
const weather=$("tempWeather"+i)?.checked || false;
|
||||
const group=$("tempGroup"+i)?.value || temps[i].group || "cabin";
|
||||
const priority=parseInt($("tempPriority"+i)?.value || temps[i].priority || (i+1),10);
|
||||
|
||||
await fetch(api("/config/temp"),{
|
||||
method:"POST",
|
||||
@@ -1278,7 +1287,8 @@ async function saveTempConfig(){
|
||||
address:temps[i].address||"",
|
||||
enabled:enabled,
|
||||
weather:weather,
|
||||
group:group
|
||||
group:group,
|
||||
priority:priority
|
||||
})
|
||||
});
|
||||
}
|
||||
@@ -1288,7 +1298,7 @@ async function saveTempConfig(){
|
||||
alert("Temperature config saved");
|
||||
clearConfigTouched([
|
||||
"tempEnabledCount",
|
||||
...temps.flatMap((_,i)=>["tempName"+i,"tempEnabled"+i,"tempWeather"+i,"tempGroup"+i])
|
||||
...temps.flatMap((_,i)=>["tempName"+i,"tempEnabled"+i,"tempWeather"+i,"tempGroup"+i,"tempPriority"+i])
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -2017,6 +2027,7 @@ void buildConfigDocument(JsonObject doc) {
|
||||
temp["enabled"] = appConfig.tempSensors[i].enabled;
|
||||
temp["weather"] = appConfig.tempSensors[i].weather;
|
||||
temp["group"] = appConfig.tempSensors[i].group;
|
||||
temp["priority"] = appConfig.tempSensors[i].priority;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2211,6 +2222,7 @@ void applyImportedConfig(JsonObject doc) {
|
||||
if (temp["enabled"].is<bool>()) appConfig.tempSensors[index].enabled = temp["enabled"].as<bool>();
|
||||
if (temp["weather"].is<bool>()) appConfig.tempSensors[index].weather = temp["weather"].as<bool>();
|
||||
if (temp["group"].is<String>()) appConfig.tempSensors[index].group = temp["group"].as<String>();
|
||||
if (temp["priority"].is<int>()) appConfig.tempSensors[index].priority = temp["priority"].as<int>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2317,6 +2329,7 @@ void buildStatusDocument(JsonDocument& doc) {
|
||||
temp["enabled"] = appConfig.tempSensors[i].enabled;
|
||||
temp["weather"] = appConfig.tempSensors[i].weather;
|
||||
temp["group"] = appConfig.tempSensors[i].group;
|
||||
temp["priority"] = appConfig.tempSensors[i].priority;
|
||||
temp["online"] = sensors.online[i];
|
||||
if (sensors.online[i]) {
|
||||
temp["temperature_f"] = sensors.tempsF[i];
|
||||
@@ -2462,6 +2475,7 @@ void sendConfigResponse(Stream& output, bool ok = true) {
|
||||
temp["enabled"] = appConfig.tempSensors[i].enabled;
|
||||
temp["weather"] = appConfig.tempSensors[i].weather;
|
||||
temp["group"] = appConfig.tempSensors[i].group;
|
||||
temp["priority"] = appConfig.tempSensors[i].priority;
|
||||
}
|
||||
|
||||
serializeJson(doc, output);
|
||||
@@ -3444,6 +3458,7 @@ void handleUpdateTempSensorConfig() {
|
||||
if (doc["enabled"].is<bool>()) appConfig.tempSensors[index].enabled = doc["enabled"].as<bool>();
|
||||
if (doc["weather"].is<bool>()) appConfig.tempSensors[index].weather = doc["weather"].as<bool>();
|
||||
if (doc["group"].is<String>()) appConfig.tempSensors[index].group = doc["group"].as<String>();
|
||||
if (doc["priority"].is<int>()) appConfig.tempSensors[index].priority = doc["priority"].as<int>();
|
||||
|
||||
sendOkConfig();
|
||||
}
|
||||
@@ -3585,6 +3600,7 @@ void handleTempClear() {
|
||||
appConfig.tempSensors[i].enabled = false;
|
||||
appConfig.tempSensors[i].weather = false;
|
||||
appConfig.tempSensors[i].group = "cabin";
|
||||
appConfig.tempSensors[i].priority = i + 1;
|
||||
sensors.tempsF[i] = -127.0;
|
||||
sensors.online[i] = false;
|
||||
}
|
||||
@@ -3622,6 +3638,7 @@ void handleTempClear() {
|
||||
appConfig.tempSensors[configIndex].enabled = false;
|
||||
appConfig.tempSensors[configIndex].weather = false;
|
||||
appConfig.tempSensors[configIndex].group = "cabin";
|
||||
appConfig.tempSensors[configIndex].priority = configIndex + 1;
|
||||
sensors.tempsF[configIndex] = -127.0;
|
||||
sensors.online[configIndex] = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user