From c3e66da451009d307c16d5a0a3b473800149943a Mon Sep 17 00:00:00 2001 From: VietDzung Date: Wed, 27 Dec 2023 10:19:39 +0700 Subject: [PATCH] Support config timezone in Setup -> Others --- main/config.h | 1 + main/html_pages.h | 5 +++++ main/language_translations.h | 3 +++ main/languages/ca-ES.h | 2 ++ main/languages/da-DA.h | 2 ++ main/languages/de-DE.h | 4 +++- main/languages/en-GB.h | 4 +++- main/languages/es-ES.h | 2 ++ main/languages/fr-FR.h | 2 ++ main/languages/it-IT.h | 2 ++ main/languages/ja-JP.h | 2 ++ main/languages/vi-VN.h | 2 ++ main/languages/zh-CN.h | 2 ++ main/main.cpp | 18 +++++++++++++----- 14 files changed, 44 insertions(+), 7 deletions(-) diff --git a/main/config.h b/main/config.h index 2e24ca6..f8c3d6c 100644 --- a/main/config.h +++ b/main/config.h @@ -213,6 +213,7 @@ const PROGMEM char *mqtt_payload_unavailable = "offline"; // Define global variables for Others settings bool others_haa; String others_haa_topic; +String timezone = "ICT-7"; // Set timezone to Vietnam Standard Time // Define global variables for HA topics String ha_power_set_topic; diff --git a/main/html_pages.h b/main/html_pages.h index 382aea6..33c1a2d 100644 --- a/main/html_pages.h +++ b/main/html_pages.h @@ -126,6 +126,11 @@ const char html_page_others[] PROGMEM = "
" "" "

" + "

_TXT_OTHERS_TIME_ZONE_(_SEE_TZ_LIST)" + "
" + "" + "

