diff --git a/gulpfile.js b/gulpfile.js index fa7ff6d..5a22e2a 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,4 +1,4 @@ -const { src, dest, series, parallel } = require('gulp'); +const { src, dest, parallel } = require('gulp'); const concat = require('gulp-concat'); const gzip = require('gulp-gzip'); const postcss = require('gulp-postcss'); @@ -28,6 +28,9 @@ let paths = { 'src_data/scripts/lang.js', 'src_data/scripts/utils.js' ], + 'settings-converter.js': [ + 'src_data/scripts/settings-converter.js' + ], 'chart.js': [ 'src_data/scripts/chart.js' ] @@ -66,80 +69,56 @@ let paths = { // Tasks -const styles = (cb) => { - for (let name in paths.styles.bundles) { - const items = paths.styles.bundles[name]; +const styles = parallel(...Object.entries(paths.styles.bundles).map(([name, items]) => { + return () => src(items) + .pipe(replace( + "{BUILD_TIME}", + Math.floor(Date.now() / 1000) + )) + .pipe(postcss([ + cssnano({ preset: 'advanced' }) + ])) + .pipe(concat(name)) + .pipe(gzip({ + append: true + })) + .pipe(dest(paths.styles.dest)); +})); - src(items) - .pipe(replace( - "{BUILD_TIME}", - Math.floor(Date.now() / 1000) - )) - .pipe(postcss([ - cssnano({ preset: 'advanced' }) - ])) - .pipe(concat(name)) - .pipe(gzip({ - append: true - })) - .pipe(dest(paths.styles.dest)); - } +const scripts = parallel(...Object.entries(paths.scripts.bundles).map(([name, items]) => { + return () => src(items) + .pipe(replace( + "{BUILD_TIME}", + Math.floor(Date.now() / 1000) + )) + .pipe(terser()) + .pipe(concat(name)) + .pipe(gzip({ + append: true + })) + .pipe(dest(paths.scripts.dest)); +})); - cb(); -} +const jsonFiles = parallel(...paths.json.map((item) => { + return () => src(item.src) + .pipe(replace( + "{BUILD_TIME}", + Math.floor(Date.now() / 1000) + )) + .pipe(jsonminify()) + .pipe(gzip({ + append: true + })) + .pipe(dest(item.dest)); +})); -const scripts = (cb) => { - for (let name in paths.scripts.bundles) { - const items = paths.scripts.bundles[name]; - - src(items) - .pipe(replace( - "{BUILD_TIME}", - Math.floor(Date.now() / 1000) - )) - .pipe(terser().on('error', console.error)) - .pipe(concat(name)) - .pipe(gzip({ - append: true - })) - .pipe(dest(paths.scripts.dest)); - } - - cb(); -} - -const jsonFiles = (cb) => { - for (let i in paths.json) { - const item = paths.json[i]; - - src(item.src) - .pipe(replace( - "{BUILD_TIME}", - Math.floor(Date.now() / 1000) - )) - .pipe(jsonminify()) - .pipe(gzip({ - append: true - })) - .pipe(dest(item.dest)); - } - - cb(); -} - -const staticFiles = (cb) => { - for (let i in paths.static) { - const item = paths.static[i]; - - src(item.src, { encoding: false }) - .pipe(gzip({ - append: true - })) - .pipe(dest(item.dest)); - } - - cb(); -} +const staticFiles = parallel(...paths.static.map((item) => { + return () => src(item.src, { encoding: false }) + .pipe(gzip({ + append: true + })) + .pipe(dest(item.dest)); +})); const pages = () => { return src(paths.pages.src) @@ -167,4 +146,4 @@ exports.build_scripts = scripts; exports.build_json = jsonFiles; exports.build_static = staticFiles; exports.build_pages = pages; -exports.build_all = parallel(styles, scripts, jsonFiles, staticFiles, pages); \ No newline at end of file +exports.build_all = parallel(styles, scripts, jsonFiles, staticFiles, pages); diff --git a/src_data/locales/cn.json b/src_data/locales/cn.json index 73cea76..690ade5 100644 --- a/src_data/locales/cn.json +++ b/src_data/locales/cn.json @@ -66,10 +66,10 @@ "freq": "频率" }, "flash": { - "size": "闪存容量", - "realSize": "实际容量" + "size": "闪存容量" }, - "lastResetReason": "上次重置原因" + "lastResetReason": "上次重置原因", + "coreDump": "内存转储" } }, "dashboard": { diff --git a/src_data/locales/en.json b/src_data/locales/en.json index 9912938..c180e1a 100644 --- a/src_data/locales/en.json +++ b/src_data/locales/en.json @@ -66,10 +66,10 @@ "freq": "frequency" }, "flash": { - "size": "Flash size", - "realSize": "real size" + "size": "Flash size" }, - "lastResetReason": "Last reset reason" + "lastResetReason": "Last reset reason", + "coreDump": "Core dump" } }, "dashboard": { diff --git a/src_data/locales/it.json b/src_data/locales/it.json index e503a5e..3e5176b 100644 --- a/src_data/locales/it.json +++ b/src_data/locales/it.json @@ -66,10 +66,10 @@ "freq": "frequenza" }, "flash": { - "size": "Dimensioni del flash", - "realSize": "dimensione reale" + "size": "Dimensioni del flash" }, - "lastResetReason": "Motivo ultimo Reset" + "lastResetReason": "Motivo ultimo Reset", + "coreDump": "Dump di memoria" } }, "dashboard": { diff --git a/src_data/locales/nl.json b/src_data/locales/nl.json index aa368bc..21ba8f9 100644 --- a/src_data/locales/nl.json +++ b/src_data/locales/nl.json @@ -66,10 +66,10 @@ "freq": "frequentie" }, "flash": { - "size": "Flash-grootte", - "realSize": "werkelijke grootte" + "size": "Flash-grootte" }, - "lastResetReason": "Reden laatste herstart" + "lastResetReason": "Reden laatste herstart", + "coreDump": "Geheugendump" } }, "dashboard": { diff --git a/src_data/locales/ru.json b/src_data/locales/ru.json index 7eed3d8..3b91120 100644 --- a/src_data/locales/ru.json +++ b/src_data/locales/ru.json @@ -66,10 +66,10 @@ "freq": "частота" }, "flash": { - "size": "Размер ПЗУ", - "realSize": "реальный размер" + "size": "Размер ПЗУ" }, - "lastResetReason": "Причина перезагрузки" + "lastResetReason": "Причина перезагрузки", + "coreDump": "Дамп памяти" } }, "dashboard": { diff --git a/src_data/pages/dashboard.html b/src_data/pages/dashboard.html index 65025f2..c816ed6 100644 --- a/src_data/pages/dashboard.html +++ b/src_data/pages/dashboard.html @@ -312,12 +312,12 @@ let prevSettings; let newSettings = { heating: { - enable: false, + enabled: false, turbo: false, target: 0 }, dhw: { - enable: false, + enabled: false, target: 0 } }; @@ -326,78 +326,89 @@ const lang = new Lang(document.getElementById('lang')); await lang.build(); - let actionTimer = null; - let actionLongPress = false; + let activePress = null; + const stopPress = () => { + if (!activePress) { + return; + } + + const press = activePress; + activePress = null; + clearInterval(press.timer); + if (press.button.hasPointerCapture(press.pointerId)) { + press.button.releasePointerCapture(press.pointerId); + } + }; + document.querySelectorAll('.tAction').forEach((item) => { const action = item.dataset.action; const tContainer = item.parentNode.parentNode; + const changeTarget = (step, minTemp, maxTemp) => { + const purpose = tContainer.dataset.purpose; + let value = 0; + if (action == 'increment') { + value = step; - for (const eName of ['pointerup', 'pointercancel']) { - item.addEventListener(eName, (event) => { - clearInterval(actionTimer); + } else if (action == 'decrement') { + value = -(step); + } - const purpose = tContainer.dataset.purpose; - const minTemp = parseFloat(tContainer.dataset.min); - const maxTemp = parseFloat(tContainer.dataset.max); - const step = parseFloat(tContainer.dataset.step); - const bigStep = parseFloat(tContainer.dataset.bigStep); + const newValue = parseFloat(constrain(newSettings[purpose].target + value, minTemp, maxTemp).toFixed(2)); + if (newSettings[purpose].target != newValue) { + newSettings[purpose].target = newValue; + modifiedTime = Date.now(); - if (!actionLongPress && prevSettings) { - let value = 0; - if (action == 'increment') { - value = step; - - } else if (action == 'decrement') { - value = -(step); - } - - const newValue = parseFloat(constrain(newSettings[purpose].target + value, minTemp, maxTemp).toFixed(2)); - if (newSettings[purpose].target != newValue) { - newSettings[purpose].target = newValue; - modifiedTime = Date.now(); - - setValue('.targetTemp', newValue, tContainer); - tContainer.querySelector('.thermostat-header').setAttribute("aria-busy", "true"); - } - } - }); - } + setValue('.targetTemp', newValue, tContainer); + tContainer.querySelector('.thermostat-header').setAttribute("aria-busy", "true"); + } + }; item.addEventListener('pointerdown', (event) => { - if (!prevSettings) { + if (!prevSettings || activePress || event.button !== 0) { return; } - const purpose = tContainer.dataset.purpose; const minTemp = parseFloat(tContainer.dataset.min); const maxTemp = parseFloat(tContainer.dataset.max); - const step = parseFloat(tContainer.dataset.step); const bigStep = parseFloat(tContainer.dataset.bigStep); - - actionLongPress = false; - actionTimer = setInterval(() => { - if (!actionLongPress) { - actionLongPress = true; - } - - let value = 0; - if (action == 'increment') { - value = bigStep; - - } else if (action == 'decrement') { - value = -(bigStep); - } - - const newValue = parseFloat(constrain(newSettings[purpose].target + value, minTemp, maxTemp).toFixed(2)); - if (newSettings[purpose].target != newValue) { - newSettings[purpose].target = newValue; - modifiedTime = Date.now(); - - setValue('.targetTemp', newSettings[purpose].target, tContainer); - tContainer.querySelector('.thermostat-header').setAttribute("aria-busy", "true"); - } + const press = {button: item, pointerId: event.pointerId, timer: null, longPress: false}; + activePress = press; + item.setPointerCapture(event.pointerId); + press.timer = setInterval(() => { + press.longPress = true; + changeTarget(bigStep, minTemp, maxTemp); }, 500); }); + + item.addEventListener('pointerup', (event) => { + if (!activePress || activePress.button !== item || activePress.pointerId !== event.pointerId) { + return; + } + + const longPress = activePress.longPress; + stopPress(); + if (!longPress) { + changeTarget( + parseFloat(tContainer.dataset.step), + parseFloat(tContainer.dataset.min), parseFloat(tContainer.dataset.max) + ); + } + }); + + for (const eName of ['pointercancel', 'lostpointercapture']) { + item.addEventListener(eName, (event) => { + if (activePress && activePress.button === item && activePress.pointerId === event.pointerId) { + stopPress(); + } + }); + } + }); + + window.addEventListener('blur', stopPress); + document.addEventListener('visibilitychange', () => { + if (document.hidden) { + stopPress(); + } }); document.querySelector('#tHeatEnabled').addEventListener('change', (event) => { @@ -445,7 +456,7 @@ }, body: JSON.stringify({ "actions": { - "resetFault": true + "reset_fault": true } }) }); @@ -472,7 +483,7 @@ }, body: JSON.stringify({ "actions": { - "resetDiagnostic": true + "reset_diagnostic": true } }) }); @@ -484,6 +495,27 @@ }, 10000); }); + const requestSettingsSection = async (section, values = null) => { + const parameters = { + method: "GET", + cache: "no-cache", + credentials: "include" + }; + + if (values !== null) { + parameters.method = "POST"; + parameters.headers = {"Content-Type": "application/json"}; + parameters.body = JSON.stringify(values); + } + + const response = await fetch(`/api/settings/${section}`, parameters); + if (!response.ok) { + throw new Error('Response not valid'); + } + + return response.json(); + }; + setTimeout(async function onLoadPage() { let unitSystem = null; @@ -498,66 +530,55 @@ // settings try { - let modified = prevSettings && ( - (prevSettings.heating.enabled != newSettings.heating.enabled) - || (prevSettings.heating.turbo != newSettings.heating.turbo) - || (prevSettings.heating.target != newSettings.heating.target) - || (prevSettings.opentherm.options.dhwSupport && prevSettings.dhw.enabled != newSettings.dhw.enabled) - || (prevSettings.opentherm.options.dhwSupport && prevSettings.dhw.target != newSettings.dhw.target) + const heatingSettings = {...newSettings.heating}; + const dhwSettings = {...newSettings.dhw}; + const heatingModified = prevSettings && ( + (prevSettings.heating.enabled != heatingSettings.enabled) + || (prevSettings.heating.turbo != heatingSettings.turbo) + || (prevSettings.heating.target != heatingSettings.target) + ); + const dhwModified = prevSettings && prevSettings.opentherm.options.dhw_support && ( + (prevSettings.dhw.enabled != dhwSettings.enabled) + || (prevSettings.dhw.target != dhwSettings.target) ); - if (modified) { - console.log(newSettings); - } - - let parameters = { - method: "GET", - cache: "no-cache", - credentials: "include" - }; - - if (modified) { - parameters.method = "POST"; - parameters.body = JSON.stringify(newSettings); - parameters.headers = { - "Content-Type": "application/json" - }; - } - - const response = await fetch("/api/settings", parameters); - if (!response.ok) { - throw new Error('Response not valid'); - } - - const result = await response.json(); + const system = await requestSettingsSection('system'); + const opentherm = await requestSettingsSection('opentherm'); + const heating = await requestSettingsSection('heating', heatingModified ? heatingSettings : null); + const dhw = await requestSettingsSection('dhw', dhwModified ? dhwSettings : null); + const result = {system, opentherm, heating, dhw}; prevSettings = result; - unitSystem = result.system.unitSystem; - newSettings.heating.enabled = result.heating.enabled; - newSettings.heating.turbo = result.heating.turbo; - newSettings.heating.target = result.heating.target; - newSettings.dhw.enabled = result.dhw.enabled; - newSettings.dhw.target = result.dhw.target; + unitSystem = result.system.unit_system; - if (result.opentherm.options.dhwSupport) { + if (result.opentherm.options.dhw_support) { show('.tDhw'); } else { hide('.tDhw'); } - setCheckboxValue('#tHeatEnabled', result.heating.enabled); - setCheckboxValue('#tHeatTurbo', result.heating.turbo); - setValue('.tHeat .targetTemp', result.heating.target); - - setCheckboxValue('#tDhwEnabled', result.dhw.enabled); - setValue('.tDhw .targetTemp', result.dhw.target); - setValue('.tempUnit', temperatureUnit(unitSystem)); setValue('.pressureUnit', pressureUnit(unitSystem)); setValue('.volumeUnit', volumeUnit(unitSystem)); - document.querySelectorAll('.thermostat-header').forEach((item) => { - item.setAttribute("aria-busy", "false"); - }); + // An edit made while these requests were in flight is still waiting to be sent. + if (modifiedTime === null) { + newSettings.heating.enabled = result.heating.enabled; + newSettings.heating.turbo = result.heating.turbo; + newSettings.heating.target = result.heating.target; + newSettings.dhw.enabled = result.dhw.enabled; + newSettings.dhw.target = result.dhw.target; + + setCheckboxValue('#tHeatEnabled', result.heating.enabled); + setCheckboxValue('#tHeatTurbo', result.heating.turbo); + setValue('.tHeat .targetTemp', result.heating.target); + + setCheckboxValue('#tDhwEnabled', result.dhw.enabled); + setValue('.tDhw .targetTemp', result.dhw.target); + + document.querySelectorAll('.thermostat-header').forEach((item) => { + item.setAttribute("aria-busy", "false"); + }); + } } catch (error) { console.log(error); @@ -577,20 +598,20 @@ const result = await response.json(); // Graph - setValue('#tHeatCurrentTemp', result.master.heating.indoorTempControl - ? result.master.heating.indoorTemp - : result.master.heating.currentTemp + setValue('#tHeatCurrentTemp', result.master.heating.indoor_temp_control + ? result.master.heating.indoor_temp + : result.master.heating.current_temp ); - setValue('#tDhwCurrentTemp', result.master.dhw.currentTemp); + setValue('#tDhwCurrentTemp', result.master.dhw.current_temp); // SLAVE - setValue('.sMemberId', result.slave.memberId); - setValue('.sVendor', memberIdToVendor(result.slave.memberId)); + setValue('.sMemberId', result.slave.member_id); + setValue('.sVendor', memberIdToVendor(result.slave.member_id)); setValue('.sFlags', result.slave.flags); setValue('.sType', result.slave.type); - setValue('.sAppVersion', result.slave.appVersion); - setValue('.sProtocolVersion', result.slave.protocolVersion); + setValue('.sAppVersion', result.slave.app_version); + setValue('.sProtocolVersion', result.slave.protocol_version); setStatus( '.sConnected', @@ -609,12 +630,12 @@ setValue('.sPowerMax', result.slave.power.max); setState('.sHeatActive', result.slave.heating.active); - setValue('.sHeatMinTemp', result.slave.heating.minTemp); - setValue('.sHeatMaxTemp', result.slave.heating.maxTemp); + setValue('.sHeatMinTemp', result.slave.heating.min_temp); + setValue('.sHeatMaxTemp', result.slave.heating.max_temp); setState('.sDhwActive', result.slave.dhw.active); - setValue('.sDhwMinTemp', result.slave.dhw.minTemp); - setValue('.sDhwMaxTemp', result.slave.dhw.maxTemp); + setValue('.sDhwMinTemp', result.slave.dhw.min_temp); + setValue('.sDhwMaxTemp', result.slave.dhw.max_temp); setStatus( '.sFaultActive', @@ -662,7 +683,7 @@ result.master.heating.blocking ? "success" : "error", result.master.heating.blocking ? "red" : "green" ); - setState('.mHeatIndoorTempControl', result.master.heating.indoorTempControl); + setState('.mHeatIndoorTempControl', result.master.heating.indoor_temp_control); setStatus( '.mHeatOverheat', result.master.heating.overheat ? "success" : "error", @@ -673,14 +694,14 @@ result.master.heating.freezing ? "success" : "error", result.master.heating.freezing ? "red" : "green" ); - setValue('.mHeatSetpointTemp', result.master.heating.setpointTemp); - setValue('.mHeatTargetTemp', result.master.heating.targetTemp); - setValue('.mHeatCurrTemp', result.master.heating.currentTemp); - setValue('.mHeatRetTemp', result.master.heating.returnTemp); - setValue('.mHeatIndoorTemp', result.master.heating.indoorTemp); - setValue('.mHeatOutdoorTemp', result.master.heating.outdoorTemp); - setValue('.mHeatMinTemp', result.master.heating.minTemp); - setValue('.mHeatMaxTemp', result.master.heating.maxTemp); + setValue('.mHeatSetpointTemp', result.master.heating.setpoint_temp); + setValue('.mHeatTargetTemp', result.master.heating.target_temp); + setValue('.mHeatCurrTemp', result.master.heating.current_temp); + setValue('.mHeatRetTemp', result.master.heating.return_temp); + setValue('.mHeatIndoorTemp', result.master.heating.indoor_temp); + setValue('.mHeatOutdoorTemp', result.master.heating.outdoor_temp); + setValue('.mHeatMinTemp', result.master.heating.min_temp); + setValue('.mHeatMaxTemp', result.master.heating.max_temp); setState('.mDhwEnabled', result.master.dhw.enabled); setStatus( @@ -688,11 +709,11 @@ result.master.dhw.overheat ? "success" : "error", result.master.dhw.overheat ? "red" : "green" ); - setValue('.mDhwTargetTemp', result.master.dhw.targetTemp); - setValue('.mDhwCurrTemp', result.master.dhw.currentTemp); - setValue('.mDhwRetTemp', result.master.dhw.returnTemp); - setValue('.mDhwMinTemp', result.master.dhw.minTemp); - setValue('.mDhwMaxTemp', result.master.dhw.maxTemp); + setValue('.mDhwTargetTemp', result.master.dhw.target_temp); + setValue('.mDhwCurrTemp', result.master.dhw.current_temp); + setValue('.mDhwRetTemp', result.master.dhw.return_temp); + setValue('.mDhwMinTemp', result.master.dhw.min_temp); + setValue('.mDhwMaxTemp', result.master.dhw.max_temp); setStatus( '.mNetworkConnected', @@ -705,17 +726,17 @@ result.master.emergency.state ? "success" : "error", result.master.emergency.state ? "red" : "green" ); - setState('.mExtPumpState', result.master.externalPump.state); - setState('.mCascadeControlInput', result.master.cascadeControl.input); - setState('.mCascadeControlOutput', result.master.cascadeControl.output); + setState('.mExtPumpState', result.master.ext_pump.state); + setState('.mCascadeControlInput', result.master.cascade_control.input); + setState('.mCascadeControlOutput', result.master.cascade_control.output); const tHeat = document.querySelector('.tHeat'); - tHeat.dataset.min = result.master.heating.minTemp; - tHeat.dataset.max = result.master.heating.maxTemp; + tHeat.dataset.min = result.master.heating.min_temp; + tHeat.dataset.max = result.master.heating.max_temp; const tDhw = document.querySelector('.tDhw'); - tDhw.dataset.min = result.master.dhw.minTemp; - tDhw.dataset.max = result.master.dhw.maxTemp; + tDhw.dataset.min = result.master.dhw.min_temp; + tDhw.dataset.max = result.master.dhw.max_temp; setBusy('#dashboard-busy', '#dashboard-container', false); @@ -775,7 +796,7 @@ const statusNode = sensorNode.querySelector(`.sStatusContainer`); if (statusNode) { - statusNode.dataset.tooltip = `${sData.signalQuality}%`; + statusNode.dataset.tooltip = `${sData.signal_quality}%`; } if (sData.value !== undefined) { @@ -810,4 +831,4 @@ }); - \ No newline at end of file + diff --git a/src_data/pages/index.html b/src_data/pages/index.html index 6cdde46..1719244 100644 --- a/src_data/pages/index.html +++ b/src_data/pages/index.html @@ -138,14 +138,14 @@ index.system.chip.model: (rev. )
index.system.chip.cores: , index.system.chip.freq: units.mhz
- index.system.flash.size: units.mbyte (index.system.flash.realSize: units.mbyte) + index.system.flash.size: units.mbyte index.system.lastResetReason
- Save debug data + index.system.coreDump @@ -157,7 +157,7 @@ sensors.name logs.name upgrade.name - button.restart + button.restart @@ -180,6 +180,44 @@ const lang = new Lang(document.getElementById('lang')); await lang.build(); + const restartButton = document.querySelector('.restart'); + restartButton.addEventListener('click', async (event) => { + event.preventDefault(); + if (restartButton.disabled) { + return; + } + + restartButton.disabled = true; + restartButton.setAttribute('aria-busy', true); + restartButton.textContent = i18n('button.wait'); + + try { + const response = await fetch('/api/restart', { + method: 'POST', + cache: 'no-cache', + credentials: 'include' + }); + if (response.status !== 202) { + throw new Error('Restart request failed'); + } + + restartButton.textContent = i18n('button.restart'); + restartButton.classList.add('success'); + + } catch { + restartButton.textContent = i18n('button.error'); + restartButton.classList.add('failed'); + restartButton.removeAttribute('aria-busy'); + } + + setTimeout(() => { + restartButton.disabled = false; + restartButton.classList.remove('success', 'failed'); + restartButton.removeAttribute('aria-busy'); + restartButton.textContent = i18n('button.restart'); + }, 15000); + }); + setTimeout(async function onLoadPage() { try { const response = await fetch("/api/info", { @@ -192,7 +230,7 @@ } const result = await response.json(); - setTextValue('#reset-reason', result.system.resetReason); + setTextValue('#reset-reason', result.system.reset_reason); setValue('#uptime', result.system.uptime); setValue('#uptime-days', Math.floor(result.system.uptime / 86400)); setValue('#uptime-hours', Math.floor(result.system.uptime % 86400 / 3600)); @@ -207,7 +245,7 @@ result.network.connected ? "green" : "red" ); setTextValue('#network-ssid', result.network.ssid); - setValue('#network-signal', result.network.signalQuality); + setValue('#network-signal', result.network.signal_quality); setTextValue('#network-ip', result.network.ip); setTextValue('#network-subnet', result.network.subnet); setTextValue('#network-gateway', result.network.gateway); @@ -223,21 +261,20 @@ setValue('#heap-total', result.heap.total); setValue('#heap-free', result.heap.free); - setValue('#heap-min-free', result.heap.minFree); - setValue('#heap-max-free-block', result.heap.maxFreeBlock); - setValue('#heap-min-max-free-block', result.heap.minMaxFreeBlock); + setValue('#heap-min-free', result.heap.min_free); + setValue('#heap-max-free-block', result.heap.max_free_block); + setValue('#heap-min-max-free-block', result.heap.min_max_free_block); setValue('#psram-total', result.psram.total); setValue('#psram-free', result.psram.free); - setValue('#psram-min-free', result.psram.minFree); - setValue('#psram-max-free-block', result.psram.maxFreeBlock); + setValue('#psram-min-free', result.psram.min_free); + setValue('#psram-max-free-block', result.psram.max_free_block); setTextValue('#chip-model', result.chip.model); setValue('#chip-rev', result.chip.rev); setValue('#chip-cores', result.chip.cores); setValue('#chip-freq', result.chip.freq); setValue('#flash-size', result.flash.size / 1024 / 1024); - setValue('#flash-real-size', result.flash.realSize / 1024 / 1024); setBusy('#system-busy', '#system-table', false); diff --git a/src_data/pages/logs.html b/src_data/pages/logs.html index ac31f77..76a6a14 100644 --- a/src_data/pages/logs.html +++ b/src_data/pages/logs.html @@ -107,18 +107,16 @@

logs.desc

-
+
- + + + + + +
@@ -370,7 +368,7 @@ return; } const level = Number(levelSelect.value); - if (save && (!Number.isInteger(level) || level < 0 || level > 7)) { + if (save && (!Number.isInteger(level) || level < 0 || level > 5)) { return; } levelBusy = true; @@ -382,15 +380,15 @@ if (save) { options.method = 'POST'; options.headers = {'Content-Type': 'application/json'}; - options.body = JSON.stringify({system: {logLevel: level}}); + options.body = JSON.stringify({loglevel: level}); } const response = await fetch(levelForm.action, options); if (!response.ok) { throw new Error('Response not valid'); } const result = await response.json(); - const value = result.system && result.system.logLevel; - if (!Number.isInteger(value) || value < 0 || value > 7) { + const value = result.loglevel; + if (!Number.isInteger(value) || value < 0 || value > 5) { throw new Error('Invalid log level'); } confirmedLevel = value; diff --git a/src_data/pages/network.html b/src_data/pages/network.html index 526da15..ddc0b91 100644 --- a/src_data/pages/network.html +++ b/src_data/pages/network.html @@ -47,7 +47,7 @@
@@ -56,22 +56,22 @@ @@ -183,11 +183,11 @@ const fillData = (data) => { setInputValue("[name='hostname']", data.hostname); - setCheckboxValue("[name='useDhcp']", data.useDhcp); - setInputValue("[name='staticConfig[ip]']", data.staticConfig.ip); - setInputValue("[name='staticConfig[gateway]']", data.staticConfig.gateway); - setInputValue("[name='staticConfig[subnet]']", data.staticConfig.subnet); - setInputValue("[name='staticConfig[dns]']", data.staticConfig.dns); + setCheckboxValue("[name='use_dhcp']", data.use_dhcp); + setInputValue("[name='static_config[ip]']", data.static_config.ip); + setInputValue("[name='static_config[gateway]']", data.static_config.gateway); + setInputValue("[name='static_config[subnet]']", data.static_config.subnet); + setInputValue("[name='static_config[dns]']", data.static_config.dns); setBusy('#network-settings-busy', '#network-settings', false); setInputValue("[name='sta[ssid]']", data.sta.ssid); @@ -214,7 +214,7 @@ const result = await response.json(); fillData(result); - setupForm('#network-settings', fillData, ['hostname']); + setupForm('#network-settings', fillData, ['hostname', 'static_config.ip', 'static_config.gateway', 'static_config.subnet', 'static_config.dns']); setupNetworkScanForm('#network-scan', '#networks'); setupForm('#sta-settings', fillData, ['sta.ssid', 'sta.password']); setupForm('#ap-settings', fillData, ['ap.ssid', 'ap.password']); diff --git a/src_data/pages/sensors.html b/src_data/pages/sensors.html index d71a05c..568b9dd 100644 --- a/src_data/pages/sensors.html +++ b/src_data/pages/sensors.html @@ -174,7 +174,7 @@ @@ -242,7 +242,7 @@ setInputValue("[name='offset']", data.offset, {}, sensorForm); setInputValue("[name='factor']", data.factor, {}, sensorForm); setCheckboxValue("[name='filtering']", data.filtering, sensorForm); - setInputValue("[name='filteringFactor']", data.filteringFactor, {}, sensorForm); + setInputValue("[name='filtering_factor']", data.filtering_factor, {}, sensorForm); setTimeout(() => { sensorForm.querySelector("[name='type']").dispatchEvent(new Event("change")); diff --git a/src_data/pages/settings.html b/src_data/pages/settings.html index 5571a4a..53d9fe0 100644 --- a/src_data/pages/settings.html +++ b/src_data/pages/settings.html @@ -42,26 +42,26 @@ settings.section.portal
- +

@@ -77,17 +77,17 @@ settings.section.system
- +
settings.system.unit
@@ -95,13 +95,13 @@
@@ -649,17 +633,17 @@ settings.ot.disablingAction.dhw @@ -670,17 +654,17 @@ settings.ot.disablingAction.ch2 @@ -699,94 +683,94 @@

@@ -806,15 +790,15 @@ settings.section.mqtt
- +
@@ -822,36 +806,36 @@
@@ -866,15 +850,15 @@ settings.section.extPump
- +
@@ -882,24 +866,24 @@
@@ -914,17 +898,17 @@ settings.section.cascadeControl
- +
@@ -932,12 +916,12 @@
@@ -945,14 +929,14 @@
@@ -960,12 +944,12 @@
@@ -973,17 +957,17 @@ settings.cascadeControl.output.events.desc
@@ -1134,7 +1118,9 @@ data.push({ x: parseFloat(outdoorTemp.toFixed(1)), - y: parseFloat(calculateEquithermTemp(outdoorTemp).toFixed(1)) + y: parseFloat((etChartConfig.unitSystem == 0 + ? calculateEquithermTemp(value) + : c2f(calculateEquithermTemp(value))).toFixed(1)) }); } @@ -1146,278 +1132,384 @@ } const calculateEquithermTemp = (outdoorTemp) => { - const tempDelta = etChartConfig.targetTemp - outdoorTemp; - const maxPoint = etChartConfig.targetTemp - ( - etChartConfig.maxTemp - etChartConfig.targetTemp - ) / etChartConfig.slope; + let result = etChartConfig.targetTemp + etChartConfig.shift; - const sf = (etChartConfig.maxTemp - etChartConfig.targetTemp) / Math.pow( - etChartConfig.targetTemp - maxPoint, - 1 / etChartConfig.exponent - ); - const result = etChartConfig.targetTemp + etChartConfig.shift + sf * ( - tempDelta >= 0 - ? Math.pow(tempDelta, 1 / etChartConfig.exponent) - : -(Math.pow(-(tempDelta), 1 / etChartConfig.exponent)) - ); + if (etChartConfig.maxTemp > etChartConfig.targetTemp) { + const tempDelta = etChartConfig.targetTemp - outdoorTemp; + const maxPoint = etChartConfig.targetTemp - ( + etChartConfig.maxTemp - etChartConfig.targetTemp + ) / etChartConfig.slope; + + const sf = (etChartConfig.maxTemp - etChartConfig.targetTemp) / Math.pow( + etChartConfig.targetTemp - maxPoint, + 1 / etChartConfig.exponent + ); + result = etChartConfig.targetTemp + etChartConfig.shift + sf * ( + tempDelta >= 0 + ? Math.pow(tempDelta, 1 / etChartConfig.exponent) + : -(Math.pow(-(tempDelta), 1 / etChartConfig.exponent)) + ); + } + + if (!Number.isFinite(result)) { + result = etChartConfig.targetTemp + etChartConfig.shift; + } return Math.max(Math.min(result, etChartConfig.maxTemp), etChartConfig.minTemp); } - const fillData = (data) => { - // System - setSelectValue("[name='system[logLevel]']", data.system.logLevel); - setCheckboxValue("[name='system[serial][enabled]']", data.system.serial.enabled); - setSelectValue("[name='system[serial][baudrate]']", data.system.serial.baudrate); - setCheckboxValue("[name='system[webSerial][enabled]']", data.system.webSerial.enabled); - setInputValue("[name='system[ntp][server]']", data.system.ntp.server); - setInputValue("[name='system[ntp][timezone]']", data.system.ntp.timezone); - setRadioValue("[name='system[unitSystem]']", data.system.unitSystem); - setInputValue("[name='system[statusLedGpio]']", data.system.statusLedGpio < 255 ? data.system.statusLedGpio : ''); - setBusy('#system-settings-busy', '#system-settings', false); + const fillData = (form, data) => { + const section = form.dataset.section; + if (section === 'system') { + setSelectValue("[name='loglevel']", data.system.loglevel, form); + setCheckboxValue("[name='serial[enabled]']", data.system.serial.enabled, form); + setSelectValue("[name='serial[baudrate]']", data.system.serial.baudrate, form); + setCheckboxValue("[name='web_serial[enabled]']", data.system.web_serial.enabled, form); + setInputValue("[name='ntp[server]']", data.system.ntp.server, {}, form); + setInputValue("[name='ntp[timezone]']", data.system.ntp.timezone, {}, form); + setRadioValue("[name='unit_system']", data.system.unit_system, form); + setInputValue("[name='status_led_gpio']", data.system.status_led_gpio < 255 ? data.system.status_led_gpio : '', {}, form); - // Portal - setCheckboxValue("[name='portal[auth]']", data.portal.auth); - setInputValue("[name='portal[login]']", data.portal.login); - setInputValue("[name='portal[password]']", data.portal.password); - setCheckboxValue("[name='portal[mdns]']", data.portal.mdns); - setBusy('#portal-settings-busy', '#portal-settings', false); + } else if (section === 'portal') { + setCheckboxValue("[name='auth']", data.portal.auth, form); + setInputValue("[name='login']", data.portal.login, {}, form); + setInputValue("[name='password']", data.portal.password, {}, form); + setCheckboxValue("[name='mdns']", data.portal.mdns, form); - // Opentherm - setRadioValue("[name='opentherm[unitSystem]']", data.opentherm.unitSystem); - setInputValue("[name='opentherm[inGpio]']", data.opentherm.inGpio < 255 ? data.opentherm.inGpio : ''); - setInputValue("[name='opentherm[outGpio]']", data.opentherm.outGpio < 255 ? data.opentherm.outGpio : ''); - setInputValue("[name='opentherm[rxLedGpio]']", data.opentherm.rxLedGpio < 255 ? data.opentherm.rxLedGpio : ''); - setInputValue("[name='opentherm[memberId]']", data.opentherm.memberId); - setInputValue("[name='opentherm[flags]']", data.opentherm.flags); - setInputValue("[name='opentherm[minPower]']", data.opentherm.minPower); - setInputValue("[name='opentherm[maxPower]']", data.opentherm.maxPower); - setRadioValue("[name='opentherm[heatingDisablingAction]']", data.opentherm.heatingDisablingAction); - setRadioValue("[name='opentherm[dhwDisablingAction]']", data.opentherm.dhwDisablingAction); - setRadioValue("[name='opentherm[ch2DisablingAction]']", data.opentherm.ch2DisablingAction); - setCheckboxValue("[name='opentherm[options][dhwSupport]']", data.opentherm.options.dhwSupport); - setCheckboxValue("[name='opentherm[options][coolingSupport]']", data.opentherm.options.coolingSupport); - setCheckboxValue("[name='opentherm[options][summerWinterMode]']", data.opentherm.options.summerWinterMode); - setCheckboxValue("[name='opentherm[options][heatingStateToSummerWinterMode]']", data.opentherm.options.heatingStateToSummerWinterMode); - setCheckboxValue("[name='opentherm[options][ch2AlwaysEnabled]']", data.opentherm.options.ch2AlwaysEnabled); - setCheckboxValue("[name='opentherm[options][heatingToCh2]']", data.opentherm.options.heatingToCh2); - setCheckboxValue("[name='opentherm[options][dhwToCh2]']", data.opentherm.options.dhwToCh2); - setCheckboxValue("[name='opentherm[options][dhwBlocking]']", data.opentherm.options.dhwBlocking); - setCheckboxValue("[name='opentherm[options][dhwStateAsDhwBlocking]']", data.opentherm.options.dhwStateAsDhwBlocking); - setCheckboxValue("[name='opentherm[options][maxTempSyncWithTargetTemp]']", data.opentherm.options.maxTempSyncWithTargetTemp); - setCheckboxValue("[name='opentherm[options][getMinMaxTemp]']", data.opentherm.options.getMinMaxTemp); - setCheckboxValue("[name='opentherm[options][ignoreDiagState]']", data.opentherm.options.ignoreDiagState); - setCheckboxValue("[name='opentherm[options][autoFaultReset]']", data.opentherm.options.autoFaultReset); - setCheckboxValue("[name='opentherm[options][autoDiagReset]']", data.opentherm.options.autoDiagReset); - setCheckboxValue("[name='opentherm[options][setDateAndTime]']", data.opentherm.options.setDateAndTime); - setCheckboxValue("[name='opentherm[options][nativeOTC]']", data.opentherm.options.nativeOTC); - setCheckboxValue("[name='opentherm[options][immergasFix]']", data.opentherm.options.immergasFix); - setCheckboxValue("[name='opentherm[options][alwaysSendIndoorTemp]']", data.opentherm.options.alwaysSendIndoorTemp); - setBusy('#ot-settings-busy', '#ot-settings', false); + } else if (section === 'opentherm') { + setInputValue("[name='in_gpio']", data.opentherm.in_gpio < 255 ? data.opentherm.in_gpio : '', {}, form); + setInputValue("[name='out_gpio']", data.opentherm.out_gpio < 255 ? data.opentherm.out_gpio : '', {}, form); + setInputValue("[name='rx_led_gpio']", data.opentherm.rx_led_gpio < 255 ? data.opentherm.rx_led_gpio : '', {}, form); + setInputValue("[name='member_id']", data.opentherm.member_id, {}, form); + setInputValue("[name='flags']", data.opentherm.flags, {}, form); + setInputValue("[name='min_power']", data.opentherm.min_power, {}, form); + setInputValue("[name='max_power']", data.opentherm.max_power, {}, form); + setRadioValue("[name='heating_disabling_action']", data.opentherm.heating_disabling_action, form); + setRadioValue("[name='dhw_disabling_action']", data.opentherm.dhw_disabling_action, form); + setRadioValue("[name='ch2_disabling_action']", data.opentherm.ch2_disabling_action, form); + setCheckboxValue("[name='options[dhw_support]']", data.opentherm.options.dhw_support, form); + setCheckboxValue("[name='options[cooling_support]']", data.opentherm.options.cooling_support, form); + setCheckboxValue("[name='options[summer_winter_mode]']", data.opentherm.options.summer_winter_mode, form); + setCheckboxValue("[name='options[heating_state_to_summer_winter_mode]']", data.opentherm.options.heating_state_to_summer_winter_mode, form); + setCheckboxValue("[name='options[ch2_always_enabled]']", data.opentherm.options.ch2_always_enabled, form); + setCheckboxValue("[name='options[heating_to_ch2]']", data.opentherm.options.heating_to_ch2, form); + setCheckboxValue("[name='options[dhw_to_ch2]']", data.opentherm.options.dhw_to_ch2, form); + setCheckboxValue("[name='options[dhw_blocking]']", data.opentherm.options.dhw_blocking, form); + setCheckboxValue("[name='options[dhw_state_as_dhw_blocking]']", data.opentherm.options.dhw_state_as_dhw_blocking, form); + setCheckboxValue("[name='options[max_temp_sync_with_target_temp]']", data.opentherm.options.max_temp_sync_with_target_temp, form); + setCheckboxValue("[name='options[get_min_max_temp]']", data.opentherm.options.get_min_max_temp, form); + setCheckboxValue("[name='options[ignore_diag_state]']", data.opentherm.options.ignore_diag_state, form); + setCheckboxValue("[name='options[auto_fault_reset]']", data.opentherm.options.auto_fault_reset, form); + setCheckboxValue("[name='options[auto_diag_reset]']", data.opentherm.options.auto_diag_reset, form); + setCheckboxValue("[name='options[set_date_and_time]']", data.opentherm.options.set_date_and_time, form); + setCheckboxValue("[name='options[native_otc]']", data.opentherm.options.native_otc, form); + setCheckboxValue("[name='options[immergas_fix]']", data.opentherm.options.immergas_fix, form); + setCheckboxValue("[name='options[always_send_indoor_temp]']", data.opentherm.options.always_send_indoor_temp, form); - // MQTT - setCheckboxValue("[name='mqtt[enabled]']", data.mqtt.enabled); - setCheckboxValue("[name='mqtt[homeAssistantDiscovery]']", data.mqtt.homeAssistantDiscovery); - setInputValue("[name='mqtt[server]']", data.mqtt.server); - setInputValue("[name='mqtt[port]']", data.mqtt.port); - setInputValue("[name='mqtt[user]']", data.mqtt.user); - setInputValue("[name='mqtt[password]']", data.mqtt.password); - setInputValue("[name='mqtt[prefix]']", data.mqtt.prefix); - setInputValue("[name='mqtt[interval]']", data.mqtt.interval); - setBusy('#mqtt-settings-busy', '#mqtt-settings', false); + } else if (section === 'mqtt') { + setCheckboxValue("[name='enabled']", data.mqtt.enabled, form); + setCheckboxValue("[name='ha_discovery']", data.mqtt.ha_discovery, form); + setInputValue("[name='server']", data.mqtt.server, {}, form); + setInputValue("[name='port']", data.mqtt.port, {}, form); + setInputValue("[name='user']", data.mqtt.user, {}, form); + setInputValue("[name='password']", data.mqtt.password, {}, form); + setInputValue("[name='prefix']", data.mqtt.prefix, {}, form); + setInputValue("[name='interval']", data.mqtt.interval, {}, form); - // Extpump - setCheckboxValue("[name='externalPump[use]']", data.externalPump.use); - setInputValue("[name='externalPump[gpio]']", data.externalPump.gpio < 255 ? data.externalPump.gpio : ''); - setCheckboxValue("[name='externalPump[invertState]']", data.externalPump.invertState); - setInputValue("[name='externalPump[postCirculationTime]']", data.externalPump.postCirculationTime); - setInputValue("[name='externalPump[antiStuckInterval]']", data.externalPump.antiStuckInterval); - setInputValue("[name='externalPump[antiStuckTime]']", data.externalPump.antiStuckTime); - setBusy('#extpump-settings-busy', '#extpump-settings', false); + } else if (section === 'ext_pump') { + setCheckboxValue("[name='use']", data.ext_pump.use, form); + setInputValue("[name='gpio']", data.ext_pump.gpio < 255 ? data.ext_pump.gpio : '', {}, form); + setCheckboxValue("[name='invert_state']", data.ext_pump.invert_state, form); + setInputValue("[name='post_circulation_time']", data.ext_pump.post_circulation_time, {}, form); + setInputValue("[name='antistuck_interval']", data.ext_pump.antistuck_interval, {}, form); + setInputValue("[name='antistuck_time']", data.ext_pump.antistuck_time, {}, form); - // Cascade control - setCheckboxValue("[name='cascadeControl[input][enabled]']", data.cascadeControl.input.enabled); - setInputValue("[name='cascadeControl[input][gpio]']", data.cascadeControl.input.gpio < 255 ? data.cascadeControl.input.gpio : ''); - setCheckboxValue("[name='cascadeControl[input][invertState]']", data.cascadeControl.input.invertState); - setInputValue("[name='cascadeControl[input][thresholdTime]']", data.cascadeControl.input.thresholdTime); + } else if (section === 'cascade_control') { + setCheckboxValue("[name='input[enabled]']", data.cascade_control.input.enabled, form); + setInputValue("[name='input[gpio]']", data.cascade_control.input.gpio < 255 ? data.cascade_control.input.gpio : '', {}, form); + setCheckboxValue("[name='input[invert_state]']", data.cascade_control.input.invert_state, form); + setInputValue("[name='input[threshold_time]']", data.cascade_control.input.threshold_time, {}, form); - setCheckboxValue("[name='cascadeControl[output][enabled]']", data.cascadeControl.output.enabled); - setInputValue("[name='cascadeControl[output][gpio]']", data.cascadeControl.output.gpio < 255 ? data.cascadeControl.output.gpio : ''); - setCheckboxValue("[name='cascadeControl[output][invertState]']", data.cascadeControl.output.invertState); - setInputValue("[name='cascadeControl[output][thresholdTime]']", data.cascadeControl.output.thresholdTime); - setCheckboxValue("[name='cascadeControl[output][onFault]']", data.cascadeControl.output.onFault); - setCheckboxValue("[name='cascadeControl[output][onLossConnection]']", data.cascadeControl.output.onLossConnection); - setCheckboxValue("[name='cascadeControl[output][onEnabledHeating]']", data.cascadeControl.output.onEnabledHeating); - setBusy('#cc-settings-busy', '#cc-settings', false); + setCheckboxValue("[name='output[enabled]']", data.cascade_control.output.enabled, form); + setInputValue("[name='output[gpio]']", data.cascade_control.output.gpio < 255 ? data.cascade_control.output.gpio : '', {}, form); + setCheckboxValue("[name='output[invert_state]']", data.cascade_control.output.invert_state, form); + setInputValue("[name='output[threshold_time]']", data.cascade_control.output.threshold_time, {}, form); + setCheckboxValue("[name='output[on_fault]']", data.cascade_control.output.on_fault, form); + setCheckboxValue("[name='output[on_loss_connection]']", data.cascade_control.output.on_loss_connection, form); + setCheckboxValue("[name='output[on_enabled_heating]']", data.cascade_control.output.on_enabled_heating, form); - // Heating - setInputValue("[name='heating[minTemp]']", data.heating.minTemp, { - "min": data.system.unitSystem == 0 ? 0 : 32, - "max": data.system.unitSystem == 0 ? 99 : 211 - }); - setInputValue("[name='heating[maxTemp]']", data.heating.maxTemp, { - "min": data.system.unitSystem == 0 ? 1 : 33, - "max": data.system.unitSystem == 0 ? 100 : 212 - }); - setCheckboxValue("[name='heating[hysteresis][enabled]']", data.heating.hysteresis.enabled); - setInputValue("[name='heating[hysteresis][value]']", data.heating.hysteresis.value); - setInputValue("[name='heating[turboFactor]']", data.heating.turboFactor); - setInputValue("[name='heating[maxModulation]']", data.heating.maxModulation); - setSelectValue("[name='heating[indoorTempAvgType]']", data.heating.indoorTempAvgType); - setSelectValue("[name='heating[outdoorTempAvgType]']", data.heating.outdoorTempAvgType); - setInputValue("[name='heating[overheatProtection][highTemp]']", data.heating.overheatProtection.highTemp, { - "min": 0, - "max": data.system.unitSystem == 0 ? 100 : 212 - }); - setInputValue("[name='heating[overheatProtection][lowTemp]']", data.heating.overheatProtection.lowTemp, { - "min": 0, - "max": data.system.unitSystem == 0 ? 99 : 211 - }); - setInputValue("[name='heating[freezeProtection][highTemp]']", data.heating.freezeProtection.highTemp, { - "min": data.system.unitSystem == 0 ? 1 : 34, - "max": data.system.unitSystem == 0 ? 50 : 122 - }); - setInputValue("[name='heating[freezeProtection][lowTemp]']", data.heating.freezeProtection.lowTemp, { - "min": data.system.unitSystem == 0 ? 1 : 34, - "max": data.system.unitSystem == 0 ? 30 : 86 - }); - setBusy('#heating-settings-busy', '#heating-settings', false); + } else if (section === 'heating') { + setInputValue("[name='min_temp']", Number(data.heating.min_temp.toFixed(1)), { + "min": data.system.unit_system == 0 ? 0 : 32, + "max": data.system.unit_system == 0 ? 99 : 211 + }, form); + setInputValue("[name='max_temp']", Number(data.heating.max_temp.toFixed(1)), { + "min": data.system.unit_system == 0 ? 1 : 33.8, + "max": data.system.unit_system == 0 ? 100 : 212 + }, form); + setCheckboxValue("[name='hysteresis[enabled]']", data.heating.hysteresis.enabled, form); + setInputValue("[name='hysteresis[value]']", data.heating.hysteresis.value, {}, form); + setInputValue("[name='turbo_factor']", data.heating.turbo_factor, {}, form); + setInputValue("[name='max_modulation']", data.heating.max_modulation, {}, form); + setSelectValue("[name='indoor_temp_avg_type']", data.heating.indoor_temp_avg_type, form); + setSelectValue("[name='outdoor_temp_avg_type']", data.heating.outdoor_temp_avg_type, form); + setInputValue("[name='overheat_protection[high_temp]']", Number(data.heating.overheat_protection.high_temp.toFixed(1)), { + "min": 0, + "max": data.system.unit_system == 0 ? 100 : 212 + }, form); + setInputValue("[name='overheat_protection[low_temp]']", Number(data.heating.overheat_protection.low_temp.toFixed(1)), { + "min": 0, + "max": data.system.unit_system == 0 ? 99 : 211 + }, form); + setInputValue("[name='freeze_protection[high_temp]']", Number(data.heating.freeze_protection.high_temp.toFixed(1)), { + "min": data.system.unit_system == 0 ? 1 : 33.8, + "max": data.system.unit_system == 0 ? 50 : 122 + }, form); + setInputValue("[name='freeze_protection[low_temp]']", Number(data.heating.freeze_protection.low_temp.toFixed(1)), { + "min": data.system.unit_system == 0 ? 1 : 33.8, + "max": data.system.unit_system == 0 ? 30 : 86 + }, form); - // DHW - setInputValue("[name='dhw[minTemp]']", data.dhw.minTemp, { - "min": data.system.unitSystem == 0 ? 0 : 32, - "max": data.system.unitSystem == 0 ? 99 : 211 - }); - setInputValue("[name='dhw[maxTemp]']", data.dhw.maxTemp, { - "min": data.system.unitSystem == 0 ? 1 : 33, - "max": data.system.unitSystem == 0 ? 100 : 212 - }); - setInputValue("[name='dhw[maxModulation]']", data.dhw.maxModulation); - setInputValue("[name='dhw[overheatProtection][highTemp]']", data.dhw.overheatProtection.highTemp, { - "min": 0, - "max": data.system.unitSystem == 0 ? 100 : 212 - }); - setInputValue("[name='dhw[overheatProtection][lowTemp]']", data.dhw.overheatProtection.lowTemp, { - "min": 0, - "max": data.system.unitSystem == 0 ? 99 : 211 - }); - setBusy('#dhw-settings-busy', '#dhw-settings', false); + } else if (section === 'dhw') { + setInputValue("[name='min_temp']", Number(data.dhw.min_temp.toFixed(1)), { + "min": data.system.unit_system == 0 ? 0 : 32, + "max": data.system.unit_system == 0 ? 99 : 211 + }, form); + setInputValue("[name='max_temp']", Number(data.dhw.max_temp.toFixed(1)), { + "min": data.system.unit_system == 0 ? 1 : 33.8, + "max": data.system.unit_system == 0 ? 100 : 212 + }, form); + setInputValue("[name='max_modulation']", data.dhw.max_modulation, {}, form); + setInputValue("[name='overheat_protection[high_temp]']", Number(data.dhw.overheat_protection.high_temp.toFixed(1)), { + "min": 0, + "max": data.system.unit_system == 0 ? 100 : 212 + }, form); + setInputValue("[name='overheat_protection[low_temp]']", Number(data.dhw.overheat_protection.low_temp.toFixed(1)), { + "min": 0, + "max": data.system.unit_system == 0 ? 99 : 211 + }, form); - // Emergency mode - if (data.opentherm.options.nativeOTC) { - setInputValue("[name='emergency[target]']", data.emergency.target, { - "min": data.system.unitSystem == 0 ? 5 : 41, - "max": data.system.unitSystem == 0 ? 40 : 104 - }); + } else if (section === 'emergency') { + if (data.opentherm.options.native_otc) { + setInputValue("[name='target']", data.emergency.target, { + "min": data.system.unit_system == 0 ? 5 : 41, + "max": data.system.unit_system == 0 ? 40 : 104 + }, form); - } else { - setInputValue("[name='emergency[target]']", data.emergency.target, { - "min": data.heating.minTemp, - "max": data.heating.maxTemp, - }); + } else { + setInputValue("[name='target']", data.emergency.target, { + "min": data.heating.min_temp, + "max": data.heating.max_temp, + }, form); + } + setInputValue("[name='treshold_time']", data.emergency.treshold_time, {}, form); + + } else if (section === 'equitherm') { + setCheckboxValue("[name='enabled']", data.equitherm.enabled, form); + setInputValue("[name='slope']", data.equitherm.slope, {}, form); + setInputValue("[name='exponent']", data.equitherm.exponent, {}, form); + setInputValue("[name='shift']", data.equitherm.shift, {}, form); + setInputValue("[name='target_diff_factor']", data.equitherm.target_diff_factor, {}, form); + + const etMinTemp = parseInt(data.system.unit_system == 0 ? 5 : 41); + const etMaxTemp = parseInt(data.system.unit_system == 0 ? 30 : 86); + const etTargetTemp = constrain(parseFloat(data.heating.target), etMinTemp, etMaxTemp); + + setInputValue(".etChartTargetTemp", etTargetTemp.toFixed(1), { + "min": etMinTemp, + "max": etMaxTemp + }, form); + + etChartConfig.slope = data.equitherm.slope; + etChartConfig.exponent = data.equitherm.exponent; + etChartConfig.shift = data.equitherm.shift; + etChartConfig.unitSystem = data.system.unit_system; + etChartConfig.targetTemp = data.system.unit_system == 0 ? etTargetTemp : f2c(etTargetTemp); + etChartConfig.minTemp = data.system.unit_system == 0 ? data.heating.min_temp : f2c(data.heating.min_temp); + etChartConfig.maxTemp = data.system.unit_system == 0 ? data.heating.max_temp : f2c(data.heating.max_temp); + + makeEquithermChart(); + + } else if (section === 'pid') { + setCheckboxValue("[name='enabled']", data.pid.enabled, form); + setInputValue("[name='p_factor']", data.pid.p_factor, {}, form); + setInputValue("[name='i_factor']", data.pid.i_factor, {}, form); + setInputValue("[name='d_factor']", data.pid.d_factor, {}, form); + setInputValue("[name='dt']", data.pid.dt, {}, form); + setInputValue("[name='min_temp']", Number(data.pid.min_temp.toFixed(1)), { + "min": data.equitherm.enabled ? -99 : (data.system.unit_system == 0 ? 0 : 32), + "max": data.equitherm.enabled ? 99 : (data.system.unit_system == 0 ? 99 : 211), + "step": data.equitherm.enabled ? 1 : 0.1 + }, form); + setInputValue("[name='max_temp']", Number(data.pid.max_temp.toFixed(1)), { + "min": data.equitherm.enabled ? 1 : (data.system.unit_system == 0 ? 1 : 33.8), + "max": data.equitherm.enabled ? 99 : (data.system.unit_system == 0 ? 100 : 212), + "step": data.equitherm.enabled ? 1 : 0.1 + }, form); + setCheckboxValue("[name='deadband[enabled]']", data.pid.deadband.enabled, form); + setInputValue("[name='deadband[p_multiplier]']", data.pid.deadband.p_multiplier, {}, form); + setInputValue("[name='deadband[i_multiplier]']", data.pid.deadband.i_multiplier, {}, form); + setInputValue("[name='deadband[d_multiplier]']", data.pid.deadband.d_multiplier, {}, form); + setInputValue("[name='deadband[threshold_high]']", data.pid.deadband.threshold_high, {}, form); + setInputValue("[name='deadband[threshold_low]']", data.pid.deadband.threshold_low, {}, form); } - setInputValue("[name='emergency[tresholdTime]']", data.emergency.tresholdTime); - setBusy('#emergency-settings-busy', '#emergency-settings', false); - - // Equitherm - setCheckboxValue("[name='equitherm[enabled]']", data.equitherm.enabled); - setInputValue("[name='equitherm[slope]']", data.equitherm.slope); - setInputValue("[name='equitherm[exponent]']", data.equitherm.exponent); - setInputValue("[name='equitherm[shift]']", data.equitherm.shift); - setInputValue("[name='equitherm[targetDiffFactor]']", data.equitherm.targetDiffFactor); - setBusy('#equitherm-settings-busy', '#equitherm-settings', false); - - // PID - setCheckboxValue("[name='pid[enabled]']", data.pid.enabled); - setInputValue("[name='pid[p_factor]']", data.pid.p_factor); - setInputValue("[name='pid[i_factor]']", data.pid.i_factor); - setInputValue("[name='pid[d_factor]']", data.pid.d_factor); - setInputValue("[name='pid[dt]']", data.pid.dt); - setInputValue("[name='pid[minTemp]']", data.pid.minTemp, { - "min": data.equitherm.enabled ? (data.system.unitSystem == 0 ? -100 : -146) : (data.system.unitSystem == 0 ? 0 : 32), - "max": (data.system.unitSystem == 0 ? 99 : 211) - }); - setInputValue("[name='pid[maxTemp]']", data.pid.maxTemp, { - "min": (data.system.unitSystem == 0 ? 0 : 33), - "max": (data.system.unitSystem == 0 ? 100 : 212) - }); - setCheckboxValue("[name='pid[deadband][enabled]']", data.pid.deadband.enabled); - setInputValue("[name='pid[deadband][p_multiplier]']", data.pid.deadband.p_multiplier); - setInputValue("[name='pid[deadband][i_multiplier]']", data.pid.deadband.i_multiplier); - setInputValue("[name='pid[deadband][d_multiplier]']", data.pid.deadband.d_multiplier); - setInputValue("[name='pid[deadband][thresholdHigh]']", data.pid.deadband.thresholdHigh); - setInputValue("[name='pid[deadband][thresholdLow]']", data.pid.deadband.thresholdLow); - setBusy('#pid-settings-busy', '#pid-settings', false); - - const etMinTemp = parseInt(data.system.unitSystem == 0 ? 5 : 41); - const etMaxTemp = parseInt(data.system.unitSystem == 0 ? 30 : 86); - const etTargetTemp = constrain(parseFloat(data.heating.target), etMinTemp, etMaxTemp); - - setInputValue(".etChartTargetTemp", etTargetTemp.toFixed(1), { - "min": etMinTemp, - "max": etMaxTemp - }); - - etChartConfig.slope = data.equitherm.slope; - etChartConfig.exponent = data.equitherm.exponent; - etChartConfig.shift = data.equitherm.shift; - etChartConfig.unitSystem = data.system.unitSystem; - etChartConfig.minTemp = data.heating.minTemp; - etChartConfig.maxTemp = data.heating.maxTemp; - - makeEquithermChart(); + setBusy(`#${form.id}-busy`, `#${form.id}`, false); }; - try { + const loadedSettings = {}; + let sectionLoading = Promise.resolve(); + + const getSettings = async (section) => { + const response = await fetch(`/api/settings/${section}`, { + cache: "no-cache", + credentials: "include" + }); + if (!response.ok) { + throw new Error('Response not valid'); + } + return response.json(); + }; + + const loadTimezones = async () => { + const selector = document.querySelector(".presetTimezones"); + if (selector.options.length > 1) { + return; + } const response = await fetch("/static/timezones.json"); if (!response.ok) { throw new Error('Response not valid'); } - - const result = await response.json(); - const ptzSelector = document.querySelector(".presetTimezones"); - for (const ptzName in result) { - ptzSelector.appendChild( - new Option(ptzName, result[ptzName]) - ); + const timezones = await response.json(); + for (const name in timezones) { + selector.appendChild(new Option(name, timezones[name])); } + }; - ptzSelector.addEventListener("change", async (event) => { - document.querySelector("[name='system[ntp][timezone]']").value = event.target.value; - }); - - } catch (error) { - console.log(error); - } - - try { - const response = await fetch("/api/settings", { - cache: "no-cache", - credentials: "include" - }); - - if (!response.ok) { - throw new Error('Response not valid'); + const loadSection = (form, result = null) => { + const details = form.closest('details'); + if (details.dataset.loading === '1') { + if (result !== null) { + // The saved value must replace any older response still in flight. + details.dataset.reload = '1'; + } + return; } + details.dataset.loading = '1'; + const busy = document.getElementById(`${form.id}-busy`); + busy.textContent = ''; + busy.setAttribute('aria-busy', true); + setBusy(`#${busy.id}`, `#${form.id}`, true); - const result = await response.json(); - fillData(result); + // Read one section at a time, including when several cards are opened. + sectionLoading = sectionLoading.then(async () => { + try { + if (!details.open && result === null) { + return; + } + const section = form.dataset.section; + const data = {}; + if (['heating', 'dhw', 'emergency', 'equitherm', 'pid'].includes(section)) { + data.system = await getSettings('system'); + } + if (section === 'emergency') { + data.opentherm = await getSettings('opentherm'); + if (!data.opentherm.options.native_otc) { + data.heating = await getSettings('heating'); + } + } else if (section === 'equitherm') { + data.heating = await getSettings('heating'); + } else if (section === 'pid') { + data.equitherm = await getSettings('equitherm'); + } + data[section] = result === null ? await getSettings(section) : result; + if (section === 'system') { + try { + await loadTimezones(); + } catch (error) { + console.log(error); + } + } + if (details.dataset.reload === '1') { + return; + } + fillData(form, data); + loadedSettings[section] = data[section]; + details.dataset.preloaded = '1'; + } catch (error) { + details.dataset.preloaded = '0'; + busy.setAttribute('aria-busy', false); + busy.textContent = i18n('button.error'); + console.log(error); + } finally { + details.dataset.loading = '0'; + if (details.dataset.reload === '1') { + details.dataset.reload = '0'; + if (details.open) { + loadSection(form); + } + } + } + }); + }; - setupForm('#portal-settings', fillData, ['portal.login', 'portal.password']); - setupForm('#system-settings', fillData); - setupForm('#heating-settings', fillData); - setupForm('#dhw-settings', fillData); - setupForm('#emergency-settings', fillData); - setupForm('#equitherm-settings', fillData); - setupForm('#pid-settings', fillData); - setupForm('#ot-settings', fillData); - setupForm('#mqtt-settings', fillData, ['mqtt.user', 'mqtt.password', 'mqtt.prefix']); - setupForm('#extpump-settings', fillData); - setupForm('#cc-settings', fillData); + const setupSettingsForm = (selector, noCastItems = []) => { + const form = document.querySelector(selector); + const details = form.closest('details'); + const section = form.dataset.section; + details.addEventListener('toggle', () => { + if (details.open && details.dataset.preloaded !== '1') { + loadSection(form); + } + }); + setupForm(selector, (result) => { + const previous = loadedSettings[section]; + loadSection(form, result); + let affected = []; + if (section === 'system' && previous.unit_system !== result.unit_system) { + affected = ['heating', 'dhw', 'emergency', 'equitherm', 'pid']; + } else if (section === 'opentherm' && previous.options.native_otc !== result.options.native_otc) { + affected = ['emergency', 'equitherm', 'pid']; + } else if (section === 'heating' && (previous.min_temp !== result.min_temp + || previous.max_temp !== result.max_temp || previous.target !== result.target)) { + affected = ['emergency', 'equitherm']; + } else if (section === 'equitherm' && previous.enabled !== result.enabled) { + affected = ['pid']; + } else if (section === 'pid' && previous.enabled !== result.enabled) { + affected = ['equitherm']; + } + for (const otherForm of document.querySelectorAll('form[data-section]')) { + if (affected.includes(otherForm.dataset.section)) { + const otherDetails = otherForm.closest('details'); + otherDetails.dataset.preloaded = '0'; + if (otherDetails.dataset.loading === '1') { + // Finish the old request, then read the normalized values again. + otherDetails.dataset.reload = '1'; + } else if (otherDetails.open) { + loadSection(otherForm); + } + } + } + }, noCastItems); + if (details.open) { + loadSection(form); + } + }; - } catch (error) { - console.log(error); - } + setupSettingsForm('#portal-settings', ['login', 'password']); + setupSettingsForm('#system-settings', ['ntp.server', 'ntp.timezone']); + setupSettingsForm('#heating-settings'); + setupSettingsForm('#dhw-settings'); + setupSettingsForm('#emergency-settings'); + setupSettingsForm('#equitherm-settings'); + setupSettingsForm('#pid-settings'); + setupSettingsForm('#ot-settings'); + setupSettingsForm('#mqtt-settings', ['server', 'user', 'password', 'prefix']); + setupSettingsForm('#extpump-settings'); + setupSettingsForm('#cc-settings'); + + document.querySelector(".presetTimezones").addEventListener('change', (event) => { + document.querySelector("#system-settings [name='ntp[timezone]']").value = event.target.value; + }); document.querySelector(".etChartTargetTemp").addEventListener("input", async (event) => { setValue('.etChartTargetTempValue', parseFloat(event.target.value).toFixed(1)); @@ -1428,12 +1520,13 @@ return; } - etChartConfig.targetTemp = parseFloat(event.target.value); - setValue('.etChartTargetTempValue', etChartConfig.targetTemp.toFixed(1)); + const targetTemp = parseFloat(event.target.value); + etChartConfig.targetTemp = etChartConfig.unitSystem == 0 ? targetTemp : f2c(targetTemp); + setValue('.etChartTargetTempValue', targetTemp.toFixed(1)); makeEquithermChart(); }); - document.querySelector("[name='equitherm[slope]']").addEventListener("change", async (event) => { + document.querySelector("#equitherm-settings [name='slope']").addEventListener("change", async (event) => { if (!event.target.checkValidity()) { return; } @@ -1442,7 +1535,7 @@ makeEquithermChart(); }); - document.querySelector("[name='equitherm[exponent]']").addEventListener("change", async (event) => { + document.querySelector("#equitherm-settings [name='exponent']").addEventListener("change", async (event) => { if (!event.target.checkValidity()) { return; } @@ -1451,7 +1544,7 @@ makeEquithermChart(); }); - document.querySelector("[name='equitherm[shift]']").addEventListener("change", async (event) => { + document.querySelector("#equitherm-settings [name='shift']").addEventListener("change", async (event) => { if (!event.target.checkValidity()) { return; } diff --git a/src_data/pages/upgrade.html b/src_data/pages/upgrade.html index dcdca33..1f7ddca 100644 --- a/src_data/pages/upgrade.html +++ b/src_data/pages/upgrade.html @@ -39,7 +39,7 @@

upgrade.section.backupAndRestore.desc

- +