Skip to content

Commit

Permalink
Support config timezone in Setup -> Others
Browse files Browse the repository at this point in the history
  • Loading branch information
dzungpv committed Dec 27, 2023
1 parent 88e3ea1 commit c3e66da
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 7 deletions.
1 change: 1 addition & 0 deletions main/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions main/html_pages.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ const char html_page_others[] PROGMEM =
"<br/>"
"<input type='number' id='rx_pin' step='1' min='0' max='33' name='rx_pin' placeholder=' ' value='_RX_PIN_'>"
"</p>"
"<p><b>_TXT_OTHERS_TIME_ZONE_</b>(<a href='https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv'>_SEE_TZ_LIST</a>)"
"<br/>"
"<input id='tz' name='tz' placeholder=' ' value='_TIME_ZONE_' "
"autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false'>"
"</p>"
"<br/>"
"<button name='save' type='submit' class='button bgrn'>_TXT_SAVE_</button>"
"</form>"
Expand Down
3 changes: 3 additions & 0 deletions main/language_translations.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions main/languages/ca-ES.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 2 additions & 0 deletions main/languages/da-DA.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 3 additions & 1 deletion main/languages/de-DE.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 3 additions & 1 deletion main/languages/en-GB.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 2 additions & 0 deletions main/languages/es-ES.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 2 additions & 0 deletions main/languages/fr-FR.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 2 additions & 0 deletions main/languages/it-IT.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 2 additions & 0 deletions main/languages/ja-JP.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "ステータス";
Expand Down
2 changes: 2 additions & 0 deletions main/languages/vi-VN.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 2 additions & 0 deletions main/languages/zh-CN.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "状态";
Expand Down
18 changes: 13 additions & 5 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<String>();
}
return true;
}

Expand Down Expand Up @@ -679,17 +683,18 @@ 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;
doc["debugPckts"] = debugPckts;
doc["debugLogs"] = debugLogs;
doc["txPin"] = txPin;
doc["rxPin"] = rxPin;
doc["tz"] = tz;
File configFile = SPIFFS.open(others_conf, "w");
if (!configFile)
{
Expand All @@ -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
Expand Down Expand Up @@ -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)));
Expand All @@ -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)));
Expand All @@ -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");
Expand Down

0 comments on commit c3e66da

Please sign in to comment.