From 9ff1bd14f5957c5a16ba2478347885258aaac86d Mon Sep 17 00:00:00 2001 From: Yurii Date: Sun, 22 Nov 2026 03:13:23 +0300 Subject: [PATCH] refactor: remove unused code from firmware, portal and build scripts Remove the unused sensor connection getter, slug prefix and suffix helpers, UTC conversion and array formatting routines. Drop unused shared strings and the CONFIG_URL macro. Remove setupUpgradeForm from the shared browser bundle. The upgrade page registers its own submit handler. Delete the obsolete Python gzip packer and its import. Gulp handles compression when building the web assets. --- include/Sensors.h | 36 ---------- include/macros.h | 1 - include/strings_shared.h | 7 -- include/utils.h | 55 --------------- src_data/scripts/utils.js | 142 -------------------------------------- tools/build.py | 21 ------ 6 files changed, 262 deletions(-) diff --git a/include/Sensors.h b/include/Sensors.h index 7f9c34d..73d3cd5 100644 --- a/include/Sensors.h +++ b/include/Sensors.h @@ -489,14 +489,6 @@ public: return updated; } - static bool getConnectionStatusById(const uint8_t sensorId) { - std::lock_guard lock(mutex); - if (settings == nullptr || results == nullptr || !isValidSensorId(sensorId)) { - return false; - } - return results[sensorId].connected; - } - static bool setConnectionStatusById(const uint8_t sensorId, const bool status, const bool updateActivityAt = true) { char name[sizeof(Settings::name)]; bool changed; @@ -729,34 +721,6 @@ public: return result; } - static std::string makeSlugWithSuffix(std::string_view value, std::string_view suffix, char separator = '_') { - std::string result; - result.reserve(value.size() + 1 + suffix.size()); - makeSlug(result, value, separator); - result += separator; - result.append(suffix); - return result; - } - - static std::string& makeSlugWithSuffix(std::string& result, std::string_view value, std::string_view suffix, char separator = '_') { - result = makeSlugWithSuffix(value, suffix, separator); - return result; - } - - static std::string makeSlugWithPrefix(std::string_view value, std::string_view prefix, char separator = '_') { - std::string result; - result.reserve(prefix.size() + 1 + value.size()); - makeSlug(result, value, separator); - result.insert(0, 1, separator); - result.insert(0, prefix); - return result; - } - - static std::string& makeSlugWithPrefix(std::string& result, std::string_view value, std::string_view prefix, char separator = '_') { - result = makeSlugWithPrefix(value, prefix, separator); - return result; - } - static uint8_t bluetoothRssiToQuality(int rssi) { return constrain(map(rssi, -110, -50, 0, 100), 0, 100);; } diff --git a/include/macros.h b/include/macros.h index 8c22766..34b1306 100644 --- a/include/macros.h +++ b/include/macros.h @@ -8,7 +8,6 @@ #define MQTT_RECONNECT_INTERVAL 15000 #define MQTT_SENSOR_REPUBLISH_INTERVAL 300000u -#define CONFIG_URL "http://%s/" #define SETTINGS_VALID_VALUE "stvalid" // only 8 chars! #define GPIO_IS_NOT_CONFIGURED 0xff diff --git a/include/strings_shared.h b/include/strings_shared.h index 71e85c3..8c1f1d4 100644 --- a/include/strings_shared.h +++ b/include/strings_shared.h @@ -12,7 +12,6 @@ inline const char L_PORTAL_CAPTIVE[] = "PORTAL.CAPTIVE"; inline const char L_PORTAL_OTA[] = "PORTAL.OTA"; inline const char L_MAIN[] = "MAIN"; inline const char L_MQTT[] = "MQTT"; -inline const char L_MQTT_HA[] = "MQTT.HA"; inline const char L_MQTT_MSG[] = "MQTT.MSG"; inline const char L_OT[] = "OT"; inline const char L_OT_DHW[] = "OT.DHW"; @@ -42,7 +41,6 @@ inline const char S_APP_VERSION[] = "app_version"; inline const char S_AUTH[] = "auth"; inline const char S_AUTO_DIAG_RESET[] = "auto_diag_reset"; inline const char S_AUTO_FAULT_RESET[] = "auto_fault_reset"; -inline const char S_BACKTRACE[] = "backtrace"; inline const char S_BATTERY[] = "battery"; inline const char S_BAUDRATE[] = "baudrate"; inline const char S_BLOCKING[] = "blocking"; @@ -56,14 +54,11 @@ inline const char S_CHIP[] = "chip"; inline const char S_CODE[] = "code"; inline const char S_COMMIT[] = "commit"; inline const char S_CONNECTED[] = "connected"; -inline const char S_CONTINUES[] = "continues"; inline const char S_COOLING[] = "cooling"; inline const char S_COOLING_SUPPORT[] = "cooling_support"; inline const char S_CORE[] = "core"; inline const char S_CORES[] = "cores"; -inline const char S_CRASH[] = "crash"; inline const char S_CURRENT_TEMP[] = "current_temp"; -inline const char S_DATA[] = "data"; inline const char S_DATE[] = "date"; inline const char S_DEADBAND[] = "deadband"; inline const char S_DHW[] = "dhw"; @@ -80,7 +75,6 @@ inline const char S_D_MULTIPLIER[] = "d_multiplier"; inline const char S_EMERGENCY[] = "emergency"; inline const char S_ENABLED[] = "enabled"; inline const char S_ENV[] = "env"; -inline const char S_EPC[] = "epc"; inline const char S_EQUITHERM[] = "equitherm"; inline const char S_EXPONENT[] = "exponent"; inline const char S_EXTERNAL_PUMP[] = "ext_pump"; @@ -174,7 +168,6 @@ inline const char S_PURPOSE[] = "purpose"; inline const char S_PSRAM[] = "psram"; inline const char S_P_FACTOR[] = "p_factor"; inline const char S_P_MULTIPLIER[] = "p_multiplier"; -inline const char S_REASON[] = "reason"; inline const char S_RESET_DIAGNOSTIC[] = "reset_diagnostic"; inline const char S_RESET_FAULT[] = "reset_fault"; inline const char S_RESET_REASON[] = "reset_reason"; diff --git a/include/utils.h b/include/utils.h index 3befebf..d187227 100644 --- a/include/utils.h +++ b/include/utils.h @@ -40,45 +40,6 @@ inline std::string getChipId(const char* prefix = nullptr, const char* suffix = return chipId; } -inline bool isLeapYear(short year) { - if (year % 4 != 0) { - return false; - } - - if (year % 100 != 0) { - return true; - } - - return (year % 400) == 0; -} - -// convert UTC tm time to time_t epoch time -// source: https://github.com/cyberman54/ESP32-Paxcounter/blob/master/src/timekeeper.cpp -inline time_t mkgmtime(const struct tm *ptm) { - const int SecondsPerMinute = 60; - const int SecondsPerHour = 3600; - const int SecondsPerDay = 86400; - const int DaysOfMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - time_t secs = 0; - // tm_year is years since 1900 - int year = ptm->tm_year + 1900; - for (int y = 1970; y < year; ++y) { - secs += (isLeapYear(y) ? 366 : 365) * SecondsPerDay; - } - // tm_mon is month from 0..11 - for (int m = 0; m < ptm->tm_mon; ++m) { - secs += DaysOfMonth[m] * SecondsPerDay; - if (m == 1 && isLeapYear(year)) { - secs += SecondsPerDay; - } - } - secs += (ptm->tm_mday - 1) * SecondsPerDay; - secs += ptm->tm_hour * SecondsPerHour; - secs += ptm->tm_min * SecondsPerMinute; - secs += ptm->tm_sec; - return secs; -} - inline float liter2gallon(float value) { return value / 3.785411784f; } @@ -157,22 +118,6 @@ inline float roundf(float value, uint8_t decimals = 2) { return std::isfinite(scaled) ? std::round(scaled) / multiplier : value; } -template -void arr2str(String& str, T arr[], size_t length) { - char buffer[12]; - for (size_t i = 0; i < length; i++) { - auto addr = arr[i]; - if (!addr) { - continue; - } - - sprintf(buffer, "0x%08X ", addr); - str.concat(buffer); - } - - str.trim(); -} - inline uint8_t rssiToSignalQuality(int16_t rssi) { return constrain(map(rssi, -100, -50, 0, 100), 0, 100); } diff --git a/src_data/scripts/utils.js b/src_data/scripts/utils.js index 092586e..929a46f 100644 --- a/src_data/scripts/utils.js +++ b/src_data/scripts/utils.js @@ -264,148 +264,6 @@ const setupNetworkScanForm = (formSelector, tableSelector) => { onSubmitFn(); } -const setupUpgradeForm = (formSelector) => { - const form = document.querySelector(formSelector); - if (!form) { - return; - } - - const url = form.action; - let button = form.querySelector('button[type="submit"]'); - let defaultText; - - const statusToText = (status) => { - switch (status) { - case 0: - return "None"; - case 1: - return "No file"; - case 2: - return "Success"; - case 3: - return "Prohibited"; - case 4: - return "Aborted"; - case 5: - return "Error on start"; - case 6: - return "Error on write"; - case 7: - return "Error on finish"; - default: - return "Unknown"; - } - }; - - const onResult = async (response) => { - if (!response) { - return; - } - - const result = await response.json(); - - let resItem = form.querySelector('.upgrade-firmware-result'); - if (resItem && result.firmware.status > 1) { - resItem.textContent = statusToText(result.firmware.status); - resItem.classList.remove('hidden'); - - if (result.firmware.status == 2) { - resItem.classList.remove('failed'); - resItem.classList.add('success'); - } else { - resItem.classList.remove('success'); - resItem.classList.add('failed'); - - if (result.firmware.error != "") { - resItem.textContent += `: ${result.firmware.error}`; - } - } - } - - resItem = form.querySelector('.upgrade-filesystem-result'); - if (resItem && result.filesystem.status > 1) { - resItem.textContent = statusToText(result.filesystem.status); - resItem.classList.remove('hidden'); - - if (result.filesystem.status == 2) { - resItem.classList.remove('failed'); - resItem.classList.add('success'); - } else { - resItem.classList.remove('success'); - resItem.classList.add('failed'); - - if (result.filesystem.error != "") { - resItem.textContent += `: ${result.filesystem.error}`; - } - } - } - }; - - const onSuccess = (response) => { - onResult(response); - - if (button) { - button.textContent = defaultText; - button.removeAttribute('aria-busy'); - - setTimeout(() => { - button.removeAttribute('disabled'); - button.classList.remove('success', 'failed'); - button.textContent = defaultText; - }, 5000); - } - }; - - const onFailed = (response) => { - 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); - } - }; - - form.addEventListener('submit', async (event) => { - event.preventDefault(); - - hide('.upgrade-firmware-result'); - hide('.upgrade-filesystem-result'); - - if (button) { - defaultText = button.textContent; - button.textContent = i18n('button.uploading'); - button.setAttribute('disabled', true); - button.setAttribute('aria-busy', true); - } - - try { - let fd = new FormData(form); - let response = await fetch(url, { - method: "POST", - cache: "no-cache", - credentials: "include", - body: fd - }); - - if (response.status >= 200 && response.status < 500) { - onSuccess(response); - - } else { - onFailed(response); - } - - } catch (err) { - onFailed(false); - } - }); -} - - const setBusy = (busySelector, contentSelector, value, parent = undefined) => { if (!value) { hide(busySelector, parent); diff --git a/tools/build.py b/tools/build.py index baf6de0..1c238f2 100644 --- a/tools/build.py +++ b/tools/build.py @@ -1,5 +1,4 @@ import shutil -import gzip import os Import("env") @@ -19,26 +18,6 @@ def before_buildfs(source, target, env): if result: return result return env.Execute("npx gulp build_all --no-deprecation") -""" - src = os.path.join(env["PROJECT_DIR"], "src_data") - dst = os.path.join(env["PROJECT_DIR"], "data") - - for root, dirs, files in os.walk(src, topdown=False): - for name in files: - src_path = os.path.join(root, name) - - with open(src_path, 'rb') as f_in: - dst_name = name + ".gz" - dst_path = os.path.join(dst, os.path.relpath(root, src), dst_name) - - if os.path.exists(os.path.join(dst, os.path.relpath(root, src))) == False: - os.mkdir(os.path.join(dst, os.path.relpath(root, src))) - - with gzip.open(dst_path, 'wb', 9) as f_out: - shutil.copyfileobj(f_in, f_out) - - print("Compressed '%s' to '%s'" % (src_path, dst_path)) -""" def after_buildfs(source, target, env): copy_to_build_dir({