From 50bedb2b39885b077056de39b7f60c3fad13f2c6 Mon Sep 17 00:00:00 2001 From: proddy Date: Sun, 21 Sep 2025 19:20:04 +0200 Subject: [PATCH] some refactoring --- src/core/analogsensor.cpp | 2 +- src/core/command.h | 2 +- src/core/emsdevice.cpp | 2 +- src/core/emsdevice.h | 2 +- src/core/locale_translations.h | 2 +- src/core/system.cpp | 12 ++++++------ src/core/temperaturesensor.cpp | 4 ++-- src/core/temperaturesensor.h | 2 +- src/web/WebCustomEntityService.h | 2 +- src/web/WebCustomizationService.cpp | 2 +- src/web/WebCustomizationService.h | 2 +- src/web/WebSchedulerService.h | 2 +- 12 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/core/analogsensor.cpp b/src/core/analogsensor.cpp index dadebe4e4..5ec1188e8 100644 --- a/src/core/analogsensor.cpp +++ b/src/core/analogsensor.cpp @@ -746,7 +746,7 @@ bool AnalogSensor::get_value_info(JsonObject output, const char * cmd, const int // match custom name or sensor GPIO if (cmd == Helpers::toLower(sensor.name()) || Helpers::atoint(cmd) == sensor.gpio()) { get_value_json(output, sensor); - return Command::set_attribute(output, cmd, attribute_s); + return Command::get_attribute(output, cmd, attribute_s); } } diff --git a/src/core/command.h b/src/core/command.h index f85024b94..3050220e0 100644 --- a/src/core/command.h +++ b/src/core/command.h @@ -137,7 +137,7 @@ class Command { static const char * parse_command_string(const char * command, int8_t & id); static const char * get_attribute(const char * cmd); - static bool set_attribute(JsonObject output, const char * cmd, const char * attribute); + static bool get_attribute(JsonObject output, const char * cmd, const char * attribute); static const char * return_code_string(const uint8_t return_code); diff --git a/src/core/emsdevice.cpp b/src/core/emsdevice.cpp index fe6b8de0a..800bb95b5 100644 --- a/src/core/emsdevice.cpp +++ b/src/core/emsdevice.cpp @@ -1534,7 +1534,7 @@ bool EMSdevice::get_value_info(JsonObject output, const char * cmd, const int8_t get_value_json(output, dv); // if we're filtering on an attribute, go find it // if we can't find it, maybe it exists but doesn't not have a value assigned yet - return Command::set_attribute(output, cmd_s, attribute_s); + return Command::get_attribute(output, cmd_s, attribute_s); } } return false; // not found, but don't return a message error yet diff --git a/src/core/emsdevice.h b/src/core/emsdevice.h index f3d7dd0b5..9967ab8ca 100644 --- a/src/core/emsdevice.h +++ b/src/core/emsdevice.h @@ -549,7 +549,7 @@ class EMSdevice { std::vector handlers_ignored_; #if defined(EMSESP_STANDALONE) || defined(EMSESP_TEST) - public: // so we can call it from WebCustomizationService::test() and EMSESP::dump_all_entities() + public: // so we can call it from WebCustomizationService::load_test_data() and EMSESP::dump_all_entities() #endif std::vector telegram_functions_; // each EMS device has its own set of registered telegram types std::vector devicevalues_; // all the device values diff --git a/src/core/locale_translations.h b/src/core/locale_translations.h index fe3f131e6..80e5af84b 100644 --- a/src/core/locale_translations.h +++ b/src/core/locale_translations.h @@ -74,7 +74,7 @@ MAKE_WORD_TRANSLATION(watch_cmd, "watch incoming telegrams", "Beobachte eingehen MAKE_WORD_TRANSLATION(publish_cmd, "publish all to MQTT", "Publiziere MQTT", "publiceer alles naar MQTT", "publicera allt till MQTT", "opublikuj wszystko na MQTT", "Publiser alt til MQTT", "", "Hepsini MQTTye gönder", "pubblica tutto su MQTT", "zverejniť všetko na MQTT", "publikovat vše do MQTT") // TODO translate MAKE_WORD_TRANSLATION(system_info_cmd, "show system info", "Zeige Systeminformationen", "toon systeemstatus", "visa systeminformation", "pokaż status systemu", "vis system status", "", "Sistem Durumunu Göster", "visualizza stati di sistema", "zobraziť stav systému", "zobrazit informace o systému") // TODO translate MAKE_WORD_TRANSLATION(schedule_cmd, "enable schedule item", "Aktiviere Zeitplanelemente", "activeer tijdschema item", "aktivera schemalagt objekt", "aktywuj wybrany harmonogram", "", "", "program öğesini etkinleştir", "abilitare l'elemento programmato", "povoliť položku plánovania", "povolit položku plánování") // TODO translate -MAKE_WORD_TRANSLATION(entity_cmd, "set custom value on ems", "Sende eigene Entitäten zu EMS", "verstuur custom waarde naar EMS", "sätt ett eget värde i EMS", "wyślij własną wartość na EMS", "", "", "emp üzerinde özel değer ayarla", "imposta valori personalizzati su EMS", "nastaviť vlastnú hodnotu na ems", "nastavit vlastní hodnotu na ems") // TODO translate +MAKE_WORD_TRANSLATION(entity_cmd, "set custom value", "Sende eigene Entitäten", "verstuur custom waarde", "sätt ett eget värde", "wyślij własną wartość", "", "", "emp üzerinde özel değer ayarla", "imposta valori personalizzati", "nastaviť vlastnú hodnotu", "nastavit vlastní hodnotu") // TODO translate MAKE_WORD_TRANSLATION(commands_response, "get response", "Hole Antwort", "Verzoek om antwoord", "hämta svar", "uzyskaj odpowiedź", "", "", "gelen cevap", "", "získať odpoveď", "získat odpověď") // TODO translate MAKE_WORD_TRANSLATION(coldshot_cmd, "send a cold shot of water", "Zugabe einer Menge kalten Wassers", "", "sckicka en liten mängd kallvatten", "uruchom tryśnięcie zimnej wody", "", "", "soğuk su gönder", "", "pošlite studenú dávku vody", "poslat studenou vodu") // TODO translate MAKE_WORD_TRANSLATION(message_cmd, "send a message", "Eine Nachricht senden", "", "skicka ett meddelande", "", "", "", "", "", "poslať správu", "odeslat zprávu") // TODO translate diff --git a/src/core/system.cpp b/src/core/system.cpp index 064fd2f7e..d998b03a5 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -19,6 +19,8 @@ #include "system.h" #include "emsesp.h" // for send_raw_telegram() command +#include "shuntingYard.h" + #ifndef EMSESP_STANDALONE #include "esp_ota_ops.h" #endif @@ -48,8 +50,6 @@ #include #endif -#include - #ifndef EMSESP_STANDALONE #include "esp_efuse.h" #endif @@ -205,14 +205,15 @@ bool System::command_syslog_level(const char * value, const int8_t id) { } */ -// send message - to log and MQTT +// send message - to system log and MQTT bool System::command_message(const char * value, const int8_t id) { if (value == nullptr || value[0] == '\0') { return false; // must have a string value } - LOG_INFO("Message: %s", value); - Mqtt::queue_publish(F_(message), value); + auto computed_value = compute(value); + LOG_INFO("Message: %s", computed_value.c_str()); + Mqtt::queue_publish(F_(message), computed_value); return true; } @@ -1433,7 +1434,6 @@ bool System::command_service(const char * cmd, const char * value) { if (!strcmp(cmd, "fuse/mfg")) { ok = esp_efuse_write_reg(EFUSE_BLK3, 0, (uint32_t)n) == ESP_OK; ok ? LOG_INFO("fuse programed with value '%X': successful", n) : LOG_ERROR("fuse programed with value '%X': failed", n); - } if (!strcmp(cmd, "fuse/mfgadd")) { uint8_t reg = 0; diff --git a/src/core/temperaturesensor.cpp b/src/core/temperaturesensor.cpp index af03f2831..5f4ad8c67 100644 --- a/src/core/temperaturesensor.cpp +++ b/src/core/temperaturesensor.cpp @@ -399,7 +399,7 @@ bool TemperatureSensor::get_value_info(JsonObject output, const char * cmd, cons // match custom name or sensor ID if (cmd == Helpers::toLower(sensor.name()) || cmd == Helpers::toLower(sensor.id())) { get_value_json(output, sensor); - return Command::set_attribute(output, cmd, attribute_s); + return Command::get_attribute(output, cmd, attribute_s); } } @@ -618,7 +618,7 @@ bool TemperatureSensor::Sensor::apply_customization() { // hard coded tests #if defined(EMSESP_TEST) -void TemperatureSensor::test() { +void TemperatureSensor::load_test_data() { // add 2 temperature sensors // Sensor ID: 01_0203_0405_0607 uint8_t addr[ADDR_LEN] = {1, 2, 3, 4, 5, 6, 7, 8}; diff --git a/src/core/temperaturesensor.h b/src/core/temperaturesensor.h index 5ab1302ba..f137abf7c 100644 --- a/src/core/temperaturesensor.h +++ b/src/core/temperaturesensor.h @@ -113,7 +113,7 @@ class TemperatureSensor { bool update(const std::string & id, const std::string & name, int16_t offset); #if defined(EMSESP_TEST) - void test(); + void load_test_data(); #endif private: diff --git a/src/web/WebCustomEntityService.h b/src/web/WebCustomEntityService.h index 4a298c547..b9f73c6ea 100644 --- a/src/web/WebCustomEntityService.h +++ b/src/web/WebCustomEntityService.h @@ -73,7 +73,7 @@ class WebCustomEntityService : public StatefulService { } #if defined(EMSESP_TEST) - void test(); + void load_test_data(); #endif private: diff --git a/src/web/WebCustomizationService.cpp b/src/web/WebCustomizationService.cpp index dd056b801..65d2403e0 100644 --- a/src/web/WebCustomizationService.cpp +++ b/src/web/WebCustomizationService.cpp @@ -366,7 +366,7 @@ void WebCustomizationService::begin() { // hard coded tests #ifdef EMSESP_TEST -void WebCustomizationService::test() { +void WebCustomizationService::load_test_data() { update([&](WebCustomization & webCustomization) { // Temperature sensors webCustomization.sensorCustomizations.clear(); diff --git a/src/web/WebCustomizationService.h b/src/web/WebCustomizationService.h index 7762b032d..f12e5db33 100644 --- a/src/web/WebCustomizationService.h +++ b/src/web/WebCustomizationService.h @@ -85,7 +85,7 @@ class WebCustomizationService : public StatefulService { void begin(); #if defined(EMSESP_TEST) - void test(); + void load_test_data(); #endif // make all functions public so we can test in the debug and standalone mode diff --git a/src/web/WebSchedulerService.h b/src/web/WebSchedulerService.h index 8b40063b5..799067514 100644 --- a/src/web/WebSchedulerService.h +++ b/src/web/WebSchedulerService.h @@ -87,7 +87,7 @@ class WebSchedulerService : public StatefulService { bool onChange(const char * cmd); #if defined(EMSESP_TEST) - void test(); + void load_test_data(); #endif // make all functions public so we can test in the debug and standalone mode