mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
code cleanup - sonarlint
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -68,3 +68,6 @@ venv/
|
|||||||
|
|
||||||
# cspell
|
# cspell
|
||||||
words-found-verbose.txt
|
words-found-verbose.txt
|
||||||
|
|
||||||
|
# sonarlint
|
||||||
|
compile_commands.json
|
||||||
|
|||||||
4
.sonarlint/connectedMode.json
Normal file
4
.sonarlint/connectedMode.json
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sonarCloudOrganization": "emsesp",
|
||||||
|
"projectKey": "emsesp_EMS-ESP32"
|
||||||
|
}
|
||||||
@@ -86,7 +86,6 @@ void UploadFileService::handleUpload(AsyncWebServerRequest * request, const Stri
|
|||||||
Update.setMD5(_md5.data());
|
Update.setMD5(_md5.data());
|
||||||
_md5.front() = '\0';
|
_md5.front() = '\0';
|
||||||
}
|
}
|
||||||
// emsesp::EMSESP::system_.upload_status(true); // force just in case, this is stop UART, MQTT and other services
|
|
||||||
request->onDisconnect([this] { handleEarlyDisconnect(); }); // success, let's make sure we end the update if the client hangs up
|
request->onDisconnect([this] { handleEarlyDisconnect(); }); // success, let's make sure we end the update if the client hangs up
|
||||||
} else {
|
} else {
|
||||||
handleError(request, 507); // failed to begin, send an error response Insufficient Storage
|
handleError(request, 507); // failed to begin, send an error response Insufficient Storage
|
||||||
|
|||||||
@@ -102,9 +102,6 @@ void AnalogSensor::reload(bool get_nvs) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
// if (!System::is_valid_gpio(sensor.gpio)) {
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
sensors_.emplace_back(sensor.gpio, sensor.name, sensor.offset, sensor.factor, sensor.uom, sensor.type);
|
sensors_.emplace_back(sensor.gpio, sensor.name, sensor.offset, sensor.factor, sensor.uom, sensor.type);
|
||||||
sensors_.back().ha_registered = false; // this will trigger recreate of the HA config
|
sensors_.back().ha_registered = false; // this will trigger recreate of the HA config
|
||||||
if (sensor.type == AnalogType::COUNTER || sensor.type >= AnalogType::DIGITAL_OUT) {
|
if (sensor.type == AnalogType::COUNTER || sensor.type >= AnalogType::DIGITAL_OUT) {
|
||||||
@@ -610,7 +607,7 @@ void AnalogSensor::publish_values(const bool force) {
|
|||||||
|
|
||||||
// see if we need to create the [devs] discovery section, as this needs only to be done once for all sensors
|
// see if we need to create the [devs] discovery section, as this needs only to be done once for all sensors
|
||||||
bool is_ha_device_created = false;
|
bool is_ha_device_created = false;
|
||||||
for (auto & sensor : sensors_) {
|
for (auto const & sensor : sensors_) {
|
||||||
if (sensor.ha_registered) {
|
if (sensor.ha_registered) {
|
||||||
is_ha_device_created = true;
|
is_ha_device_created = true;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -420,7 +420,7 @@ uint8_t Command::call(const uint8_t device_type, const char * command, const cha
|
|||||||
} else {
|
} else {
|
||||||
if (single_command) {
|
if (single_command) {
|
||||||
// log as DEBUG (TRACE) regardless if compiled with EMSESP_DEBUG
|
// log as DEBUG (TRACE) regardless if compiled with EMSESP_DEBUG
|
||||||
logger_.debug(("%sCalled command %s"), ro.c_str(), info_s);
|
logger_.debug("%sCalled command %s", ro.c_str(), info_s);
|
||||||
} else {
|
} else {
|
||||||
if (id > 0) {
|
if (id > 0) {
|
||||||
LOG_INFO(("%sCalled command %s with value %s and id %d on device 0x%02X"), ro.c_str(), info_s, value, id, device_id);
|
LOG_INFO(("%sCalled command %s with value %s and id %d on device 0x%02X"), ro.c_str(), info_s, value, id, device_id);
|
||||||
@@ -499,7 +499,7 @@ void Command::erase_command(const uint8_t device_type, const char * cmd, uint8_t
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto it = cmdfunctions_.begin();
|
auto it = cmdfunctions_.begin();
|
||||||
for (auto & cf : cmdfunctions_) {
|
for (auto const & cf : cmdfunctions_) {
|
||||||
if (Helpers::toLower(cmd) == Helpers::toLower(cf.cmd_) && (cf.device_type_ == device_type) && ((flag & 0x3F) == (cf.flags_ & 0x3F))) {
|
if (Helpers::toLower(cmd) == Helpers::toLower(cf.cmd_) && (cf.device_type_ == device_type) && ((flag & 0x3F) == (cf.flags_ & 0x3F))) {
|
||||||
cmdfunctions_.erase(it);
|
cmdfunctions_.erase(it);
|
||||||
return;
|
return;
|
||||||
@@ -565,9 +565,9 @@ void Command::show(uuid::console::Shell & shell, uint8_t device_type, bool verbo
|
|||||||
|
|
||||||
// if not in verbose mode, just print them on a single line and exit
|
// if not in verbose mode, just print them on a single line and exit
|
||||||
if (!verbose) {
|
if (!verbose) {
|
||||||
sorted_cmds.push_front(F_(info));
|
sorted_cmds.emplace_front(F_(info));
|
||||||
sorted_cmds.push_front(F_(commands));
|
sorted_cmds.emplace_front(F_(commands));
|
||||||
sorted_cmds.push_front(F_(values));
|
sorted_cmds.emplace_front(F_(values));
|
||||||
for (const auto & cl : sorted_cmds) {
|
for (const auto & cl : sorted_cmds) {
|
||||||
shell.print(cl);
|
shell.print(cl);
|
||||||
shell.print(" ");
|
shell.print(" ");
|
||||||
|
|||||||
@@ -297,7 +297,7 @@ uint8_t EMSdevice::decode_brand(uint8_t value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// returns string of a human friendly description of the EMS device
|
// returns string of a human friendly description of the EMS device
|
||||||
const std::string EMSdevice::to_string() {
|
std::string EMSdevice::to_string() {
|
||||||
// for devices that haven't been lookup yet, don't show all details
|
// for devices that haven't been lookup yet, don't show all details
|
||||||
if (product_id_ == 0) {
|
if (product_id_ == 0) {
|
||||||
return std::string(name()) + " (DeviceID:" + Helpers::hextoa(device_id_) + ")";
|
return std::string(name()) + " (DeviceID:" + Helpers::hextoa(device_id_) + ")";
|
||||||
@@ -313,7 +313,7 @@ const std::string EMSdevice::to_string() {
|
|||||||
|
|
||||||
// returns out brand + device name
|
// returns out brand + device name
|
||||||
// translated
|
// translated
|
||||||
const std::string EMSdevice::to_string_short() {
|
std::string EMSdevice::to_string_short() {
|
||||||
if (brand_ == Brand::NO_BRAND) {
|
if (brand_ == Brand::NO_BRAND) {
|
||||||
return std::string(device_type_2_device_name_translated()) + ": " + name();
|
return std::string(device_type_2_device_name_translated()) + ": " + name();
|
||||||
}
|
}
|
||||||
@@ -554,7 +554,7 @@ void EMSdevice::add_device_value(int8_t tag, // to b
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t state = DeviceValueState::DV_DEFAULT; // determine state
|
uint8_t state = DeviceValueState::DV_DEFAULT; // determine state
|
||||||
std::string custom_fullname = std::string(""); // custom fullname
|
auto custom_fullname = std::string(""); // custom fullname
|
||||||
auto short_name = name[0]; // entity name
|
auto short_name = name[0]; // entity name
|
||||||
bool has_cmd = (f != nullptr); // is it a command?
|
bool has_cmd = (f != nullptr); // is it a command?
|
||||||
bool ignore = false; // ignore this entity?
|
bool ignore = false; // ignore this entity?
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ class EMSdevice {
|
|||||||
, flags_(flags)
|
, flags_(flags)
|
||||||
, brand_(brand) {
|
, brand_(brand) {
|
||||||
strlcpy(version_, version, sizeof(version_));
|
strlcpy(version_, version, sizeof(version_));
|
||||||
custom_name_ = ""; // init custom name to blank
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// static functions, used outside the class like in console.cpp, command.cpp, emsesp.cpp, mqtt.cpp
|
// static functions, used outside the class like in console.cpp, command.cpp, emsesp.cpp, mqtt.cpp
|
||||||
@@ -113,7 +112,7 @@ class EMSdevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set custom device name
|
// set custom device name
|
||||||
inline void custom_name(std::string & custom_name) {
|
inline void custom_name(std::string const & custom_name) {
|
||||||
custom_name_ = custom_name;
|
custom_name_ = custom_name;
|
||||||
}
|
}
|
||||||
std::string name(); // returns either default or custom name if defined
|
std::string name(); // returns either default or custom name if defined
|
||||||
@@ -206,15 +205,14 @@ class EMSdevice {
|
|||||||
int modbus_value_to_json(uint8_t tag, const std::string & shortname, const std::vector<uint8_t> & modbus_data, JsonObject jsonValue);
|
int modbus_value_to_json(uint8_t tag, const std::string & shortname, const std::vector<uint8_t> & modbus_data, JsonObject jsonValue);
|
||||||
|
|
||||||
const char * brand_to_char();
|
const char * brand_to_char();
|
||||||
const std::string to_string();
|
std::string to_string();
|
||||||
const std::string to_string_short();
|
std::string to_string_short();
|
||||||
|
|
||||||
enum Handlers : uint8_t { ALL, RECEIVED, FETCHED, PENDING, IGNORED };
|
enum Handlers : uint8_t { ALL, RECEIVED, FETCHED, PENDING, IGNORED };
|
||||||
|
|
||||||
void show_telegram_handlers(uuid::console::Shell & shell) const;
|
void show_telegram_handlers(uuid::console::Shell & shell) const;
|
||||||
char * show_telegram_handlers(char * result, const size_t len, const uint8_t handlers);
|
char * show_telegram_handlers(char * result, const size_t len, const uint8_t handlers);
|
||||||
void show_mqtt_handlers(uuid::console::Shell & shell) const;
|
void show_mqtt_handlers(uuid::console::Shell & shell) const;
|
||||||
// void list_device_entries(JsonObject output) const;
|
|
||||||
void add_handlers_ignored(const uint16_t handler);
|
void add_handlers_ignored(const uint16_t handler);
|
||||||
|
|
||||||
void set_climate_minmax(int8_t tag, int16_t min, uint32_t max);
|
void set_climate_minmax(int8_t tag, int16_t min, uint32_t max);
|
||||||
@@ -456,15 +454,13 @@ class EMSdevice {
|
|||||||
uint8_t count_entities();
|
uint8_t count_entities();
|
||||||
bool has_entities() const;
|
bool has_entities() const;
|
||||||
|
|
||||||
/*
|
// void reserve_device_values(uint8_t elements) {
|
||||||
void reserve_device_values(uint8_t elements) {
|
// devicevalues_.reserve(elements);
|
||||||
devicevalues_.reserve(elements);
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
void reserve_telegram_functions(uint8_t elements) {
|
// void reserve_telegram_functions(uint8_t elements) {
|
||||||
telegram_functions_.reserve(elements);
|
// telegram_functions_.reserve(elements);
|
||||||
}
|
// }
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(EMSESP_STANDALONE)
|
#if defined(EMSESP_STANDALONE)
|
||||||
struct TelegramFunctionDump {
|
struct TelegramFunctionDump {
|
||||||
@@ -488,7 +484,7 @@ class EMSdevice {
|
|||||||
uint8_t product_id_ = 0;
|
uint8_t product_id_ = 0;
|
||||||
char version_[6];
|
char version_[6];
|
||||||
const char * default_name_; // the fixed name the EMS model taken from the device library
|
const char * default_name_; // the fixed name the EMS model taken from the device library
|
||||||
std::string custom_name_; // custom name
|
std::string custom_name_ = ""; // custom name
|
||||||
uint8_t flags_ = 0;
|
uint8_t flags_ = 0;
|
||||||
uint8_t brand_ = Brand::NO_BRAND;
|
uint8_t brand_ = Brand::NO_BRAND;
|
||||||
|
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ void EMSESP::uart_init() {
|
|||||||
uint8_t tx_mode = 0;
|
uint8_t tx_mode = 0;
|
||||||
uint8_t rx_gpio = 0;
|
uint8_t rx_gpio = 0;
|
||||||
uint8_t tx_gpio = 0;
|
uint8_t tx_gpio = 0;
|
||||||
EMSESP::webSettingsService.read([&](WebSettings & settings) {
|
EMSESP::webSettingsService.read([&](WebSettings const & settings) {
|
||||||
tx_mode = settings.tx_mode;
|
tx_mode = settings.tx_mode;
|
||||||
rx_gpio = settings.rx_gpio;
|
rx_gpio = settings.rx_gpio;
|
||||||
tx_gpio = settings.tx_gpio;
|
tx_gpio = settings.tx_gpio;
|
||||||
@@ -279,7 +279,7 @@ void EMSESP::show_ems(uuid::console::Shell & shell) {
|
|||||||
|
|
||||||
if (bus_status() != BUS_STATUS_OFFLINE) {
|
if (bus_status() != BUS_STATUS_OFFLINE) {
|
||||||
shell.printfln("EMS Bus info:");
|
shell.printfln("EMS Bus info:");
|
||||||
EMSESP::webSettingsService.read([&](WebSettings & settings) { shell.printfln(" Tx mode: %d", settings.tx_mode); });
|
EMSESP::webSettingsService.read([&](WebSettings const & settings) { shell.printfln(" Tx mode: %d", settings.tx_mode); });
|
||||||
shell.printfln(" Bus protocol: %s", EMSbus::is_ht3() ? "HT3" : "Buderus");
|
shell.printfln(" Bus protocol: %s", EMSbus::is_ht3() ? "HT3" : "Buderus");
|
||||||
shell.printfln(" #recognized EMS devices: %d", EMSESP::emsdevices.size());
|
shell.printfln(" #recognized EMS devices: %d", EMSESP::emsdevices.size());
|
||||||
shell.printfln(" #telegrams received: %d", rxservice_.telegram_count());
|
shell.printfln(" #telegrams received: %d", rxservice_.telegram_count());
|
||||||
@@ -1317,7 +1317,7 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, const
|
|||||||
emsdevices.push_back(EMSFactory::add(device_type, device_id, product_id, version, default_name, flags, brand));
|
emsdevices.push_back(EMSFactory::add(device_type, device_id, product_id, version, default_name, flags, brand));
|
||||||
|
|
||||||
// see if we have a custom device name in our Customizations list, and if so set it
|
// see if we have a custom device name in our Customizations list, and if so set it
|
||||||
webCustomizationService.read([&](WebCustomization & settings) {
|
webCustomizationService.read([&](WebCustomization const & settings) {
|
||||||
for (EntityCustomization e : settings.entityCustomizations) {
|
for (EntityCustomization e : settings.entityCustomizations) {
|
||||||
if ((e.device_id == device_id) && (e.product_id == product_id)) {
|
if ((e.device_id == device_id) && (e.product_id == product_id)) {
|
||||||
LOG_DEBUG("Have customizations for %s with deviceID 0x%02X productID %d", e.custom_name.c_str(), device_id, product_id);
|
LOG_DEBUG("Have customizations for %s with deviceID 0x%02X productID %d", e.custom_name.c_str(), device_id, product_id);
|
||||||
|
|||||||
@@ -798,10 +798,6 @@ uint16_t Helpers::string2minutes(const std::string & str) {
|
|||||||
if (tmp > 60) {
|
if (tmp > 60) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// Serial.print("*");
|
|
||||||
// Serial.print(tmp);
|
|
||||||
// Serial.println("*");
|
|
||||||
|
|
||||||
res += tmp;
|
res += tmp;
|
||||||
}
|
}
|
||||||
// Or we got an extra colon
|
// Or we got an extra colon
|
||||||
|
|||||||
@@ -14,9 +14,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#if defined(EMSESP_STANDALONE)
|
#if defined(EMSESP_STANDALONE)
|
||||||
|
#include <../test/test_modbus/modbus_test.h>
|
||||||
#include <modbus_test.h>
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef EMSESP_STANDALONE
|
#ifndef EMSESP_STANDALONE
|
||||||
|
|||||||
@@ -124,10 +124,7 @@ void Roomctrl::send(uint8_t addr) {
|
|||||||
}
|
}
|
||||||
temperature(addr, 0x10, hc); // send to master-thermostat
|
temperature(addr, 0x10, hc); // send to master-thermostat
|
||||||
}
|
}
|
||||||
} else if (type_[hc] == RC200 || type_[hc] == RC100) {
|
} else if (type_[hc] == RC200 || type_[hc] == RC100 || type_[hc] == FB10) {
|
||||||
send_time_[hc] = uuid::get_uptime();
|
|
||||||
temperature(addr, 0x10, hc);
|
|
||||||
} else if (type_[hc] == FB10) {
|
|
||||||
send_time_[hc] = uuid::get_uptime();
|
send_time_[hc] = uuid::get_uptime();
|
||||||
temperature(addr, 0x10, hc); // send to master-thermostat (https://github.com/emsesp/EMS-ESP32/issues/336)
|
temperature(addr, 0x10, hc); // send to master-thermostat (https://github.com/emsesp/EMS-ESP32/issues/336)
|
||||||
} else { // type==RC20 or SENSOR
|
} else { // type==RC20 or SENSOR
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ uuid::log::Logger Shower::logger_{F_(shower), uuid::log::Facility::CONSOLE};
|
|||||||
static bool force_coldshot = false;
|
static bool force_coldshot = false;
|
||||||
|
|
||||||
void Shower::start() {
|
void Shower::start() {
|
||||||
EMSESP::webSettingsService.read([&](WebSettings & settings) {
|
EMSESP::webSettingsService.read([&](WebSettings const & settings) {
|
||||||
shower_timer_ = settings.shower_timer;
|
shower_timer_ = settings.shower_timer;
|
||||||
shower_alert_ = settings.shower_alert;
|
shower_alert_ = settings.shower_alert;
|
||||||
shower_alert_trigger_ = settings.shower_alert_trigger * 60; // convert from minutes to seconds
|
shower_alert_trigger_ = settings.shower_alert_trigger * 60; // convert from minutes to seconds
|
||||||
@@ -61,7 +61,6 @@ void Shower::loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// uint32_t time_now = uuid::get_uptime(); // in ms
|
|
||||||
auto time_now = uuid::get_uptime_sec(); // in sec
|
auto time_now = uuid::get_uptime_sec(); // in sec
|
||||||
|
|
||||||
// if already in cold mode, ignore all this logic until we're out of the cold blast
|
// if already in cold mode, ignore all this logic until we're out of the cold blast
|
||||||
|
|||||||
@@ -118,13 +118,13 @@ bool System::command_fetch(const char * value, const int8_t id) {
|
|||||||
if (value_s == "all") {
|
if (value_s == "all") {
|
||||||
LOG_INFO("Requesting data from EMS devices");
|
LOG_INFO("Requesting data from EMS devices");
|
||||||
EMSESP::fetch_device_values();
|
EMSESP::fetch_device_values();
|
||||||
} else if (value_s == (F_(boiler))) {
|
} else if (value_s == F_(boiler)) {
|
||||||
EMSESP::fetch_device_values_type(EMSdevice::DeviceType::BOILER);
|
EMSESP::fetch_device_values_type(EMSdevice::DeviceType::BOILER);
|
||||||
} else if (value_s == (F_(thermostat))) {
|
} else if (value_s == F_(thermostat)) {
|
||||||
EMSESP::fetch_device_values_type(EMSdevice::DeviceType::THERMOSTAT);
|
EMSESP::fetch_device_values_type(EMSdevice::DeviceType::THERMOSTAT);
|
||||||
} else if (value_s == (F_(solar))) {
|
} else if (value_s == F_(solar)) {
|
||||||
EMSESP::fetch_device_values_type(EMSdevice::DeviceType::SOLAR);
|
EMSESP::fetch_device_values_type(EMSdevice::DeviceType::SOLAR);
|
||||||
} else if (value_s == (F_(mixer))) {
|
} else if (value_s == F_(mixer)) {
|
||||||
EMSESP::fetch_device_values_type(EMSdevice::DeviceType::MIXER);
|
EMSESP::fetch_device_values_type(EMSdevice::DeviceType::MIXER);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -339,9 +339,6 @@ void System::syslog_init() {
|
|||||||
syslog_.destination(syslog_host_.c_str(), syslog_port_);
|
syslog_.destination(syslog_host_.c_str(), syslog_port_);
|
||||||
syslog_.hostname(hostname().c_str());
|
syslog_.hostname(hostname().c_str());
|
||||||
|
|
||||||
// removed in 3.6.0
|
|
||||||
// Command::add(EMSdevice::DeviceType::SYSTEM, F_(syslog), System::command_syslog_level, FL_(changeloglevel_cmd), CommandFlag::ADMIN_ONLY);
|
|
||||||
|
|
||||||
} else if (syslog_.started()) {
|
} else if (syslog_.started()) {
|
||||||
// in case service is still running, this flushes the queue
|
// in case service is still running, this flushes the queue
|
||||||
// https://github.com/emsesp/EMS-ESP/issues/496
|
// https://github.com/emsesp/EMS-ESP/issues/496
|
||||||
@@ -1053,7 +1050,7 @@ void System::show_system(uuid::console::Shell & shell) {
|
|||||||
shell.printfln(" WiFi Network: Disconnected");
|
shell.printfln(" WiFi Network: Disconnected");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WL_NO_SHIELD:
|
// case WL_NO_SHIELD:
|
||||||
default:
|
default:
|
||||||
shell.printfln(" WiFi MAC address: %s", WiFi.macAddress().c_str());
|
shell.printfln(" WiFi MAC address: %s", WiFi.macAddress().c_str());
|
||||||
shell.printfln(" WiFi Network: not connected");
|
shell.printfln(" WiFi Network: not connected");
|
||||||
@@ -1087,7 +1084,7 @@ void System::show_system(uuid::console::Shell & shell) {
|
|||||||
} else {
|
} else {
|
||||||
shell.printfln(" Syslog: %s", syslog_.started() ? "started" : "stopped");
|
shell.printfln(" Syslog: %s", syslog_.started() ? "started" : "stopped");
|
||||||
shell.print(" ");
|
shell.print(" ");
|
||||||
shell.printfln(F_(host_fmt), !syslog_host_.isEmpty() ? syslog_host_.c_str() : (F_(unset)));
|
shell.printfln(F_(host_fmt), !syslog_host_.isEmpty() ? syslog_host_.c_str() : F_(unset));
|
||||||
shell.printfln(" IP: %s", uuid::printable_to_string(syslog_.ip()).c_str());
|
shell.printfln(" IP: %s", uuid::printable_to_string(syslog_.ip()).c_str());
|
||||||
shell.print(" ");
|
shell.print(" ");
|
||||||
shell.printfln(F_(port_fmt), syslog_port_);
|
shell.printfln(F_(port_fmt), syslog_port_);
|
||||||
@@ -1167,7 +1164,7 @@ bool System::check_upgrade(bool factory_settings) {
|
|||||||
|
|
||||||
if (!factory_settings) {
|
if (!factory_settings) {
|
||||||
// fetch current version from settings file
|
// fetch current version from settings file
|
||||||
EMSESP::webSettingsService.read([&](WebSettings & settings) { settingsVersion = settings.version.c_str(); });
|
EMSESP::webSettingsService.read([&](WebSettings const & settings) { settingsVersion = settings.version.c_str(); });
|
||||||
|
|
||||||
// see if we're missing a version, will be < 3.5.0b13 from Dec 23 2022
|
// see if we're missing a version, will be < 3.5.0b13 from Dec 23 2022
|
||||||
missing_version = (settingsVersion.empty() || (settingsVersion.length() < 5));
|
missing_version = (settingsVersion.empty() || (settingsVersion.length() < 5));
|
||||||
@@ -1338,14 +1335,11 @@ bool System::get_value_info(JsonObject output, const char * cmd) {
|
|||||||
if (!strcmp(cmd, F_(entities))) {
|
if (!strcmp(cmd, F_(entities))) {
|
||||||
for (JsonPair p : root) {
|
for (JsonPair p : root) {
|
||||||
if (p.value().is<JsonObject>()) {
|
if (p.value().is<JsonObject>()) {
|
||||||
// String prefix = p.key().c_str();
|
|
||||||
for (JsonPair p1 : p.value().as<JsonObject>()) {
|
for (JsonPair p1 : p.value().as<JsonObject>()) {
|
||||||
JsonObject entity = output[std::string(p.key().c_str()) + "." + p1.key().c_str()].to<JsonObject>();
|
JsonObject entity = output[std::string(p.key().c_str()) + "." + p1.key().c_str()].to<JsonObject>();
|
||||||
get_value_json(entity, p.key().c_str(), p1.key().c_str(), p1.value());
|
get_value_json(entity, p.key().c_str(), p1.key().c_str(), p1.value());
|
||||||
}
|
}
|
||||||
} // else { // we don't have pairs in json root object
|
}
|
||||||
// get_value_json(entity, "", p.key().c_str(), p.value());
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1498,7 +1492,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject output
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
#ifndef EMSESP_STANDALONE
|
#ifndef EMSESP_STANDALONE
|
||||||
EMSESP::esp8266React.getAPSettingsService()->read([&](APSettings & settings) {
|
EMSESP::esp8266React.getAPSettingsService()->read([&](const APSettings & settings) {
|
||||||
const char * pM[] = {"always", "disconnected", "never"};
|
const char * pM[] = {"always", "disconnected", "never"};
|
||||||
node["APProvisionMode"] = pM[settings.provisionMode];
|
node["APProvisionMode"] = pM[settings.provisionMode];
|
||||||
node["APSecurity"] = settings.password.length() ? "wpa2" : "open";
|
node["APSecurity"] = settings.password.length() ? "wpa2" : "open";
|
||||||
@@ -1510,11 +1504,10 @@ bool System::command_info(const char * value, const int8_t id, JsonObject output
|
|||||||
node = output["ntp"].to<JsonObject>();
|
node = output["ntp"].to<JsonObject>();
|
||||||
#ifndef EMSESP_STANDALONE
|
#ifndef EMSESP_STANDALONE
|
||||||
node["NTPStatus"] = EMSESP::system_.ntp_connected() ? "connected" : "disconnected";
|
node["NTPStatus"] = EMSESP::system_.ntp_connected() ? "connected" : "disconnected";
|
||||||
EMSESP::esp8266React.getNTPSettingsService()->read([&](NTPSettings & settings) {
|
EMSESP::esp8266React.getNTPSettingsService()->read([&](const NTPSettings & settings) {
|
||||||
node["enabled"] = settings.enabled;
|
node["enabled"] = settings.enabled;
|
||||||
node["server"] = settings.server;
|
node["server"] = settings.server;
|
||||||
node["tzLabel"] = settings.tzLabel;
|
node["tzLabel"] = settings.tzLabel;
|
||||||
// node["tz format"] = settings.tzFormat;
|
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1527,7 +1520,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject output
|
|||||||
node["MQTTPublishFails"] = Mqtt::publish_fails();
|
node["MQTTPublishFails"] = Mqtt::publish_fails();
|
||||||
node["MQTTConnects"] = Mqtt::connect_count();
|
node["MQTTConnects"] = Mqtt::connect_count();
|
||||||
}
|
}
|
||||||
EMSESP::esp8266React.getMqttSettingsService()->read([&](MqttSettings & settings) {
|
EMSESP::esp8266React.getMqttSettingsService()->read([&](const MqttSettings & settings) {
|
||||||
node["enabled"] = settings.enabled;
|
node["enabled"] = settings.enabled;
|
||||||
node["clientID"] = settings.clientId;
|
node["clientID"] = settings.clientId;
|
||||||
node["keepAlive"] = settings.keepAlive;
|
node["keepAlive"] = settings.keepAlive;
|
||||||
@@ -1606,7 +1599,6 @@ bool System::command_info(const char * value, const int8_t id, JsonObject output
|
|||||||
node["busStatus"] = "unknown";
|
node["busStatus"] = "unknown";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// if (EMSESP::bus_status() != EMSESP::BUS_STATUS_OFFLINE) {
|
|
||||||
node["busProtocol"] = EMSbus::is_ht3() ? "HT3" : "Buderus";
|
node["busProtocol"] = EMSbus::is_ht3() ? "HT3" : "Buderus";
|
||||||
node["busTelegramsReceived"] = EMSESP::rxservice_.telegram_count();
|
node["busTelegramsReceived"] = EMSESP::rxservice_.telegram_count();
|
||||||
node["busReads"] = EMSESP::txservice_.telegram_read_count();
|
node["busReads"] = EMSESP::txservice_.telegram_read_count();
|
||||||
@@ -1616,11 +1608,10 @@ bool System::command_info(const char * value, const int8_t id, JsonObject output
|
|||||||
node["busWritesFailed"] = EMSESP::txservice_.telegram_write_fail_count();
|
node["busWritesFailed"] = EMSESP::txservice_.telegram_write_fail_count();
|
||||||
node["busRxLineQuality"] = EMSESP::rxservice_.quality();
|
node["busRxLineQuality"] = EMSESP::rxservice_.quality();
|
||||||
node["busTxLineQuality"] = (EMSESP::txservice_.read_quality() + EMSESP::txservice_.read_quality()) / 2;
|
node["busTxLineQuality"] = (EMSESP::txservice_.read_quality() + EMSESP::txservice_.read_quality()) / 2;
|
||||||
// }
|
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
node = output["settings"].to<JsonObject>();
|
node = output["settings"].to<JsonObject>();
|
||||||
EMSESP::webSettingsService.read([&](WebSettings & settings) {
|
EMSESP::webSettingsService.read([&](const WebSettings & settings) {
|
||||||
node["boardProfile"] = settings.board_profile;
|
node["boardProfile"] = settings.board_profile;
|
||||||
node["locale"] = settings.locale;
|
node["locale"] = settings.locale;
|
||||||
node["txMode"] = settings.tx_mode;
|
node["txMode"] = settings.tx_mode;
|
||||||
@@ -1707,7 +1698,6 @@ bool System::command_info(const char * value, const int8_t id, JsonObject output
|
|||||||
obj["name"] = F_(temperaturesensor);
|
obj["name"] = F_(temperaturesensor);
|
||||||
obj["entities"] = EMSESP::temperaturesensor_.count_entities();
|
obj["entities"] = EMSESP::temperaturesensor_.count_entities();
|
||||||
}
|
}
|
||||||
// if (EMSESP::analog_enabled()) {
|
|
||||||
if (EMSESP::analogsensor_.count_entities()) {
|
if (EMSESP::analogsensor_.count_entities()) {
|
||||||
JsonObject obj = devices.add<JsonObject>();
|
JsonObject obj = devices.add<JsonObject>();
|
||||||
obj["type"] = F_(analogsensor);
|
obj["type"] = F_(analogsensor);
|
||||||
@@ -1870,7 +1860,7 @@ std::string System::reset_reason(uint8_t cpu) const {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return ("Unknown");
|
return "Unknown";
|
||||||
}
|
}
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ class System {
|
|||||||
static bool command_fetch(const char * value, const int8_t id);
|
static bool command_fetch(const char * value, const int8_t id);
|
||||||
static bool command_restart(const char * value, const int8_t id);
|
static bool command_restart(const char * value, const int8_t id);
|
||||||
static bool command_format(const char * value, const int8_t id);
|
static bool command_format(const char * value, const int8_t id);
|
||||||
// static bool command_syslog_level(const char * value, const int8_t id);
|
|
||||||
static bool command_watch(const char * value, const int8_t id);
|
static bool command_watch(const char * value, const int8_t id);
|
||||||
static bool command_message(const char * value, const int8_t id);
|
static bool command_message(const char * value, const int8_t id);
|
||||||
static bool command_info(const char * value, const int8_t id, JsonObject output);
|
static bool command_info(const char * value, const int8_t id, JsonObject output);
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ void TemperatureSensor::start() {
|
|||||||
// load settings
|
// load settings
|
||||||
void TemperatureSensor::reload() {
|
void TemperatureSensor::reload() {
|
||||||
// load the service settings
|
// load the service settings
|
||||||
EMSESP::webSettingsService.read([&](WebSettings & settings) {
|
EMSESP::webSettingsService.read([&](WebSettings const & settings) {
|
||||||
dallas_gpio_ = settings.dallas_gpio;
|
dallas_gpio_ = settings.dallas_gpio;
|
||||||
parasite_ = settings.dallas_parasite;
|
parasite_ = settings.dallas_parasite;
|
||||||
});
|
});
|
||||||
@@ -274,7 +274,7 @@ int16_t TemperatureSensor::get_temperature_c(const uint8_t addr[]) {
|
|||||||
case 11:
|
case 11:
|
||||||
raw_value &= ~0x1;
|
raw_value &= ~0x1;
|
||||||
break;
|
break;
|
||||||
case 12:
|
default: // 12
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -302,7 +302,7 @@ bool TemperatureSensor::update(const std::string & id, const std::string & name,
|
|||||||
sensor.set_offset(offset);
|
sensor.set_offset(offset);
|
||||||
|
|
||||||
// store the new name and offset in our configuration
|
// store the new name and offset in our configuration
|
||||||
EMSESP::webCustomizationService.update([&](WebCustomization & settings) {
|
EMSESP::webCustomizationService.update([&id, &name, &offset, &sensor](WebCustomization & settings) {
|
||||||
// look it up to see if it exists
|
// look it up to see if it exists
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (auto & SensorCustomization : settings.sensorCustomizations) {
|
for (auto & SensorCustomization : settings.sensorCustomizations) {
|
||||||
@@ -315,7 +315,7 @@ bool TemperatureSensor::update(const std::string & id, const std::string & name,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
SensorCustomization newSensor = SensorCustomization();
|
auto newSensor = SensorCustomization();
|
||||||
newSensor.id = id;
|
newSensor.id = id;
|
||||||
newSensor.name = name;
|
newSensor.name = name;
|
||||||
newSensor.offset = offset;
|
newSensor.offset = offset;
|
||||||
@@ -401,9 +401,9 @@ void TemperatureSensor::publish_sensor(const Sensor & sensor) {
|
|||||||
if (Mqtt::enabled() && Mqtt::publish_single()) {
|
if (Mqtt::enabled() && Mqtt::publish_single()) {
|
||||||
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
||||||
if (Mqtt::publish_single2cmd()) {
|
if (Mqtt::publish_single2cmd()) {
|
||||||
snprintf(topic, sizeof(topic), "%s/%s", (F_(temperaturesensor)), sensor.name().c_str());
|
snprintf(topic, sizeof(topic), "%s/%s", F_(temperaturesensor), sensor.name().c_str());
|
||||||
} else {
|
} else {
|
||||||
snprintf(topic, sizeof(topic), "%s%s/%s", (F_(temperaturesensor)), "_data", sensor.name().c_str());
|
snprintf(topic, sizeof(topic), "%s%s/%s", F_(temperaturesensor), "_data", sensor.name().c_str());
|
||||||
}
|
}
|
||||||
char payload[10];
|
char payload[10];
|
||||||
Mqtt::queue_publish(topic, Helpers::render_value(payload, sensor.temperature_c, 10, EMSESP::system_.fahrenheit() ? 2 : 0));
|
Mqtt::queue_publish(topic, Helpers::render_value(payload, sensor.temperature_c, 10, EMSESP::system_.fahrenheit() ? 2 : 0));
|
||||||
@@ -513,7 +513,7 @@ void TemperatureSensor::publish_values(const bool force) {
|
|||||||
|
|
||||||
// see if we need to create the [devs] discovery section, as this needs only to be done once for all sensors
|
// see if we need to create the [devs] discovery section, as this needs only to be done once for all sensors
|
||||||
bool is_ha_device_created = false;
|
bool is_ha_device_created = false;
|
||||||
for (auto & sensor : sensors_) {
|
for (const auto & sensor : sensors_) {
|
||||||
if (sensor.ha_registered) {
|
if (sensor.ha_registered) {
|
||||||
is_ha_device_created = true;
|
is_ha_device_created = true;
|
||||||
break;
|
break;
|
||||||
@@ -570,8 +570,8 @@ std::string TemperatureSensor::Sensor::name() const {
|
|||||||
// look up in customization service for a specific sensor
|
// look up in customization service for a specific sensor
|
||||||
// and set the name and offset from that entry if it exists
|
// and set the name and offset from that entry if it exists
|
||||||
bool TemperatureSensor::Sensor::apply_customization() {
|
bool TemperatureSensor::Sensor::apply_customization() {
|
||||||
EMSESP::webCustomizationService.read([&](WebCustomization & settings) {
|
EMSESP::webCustomizationService.read([&](const WebCustomization & settings) {
|
||||||
auto sensors = settings.sensorCustomizations;
|
auto const & sensors = settings.sensorCustomizations;
|
||||||
if (!sensors.empty()) {
|
if (!sensors.empty()) {
|
||||||
for (const auto & sensor : sensors) {
|
for (const auto & sensor : sensors) {
|
||||||
if (id_ == sensor.id) {
|
if (id_ == sensor.id) {
|
||||||
|
|||||||
@@ -90,23 +90,23 @@ class TemperatureSensor {
|
|||||||
return sensors_;
|
return sensors_;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t reads() {
|
uint32_t reads() const {
|
||||||
return sensorreads_;
|
return sensorreads_;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t fails() {
|
uint32_t fails() const {
|
||||||
return sensorfails_;
|
return sensorfails_;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sensor_enabled() {
|
bool sensor_enabled() const {
|
||||||
return (dallas_gpio_ != 0);
|
return (dallas_gpio_ != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool have_sensors() {
|
bool have_sensors() const {
|
||||||
return (!sensors_.empty());
|
return (!sensors_.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t count_entities() {
|
size_t count_entities() const {
|
||||||
return sensors_.size();
|
return sensors_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ void WebAPIService::webAPIService(AsyncWebServerRequest * request) {
|
|||||||
void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject input) {
|
void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject input) {
|
||||||
// check if the user has admin privileges (token is included and authorized)
|
// check if the user has admin privileges (token is included and authorized)
|
||||||
bool is_admin = false;
|
bool is_admin = false;
|
||||||
EMSESP::webSettingsService.read([&](WebSettings & settings) {
|
EMSESP::webSettingsService.read([&](WebSettings const & settings) {
|
||||||
Authentication authentication = _securityManager->authenticateRequest(request);
|
Authentication authentication = _securityManager->authenticateRequest(request);
|
||||||
is_admin = settings.notoken_api || AuthenticationPredicates::IS_ADMIN(authentication);
|
is_admin = settings.notoken_api || AuthenticationPredicates::IS_ADMIN(authentication);
|
||||||
});
|
});
|
||||||
@@ -94,7 +94,7 @@ void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject input) {
|
|||||||
emsesp::EMSESP::system_.refreshHeapMem();
|
emsesp::EMSESP::system_.refreshHeapMem();
|
||||||
|
|
||||||
// output json buffer
|
// output json buffer
|
||||||
AsyncJsonResponse * response = new AsyncJsonResponse(false);
|
auto response = new AsyncJsonResponse(false);
|
||||||
|
|
||||||
// add more mem if needed - won't be needed in ArduinoJson 7
|
// add more mem if needed - won't be needed in ArduinoJson 7
|
||||||
// while (!response->getSize()) {
|
// while (!response->getSize()) {
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ void WebCustomEntityService::begin() {
|
|||||||
void WebCustomEntity::read(WebCustomEntity & webEntity, JsonObject root) {
|
void WebCustomEntity::read(WebCustomEntity & webEntity, JsonObject root) {
|
||||||
JsonArray entity = root["entities"].to<JsonArray>();
|
JsonArray entity = root["entities"].to<JsonArray>();
|
||||||
uint8_t counter = 0;
|
uint8_t counter = 0;
|
||||||
for (const CustomEntityItem & entityItem : webEntity.customEntityItems) {
|
for (CustomEntityItem & entityItem : webEntity.customEntityItems) {
|
||||||
JsonObject ei = entity.add<JsonObject>();
|
JsonObject ei = entity.add<JsonObject>();
|
||||||
ei["id"] = counter++; // id is only used to render the table and must be unique
|
ei["id"] = counter++; // id is only used to render the table and must be unique
|
||||||
ei["ram"] = entityItem.ram;
|
ei["ram"] = entityItem.ram;
|
||||||
@@ -213,7 +213,7 @@ bool WebCustomEntityService::command_setvalue(const char * value, const int8_t i
|
|||||||
|
|
||||||
// output of a single value
|
// output of a single value
|
||||||
// if add_uom is true it will add the UOM string to the value
|
// if add_uom is true it will add the UOM string to the value
|
||||||
void WebCustomEntityService::render_value(JsonObject output, CustomEntityItem entity, const bool useVal, const bool web, const bool add_uom) {
|
void WebCustomEntityService::render_value(JsonObject output, CustomEntityItem & entity, const bool useVal, const bool web, const bool add_uom) {
|
||||||
char payload[12];
|
char payload[12];
|
||||||
std::string name = useVal ? "value" : entity.name;
|
std::string name = useVal ? "value" : entity.name;
|
||||||
switch (entity.value_type) {
|
switch (entity.value_type) {
|
||||||
@@ -262,7 +262,7 @@ void WebCustomEntityService::render_value(JsonObject output, CustomEntityItem en
|
|||||||
output[name] = add_uom ? serialized(v + ' ' + EMSdevice::uom_to_string(entity.uom)) : serialized(v);
|
output[name] = add_uom ? serialized(v + ' ' + EMSdevice::uom_to_string(entity.uom)) : serialized(v);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DeviceValueType::STRING:
|
// case DeviceValueType::STRING:
|
||||||
default:
|
default:
|
||||||
// if no type treat it as a string
|
// if no type treat it as a string
|
||||||
if (entity.data.length() > 0) {
|
if (entity.data.length() > 0) {
|
||||||
@@ -275,7 +275,7 @@ void WebCustomEntityService::render_value(JsonObject output, CustomEntityItem en
|
|||||||
// display all custom entities
|
// display all custom entities
|
||||||
// adding each one, with UOM to a json object string
|
// adding each one, with UOM to a json object string
|
||||||
void WebCustomEntityService::show_values(JsonObject output) {
|
void WebCustomEntityService::show_values(JsonObject output) {
|
||||||
for (const CustomEntityItem & entity : *customEntityItems_) {
|
for (CustomEntityItem & entity : *customEntityItems_) {
|
||||||
render_value(output, entity, false, false, true); // with add_uom
|
render_value(output, entity, false, false, true); // with add_uom
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -285,14 +285,14 @@ bool WebCustomEntityService::get_value_info(JsonObject output, const char * cmd)
|
|||||||
// if no custom entries, return empty json
|
// if no custom entries, return empty json
|
||||||
// even if we're looking for a specific entity
|
// even if we're looking for a specific entity
|
||||||
// https://github.com/emsesp/EMS-ESP32/issues/1297
|
// https://github.com/emsesp/EMS-ESP32/issues/1297
|
||||||
if (customEntityItems_->size() == 0) {
|
if (customEntityItems_->empty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if it's info or values...
|
// if it's info or values...
|
||||||
if (!strlen(cmd) || !strcmp(cmd, F_(values)) || !strcmp(cmd, F_(info))) {
|
if (!strlen(cmd) || !strcmp(cmd, F_(values)) || !strcmp(cmd, F_(info))) {
|
||||||
// list all names
|
// list all names
|
||||||
for (const CustomEntityItem & entity : *customEntityItems_) {
|
for (CustomEntityItem & entity : *customEntityItems_) {
|
||||||
render_value(output, entity);
|
render_value(output, entity);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -300,7 +300,7 @@ bool WebCustomEntityService::get_value_info(JsonObject output, const char * cmd)
|
|||||||
|
|
||||||
// list all entities
|
// list all entities
|
||||||
if (!strcmp(cmd, F_(entities))) {
|
if (!strcmp(cmd, F_(entities))) {
|
||||||
for (const auto & entity : *customEntityItems_) {
|
for (auto & entity : *customEntityItems_) {
|
||||||
auto nest = output[entity.name].to<JsonObject>();
|
auto nest = output[entity.name].to<JsonObject>();
|
||||||
get_value_json(nest, entity);
|
get_value_json(nest, entity);
|
||||||
}
|
}
|
||||||
@@ -309,7 +309,7 @@ bool WebCustomEntityService::get_value_info(JsonObject output, const char * cmd)
|
|||||||
|
|
||||||
// specific value info
|
// specific value info
|
||||||
const char * attribute_s = Command::get_attribute(cmd);
|
const char * attribute_s = Command::get_attribute(cmd);
|
||||||
for (const auto & entity : *customEntityItems_) {
|
for (auto & entity : *customEntityItems_) {
|
||||||
if (Helpers::toLower(entity.name) == cmd) {
|
if (Helpers::toLower(entity.name) == cmd) {
|
||||||
get_value_json(output, entity);
|
get_value_json(output, entity);
|
||||||
return Command::set_attribute(output, cmd, attribute_s);
|
return Command::set_attribute(output, cmd, attribute_s);
|
||||||
@@ -319,7 +319,7 @@ bool WebCustomEntityService::get_value_info(JsonObject output, const char * cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// build the json for specific entity
|
// build the json for specific entity
|
||||||
void WebCustomEntityService::get_value_json(JsonObject output, const CustomEntityItem & entity) {
|
void WebCustomEntityService::get_value_json(JsonObject output, CustomEntityItem & entity) {
|
||||||
output["name"] = entity.name;
|
output["name"] = entity.name;
|
||||||
output["fullname"] = entity.name;
|
output["fullname"] = entity.name;
|
||||||
output["storage"] = entity.ram ? "ram" : "ems";
|
output["storage"] = entity.ram ? "ram" : "ems";
|
||||||
@@ -344,7 +344,7 @@ void WebCustomEntityService::get_value_json(JsonObject output, const CustomEntit
|
|||||||
}
|
}
|
||||||
|
|
||||||
// publish single value
|
// publish single value
|
||||||
void WebCustomEntityService::publish_single(const CustomEntityItem & entity) {
|
void WebCustomEntityService::publish_single(CustomEntityItem & entity) {
|
||||||
if (!Mqtt::enabled() || !Mqtt::publish_single()) {
|
if (!Mqtt::enabled() || !Mqtt::publish_single()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -372,11 +372,11 @@ void WebCustomEntityService::publish(const bool force) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (customEntityItems_->size() == 0) {
|
if (customEntityItems_->empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Mqtt::publish_single() && force) {
|
if (Mqtt::publish_single() && force) {
|
||||||
for (const CustomEntityItem & entityItem : *customEntityItems_) {
|
for (CustomEntityItem & entityItem : *customEntityItems_) {
|
||||||
publish_single(entityItem);
|
publish_single(entityItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -385,7 +385,7 @@ void WebCustomEntityService::publish(const bool force) {
|
|||||||
JsonObject output = doc.to<JsonObject>();
|
JsonObject output = doc.to<JsonObject>();
|
||||||
bool ha_created = ha_registered_;
|
bool ha_created = ha_registered_;
|
||||||
|
|
||||||
for (const CustomEntityItem & entityItem : *customEntityItems_) {
|
for (CustomEntityItem & entityItem : *customEntityItems_) {
|
||||||
render_value(output, entityItem);
|
render_value(output, entityItem);
|
||||||
// create HA config
|
// create HA config
|
||||||
if (Mqtt::ha_enabled() && !ha_registered_) {
|
if (Mqtt::ha_enabled() && !ha_registered_) {
|
||||||
@@ -454,14 +454,15 @@ void WebCustomEntityService::publish(const bool force) {
|
|||||||
|
|
||||||
// count only entities with valid value or command to show in dashboard
|
// count only entities with valid value or command to show in dashboard
|
||||||
uint8_t WebCustomEntityService::count_entities() {
|
uint8_t WebCustomEntityService::count_entities() {
|
||||||
if (customEntityItems_->size() == 0) {
|
if (customEntityItems_->empty()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonDocument doc;
|
JsonDocument doc;
|
||||||
JsonObject output = doc.to<JsonObject>();
|
JsonObject output = doc.to<JsonObject>();
|
||||||
uint8_t count = 0;
|
uint8_t count = 0;
|
||||||
for (const CustomEntityItem & entity : *customEntityItems_) {
|
|
||||||
|
for (CustomEntityItem & entity : *customEntityItems_) {
|
||||||
render_value(output, entity);
|
render_value(output, entity);
|
||||||
if (output[entity.name].is<JsonVariantConst>() || entity.writeable) {
|
if (output[entity.name].is<JsonVariantConst>() || entity.writeable) {
|
||||||
count++;
|
count++;
|
||||||
@@ -557,7 +558,7 @@ void WebCustomEntityService::generate_value_web(JsonObject output) {
|
|||||||
void WebCustomEntityService::fetch() {
|
void WebCustomEntityService::fetch() {
|
||||||
const uint8_t len[] = {1, 1, 1, 2, 2, 3, 3, 4};
|
const uint8_t len[] = {1, 1, 1, 2, 2, 3, 3, 4};
|
||||||
|
|
||||||
for (auto & entity : *customEntityItems_) {
|
for (auto const & entity : *customEntityItems_) {
|
||||||
if (entity.device_id > 0 && entity.type_id > 0) { // this excludes also RAM type
|
if (entity.device_id > 0 && entity.type_id > 0) { // this excludes also RAM type
|
||||||
bool needFetch = true;
|
bool needFetch = true;
|
||||||
uint8_t fetchblock = entity.type_id > 0x0FF ? 25 : 27;
|
uint8_t fetchblock = entity.type_id > 0x0FF ? 25 : 27;
|
||||||
@@ -579,7 +580,6 @@ void WebCustomEntityService::fetch() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// EMSESP::logger().debug("fetch custom entities");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// called on process telegram, read from telegram
|
// called on process telegram, read from telegram
|
||||||
|
|||||||
@@ -55,14 +55,14 @@ class WebCustomEntityService : public StatefulService<WebCustomEntity> {
|
|||||||
WebCustomEntityService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager);
|
WebCustomEntityService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager);
|
||||||
|
|
||||||
void begin();
|
void begin();
|
||||||
void publish_single(const CustomEntityItem & entity);
|
void publish_single(CustomEntityItem & entity);
|
||||||
void publish(const bool force = false);
|
void publish(const bool force = false);
|
||||||
bool command_setvalue(const char * value, const int8_t id, const char * name);
|
bool command_setvalue(const char * value, const int8_t id, const char * name);
|
||||||
bool get_value_info(JsonObject output, const char * cmd);
|
bool get_value_info(JsonObject output, const char * cmd);
|
||||||
void get_value_json(JsonObject output, const CustomEntityItem & entity);
|
void get_value_json(JsonObject output, CustomEntityItem & entity);
|
||||||
bool get_value(std::shared_ptr<const Telegram> telegram);
|
bool get_value(std::shared_ptr<const Telegram> telegram);
|
||||||
void fetch();
|
void fetch();
|
||||||
void render_value(JsonObject output, CustomEntityItem entity, const bool useVal = false, const bool web = false, const bool add_uom = false);
|
void render_value(JsonObject output, CustomEntityItem & entity, const bool useVal = false, const bool web = false, const bool add_uom = false);
|
||||||
void show_values(JsonObject output);
|
void show_values(JsonObject output);
|
||||||
void generate_value_web(JsonObject output);
|
void generate_value_web(JsonObject output);
|
||||||
|
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ bool WebSchedulerService::command_setvalue(const char * value, const int8_t id,
|
|||||||
|
|
||||||
// process json output for info/commands and value_info
|
// process json output for info/commands and value_info
|
||||||
bool WebSchedulerService::get_value_info(JsonObject output, const char * cmd) {
|
bool WebSchedulerService::get_value_info(JsonObject output, const char * cmd) {
|
||||||
if (scheduleItems_->size() == 0) {
|
if (scheduleItems_->empty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,7 +233,7 @@ void WebSchedulerService::publish(const bool force) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scheduleItems_->size() == 0) {
|
if (scheduleItems_->empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -449,7 +449,7 @@ void WebSchedulerService::loop() {
|
|||||||
static uint32_t last_uptime_sec = 0;
|
static uint32_t last_uptime_sec = 0;
|
||||||
|
|
||||||
// get list of scheduler events and exit if it's empty
|
// get list of scheduler events and exit if it's empty
|
||||||
if (scheduleItems_->size() == 0) {
|
if (scheduleItems_->empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user