" "
" "" "" diff --git a/main/language_translations.h b/main/language_translations.h index edbe6b0..4ba1561 100644 --- a/main/language_translations.h +++ b/main/language_translations.h @@ -125,6 +125,9 @@ MAKE_WORD_TRANSLATION(txt_others_debug_packets, en::txt_others_debug_packets, vi MAKE_WORD_TRANSLATION(txt_others_debug_log, en::txt_others_debug_log, vi::txt_others_debug_log, da::txt_others_debug_log, de::txt_others_debug_log, es::txt_others_debug_log, fr::txt_others_debug_log, it::txt_others_debug_log, ja::txt_others_debug_log, zh::txt_others_debug_log, ca::txt_others_debug_log) // TODO translate MAKE_WORD_TRANSLATION(txt_others_tx_pin, en::txt_others_tx_pin, vi::txt_others_tx_pin, da::txt_others_tx_pin, de::txt_others_tx_pin, es::txt_others_tx_pin, fr::txt_others_tx_pin, it::txt_others_tx_pin, ja::txt_others_tx_pin, zh::txt_others_tx_pin, ca::txt_others_tx_pin) // TODO translate MAKE_WORD_TRANSLATION(txt_others_rx_pin, en::txt_others_rx_pin, vi::txt_others_rx_pin, da::txt_others_rx_pin, de::txt_others_rx_pin, es::txt_others_rx_pin, fr::txt_others_rx_pin, it::txt_others_rx_pin, ja::txt_others_rx_pin, zh::txt_others_rx_pin, ca::txt_others_rx_pin) // TODO translate +MAKE_WORD_TRANSLATION(txt_others_tz, en::txt_others_tz, vi::txt_others_tz, da::txt_others_tz, de::txt_others_tz, es::txt_others_tz, fr::txt_others_tz, it::txt_others_tz, ja::txt_others_tz, zh::txt_others_tz, ca::txt_others_tz) // TODO translate +MAKE_WORD_TRANSLATION(txt_others_tz_list, en::txt_others_tz_list, vi::txt_others_tz_list, da::txt_others_tz_list, de::txt_others_tz_list, es::txt_others_tz_list, fr::txt_others_tz_list, it::txt_others_tz_list, ja::txt_others_tz_list, zh::txt_others_tz_list, ca::txt_others_tz_list) // TODO translate + // Page Status MAKE_WORD_TRANSLATION(txt_status_title, en::txt_status_title, vi::txt_status_title, da::txt_status_title, de::txt_status_title, es::txt_status_title, fr::txt_status_title, it::txt_status_title, ja::txt_status_title, zh::txt_status_title, ca::txt_status_title) // TODO translate MAKE_WORD_TRANSLATION(txt_status_hvac, en::txt_status_hvac, vi::txt_status_hvac, da::txt_status_hvac, de::txt_status_hvac, es::txt_status_hvac, fr::txt_status_hvac, it::txt_status_hvac, ja::txt_status_hvac, zh::txt_status_hvac, ca::txt_status_hvac) // TODO translate diff --git a/main/languages/ca-ES.h b/main/languages/ca-ES.h index 8e009f9..3e459b8 100644 --- a/main/languages/ca-ES.h +++ b/main/languages/ca-ES.h @@ -95,6 +95,8 @@ namespace ca const char txt_others_debug_log[] PROGMEM = "MQTT topic debug logs"; const char txt_others_tx_pin[] PROGMEM = "TX pin (ESP32, 0 use UART1)"; const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use UART1)"; + const char txt_others_tz[] PROGMEM = "Timezone"; + const char txt_others_tz_list[] PROGMEM = "See list"; // Page Status const char txt_status_title[] PROGMEM = "Estat"; diff --git a/main/languages/da-DA.h b/main/languages/da-DA.h index d3dfc6b..09ddc7c 100644 --- a/main/languages/da-DA.h +++ b/main/languages/da-DA.h @@ -94,6 +94,8 @@ namespace da const char txt_others_debug_log[] PROGMEM = "MQTT topic debug logs"; const char txt_others_tx_pin[] PROGMEM = "TX pin (ESP32, 0 use UART1)"; const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use UART1)"; + const char txt_others_tz[] PROGMEM = "Timezone"; + const char txt_others_tz_list[] PROGMEM = "See list"; // Page Status const char txt_status_title[] PROGMEM = "Status"; diff --git a/main/languages/de-DE.h b/main/languages/de-DE.h index 3ea02e7..ba43dd9 100644 --- a/main/languages/de-DE.h +++ b/main/languages/de-DE.h @@ -94,7 +94,9 @@ namespace de const char txt_others_debug_log[] PROGMEM = "MQTT topic debug logs"; const char txt_others_tx_pin[] PROGMEM = "TX pin (ESP32, 0 use UART1)"; const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use UART1)"; - + const char txt_others_tz[] PROGMEM = "Timezone"; + const char txt_others_tz_list[] PROGMEM = "See list"; + // Page Status const char txt_status_title[] PROGMEM = "Status"; const char txt_status_hvac[] PROGMEM = "HVAC Status"; diff --git a/main/languages/en-GB.h b/main/languages/en-GB.h index b9ddeb4..513021a 100644 --- a/main/languages/en-GB.h +++ b/main/languages/en-GB.h @@ -95,7 +95,9 @@ namespace en const char txt_others_debug_log[] PROGMEM = "MQTT debug logs"; const char txt_others_tx_pin[] PROGMEM = "TX pin (ESP32, 0 use UART1)"; const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use UART1)"; - + const char txt_others_tz[] PROGMEM = "Timezone"; + const char txt_others_tz_list[] PROGMEM = "See list"; + // Page Status const char txt_status_title[] PROGMEM = "Status"; const char txt_status_hvac[] PROGMEM = "HVAC Status"; diff --git a/main/languages/es-ES.h b/main/languages/es-ES.h index 65f7c3f..46d6e4a 100644 --- a/main/languages/es-ES.h +++ b/main/languages/es-ES.h @@ -95,6 +95,8 @@ namespace es const char txt_others_debug_log[] PROGMEM = "MQTT topic debug logs"; const char txt_others_tx_pin[] PROGMEM = "TX pin (ESP32, 0 use UART1)"; const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use UART1)"; + const char txt_others_tz[] PROGMEM = "Timezone"; + const char txt_others_tz_list[] PROGMEM = "See list"; // Page Status const char txt_status_title[] PROGMEM = "Estado"; diff --git a/main/languages/fr-FR.h b/main/languages/fr-FR.h index cd22bc5..9d517a8 100644 --- a/main/languages/fr-FR.h +++ b/main/languages/fr-FR.h @@ -95,6 +95,8 @@ namespace fr const char txt_others_debug_log[] PROGMEM = "MQTT topic debug logs"; const char txt_others_tx_pin[] PROGMEM = "TX pin (ESP32, 0 use UART1)"; const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use UART1)"; + const char txt_others_tz[] PROGMEM = "Timezone"; + const char txt_others_tz_list[] PROGMEM = "See list"; // Page Status const char txt_status_title[] PROGMEM = "Etats"; diff --git a/main/languages/it-IT.h b/main/languages/it-IT.h index 0a997e0..8d3c243 100644 --- a/main/languages/it-IT.h +++ b/main/languages/it-IT.h @@ -95,6 +95,8 @@ namespace it const char txt_others_debug_log[] PROGMEM = "MQTT topic debug logs"; const char txt_others_tx_pin[] PROGMEM = "TX pin (ESP32, 0 use UART1)"; const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use UART1)"; + const char txt_others_tz[] PROGMEM = "Timezone"; + const char txt_others_tz_list[] PROGMEM = "See list"; // Page Status const char txt_status_title[] PROGMEM = "Stato"; diff --git a/main/languages/ja-JP.h b/main/languages/ja-JP.h index 31dc90f..708311e 100644 --- a/main/languages/ja-JP.h +++ b/main/languages/ja-JP.h @@ -95,6 +95,8 @@ namespace ja const char txt_others_debug_log[] PROGMEM = "MQTT topic debug logs"; const char txt_others_tx_pin[] PROGMEM = "TX pin (ESP32, 0 use UART1)"; const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use UART1)"; + const char txt_others_tz[] PROGMEM = "Timezone"; + const char txt_others_tz_list[] PROGMEM = "See list"; // Page Status const char txt_status_title[] PROGMEM = "ステータス"; diff --git a/main/languages/vi-VN.h b/main/languages/vi-VN.h index 2798841..9205238 100644 --- a/main/languages/vi-VN.h +++ b/main/languages/vi-VN.h @@ -95,6 +95,8 @@ namespace vi const char txt_others_debug_log[] PROGMEM = "MQTT gỡ lỗi nhật ký"; const char txt_others_tx_pin[] PROGMEM = "Chân TX (ESP32, 0 dùng UART1)"; const char txt_others_rx_pin[] PROGMEM = "Chân RX (ESP32, 0 dùng UART1)"; + const char txt_others_tz[] PROGMEM = "Múi giờ"; + const char txt_others_tz_list[] PROGMEM = "Xem danh sách"; // Page Status const char txt_status_title[] PROGMEM = "Trạng thái"; diff --git a/main/languages/zh-CN.h b/main/languages/zh-CN.h index c29078d..3544101 100644 --- a/main/languages/zh-CN.h +++ b/main/languages/zh-CN.h @@ -95,6 +95,8 @@ namespace zh const char txt_others_debug_log[] PROGMEM = "MQTT topic debug logs"; const char txt_others_tx_pin[] PROGMEM = "TX pin (ESP32, 0 use UART1)"; const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use UART1)"; + const char txt_others_tz[] PROGMEM = "Timezone"; + const char txt_others_tz_list[] PROGMEM = "See list"; // Page Status const char txt_status_title[] PROGMEM = "状态"; diff --git a/main/main.cpp b/main/main.cpp index 2dc5444..444ad7c 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -540,7 +540,7 @@ bool loadOthers() return false; } // Allocate document capacity. - const size_t capacity = JSON_OBJECT_SIZE(6) + 300; + const size_t capacity = JSON_OBJECT_SIZE(7) + 350; DynamicJsonDocument doc(capacity); deserializeJson(doc, configFile); // unit @@ -574,6 +574,10 @@ bool loadOthers() HP_RX = atoi(rxPin.c_str()); } } + if (doc.containsKey("tz")) // check key to prevent data is "null" if not exist + { + timezone = doc["tz"].as(); + } return true; } @@ -679,10 +683,10 @@ void saveWifi(String apSsid, const String& apPwd, String hostName, const String& configFile.close(); } -void saveOthers(const String& haa, const String& haat, const String& debugPckts, const String& debugLogs, const String& txPin, const String& rxPin) +void saveOthers(const String& haa, const String& haat, const String& debugPckts, const String& debugLogs, const String& txPin, const String& rxPin, const String& tz) { // Allocate document capacity. - const size_t capacity = JSON_OBJECT_SIZE(6) + 300; + const size_t capacity = JSON_OBJECT_SIZE(7) + 350; DynamicJsonDocument doc(capacity); doc["haa"] = haa; doc["haat"] = haat; @@ -690,6 +694,7 @@ void saveOthers(const String& haa, const String& haat, const String& debugPckts, doc["debugLogs"] = debugLogs; doc["txPin"] = txPin; doc["rxPin"] = rxPin; + doc["tz"] = tz; File configFile = SPIFFS.open(others_conf, "w"); if (!configFile) { @@ -704,7 +709,7 @@ void saveCurrentOthers() String haa = others_haa ? "ON" : "OFF"; String debugPckts = _debugModePckts ? "ON" : "OFF"; String debugLogs = _debugModeLogs ? "ON" : "OFF"; - saveOthers(haa, others_haa_topic, debugPckts, debugLogs, String(HP_TX), String(HP_RX)); + saveOthers(haa, others_haa_topic, debugPckts, debugLogs, String(HP_TX), String(HP_RX), timezone); } // Initialize captive portal page @@ -1130,7 +1135,7 @@ void handleOthers(AsyncWebServerRequest *request) checkLogin(request); if (request->hasArg("save")) { - saveOthers(request->arg("HAA"), request->arg("haat"), request->arg("DebugPckts"), request->arg("DebugLogs"), request->arg("tx_pin"), request->arg("rx_pin")); + saveOthers(request->arg("HAA"), request->arg("haat"), request->arg("DebugPckts"), request->arg("DebugLogs"), request->arg("tx_pin"), request->arg("rx_pin"), request->arg("tz")); String saveRebootPage = FPSTR(html_page_save_reboot); // localize saveRebootPage.replace("_TXT_M_SAVE_", translatedWord(FL_(txt_m_save))); @@ -1147,6 +1152,8 @@ void handleOthers(AsyncWebServerRequest *request) othersPage.replace("_TXT_OTHERS_HATOPIC_", translatedWord(FL_(txt_others_hatopic))); othersPage.replace("_TXT_OTHERS_DEBUG_PCKTS_", translatedWord(FL_(txt_others_debug_packets))); othersPage.replace("_TXT_OTHERS_DEBUG_LOGS_", translatedWord(FL_(txt_others_debug_log))); + othersPage.replace("_TXT_OTHERS_TIME_ZONE_", translatedWord(FL_(txt_others_tz))); + othersPage.replace("_SEE_TZ_LIST", translatedWord(FL_(txt_others_tz_list))); othersPage.replace("_TXT_TX_PIN_", translatedWord(FL_(txt_others_tx_pin))); othersPage.replace("_TXT_RX_PIN_", translatedWord(FL_(txt_others_rx_pin))); othersPage.replace("_TXT_F_ON_", translatedWord(FL_(txt_f_on))); @@ -1157,6 +1164,7 @@ void handleOthers(AsyncWebServerRequest *request) othersPage.replace("_HAA_TOPIC_", others_haa_topic); othersPage.replace("_TX_PIN_", String(HP_TX)); othersPage.replace("_RX_PIN_", String(HP_RX)); + othersPage.replace("_TIME_ZONE_", timezone); if (others_haa) { othersPage.replace("_HAA_ON_", "selected");