sonar recommendations

This commit is contained in:
proddy
2022-03-05 16:21:00 +01:00
parent 10830dee36
commit d09e2237ee
20 changed files with 51 additions and 120 deletions

1
.gitignore vendored
View File

@@ -32,3 +32,4 @@ scripts/__pycache__
# sonar # sonar
.scannerwork/ .scannerwork/
sonar/ sonar/
build_wrapper_output_directory/

View File

@@ -4,5 +4,5 @@
# export SONAR_TOKEN="" # export SONAR_TOKEN=""
make clean make clean
build-wrapper-linux-x86-64 --out-dir sonar/build_wrapper_output_directory make all build-wrapper-linux-x86-64 --out-dir build_wrapper_output_directory make all
sonar-scanner sonar-scanner

View File

@@ -64,12 +64,11 @@ void AnalogSensor::reload() {
// load the list of analog sensors from the customization service // load the list of analog sensors from the customization service
// and store them locally and then activate them // and store them locally and then activate them
EMSESP::webCustomizationService.read([&](WebCustomization & settings) { EMSESP::webCustomizationService.read([&](WebCustomization & settings) {
auto sensors = settings.analogCustomizations; auto it = sensors_.begin();
auto it = sensors_.begin();
for (auto & sensor_ : sensors_) { for (auto & sensor_ : sensors_) {
// update existing sensors // update existing sensors
bool found = false; bool found = false;
for (auto & sensor : sensors) { //search customlist for (const auto & sensor : settings.analogCustomizations) { //search customlist
if (sensor_.id() == sensor.id) { if (sensor_.id() == sensor.id) {
// for output sensors set value to new start-value // for output sensors set value to new start-value
if ((sensor.type == AnalogType::COUNTER || sensor.type >= AnalogType::DIGITAL_OUT) if ((sensor.type == AnalogType::COUNTER || sensor.type >= AnalogType::DIGITAL_OUT)
@@ -90,10 +89,11 @@ void AnalogSensor::reload() {
} }
it++; it++;
} }
// add new sensors from list // add new sensors from list
for (auto & sensor : sensors) { for (const auto & sensor : settings.analogCustomizations) {
bool found = false; bool found = false;
for (auto & sensor_ : sensors_) { for (const auto & sensor_ : sensors_) {
if (sensor_.id() == sensor.id) { if (sensor_.id() == sensor.id) {
found = true; found = true;
} }

View File

@@ -151,7 +151,7 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
return_code = Command::call(device_type, command_p, Helpers::itoa((int16_t)data.as<int>(), data_str), is_admin, id_n, output); return_code = Command::call(device_type, command_p, Helpers::itoa((int16_t)data.as<int>(), data_str), is_admin, id_n, output);
} else if (data.is<float>()) { } else if (data.is<float>()) {
char data_str[10]; char data_str[10];
return_code = Command::call(device_type, command_p, Helpers::render_value(data_str, (float)data.as<float>(), 2), is_admin, id_n, output); return_code = Command::call(device_type, command_p, Helpers::render_value(data_str, data.as<float>(), 2), is_admin, id_n, output);
} else if (data.isNull()) { } else if (data.isNull()) {
return_code = Command::call(device_type, command_p, "", is_admin, id_n, output); // empty, will do a query instead return_code = Command::call(device_type, command_p, "", is_admin, id_n, output); // empty, will do a query instead
} else { } else {
@@ -160,23 +160,18 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
return return_code; return return_code;
} }
const std::string Command::return_code_string(const uint8_t return_code) { std::string Command::return_code_string(const uint8_t return_code) {
switch (return_code) { switch (return_code) {
case CommandRet::ERROR: case CommandRet::ERROR:
return read_flash_string(F("Error")); return read_flash_string(F("Error"));
break;
case CommandRet::OK: case CommandRet::OK:
return read_flash_string(F("OK")); return read_flash_string(F("OK"));
break;
case CommandRet::NOT_FOUND: case CommandRet::NOT_FOUND:
return read_flash_string(F("Not Found")); return read_flash_string(F("Not Found"));
break;
case CommandRet::NOT_ALLOWED: case CommandRet::NOT_ALLOWED:
return read_flash_string(F("Not Authorized")); return read_flash_string(F("Not Authorized"));
break;
case CommandRet::FAIL: case CommandRet::FAIL:
return read_flash_string(F("Failed")); return read_flash_string(F("Failed"));
break;
default: default:
break; break;
} }
@@ -367,7 +362,7 @@ bool Command::list(const uint8_t device_type, JsonObject & output) {
} }
sorted_cmds.sort(); sorted_cmds.sort();
for (auto & cl : sorted_cmds) { for (const auto & cl : sorted_cmds) {
for (const auto & cf : cmdfunctions_) { for (const auto & cf : cmdfunctions_) {
if ((cf.device_type_ == device_type) && !cf.has_flags(CommandFlag::HIDDEN) && cf.description_ && (cl == read_flash_string(cf.cmd_))) { if ((cf.device_type_ == device_type) && !cf.has_flags(CommandFlag::HIDDEN) && cf.description_ && (cl == read_flash_string(cf.cmd_))) {
output[cl] = cf.description_; output[cl] = cf.description_;
@@ -396,7 +391,7 @@ 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 // if not in verbose mode, just print them on a single line
if (!verbose) { if (!verbose) {
for (auto & cl : sorted_cmds) { for (const auto & cl : sorted_cmds) {
shell.print(cl); shell.print(cl);
shell.print(" "); shell.print(" ");
} }
@@ -406,7 +401,7 @@ void Command::show(uuid::console::Shell & shell, uint8_t device_type, bool verbo
// verbose mode // verbose mode
shell.println(); shell.println();
for (auto & cl : sorted_cmds) { for (const auto & cl : sorted_cmds) {
// find and print the description // find and print the description
for (const auto & cf : cmdfunctions_) { for (const auto & cf : cmdfunctions_) {
if ((cf.device_type_ == device_type) && !cf.has_flags(CommandFlag::HIDDEN) && cf.description_ && (cl == read_flash_string(cf.cmd_))) { if ((cf.device_type_ == device_type) && !cf.has_flags(CommandFlag::HIDDEN) && cf.description_ && (cl == read_flash_string(cf.cmd_))) {
@@ -543,7 +538,7 @@ void Command::show_all(uuid::console::Shell & shell) {
// e.g. //one/two////three/// becomes /one/two/three // e.g. //one/two////three/// becomes /one/two/three
std::string SUrlParser::path() { std::string SUrlParser::path() {
std::string s = "/"; // set up the beginning slash std::string s = "/"; // set up the beginning slash
for (std::string & f : m_folders) { for (const std::string & f : m_folders) {
s += f; s += f;
s += "/"; s += "/";
} }

View File

@@ -125,7 +125,7 @@ class Command {
static const char * parse_command_string(const char * command, int8_t & id); static const char * parse_command_string(const char * command, int8_t & id);
static const std::string return_code_string(const uint8_t return_code); static std::string return_code_string(const uint8_t return_code);
private: private:
static uuid::log::Logger logger_; static uuid::log::Logger logger_;
@@ -134,13 +134,13 @@ class Command {
inline static uint8_t message(uint8_t error_code, const char * message, const JsonObject & output) { inline static uint8_t message(uint8_t error_code, const char * message, const JsonObject & output) {
output.clear(); output.clear();
output["message"] = (const char *)message; output["message"] = message;
return error_code; return error_code;
} }
}; };
typedef std::unordered_map<std::string, std::string> KeyValueMap_t; using KeyValueMap_t = std::unordered_map<std::string, std::string>;
typedef std::vector<std::string> Folder_t; using Folder_t = std::vector<std::string>;
class SUrlParser { class SUrlParser {
private: private:

View File

@@ -467,7 +467,7 @@ void Console::load_standard_commands(unsigned int context) {
flash_string_vector{F("test")}, flash_string_vector{F("test")},
flash_string_vector{F_(name_optional), F_(data_optional)}, flash_string_vector{F_(name_optional), F_(data_optional)},
[](Shell & shell, const std::vector<std::string> & arguments) { [](Shell & shell, const std::vector<std::string> & arguments) {
if (arguments.size() == 0) { if (arguments.empty()) {
Test::run_test(shell, "default"); Test::run_test(shell, "default");
} else if (arguments.size() == 1) { } else if (arguments.size() == 1) {
Test::run_test(shell, arguments.front()); Test::run_test(shell, arguments.front());
@@ -487,7 +487,7 @@ void Console::load_standard_commands(unsigned int context) {
flash_string_vector{F_(debug)}, flash_string_vector{F_(debug)},
flash_string_vector{F_(name_optional)}, flash_string_vector{F_(name_optional)},
[](Shell & shell, const std::vector<std::string> & arguments) { [](Shell & shell, const std::vector<std::string> & arguments) {
if (arguments.size() == 0) { if (arguments.empty()) {
Test::debug(shell, "default"); Test::debug(shell, "default");
} else { } else {
Test::debug(shell, arguments.front()); Test::debug(shell, arguments.front());

View File

@@ -354,7 +354,7 @@ bool DallasSensor::command_commands(const char * value, const int8_t id, JsonObj
// creates JSON doc from values // creates JSON doc from values
// returns false if there are no sensors // returns false if there are no sensors
bool DallasSensor::command_info(const char * value, const int8_t id, JsonObject & output) { bool DallasSensor::command_info(const char * value, const int8_t id, JsonObject & output) {
if (sensors_.size() == 0) { if (sensors_.empty()) {
return false; return false;
} }
@@ -535,8 +535,8 @@ std::string DallasSensor::Sensor::name() const {
bool DallasSensor::Sensor::apply_customization() { bool DallasSensor::Sensor::apply_customization() {
EMSESP::webCustomizationService.read([&](WebCustomization & settings) { EMSESP::webCustomizationService.read([&](WebCustomization & settings) {
auto sensors = settings.sensorCustomizations; auto sensors = settings.sensorCustomizations;
if (sensors.size() != 0) { if (sensors.empty()) {
for (auto & sensor : sensors) { for (const auto & sensor : sensors) {
#if defined(EMSESP_DEBUG) #if defined(EMSESP_DEBUG)
LOG_DEBUG(F("Loading customization for dallas sensor %s"), sensor.id_str.c_str()); LOG_DEBUG(F("Loading customization for dallas sensor %s"), sensor.id_str.c_str());
#endif #endif

View File

@@ -85,7 +85,7 @@ class DallasSensor {
bool get_value_info(JsonObject & output, const char * cmd, const int8_t id); bool get_value_info(JsonObject & output, const char * cmd, const int8_t id);
// return back reference to the sensor list, used by other classes // return back reference to the sensor list, used by other classes
const std::vector<Sensor> sensors() const { std::vector<Sensor> sensors() const {
return sensors_; return sensors_;
} }
@@ -102,7 +102,7 @@ class DallasSensor {
} }
bool have_sensors() { bool have_sensors() {
return (sensors_.size() > 0); return (!sensors_.empty());
} }
size_t no_sensors() { size_t no_sensors() {

View File

@@ -325,7 +325,7 @@ std::shared_ptr<Thermostat::HeatingCircuit> Thermostat::heating_circuit(std::sha
*/ */
// if it's the first set the status flag // if it's the first set the status flag
if (heating_circuits_.size() == 0) { if (heating_circuits_.empty()) {
strlcpy(status_, "online", sizeof(status_)); strlcpy(status_, "online", sizeof(status_));
} }
@@ -489,65 +489,44 @@ std::string Thermostat::mode_tostring(uint8_t mode) {
switch (mode) { switch (mode) {
case HeatingCircuit::Mode::OFF: case HeatingCircuit::Mode::OFF:
return read_flash_string(F_(off)); return read_flash_string(F_(off));
break;
case HeatingCircuit::Mode::MANUAL: case HeatingCircuit::Mode::MANUAL:
return read_flash_string(F_(manual)); return read_flash_string(F_(manual));
break;
case HeatingCircuit::Mode::DAY: case HeatingCircuit::Mode::DAY:
return read_flash_string(F_(day)); return read_flash_string(F_(day));
break;
case HeatingCircuit::Mode::NIGHT: case HeatingCircuit::Mode::NIGHT:
return read_flash_string(F_(night)); return read_flash_string(F_(night));
break;
case HeatingCircuit::Mode::ECO: case HeatingCircuit::Mode::ECO:
return read_flash_string(F_(eco)); return read_flash_string(F_(eco));
break;
case HeatingCircuit::Mode::COMFORT: case HeatingCircuit::Mode::COMFORT:
return read_flash_string(F_(comfort)); return read_flash_string(F_(comfort));
break;
case HeatingCircuit::Mode::HEAT: case HeatingCircuit::Mode::HEAT:
return read_flash_string(F_(heat)); return read_flash_string(F_(heat));
break;
case HeatingCircuit::Mode::HOLIDAY: case HeatingCircuit::Mode::HOLIDAY:
return read_flash_string(F_(holiday)); return read_flash_string(F_(holiday));
break;
case HeatingCircuit::Mode::NOFROST: case HeatingCircuit::Mode::NOFROST:
return read_flash_string(F_(nofrost)); return read_flash_string(F_(nofrost));
break;
case HeatingCircuit::Mode::AUTO: case HeatingCircuit::Mode::AUTO:
return read_flash_string(F_(auto)); return read_flash_string(F_(auto));
break;
case HeatingCircuit::Mode::SUMMER: case HeatingCircuit::Mode::SUMMER:
return read_flash_string(F_(summer)); return read_flash_string(F_(summer));
break;
case HeatingCircuit::Mode::OFFSET: case HeatingCircuit::Mode::OFFSET:
return read_flash_string(F_(offset)); return read_flash_string(F_(offset));
break;
case HeatingCircuit::Mode::DESIGN: case HeatingCircuit::Mode::DESIGN:
return read_flash_string(F_(design)); return read_flash_string(F_(design));
break;
case HeatingCircuit::Mode::MINFLOW: case HeatingCircuit::Mode::MINFLOW:
return read_flash_string(F_(minflow)); return read_flash_string(F_(minflow));
break;
case HeatingCircuit::Mode::MAXFLOW: case HeatingCircuit::Mode::MAXFLOW:
return read_flash_string(F_(maxflow)); return read_flash_string(F_(maxflow));
break;
case HeatingCircuit::Mode::ROOMINFLUENCE: case HeatingCircuit::Mode::ROOMINFLUENCE:
return read_flash_string(F_(roominfluence[0])); return read_flash_string(F_(roominfluence[0]));
break;
case HeatingCircuit::Mode::FLOWOFFSET: case HeatingCircuit::Mode::FLOWOFFSET:
return read_flash_string(F_(flowtempoffset[0])); return read_flash_string(F_(flowtempoffset[0]));
break;
case HeatingCircuit::Mode::TEMPAUTO: case HeatingCircuit::Mode::TEMPAUTO:
return read_flash_string(F_(tempauto)); return read_flash_string(F_(tempauto));
break;
case HeatingCircuit::Mode::NOREDUCE: case HeatingCircuit::Mode::NOREDUCE:
return read_flash_string(F_(noreduce)); return read_flash_string(F_(noreduce));
break;
default: default:
case HeatingCircuit::Mode::UNKNOWN:
return read_flash_string(F_(unknown)); return read_flash_string(F_(unknown));
break;
} }
} }
@@ -1947,9 +1926,7 @@ bool Thermostat::set_mode_n(const uint8_t mode, const uint8_t hc_num) {
set_mode_value = 1; set_mode_value = 1;
break; break;
default: default: // AUTO & ECO
case HeatingCircuit::Mode::AUTO:
case HeatingCircuit::Mode::ECO:
set_mode_value = 2; set_mode_value = 2;
break; break;
} }
@@ -2504,7 +2481,7 @@ bool Thermostat::set_temperature(const float temperature, const uint8_t mode, co
factor = 1; factor = 1;
break; break;
default: default:
case HeatingCircuit::Mode::AUTO: // HeatingCircuit::Mode::AUTO:
uint8_t mode_ = hc->get_mode(); uint8_t mode_ = hc->get_mode();
if (mode_ == HeatingCircuit::Mode::MANUAL) { if (mode_ == HeatingCircuit::Mode::MANUAL) {
offset = 0x0A; // manual offset offset = 0x0A; // manual offset
@@ -2543,7 +2520,7 @@ bool Thermostat::set_temperature(const float temperature, const uint8_t mode, co
offset = EMS_OFFSET_RC20_2_Set_temp_day; offset = EMS_OFFSET_RC20_2_Set_temp_day;
break; break;
default: default:
case HeatingCircuit::Mode::AUTO: // automatic selection, if no type is defined, we use the standard code // automatic selection, if no type is defined, we use the standard code
uint8_t mode_ = hc->get_mode(); uint8_t mode_ = hc->get_mode();
if (mode_ == HeatingCircuit::Mode::NIGHT) { if (mode_ == HeatingCircuit::Mode::NIGHT) {
offset = EMS_OFFSET_RC20_2_Set_temp_night; offset = EMS_OFFSET_RC20_2_Set_temp_night;
@@ -2614,7 +2591,7 @@ bool Thermostat::set_temperature(const float temperature, const uint8_t mode, co
factor = 1; factor = 1;
break; break;
default: default:
case HeatingCircuit::Mode::AUTO: // automatic selection, if no type is defined, we use the standard code // automatic selection, if no type is defined, we use the standard code
validate_typeid = monitor_typeids[hc->hc()]; //get setpoint roomtemp back validate_typeid = monitor_typeids[hc->hc()]; //get setpoint roomtemp back
if (model == EMS_DEVICE_FLAG_RC35) { if (model == EMS_DEVICE_FLAG_RC35) {
uint8_t mode_ = hc->get_mode(); uint8_t mode_ = hc->get_mode();
@@ -2650,7 +2627,7 @@ bool Thermostat::set_temperature(const float temperature, const uint8_t mode, co
offset = EMS_OFFSET_JunkersSetMessage_day_temp; offset = EMS_OFFSET_JunkersSetMessage_day_temp;
break; break;
default: default:
case HeatingCircuit::Mode::AUTO: // automatic selection, if no type is defined, we use the standard code // automatic selection, if no type is defined, we use the standard code
uint8_t modetype = hc->get_mode_type(); uint8_t modetype = hc->get_mode_type();
if (modetype == HeatingCircuit::Mode::NIGHT || modetype == HeatingCircuit::Mode::ECO) { if (modetype == HeatingCircuit::Mode::NIGHT || modetype == HeatingCircuit::Mode::ECO) {
offset = EMS_OFFSET_JunkersSetMessage_night_temp; offset = EMS_OFFSET_JunkersSetMessage_night_temp;
@@ -2677,7 +2654,7 @@ bool Thermostat::set_temperature(const float temperature, const uint8_t mode, co
offset = EMS_OFFSET_JunkersSetMessage2_heat_temp; offset = EMS_OFFSET_JunkersSetMessage2_heat_temp;
break; break;
default: default:
case HeatingCircuit::Mode::AUTO: // automatic selection, if no type is defined, we use the standard code // automatic selection, if no type is defined, we use the standard code
uint8_t modetype = hc->get_mode_type(); uint8_t modetype = hc->get_mode_type();
if (modetype == HeatingCircuit::Mode::NIGHT || modetype == HeatingCircuit::Mode::ECO) { if (modetype == HeatingCircuit::Mode::NIGHT || modetype == HeatingCircuit::Mode::ECO) {
offset = EMS_OFFSET_JunkersSetMessage2_eco_temp; offset = EMS_OFFSET_JunkersSetMessage2_eco_temp;
@@ -2695,7 +2672,7 @@ bool Thermostat::set_temperature(const float temperature, const uint8_t mode, co
if (offset != -1) { if (offset != -1) {
// add the write command to the Tx queue. value is *2 // add the write command to the Tx queue. value is *2
// post validate is the corresponding monitor or set type IDs as they can differ per model // post validate is the corresponding monitor or set type IDs as they can differ per model
write_command(set_typeid, offset, (uint8_t)((float)temperature * (float)factor), validate_typeid); write_command(set_typeid, offset, (uint8_t)(temperature * (float)factor), validate_typeid);
return true; return true;
} }

View File

@@ -62,32 +62,21 @@ std::string EMSdevice::brand_to_string() const {
switch (brand_) { switch (brand_) {
case EMSdevice::Brand::BOSCH: case EMSdevice::Brand::BOSCH:
return read_flash_string(F("Bosch")); return read_flash_string(F("Bosch"));
break;
case EMSdevice::Brand::JUNKERS: case EMSdevice::Brand::JUNKERS:
return read_flash_string(F("Junkers")); return read_flash_string(F("Junkers"));
break;
case EMSdevice::Brand::BUDERUS: case EMSdevice::Brand::BUDERUS:
return read_flash_string(F("Buderus")); return read_flash_string(F("Buderus"));
break;
case EMSdevice::Brand::NEFIT: case EMSdevice::Brand::NEFIT:
return read_flash_string(F("Nefit")); return read_flash_string(F("Nefit"));
break;
case EMSdevice::Brand::SIEGER: case EMSdevice::Brand::SIEGER:
return read_flash_string(F("Sieger")); return read_flash_string(F("Sieger"));
break;
case EMSdevice::Brand::WORCESTER: case EMSdevice::Brand::WORCESTER:
return read_flash_string(F("Worcester")); return read_flash_string(F("Worcester"));
break;
case EMSdevice::Brand::IVT: case EMSdevice::Brand::IVT:
return read_flash_string(F("IVT")); return read_flash_string(F("IVT"));
break;
case EMSdevice::Brand::NO_BRAND:
default: default:
return read_flash_string(F("")); return read_flash_string(F(""));
break;
} }
return std::string{};
} }
// returns the name of the MQTT topic to use for a specific device, without the base // returns the name of the MQTT topic to use for a specific device, without the base
@@ -95,55 +84,30 @@ std::string EMSdevice::device_type_2_device_name(const uint8_t device_type) {
switch (device_type) { switch (device_type) {
case DeviceType::SYSTEM: case DeviceType::SYSTEM:
return read_flash_string(F_(system)); return read_flash_string(F_(system));
break;
case DeviceType::BOILER: case DeviceType::BOILER:
return read_flash_string(F_(boiler)); return read_flash_string(F_(boiler));
break;
case DeviceType::THERMOSTAT: case DeviceType::THERMOSTAT:
return read_flash_string(F_(thermostat)); return read_flash_string(F_(thermostat));
break;
case DeviceType::HEATPUMP: case DeviceType::HEATPUMP:
return read_flash_string(F_(heatpump)); return read_flash_string(F_(heatpump));
break;
case DeviceType::SOLAR: case DeviceType::SOLAR:
return read_flash_string(F_(solar)); return read_flash_string(F_(solar));
break;
case DeviceType::CONNECT: case DeviceType::CONNECT:
return read_flash_string(F_(connect)); return read_flash_string(F_(connect));
break;
case DeviceType::MIXER: case DeviceType::MIXER:
return read_flash_string(F_(mixer)); return read_flash_string(F_(mixer));
break;
case DeviceType::DALLASSENSOR: case DeviceType::DALLASSENSOR:
return read_flash_string(F_(dallassensor)); return read_flash_string(F_(dallassensor));
break;
case DeviceType::ANALOGSENSOR: case DeviceType::ANALOGSENSOR:
return read_flash_string(F_(analogsensor)); return read_flash_string(F_(analogsensor));
break;
case DeviceType::CONTROLLER: case DeviceType::CONTROLLER:
return read_flash_string(F_(controller)); return read_flash_string(F_(controller));
break;
case DeviceType::SWITCH: case DeviceType::SWITCH:
return read_flash_string(F_(switch)); return read_flash_string(F_(switch));
break;
case DeviceType::GATEWAY: case DeviceType::GATEWAY:
return read_flash_string(F_(gateway)); return read_flash_string(F_(gateway));
break;
default: default:
return read_flash_string(F_(unknown)); return read_flash_string(F_(unknown));
break;
} }
} }
@@ -207,28 +171,20 @@ uint8_t EMSdevice::decode_brand(uint8_t value) {
switch (value) { switch (value) {
case 1: case 1:
return EMSdevice::Brand::BOSCH; return EMSdevice::Brand::BOSCH;
break;
case 2: case 2:
return EMSdevice::Brand::JUNKERS; return EMSdevice::Brand::JUNKERS;
break;
case 3: case 3:
return EMSdevice::Brand::BUDERUS; return EMSdevice::Brand::BUDERUS;
break;
case 4: case 4:
return EMSdevice::Brand::NEFIT; return EMSdevice::Brand::NEFIT;
break;
case 5: case 5:
return EMSdevice::Brand::SIEGER; return EMSdevice::Brand::SIEGER;
break;
case 11: case 11:
return EMSdevice::Brand::WORCESTER; return EMSdevice::Brand::WORCESTER;
break;
case 13: case 13:
return EMSdevice::Brand::IVT; return EMSdevice::Brand::IVT;
break;
default: default:
return EMSdevice::Brand::NO_BRAND; return EMSdevice::Brand::NO_BRAND;
break;
} }
} }
@@ -579,7 +535,6 @@ void EMSdevice::publish_value(void * value_p) const {
} }
break; break;
} }
case DeviceValueType::USHORT: case DeviceValueType::USHORT:
Helpers::render_value(payload, *(uint16_t *)(value_p), divider, fahrenheit); Helpers::render_value(payload, *(uint16_t *)(value_p), divider, fahrenheit);
break; break;
@@ -603,11 +558,12 @@ void EMSdevice::publish_value(void * value_p) const {
Helpers::render_value(payload, *(uint32_t *)(value_p), divider); Helpers::render_value(payload, *(uint32_t *)(value_p), divider);
break; break;
case DeviceValueType::STRING: case DeviceValueType::STRING:
default:
if (Helpers::hasValue((char *)(value_p))) { if (Helpers::hasValue((char *)(value_p))) {
strlcpy(payload, (char *)(value_p), sizeof(payload)); strlcpy(payload, (char *)(value_p), sizeof(payload));
} }
break; break;
default:
break;
} }
if (payload[0] != '\0') { if (payload[0] != '\0') {

View File

@@ -587,12 +587,12 @@ bool Helpers::value2bool(const char * v, bool & value) {
std::string bool_str = toLower(v); // convert to lower case std::string bool_str = toLower(v); // convert to lower case
if ((bool_str == read_flash_string(F_(on))) || (bool_str == "1") or (bool_str == "true")) { if ((bool_str == read_flash_string(F_(on))) || (bool_str == "1") || (bool_str == "true")) {
value = true; value = true;
return true; // is a bool return true; // is a bool
} }
if ((bool_str == read_flash_string(F_(off))) || (bool_str == "0") or (bool_str == "false")) { if ((bool_str == read_flash_string(F_(off))) || (bool_str == "0") || (bool_str == "false")) {
value = false; value = false;
return true; // is a bool return true; // is a bool
} }

View File

@@ -1313,7 +1313,7 @@ void Mqtt::publish_ha_climate_config(uint8_t tag, bool has_roomtemp, bool remove
// based on the device and tag, create the MQTT topic name (without the basename) // based on the device and tag, create the MQTT topic name (without the basename)
// differs based on whether MQTT nested is enabled // differs based on whether MQTT nested is enabled
// tag = EMSdevice::DeviceValueTAG // tag = EMSdevice::DeviceValueTAG
const std::string Mqtt::tag_to_topic(uint8_t device_type, uint8_t tag) { std::string Mqtt::tag_to_topic(uint8_t device_type, uint8_t tag) {
// the system device is treated differently. The topic is 'heartbeat' and doesn't follow the usual convention // the system device is treated differently. The topic is 'heartbeat' and doesn't follow the usual convention
if (device_type == EMSdevice::DeviceType::SYSTEM) { if (device_type == EMSdevice::DeviceType::SYSTEM) {
return EMSdevice::tag_to_mqtt(tag); return EMSdevice::tag_to_mqtt(tag);

View File

@@ -220,7 +220,7 @@ class Mqtt {
return mqtt_messages_.empty(); return mqtt_messages_.empty();
} }
static const std::string tag_to_topic(uint8_t device_type, uint8_t tag); static std::string tag_to_topic(uint8_t device_type, uint8_t tag);
struct QueuedMqttMessage { struct QueuedMqttMessage {
const uint32_t id_; const uint32_t id_;

View File

@@ -1135,9 +1135,11 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp
node["bus status"] = (F("connected, tx issues - try a different tx-mode")); node["bus status"] = (F("connected, tx issues - try a different tx-mode"));
break; break;
case EMSESP::BUS_STATUS_CONNECTED: case EMSESP::BUS_STATUS_CONNECTED:
default:
node["bus status"] = (F("connected")); node["bus status"] = (F("connected"));
break; break;
default:
node["bus status"] = (F("unknown"));
break;
} }
if (EMSESP::bus_status() != EMSESP::BUS_STATUS_OFFLINE) { if (EMSESP::bus_status() != EMSESP::BUS_STATUS_OFFLINE) {
@@ -1280,7 +1282,7 @@ bool System::command_restart(const char * value, const int8_t id) {
return true; return true;
} }
const std::string System::reset_reason(uint8_t cpu) { std::string System::reset_reason(uint8_t cpu) const {
#ifndef EMSESP_STANDALONE #ifndef EMSESP_STANDALONE
switch (rtc_get_reset_reason(cpu)) { switch (rtc_get_reset_reason(cpu)) {
case 1: case 1:

View File

@@ -65,7 +65,7 @@ class System {
static bool command_customizations(const char * value, const int8_t id, JsonObject & output); static bool command_customizations(const char * value, const int8_t id, JsonObject & output);
static bool command_commands(const char * value, const int8_t id, JsonObject & output); static bool command_commands(const char * value, const int8_t id, JsonObject & output);
const std::string reset_reason(uint8_t cpu); std::string reset_reason(uint8_t cpu) const;
void system_restart(); void system_restart();
void format(uuid::console::Shell & shell); void format(uuid::console::Shell & shell);

View File

@@ -270,7 +270,7 @@ class RxService : public EMSbus {
} }
}; };
const std::deque<QueuedRxTelegram> queue() const { std::deque<QueuedRxTelegram> queue() const {
return rx_telegrams_; return rx_telegrams_;
} }
@@ -400,12 +400,12 @@ class TxService : public EMSbus {
} }
}; };
const std::deque<QueuedTxTelegram> queue() const { std::deque<QueuedTxTelegram> queue() const {
return tx_telegrams_; return tx_telegrams_;
} }
bool tx_queue_empty() const { bool tx_queue_empty() const {
return tx_telegrams_.size() == 0; return tx_telegrams_.empty();
} }
#if defined(EMSESP_DEBUG) #if defined(EMSESP_DEBUG)

View File

@@ -49,7 +49,7 @@ void WebAPIService::webAPIService_get(AsyncWebServerRequest * request) {
// POST /{device}[/{hc|id}][/{name}] // POST /{device}[/{hc|id}][/{name}]
void WebAPIService::webAPIService_post(AsyncWebServerRequest * request, JsonVariant & json) { void WebAPIService::webAPIService_post(AsyncWebServerRequest * request, JsonVariant & json) {
// if no body then treat it as a secure GET // if no body then treat it as a secure GET
if (not json.is<JsonObject>()) { if (!json.is<JsonObject>()) {
webAPIService_get(request); webAPIService_get(request);
return; return;
} }

View File

@@ -162,7 +162,7 @@ void WebCustomizationService::devices(AsyncWebServerRequest * request) {
JsonObject root = response->getRoot(); JsonObject root = response->getRoot();
JsonArray devices = root.createNestedArray("devices"); JsonArray devices = root.createNestedArray("devices");
for (auto & emsdevice : EMSESP::emsdevices) { for (const auto & emsdevice : EMSESP::emsdevices) {
if (emsdevice->has_entities()) { if (emsdevice->has_entities()) {
JsonObject obj = devices.createNestedObject(); JsonObject obj = devices.createNestedObject();
obj["i"] = emsdevice->unique_id(); // a unique id obj["i"] = emsdevice->unique_id(); // a unique id

View File

@@ -76,7 +76,7 @@ void WebDataService::core_data(AsyncWebServerRequest * request) {
// list is already sorted by device type // list is already sorted by device type
// Ignore Contoller // Ignore Contoller
JsonArray devices = root.createNestedArray("devices"); JsonArray devices = root.createNestedArray("devices");
for (auto & emsdevice : EMSESP::emsdevices) { for (const auto & emsdevice : EMSESP::emsdevices) {
if (emsdevice && emsdevice->device_type() != EMSdevice::DeviceType::CONTROLLER) { if (emsdevice && emsdevice->device_type() != EMSdevice::DeviceType::CONTROLLER) {
JsonObject obj = devices.createNestedObject(); JsonObject obj = devices.createNestedObject();
obj["i"] = emsdevice->unique_id(); // a unique id obj["i"] = emsdevice->unique_id(); // a unique id
@@ -215,7 +215,7 @@ void WebDataService::write_value(AsyncWebServerRequest * request, JsonVariant &
return_code = Command::call(device_type, cmd, Helpers::render_value(s, data.as<int16_t>(), 0), true, id, output); return_code = Command::call(device_type, cmd, Helpers::render_value(s, data.as<int16_t>(), 0), true, id, output);
} else if (data.is<float>()) { } else if (data.is<float>()) {
char s[10]; char s[10];
return_code = Command::call(device_type, cmd, Helpers::render_value(s, (float)data.as<float>(), 1), true, id, output); return_code = Command::call(device_type, cmd, Helpers::render_value(s, data.as<float>(), 1), true, id, output);
} else if (data.is<bool>()) { } else if (data.is<bool>()) {
return_code = Command::call(device_type, cmd, data.as<bool>() ? "true" : "false", true, id, output); return_code = Command::call(device_type, cmd, data.as<bool>() ? "true" : "false", true, id, output);
} }

View File

@@ -213,7 +213,7 @@ void WebLogService::fetchLog(AsyncWebServerRequest * request) {
// sets the values like level after a POST // sets the values like level after a POST
void WebLogService::setValues(AsyncWebServerRequest * request, JsonVariant & json) { void WebLogService::setValues(AsyncWebServerRequest * request, JsonVariant & json) {
if (not json.is<JsonObject>()) { if (!json.is<JsonObject>()) {
return; return;
} }