mirror of
https://github.com/Laxilef/OTGateway.git
synced 2026-11-23 14:53:07 +05:00
feat: update the web portal for the new firmware APIs
Restore legacy backups through the settings APIs, update the dashboard and sensor controls, and keep translations in sync. Package the backup converter separately and wait for all compressed web assets before building LittleFS.
This commit is contained in:
1 parent
3fb433d3eb
commit
0a6ae9c5d8
16 files changed
+1092
-839
No files matched your search
@@ -0,0 +1,106 @@
|
||||
const convertLegacyBackup = (data) => {
|
||||
const aliases = {
|
||||
alwaysSendIndoorTemp: 'always_send_indoor_temp',
|
||||
antiStuckInterval: 'antistuck_interval',
|
||||
antiStuckTime: 'antistuck_time',
|
||||
autoDiagReset: 'auto_diag_reset',
|
||||
autoFaultReset: 'auto_fault_reset',
|
||||
cascadeControl: 'cascade_control',
|
||||
ch2AlwaysEnabled: 'ch2_always_enabled',
|
||||
ch2DisablingAction: 'ch2_disabling_action',
|
||||
coolingSupport: 'cooling_support',
|
||||
dhwBlocking: 'dhw_blocking',
|
||||
dhwDisablingAction: 'dhw_disabling_action',
|
||||
dhwStateAsDhwBlocking: 'dhw_state_as_dhw_blocking',
|
||||
dhwSupport: 'dhw_support',
|
||||
dhwToCh2: 'dhw_to_ch2',
|
||||
externalPump: 'ext_pump',
|
||||
filteringFactor: 'filtering_factor',
|
||||
freezeProtection: 'freeze_protection',
|
||||
getMinMaxTemp: 'get_min_max_temp',
|
||||
heatingDisablingAction: 'heating_disabling_action',
|
||||
heatingStateToSummerWinterMode: 'heating_state_to_summer_winter_mode',
|
||||
heatingToCh2: 'heating_to_ch2',
|
||||
highTemp: 'high_temp',
|
||||
homeAssistantDiscovery: 'ha_discovery',
|
||||
ignoreDiagState: 'ignore_diag_state',
|
||||
immergasFix: 'immergas_fix',
|
||||
indoorTempAvgType: 'indoor_temp_avg_type',
|
||||
inGpio: 'in_gpio',
|
||||
invertState: 'invert_state',
|
||||
logLevel: 'loglevel',
|
||||
lowTemp: 'low_temp',
|
||||
maxModulation: 'max_modulation',
|
||||
maxPower: 'max_power',
|
||||
maxTemp: 'max_temp',
|
||||
maxTempSyncWithTargetTemp: 'max_temp_sync_with_target_temp',
|
||||
memberId: 'member_id',
|
||||
minPower: 'min_power',
|
||||
minTemp: 'min_temp',
|
||||
nativeOTC: 'native_otc',
|
||||
onEnabledHeating: 'on_enabled_heating',
|
||||
onFault: 'on_fault',
|
||||
onLossConnection: 'on_loss_connection',
|
||||
outdoorTempAvgType: 'outdoor_temp_avg_type',
|
||||
outGpio: 'out_gpio',
|
||||
overheatProtection: 'overheat_protection',
|
||||
postCirculationTime: 'post_circulation_time',
|
||||
rxLedGpio: 'rx_led_gpio',
|
||||
setDateAndTime: 'set_date_and_time',
|
||||
staticConfig: 'static_config',
|
||||
statusLedGpio: 'status_led_gpio',
|
||||
summerWinterMode: 'summer_winter_mode',
|
||||
targetDiffFactor: 'target_diff_factor',
|
||||
thresholdHigh: 'threshold_high',
|
||||
thresholdLow: 'threshold_low',
|
||||
thresholdTime: 'threshold_time',
|
||||
tresholdTime: 'treshold_time',
|
||||
turboFactor: 'turbo_factor',
|
||||
unitSystem: 'unit_system',
|
||||
useDhcp: 'use_dhcp',
|
||||
webSerial: 'web_serial'
|
||||
};
|
||||
const logLevels = [0, 1, 1, 2, 3, 3, 4, 5];
|
||||
|
||||
const convert = (value) => {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map(convert);
|
||||
}
|
||||
if (value === null || typeof value !== 'object') {
|
||||
return value;
|
||||
}
|
||||
|
||||
const result = Object.create(null);
|
||||
for (const [key, field] of Object.entries(value)) {
|
||||
const convertedKey = Object.prototype.hasOwnProperty.call(aliases, key) ? aliases[key] : key;
|
||||
result[convertedKey] = convert(field);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const legacySystem = data?.settings?.system;
|
||||
if (legacySystem !== null && typeof legacySystem === 'object'
|
||||
&& Object.prototype.hasOwnProperty.call(legacySystem, 'logLevel')) {
|
||||
const system = {...legacySystem};
|
||||
if (Object.prototype.hasOwnProperty.call(system, 'loglevel')) {
|
||||
delete system.logLevel;
|
||||
|
||||
} else if (Number.isInteger(system.logLevel) && system.logLevel >= 0 && system.logLevel < logLevels.length) {
|
||||
system.logLevel = logLevels[system.logLevel];
|
||||
}
|
||||
|
||||
data = {
|
||||
...data,
|
||||
settings: {...data.settings, system}
|
||||
};
|
||||
}
|
||||
|
||||
const result = convert(data);
|
||||
|
||||
const opentherm = result?.settings?.opentherm;
|
||||
if (opentherm !== null && typeof opentherm === 'object') {
|
||||
delete opentherm.unit_system;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
+5
-177
@@ -166,20 +166,20 @@ const setupNetworkScanForm = (formSelector, tableSelector) => {
|
||||
|
||||
// signal quality
|
||||
let signalQualityIcon = document.createElement("i");
|
||||
if (result[i].signalQuality > 80) {
|
||||
if (result[i].signal_quality > 80) {
|
||||
signalQualityIcon.classList.add('icons-wifi-strength-4');
|
||||
} else if (result[i].signalQuality > 60) {
|
||||
} else if (result[i].signal_quality > 60) {
|
||||
signalQualityIcon.classList.add('icons-wifi-strength-3');
|
||||
} else if (result[i].signalQuality > 40) {
|
||||
} else if (result[i].signal_quality > 40) {
|
||||
signalQualityIcon.classList.add('icons-wifi-strength-2');
|
||||
} else if (result[i].signalQuality > 20) {
|
||||
} else if (result[i].signal_quality > 20) {
|
||||
signalQualityIcon.classList.add('icons-wifi-strength-1');
|
||||
} else {
|
||||
signalQualityIcon.classList.add('icons-wifi-strength-0');
|
||||
}
|
||||
|
||||
let signalQualityContainer = document.createElement("span");
|
||||
signalQualityContainer.dataset.tooltip = `${result[i].signalQuality}%`;
|
||||
signalQualityContainer.dataset.tooltip = `${result[i].signal_quality}%`;
|
||||
signalQualityContainer.appendChild(signalQualityIcon);
|
||||
infoCell.appendChild(signalQualityContainer);
|
||||
|
||||
@@ -264,178 +264,6 @@ const setupNetworkScanForm = (formSelector, tableSelector) => {
|
||||
onSubmitFn();
|
||||
}
|
||||
|
||||
const setupRestoreBackupForm = (formSelector) => {
|
||||
const form = document.querySelector(formSelector);
|
||||
if (!form) {
|
||||
return;
|
||||
}
|
||||
|
||||
const url = form.action;
|
||||
let button = form.querySelector('button[type="submit"]');
|
||||
let defaultText;
|
||||
|
||||
form.addEventListener('submit', async (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
if (button) {
|
||||
defaultText = button.textContent;
|
||||
button.textContent = i18n('button.wait');
|
||||
button.setAttribute('disabled', true);
|
||||
button.setAttribute('aria-busy', true);
|
||||
}
|
||||
|
||||
const onSuccess = () => {
|
||||
if (button) {
|
||||
button.textContent = i18n('button.restored');
|
||||
button.classList.add('success');
|
||||
button.removeAttribute('aria-busy');
|
||||
|
||||
setTimeout(() => {
|
||||
button.removeAttribute('disabled');
|
||||
button.classList.remove('success', 'failed');
|
||||
button.textContent = defaultText;
|
||||
}, 5000);
|
||||
}
|
||||
};
|
||||
|
||||
const onFailed = () => {
|
||||
if (button) {
|
||||
button.textContent = i18n('button.error');
|
||||
button.classList.add('failed');
|
||||
button.removeAttribute('aria-busy');
|
||||
|
||||
setTimeout(() => {
|
||||
button.removeAttribute('disabled');
|
||||
button.classList.remove('success', 'failed');
|
||||
button.textContent = defaultText;
|
||||
}, 5000);
|
||||
}
|
||||
};
|
||||
|
||||
const files = form.querySelector('#restore-file').files;
|
||||
if (files.length <= 0) {
|
||||
onFailed(false);
|
||||
return;
|
||||
}
|
||||
|
||||
let reader = new FileReader();
|
||||
reader.readAsText(files[0]);
|
||||
reader.onload = async (event) => {
|
||||
try {
|
||||
const data = JSON.parse(event.target.result);
|
||||
console.log("Backup: ", data);
|
||||
|
||||
if (data.settings != undefined) {
|
||||
for (const key in data.settings) {
|
||||
let response = await fetch(url, {
|
||||
method: "POST",
|
||||
cache: "no-cache",
|
||||
credentials: "include",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
"settings": {
|
||||
[key]: data.settings[key]
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
onFailed();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let finalPayload = {};
|
||||
if (data.settings.emergency?.target !== undefined) {
|
||||
finalPayload.emergency ??= {};
|
||||
finalPayload.emergency.target = data.settings.emergency.target;
|
||||
}
|
||||
|
||||
if (data.settings.heating?.target !== undefined) {
|
||||
finalPayload.heating ??= {};
|
||||
finalPayload.heating.target = data.settings.heating.target;
|
||||
}
|
||||
|
||||
if (data.settings.dhw?.target !== undefined) {
|
||||
finalPayload.dhw ??= {};
|
||||
finalPayload.dhw.target = data.settings.dhw.target;
|
||||
}
|
||||
|
||||
if (Object.keys(finalPayload).length) {
|
||||
let response = await fetch(url, {
|
||||
method: "POST",
|
||||
cache: "no-cache",
|
||||
credentials: "include",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
"settings": finalPayload
|
||||
})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
onFailed();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (data.sensors != undefined) {
|
||||
for (const sensorId in data.sensors) {
|
||||
const payload = {
|
||||
"sensors": {}
|
||||
};
|
||||
payload["sensors"][sensorId] = data.sensors[sensorId];
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: "POST",
|
||||
cache: "no-cache",
|
||||
credentials: "include",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
onFailed();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (data.network != undefined) {
|
||||
let response = await fetch(url, {
|
||||
method: "POST",
|
||||
cache: "no-cache",
|
||||
credentials: "include",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({"network": data.network})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
onFailed();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
onSuccess();
|
||||
|
||||
} catch (err) {
|
||||
onFailed();
|
||||
}
|
||||
};
|
||||
reader.onerror = () => {
|
||||
console.log(reader.error);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
const setupUpgradeForm = (formSelector) => {
|
||||
const form = document.querySelector(formSelector);
|
||||
if (!form) {
|
||||
|
||||
Reference in new issue
Block a user