some refactoring

This commit is contained in:
proddy
2025-09-21 19:20:04 +02:00
parent 13db83a6de
commit 50bedb2b39
12 changed files with 18 additions and 18 deletions

View File

@@ -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);
}
}

View File

@@ -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);

View File

@@ -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

View File

@@ -549,7 +549,7 @@ class EMSdevice {
std::vector<uint16_t> 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<TelegramFunction> telegram_functions_; // each EMS device has its own set of registered telegram types
std::vector<DeviceValue> devicevalues_; // all the device values

View File

@@ -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

View File

@@ -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 <esp_mac.h>
#endif
#include <HTTPClient.h>
#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;

View File

@@ -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};

View File

@@ -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:

View File

@@ -73,7 +73,7 @@ class WebCustomEntityService : public StatefulService<WebCustomEntity> {
}
#if defined(EMSESP_TEST)
void test();
void load_test_data();
#endif
private:

View File

@@ -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();

View File

@@ -85,7 +85,7 @@ class WebCustomizationService : public StatefulService<WebCustomization> {
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

View File

@@ -87,7 +87,7 @@ class WebSchedulerService : public StatefulService<WebScheduler> {
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