diff --git a/src/core/analogsensor.cpp b/src/core/analogsensor.cpp index 8007cc507..6c604d083 100644 --- a/src/core/analogsensor.cpp +++ b/src/core/analogsensor.cpp @@ -102,7 +102,7 @@ void AnalogSensor::start(const bool factory_settings) { Command::add( EMSdevice::DeviceType::ANALOGSENSOR, F_(setvalue), - [&](const char * value, const int8_t id, JsonObject) { return command_setvalue(value, id); }, + [this](const char * value, const int8_t id, JsonObject) { return command_setvalue(value, id); }, FL_(setiovalue_cmd), CommandFlag::ADMIN_ONLY); @@ -195,7 +195,7 @@ void AnalogSensor::reload(bool get_nvs) { Command::add( EMSdevice::DeviceType::ANALOGSENSOR, sensor.name, - [&](const char * value, const int8_t, JsonObject) { return command_setvalue(value, sensor.gpio); }, + [this, gpio = sensor.gpio](const char * value, const int8_t, JsonObject) { return command_setvalue(value, gpio); }, sensor.type == AnalogType::COUNTER || (sensor.type >= AnalogType::CNT_0 && sensor.type <= AnalogType::CNT_2) ? FL_(counter) : sensor.type == AnalogType::DIGITAL_OUT ? FL_(digital_out) : sensor.type == AnalogType::RGB ? FL_(RGB) diff --git a/src/core/command.cpp b/src/core/command.cpp index cd5d9a791..7f106f107 100644 --- a/src/core/command.cpp +++ b/src/core/command.cpp @@ -492,7 +492,7 @@ uint8_t Command::call(const uint8_t device_type, const char * command, const cha } // add a command to the list, which does not return json -void Command::add(const uint8_t device_type, const uint8_t device_id, const char * cmd, const cmd_function_p cb, const char * const * description, uint8_t flags) { +void Command::add(const uint8_t device_type, const uint8_t device_id, const char * cmd, const cmd_function_p & cb, const char * const * description, uint8_t flags) { // if the command already exists for that device type don't add it if (find_command(device_type, device_id, cmd, flags) != nullptr) { return; @@ -508,13 +508,13 @@ void Command::add(const uint8_t device_type, const uint8_t device_id, const char // add a command with no json output // system/temperature/analog devices uses device_id 0 -void Command::add(const uint8_t device_type, const char * cmd, const cmd_function_p cb, const char * const * description, uint8_t flags) { +void Command::add(const uint8_t device_type, const char * cmd, const cmd_function_p & cb, const char * const * description, uint8_t flags) { add(device_type, 0, cmd, cb, description, flags); } // add a command to the list, which does return a json object as output // these commands bypass the readonly check (they are actions, not entity setters) -void Command::add_json(const uint8_t device_type, const char * cmd, const cmd_function_p cb, const char * const * description, uint8_t flags) { +void Command::add_json(const uint8_t device_type, const char * cmd, const cmd_function_p & cb, const char * const * description, uint8_t flags) { // if the command already exists for that device type don't add it if (find_command(device_type, 0, cmd, flags) != nullptr) { return; @@ -828,7 +828,7 @@ uint8_t Command::json_message(uint8_t error_code, const char * message, const Js // e.g. //one/two////three/// becomes /one/two/three std::string SUrlParser::path() { std::string s = "/"; // set up the beginning slash - for (const std::string & f : m_folders) { + for (const auto & f : m_folders) { s += f; s += "/"; } diff --git a/src/core/command.h b/src/core/command.h index 9c7cb50e1..b135a59db 100644 --- a/src/core/command.h +++ b/src/core/command.h @@ -67,13 +67,13 @@ class Command { cmd_function_p cmdfunction_; const char * const * description_; - CmdFunction(const uint8_t device_type, - const uint8_t device_id, - const uint8_t flags, - const bool has_json_output, - const char * cmd, - const cmd_function_p cmdfunction, - const char * const * description) + CmdFunction(const uint8_t device_type, + const uint8_t device_id, + const uint8_t flags, + const bool has_json_output, + const char * cmd, + const cmd_function_p & cmdfunction, + const char * const * description) : device_type_(device_type) , device_id_(device_id) , flags_(flags) @@ -105,22 +105,22 @@ class Command { static uint8_t call(const uint8_t device_type, const char * cmd, const char * value, const int8_t id = -1); // with normal call back function taking a value and id - static void add(const uint8_t device_type, - const uint8_t device_id, - const char * cmd, - const cmd_function_p cb, - const char * const * description, - uint8_t flags = CommandFlag::CMD_FLAG_DEFAULT); + static void add(const uint8_t device_type, + const uint8_t device_id, + const char * cmd, + const cmd_function_p & cb, + const char * const * description, + uint8_t flags = CommandFlag::CMD_FLAG_DEFAULT); // same for system/temperature/analog devices static void - add(const uint8_t device_type, const char * cmd, const cmd_function_p cb, const char * const * description, uint8_t flags = CommandFlag::CMD_FLAG_DEFAULT); + add(const uint8_t device_type, const char * cmd, const cmd_function_p & cb, const char * const * description, uint8_t flags = CommandFlag::CMD_FLAG_DEFAULT); // command that writes a JSON object as its output; bypasses the readonly check - static void add_json(const uint8_t device_type, - const char * cmd, - const cmd_function_p cb, - const char * const * description, - uint8_t flags = CommandFlag::CMD_FLAG_DEFAULT); + static void add_json(const uint8_t device_type, + const char * cmd, + const cmd_function_p & cb, + const char * const * description, + uint8_t flags = CommandFlag::CMD_FLAG_DEFAULT); static void reserve(size_t num) { cmdfunctions_.reserve(num); diff --git a/src/core/console.cpp b/src/core/console.cpp index 20ebbd420..7a5e3de4e 100644 --- a/src/core/console.cpp +++ b/src/core/console.cpp @@ -199,10 +199,9 @@ static void setup_commands(std::shared_ptr const & commands) { } }); - commands->add_command(ShellContext::MAIN, - CommandFlags::ADMIN, - string_vector{F_(wifi), F_(reconnect)}, - [](Shell &, const std::vector &) { EMSESP::network_.reconnect(); }); + commands->add_command(ShellContext::MAIN, CommandFlags::ADMIN, string_vector{F_(wifi), F_(reconnect)}, [](Shell &, const std::vector &) { + EMSESP::network_.reconnect(); + }); // // SET commands @@ -367,9 +366,7 @@ static void setup_commands(std::shared_ptr const & commands) { // EMS device commands // - commands->add_command(ShellContext::MAIN, CommandFlags::ADMIN, {F_(scan)}, [](Shell &, const std::vector &) { - EMSESP::scan_devices(); - }); + commands->add_command(ShellContext::MAIN, CommandFlags::ADMIN, {F_(scan)}, [](Shell &, const std::vector &) { EMSESP::scan_devices(); }); /* removed scan deep commands->add_command(ShellContext::MAIN, CommandFlags::ADMIN, {F_(scan)}, {F_(deep_optional)}, [](Shell & shell, const std::vector & arguments) { diff --git a/src/core/emsdevice.cpp b/src/core/emsdevice.cpp index 409d26bf5..5fa829408 100644 --- a/src/core/emsdevice.cpp +++ b/src/core/emsdevice.cpp @@ -52,7 +52,7 @@ bool EMSdevice::has_entities() const { } bool found = false; EMSESP::webCustomizationService.read([&](WebCustomization & settings) { - for (EntityCustomization entityCustomization : settings.entityCustomizations) { + for (const auto & entityCustomization : settings.entityCustomizations) { if (entityCustomization.device_id == device_id() && entityCustomization.entity_ids.size()) { found = true; break; @@ -564,17 +564,17 @@ void EMSdevice::register_telegram_type(const uint16_t telegram_type_id, const ch // add to device value library, also know now as a "device entity" // this function will also apply any customizations to the entity -void EMSdevice::add_device_value(int8_t tag, // to be used to group mqtt together, either as separate topics as a nested object - void * value_p, // pointer to the value from the .h file - uint8_t type, // one of DeviceValueType - const char * const ** options, // options for enum, which are translated as a list of lists - const char * const * options_single, // list of names - int8_t numeric_operator, // to divide or multiply, see DeviceValueNumOps:: - const char * const * name, // list of names, including shortname and translations - uint8_t uom, // unit of measure from DeviceValueUOM - const cmd_function_p f, // command function pointer - int16_t min, // min allowed value - uint32_t max // max allowed value +void EMSdevice::add_device_value(int8_t tag, // to be used to group mqtt together, either as separate topics as a nested object + void * value_p, // pointer to the value from the .h file + uint8_t type, // one of DeviceValueType + const char * const ** options, // options for enum, which are translated as a list of lists + const char * const * options_single, // list of names + int8_t numeric_operator, // to divide or multiply, see DeviceValueNumOps:: + const char * const * name, // list of names, including shortname and translations + uint8_t uom, // unit of measure from DeviceValueUOM + const cmd_function_p & f, // command function pointer + int16_t min, // min allowed value + uint32_t max // max allowed value ) { uint8_t state = DeviceValueState::DV_DEFAULT; // determine state auto custom_fullname = std::string(""); // custom fullname @@ -636,7 +636,7 @@ void EMSdevice::add_device_value(int8_t tag, // to b // scan through customizations to see if it's on the exclusion list by matching the productID and deviceID EMSESP::webCustomizationService.read([&](WebCustomization & settings) { - for (EntityCustomization entityCustomization : settings.entityCustomizations) { + for (const auto & entityCustomization : settings.entityCustomizations) { if ((entityCustomization.product_id == product_id()) && (entityCustomization.device_id == device_id())) { char entity[70]; if (tag < DeviceValueTAG::TAG_HC1) { @@ -645,7 +645,7 @@ void EMSdevice::add_device_value(int8_t tag, // to b snprintf(entity, sizeof(entity), "%s/%s", tag_to_mqtt(tag), short_name); } - for (const std::string & entity_id : entityCustomization.entity_ids) { + for (const auto & entity_id : entityCustomization.entity_ids) { // if there is an appended custom name, strip it to get the true entity name // and extract the new custom name auto custom_name_pos = entity_id.find('|'); @@ -700,93 +700,93 @@ void EMSdevice::erase_device_values() { } // single list of options -void EMSdevice::register_device_value(int8_t tag, - void * value_p, - uint8_t type, - const char * const * options_single, - const char * const * name, - uint8_t uom, - const cmd_function_p f) { +void EMSdevice::register_device_value(int8_t tag, + void * value_p, + uint8_t type, + const char * const * options_single, + const char * const * name, + uint8_t uom, + const cmd_function_p & f) { // create a multi-list from the options add_device_value(tag, value_p, type, nullptr, options_single, 0, name, uom, f, 0, 0); }; // single list of options, with no translations, with min and max -void EMSdevice::register_device_value(int8_t tag, - void * value_p, - uint8_t type, - const char * const * options_single, - const char * const * name, - uint8_t uom, - const cmd_function_p f, - int16_t min, - uint32_t max) { +void EMSdevice::register_device_value(int8_t tag, + void * value_p, + uint8_t type, + const char * const * options_single, + const char * const * name, + uint8_t uom, + const cmd_function_p & f, + int16_t min, + uint32_t max) { // create a multi-list from the options add_device_value(tag, value_p, type, nullptr, options_single, 0, name, uom, f, min, max); }; -void EMSdevice::register_device_value(int8_t tag, - void * value_p, - uint8_t type, - int8_t numeric_operator, - const char * const * name, - uint8_t uom, - const cmd_function_p f) { +void EMSdevice::register_device_value(int8_t tag, + void * value_p, + uint8_t type, + int8_t numeric_operator, + const char * const * name, + uint8_t uom, + const cmd_function_p & f) { add_device_value(tag, value_p, type, nullptr, nullptr, numeric_operator, name, uom, f, 0, 0); } -void EMSdevice::register_device_value(int8_t tag, - void * value_p, - uint8_t type, - int8_t numeric_operator, - const char * const * name, - uint8_t uom, - const cmd_function_p f, - int16_t min, - uint32_t max) { +void EMSdevice::register_device_value(int8_t tag, + void * value_p, + uint8_t type, + int8_t numeric_operator, + const char * const * name, + uint8_t uom, + const cmd_function_p & f, + int16_t min, + uint32_t max) { add_device_value(tag, value_p, type, nullptr, nullptr, numeric_operator, name, uom, f, min, max); } // no options, no function -void EMSdevice::register_device_value(int8_t tag, void * value_p, uint8_t type, const char * const * name, uint8_t uom, const cmd_function_p f) { +void EMSdevice::register_device_value(int8_t tag, void * value_p, uint8_t type, const char * const * name, uint8_t uom, const cmd_function_p & f) { add_device_value(tag, value_p, type, nullptr, nullptr, 0, name, uom, f, 0, 0); }; // no options, with min/max -void EMSdevice::register_device_value(int8_t tag, - void * value_p, - uint8_t type, - const char * const * name, - uint8_t uom, - const cmd_function_p f, - int16_t min, - uint32_t max) { +void EMSdevice::register_device_value(int8_t tag, + void * value_p, + uint8_t type, + const char * const * name, + uint8_t uom, + const cmd_function_p & f, + int16_t min, + uint32_t max) { add_device_value(tag, value_p, type, nullptr, nullptr, 0, name, uom, f, min, max); }; // function with min and max values // adds a new command to the command list // in this function we separate out the short and long names and take any translations -void EMSdevice::register_device_value(int8_t tag, - void * value_p, - uint8_t type, - const char * const ** options, - const char * const * name, - uint8_t uom, - const cmd_function_p f, - int16_t min, - uint32_t max) { +void EMSdevice::register_device_value(int8_t tag, + void * value_p, + uint8_t type, + const char * const ** options, + const char * const * name, + uint8_t uom, + const cmd_function_p & f, + int16_t min, + uint32_t max) { add_device_value(tag, value_p, type, options, nullptr, 0, name, uom, f, min, max); } // function with no min and max values (set to 0) -void EMSdevice::register_device_value(int8_t tag, - void * value_p, - uint8_t type, - const char * const ** options, - const char * const * name, - uint8_t uom, - const cmd_function_p f) { +void EMSdevice::register_device_value(int8_t tag, + void * value_p, + uint8_t type, + const char * const ** options, + const char * const * name, + uint8_t uom, + const cmd_function_p & f) { add_device_value(tag, value_p, type, options, nullptr, 0, name, uom, f, 0, 0); } @@ -1210,10 +1210,10 @@ void EMSdevice::generate_values_web_customization(JsonArray output) { // this is when the mask has it's high bit (0x80) set // https://github.com/emsesp/EMS-ESP32/issues/891 EMSESP::webCustomizationService.read([&](WebCustomization & settings) { - for (EntityCustomization entityCustomization : settings.entityCustomizations) { + for (const auto & entityCustomization : settings.entityCustomizations) { if (entityCustomization.device_id == device_id()) { // entity_ids is a list of all entities with the mask prefixed in the string - for (const std::string & entity_id : entityCustomization.entity_ids) { + for (const auto & entity_id : entityCustomization.entity_ids) { uint8_t mask = Helpers::hextoint(entity_id.substr(0, 2).c_str()); if (mask & 0x80) { JsonObject obj = output.add(); diff --git a/src/core/emsdevice.h b/src/core/emsdevice.h index ec136b938..fa21a8744 100644 --- a/src/core/emsdevice.h +++ b/src/core/emsdevice.h @@ -290,78 +290,79 @@ class EMSdevice { void generate_values_web(JsonObject output, const bool is_dashboard = false); void generate_values_web_customization(JsonArray output); - void add_device_value(int8_t tag, - void * value_p, - uint8_t type, - const char * const ** options, - const char * const * options_single, - int8_t numeric_operator, - const char * const * name, - uint8_t uom, - const cmd_function_p f, - int16_t min, - uint32_t max); + void add_device_value(int8_t tag, + void * value_p, + uint8_t type, + const char * const ** options, + const char * const * options_single, + int8_t numeric_operator, + const char * const * name, + uint8_t uom, + const cmd_function_p & f, + int16_t min, + uint32_t max); - void register_device_value(int8_t tag, - void * value_p, - uint8_t type, - const char * const ** options, - const char * const * name, - uint8_t uom, - const cmd_function_p f, - int16_t min, - uint32_t max); + void register_device_value(int8_t tag, + void * value_p, + uint8_t type, + const char * const ** options, + const char * const * name, + uint8_t uom, + const cmd_function_p & f, + int16_t min, + uint32_t max); void erase_device_values(); void - register_device_value(int8_t tag, void * value_p, uint8_t type, const char * const ** options, const char * const * name, uint8_t uom, const cmd_function_p f); + register_device_value(int8_t tag, void * value_p, uint8_t type, const char * const ** options, const char * const * name, uint8_t uom, const cmd_function_p & f); void register_device_value(int8_t tag, void * value_p, uint8_t type, const char * const ** options, const char * const * name, uint8_t uom); - void register_device_value(int8_t tag, - void * value_p, - uint8_t type, - int8_t numeric_operator, - const char * const * name, - uint8_t uom, - const cmd_function_p f = nullptr); + void register_device_value(int8_t tag, + void * value_p, + uint8_t type, + int8_t numeric_operator, + const char * const * name, + uint8_t uom, + const cmd_function_p & f = nullptr); - void register_device_value(int8_t tag, - void * value_p, - uint8_t type, - int8_t numeric_operator, - const char * const * name, - uint8_t uom, - const cmd_function_p f, - int16_t min, - uint32_t max); + void register_device_value(int8_t tag, + void * value_p, + uint8_t type, + int8_t numeric_operator, + const char * const * name, + uint8_t uom, + const cmd_function_p & f, + int16_t min, + uint32_t max); // single list of options - void register_device_value(int8_t tag, - void * value_p, - uint8_t type, - const char * const * options_single, - const char * const * name, - uint8_t uom, - const cmd_function_p f = nullptr); + void register_device_value(int8_t tag, + void * value_p, + uint8_t type, + const char * const * options_single, + const char * const * name, + uint8_t uom, + const cmd_function_p & f = nullptr); // single list of options, with no translations, with min and max - void register_device_value(int8_t tag, - void * value_p, - uint8_t type, - const char * const * options_single, - const char * const * name, - uint8_t uom, - const cmd_function_p f, - int16_t min, - uint32_t max); + void register_device_value(int8_t tag, + void * value_p, + uint8_t type, + const char * const * options_single, + const char * const * name, + uint8_t uom, + const cmd_function_p & f, + int16_t min, + uint32_t max); // no options, optional function f - void register_device_value(int8_t tag, void * value_p, uint8_t type, const char * const * name, uint8_t uom, const cmd_function_p f = nullptr); + void register_device_value(int8_t tag, void * value_p, uint8_t type, const char * const * name, uint8_t uom, const cmd_function_p & f = nullptr); // no options, with min/max - void register_device_value(int8_t tag, void * value_p, uint8_t type, const char * const * name, uint8_t uom, const cmd_function_p f, int16_t min, uint32_t max); + void + register_device_value(int8_t tag, void * value_p, uint8_t type, const char * const * name, uint8_t uom, const cmd_function_p & f, int16_t min, uint32_t max); void write_command(const uint16_t type_id, const uint8_t offset, uint8_t * message_data, const uint8_t message_length, const uint16_t validate_typeid) const; void write_command(const uint16_t type_id, const uint8_t offset, const uint8_t value, const uint16_t validate_typeid) const; diff --git a/src/core/emsdevicevalue.h b/src/core/emsdevicevalue.h index 58154771d..dbc037e3e 100644 --- a/src/core/emsdevicevalue.h +++ b/src/core/emsdevicevalue.h @@ -192,6 +192,11 @@ class DeviceValue { int16_t min; // min range uint32_t max; // max range + // optional custom name from customization. Allocated on heap only when actually set, + // so unnamed entities (the vast majority) don't pay for an inline std::string. + // Prefer custom_fullname() / set_custom_fullname() / has_custom_fullname() over direct access. + std::unique_ptr custom_fullname_; + DeviceValue(uint8_t device_type, // EMSdevice::DeviceType int8_t tag, // DeviceValueTAG::* void * value_p, // pointer to variable of any type @@ -245,11 +250,6 @@ class DeviceValue { static const char * const * DeviceValueTAG_s[]; static const char * const DeviceValueTAG_mqtt[]; static uint8_t NUM_TAGS; // # tags - - private: - // optional custom name from customization. Allocated on heap only when actually set, - // so unnamed entities (the vast majority) don't pay for an inline std::string. - std::unique_ptr custom_fullname_; }; }; // namespace emsesp diff --git a/src/core/emsesp.cpp b/src/core/emsesp.cpp index 7e7e2461c..a3efbcf5b 100644 --- a/src/core/emsesp.cpp +++ b/src/core/emsesp.cpp @@ -54,19 +54,19 @@ bool EMSESP::entity_compaction_pending_ = false; AsyncWebServer webServer(80); #if defined(EMSESP_STANDALONE) -FS dummyFS; -auto & fsRef = dummyFS; +FS dummyFS; +FS * const fsRef = &dummyFS; #else -auto & fsRef = LittleFS; +FS * const fsRef = &LittleFS; #endif -ESP32React EMSESP::esp32React(&webServer, &fsRef); -WebSettingsService EMSESP::webSettingsService = WebSettingsService(&webServer, &fsRef, EMSESP::esp32React.getSecurityManager()); -WebCustomizationService EMSESP::webCustomizationService = WebCustomizationService(&webServer, &fsRef, EMSESP::esp32React.getSecurityManager()); -WebSchedulerService EMSESP::webSchedulerService = WebSchedulerService(&webServer, &fsRef, EMSESP::esp32React.getSecurityManager()); -WebCommandService EMSESP::webCommandService = WebCommandService(&webServer, &fsRef, EMSESP::esp32React.getSecurityManager()); -WebCustomEntityService EMSESP::webCustomEntityService = WebCustomEntityService(&webServer, &fsRef, EMSESP::esp32React.getSecurityManager()); -WebModulesService EMSESP::webModulesService = WebModulesService(&webServer, &fsRef, EMSESP::esp32React.getSecurityManager()); +ESP32React EMSESP::esp32React(&webServer, fsRef); +WebSettingsService EMSESP::webSettingsService = WebSettingsService(&webServer, fsRef, EMSESP::esp32React.getSecurityManager()); +WebCustomizationService EMSESP::webCustomizationService = WebCustomizationService(&webServer, fsRef, EMSESP::esp32React.getSecurityManager()); +WebSchedulerService EMSESP::webSchedulerService = WebSchedulerService(&webServer, fsRef, EMSESP::esp32React.getSecurityManager()); +WebCommandService EMSESP::webCommandService = WebCommandService(&webServer, fsRef, EMSESP::esp32React.getSecurityManager()); +WebCustomEntityService EMSESP::webCustomEntityService = WebCustomEntityService(&webServer, fsRef, EMSESP::esp32React.getSecurityManager()); +WebModulesService EMSESP::webModulesService = WebModulesService(&webServer, fsRef, EMSESP::esp32React.getSecurityManager()); WebActivityService EMSESP::webActivityService = WebActivityService(&webServer, EMSESP::esp32React.getSecurityManager()); WebStatusService EMSESP::webStatusService = WebStatusService(&webServer, EMSESP::esp32React.getSecurityManager()); @@ -184,13 +184,13 @@ void EMSESP::erase_device(const uint8_t type_id) { } } - // clears list of recognized devices, entities and telegrams - void EMSESP::clear_all_devices() { - for (auto & emsdevice : emsdevices) { +// clears list of recognized devices, entities and telegrams +void EMSESP::clear_all_devices() { + for (const auto & emsdevice : emsdevices) { emsdevice->erase_device_values(); } emsdevices.clear(); - } +} // called from EMSdevice/Command whenever an entity or telegram handler is registered. // Devices reserve their value/telegram vectors generously (to avoid realloc storms while @@ -1046,7 +1046,7 @@ void EMSESP::process_UBADevices(const std::shared_ptr & telegram } } else if (device_exists(device_id) && !device_hasEntities(device_id)) { LOG_DEBUG("Remove EMS device with ID 0x%02X", device_id); - erase_device(device_id); // + erase_device(device_id); // } next_byte = next_byte >> 1; // advance 1 bit } @@ -1484,7 +1484,7 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, const // see if we have a custom device name in our Customizations list, and if so set it webCustomizationService.read([&](WebCustomization const & settings) { - for (EntityCustomization e : settings.entityCustomizations) { + for (const auto & e : settings.entityCustomizations) { 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); emsdevices.back()->custom_name(e.custom_name); diff --git a/src/core/emsesp.h b/src/core/emsesp.h index f8ada23c5..3111395ff 100644 --- a/src/core/emsesp.h +++ b/src/core/emsesp.h @@ -101,7 +101,7 @@ class Module {}; // forward declaration // for Command Function callbacks (Command::cmd_function_p). The unified callback takes a JsonObject // output which entity/setter commands ignore. -#define MAKE_CF_CB(__f) [&](const char * value, const int8_t id, JsonObject output) { return __f(value, id); } +#define MAKE_CF_CB(__f) [this](const char * value, const int8_t id, JsonObject output) { return __f(value, id); } namespace emsesp { diff --git a/src/core/shower.cpp b/src/core/shower.cpp index cbbafdf61..9c6552c32 100644 --- a/src/core/shower.cpp +++ b/src/core/shower.cpp @@ -36,7 +36,7 @@ void Shower::start() { Command::add_json( EMSdevice::DeviceType::BOILER, F_(coldshot), - [&](const char * value, const int8_t id, JsonObject output) { + [this](const char * value, const int8_t id, JsonObject output) { LOG_INFO("Forcing coldshot..."); if (shower_state_) { output["message"] = "OK"; diff --git a/src/core/system.cpp b/src/core/system.cpp index 6c98ba8c3..bee672f33 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -153,10 +153,10 @@ bool System::command_sendmail(const char * value, const int8_t) { bool success = false; #ifndef EMSESP_STANDALONE - WiFiClient * basic_client = new WiFiClient; - ESP_SSLClient * ssl_client = new ESP_SSLClient; - ReadyClient * r_client = new ReadyClient(*ssl_client); - SMTPClient * smtp = new SMTPClient(*r_client); + auto * basic_client = new WiFiClient; + auto * ssl_client = new ESP_SSLClient; + auto * r_client = new ReadyClient(*ssl_client); + auto * smtp = new SMTPClient(*r_client); ssl_client->setClient(basic_client); ssl_client->setInsecure(); diff --git a/src/web/WebCustomizationService.cpp b/src/web/WebCustomizationService.cpp index 16086fa49..40e8e72ac 100644 --- a/src/web/WebCustomizationService.cpp +++ b/src/web/WebCustomizationService.cpp @@ -317,7 +317,7 @@ void WebCustomizationService::customization_entities(AsyncWebServerRequest * req // add deleted entities from file read([&](WebCustomization & settings) { - for (EntityCustomization entityCustomization : settings.entityCustomizations) { + for (const auto & entityCustomization : settings.entityCustomizations) { if (entityCustomization.device_id == device_id) { for (const auto & entity_id : entityCustomization.entity_ids) { uint8_t mask = Helpers::hextoint(entity_id.substr(0, 2).c_str());