mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-09-13 13:44:10 +00:00
various lint optimizations (add const, pass by reference)
This commit is contained in:
@@ -102,7 +102,7 @@ void AnalogSensor::start(const bool factory_settings) {
|
|||||||
Command::add(
|
Command::add(
|
||||||
EMSdevice::DeviceType::ANALOGSENSOR,
|
EMSdevice::DeviceType::ANALOGSENSOR,
|
||||||
F_(setvalue),
|
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),
|
FL_(setiovalue_cmd),
|
||||||
CommandFlag::ADMIN_ONLY);
|
CommandFlag::ADMIN_ONLY);
|
||||||
|
|
||||||
@@ -195,7 +195,7 @@ void AnalogSensor::reload(bool get_nvs) {
|
|||||||
Command::add(
|
Command::add(
|
||||||
EMSdevice::DeviceType::ANALOGSENSOR,
|
EMSdevice::DeviceType::ANALOGSENSOR,
|
||||||
sensor.name,
|
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::COUNTER || (sensor.type >= AnalogType::CNT_0 && sensor.type <= AnalogType::CNT_2) ? FL_(counter)
|
||||||
: sensor.type == AnalogType::DIGITAL_OUT ? FL_(digital_out)
|
: sensor.type == AnalogType::DIGITAL_OUT ? FL_(digital_out)
|
||||||
: sensor.type == AnalogType::RGB ? FL_(RGB)
|
: sensor.type == AnalogType::RGB ? FL_(RGB)
|
||||||
|
|||||||
@@ -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
|
// 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 the command already exists for that device type don't add it
|
||||||
if (find_command(device_type, device_id, cmd, flags) != nullptr) {
|
if (find_command(device_type, device_id, cmd, flags) != nullptr) {
|
||||||
return;
|
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
|
// add a command with no json output
|
||||||
// system/temperature/analog devices uses device_id 0
|
// 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(device_type, 0, cmd, cb, description, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
// add a command to the list, which does return a json object as output
|
// 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)
|
// 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 the command already exists for that device type don't add it
|
||||||
if (find_command(device_type, 0, cmd, flags) != nullptr) {
|
if (find_command(device_type, 0, cmd, flags) != nullptr) {
|
||||||
return;
|
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
|
// 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 (const std::string & f : m_folders) {
|
for (const auto & f : m_folders) {
|
||||||
s += f;
|
s += f;
|
||||||
s += "/";
|
s += "/";
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -72,7 +72,7 @@ class Command {
|
|||||||
const uint8_t flags,
|
const uint8_t flags,
|
||||||
const bool has_json_output,
|
const bool has_json_output,
|
||||||
const char * cmd,
|
const char * cmd,
|
||||||
const cmd_function_p cmdfunction,
|
const cmd_function_p & cmdfunction,
|
||||||
const char * const * description)
|
const char * const * description)
|
||||||
: device_type_(device_type)
|
: device_type_(device_type)
|
||||||
, device_id_(device_id)
|
, device_id_(device_id)
|
||||||
@@ -108,17 +108,17 @@ class Command {
|
|||||||
static void add(const uint8_t device_type,
|
static void add(const uint8_t device_type,
|
||||||
const uint8_t device_id,
|
const uint8_t device_id,
|
||||||
const char * cmd,
|
const char * cmd,
|
||||||
const cmd_function_p cb,
|
const cmd_function_p & cb,
|
||||||
const char * const * description,
|
const char * const * description,
|
||||||
uint8_t flags = CommandFlag::CMD_FLAG_DEFAULT);
|
uint8_t flags = CommandFlag::CMD_FLAG_DEFAULT);
|
||||||
|
|
||||||
// same for system/temperature/analog devices
|
// same for system/temperature/analog devices
|
||||||
static void
|
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
|
// command that writes a JSON object as its output; bypasses the readonly check
|
||||||
static void add_json(const uint8_t device_type,
|
static void add_json(const uint8_t device_type,
|
||||||
const char * cmd,
|
const char * cmd,
|
||||||
const cmd_function_p cb,
|
const cmd_function_p & cb,
|
||||||
const char * const * description,
|
const char * const * description,
|
||||||
uint8_t flags = CommandFlag::CMD_FLAG_DEFAULT);
|
uint8_t flags = CommandFlag::CMD_FLAG_DEFAULT);
|
||||||
|
|
||||||
|
|||||||
@@ -199,10 +199,9 @@ static void setup_commands(std::shared_ptr<Commands> const & commands) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
commands->add_command(ShellContext::MAIN,
|
commands->add_command(ShellContext::MAIN, CommandFlags::ADMIN, string_vector{F_(wifi), F_(reconnect)}, [](Shell &, const std::vector<std::string> &) {
|
||||||
CommandFlags::ADMIN,
|
EMSESP::network_.reconnect();
|
||||||
string_vector{F_(wifi), F_(reconnect)},
|
});
|
||||||
[](Shell &, const std::vector<std::string> &) { EMSESP::network_.reconnect(); });
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// SET commands
|
// SET commands
|
||||||
@@ -367,9 +366,7 @@ static void setup_commands(std::shared_ptr<Commands> const & commands) {
|
|||||||
// EMS device commands
|
// EMS device commands
|
||||||
//
|
//
|
||||||
|
|
||||||
commands->add_command(ShellContext::MAIN, CommandFlags::ADMIN, {F_(scan)}, [](Shell &, const std::vector<std::string> &) {
|
commands->add_command(ShellContext::MAIN, CommandFlags::ADMIN, {F_(scan)}, [](Shell &, const std::vector<std::string> &) { EMSESP::scan_devices(); });
|
||||||
EMSESP::scan_devices();
|
|
||||||
});
|
|
||||||
|
|
||||||
/* removed scan deep
|
/* removed scan deep
|
||||||
commands->add_command(ShellContext::MAIN, CommandFlags::ADMIN, {F_(scan)}, {F_(deep_optional)}, [](Shell & shell, const std::vector<std::string> & arguments) {
|
commands->add_command(ShellContext::MAIN, CommandFlags::ADMIN, {F_(scan)}, {F_(deep_optional)}, [](Shell & shell, const std::vector<std::string> & arguments) {
|
||||||
|
|||||||
+14
-14
@@ -52,7 +52,7 @@ bool EMSdevice::has_entities() const {
|
|||||||
}
|
}
|
||||||
bool found = false;
|
bool found = false;
|
||||||
EMSESP::webCustomizationService.read([&](WebCustomization & settings) {
|
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()) {
|
if (entityCustomization.device_id == device_id() && entityCustomization.entity_ids.size()) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
@@ -572,7 +572,7 @@ void EMSdevice::add_device_value(int8_t tag, // to b
|
|||||||
int8_t numeric_operator, // to divide or multiply, see DeviceValueNumOps::
|
int8_t numeric_operator, // to divide or multiply, see DeviceValueNumOps::
|
||||||
const char * const * name, // list of names, including shortname and translations
|
const char * const * name, // list of names, including shortname and translations
|
||||||
uint8_t uom, // unit of measure from DeviceValueUOM
|
uint8_t uom, // unit of measure from DeviceValueUOM
|
||||||
const cmd_function_p f, // command function pointer
|
const cmd_function_p & f, // command function pointer
|
||||||
int16_t min, // min allowed value
|
int16_t min, // min allowed value
|
||||||
uint32_t max // max allowed value
|
uint32_t max // max allowed value
|
||||||
) {
|
) {
|
||||||
@@ -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
|
// scan through customizations to see if it's on the exclusion list by matching the productID and deviceID
|
||||||
EMSESP::webCustomizationService.read([&](WebCustomization & settings) {
|
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())) {
|
if ((entityCustomization.product_id == product_id()) && (entityCustomization.device_id == device_id())) {
|
||||||
char entity[70];
|
char entity[70];
|
||||||
if (tag < DeviceValueTAG::TAG_HC1) {
|
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);
|
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
|
// if there is an appended custom name, strip it to get the true entity name
|
||||||
// and extract the new custom name
|
// and extract the new custom name
|
||||||
auto custom_name_pos = entity_id.find('|');
|
auto custom_name_pos = entity_id.find('|');
|
||||||
@@ -706,7 +706,7 @@ void EMSdevice::register_device_value(int8_t tag,
|
|||||||
const char * const * options_single,
|
const char * const * options_single,
|
||||||
const char * const * name,
|
const char * const * name,
|
||||||
uint8_t uom,
|
uint8_t uom,
|
||||||
const cmd_function_p f) {
|
const cmd_function_p & f) {
|
||||||
// create a multi-list from the options
|
// create a multi-list from the options
|
||||||
add_device_value(tag, value_p, type, nullptr, options_single, 0, name, uom, f, 0, 0);
|
add_device_value(tag, value_p, type, nullptr, options_single, 0, name, uom, f, 0, 0);
|
||||||
};
|
};
|
||||||
@@ -718,7 +718,7 @@ void EMSdevice::register_device_value(int8_t tag,
|
|||||||
const char * const * options_single,
|
const char * const * options_single,
|
||||||
const char * const * name,
|
const char * const * name,
|
||||||
uint8_t uom,
|
uint8_t uom,
|
||||||
const cmd_function_p f,
|
const cmd_function_p & f,
|
||||||
int16_t min,
|
int16_t min,
|
||||||
uint32_t max) {
|
uint32_t max) {
|
||||||
// create a multi-list from the options
|
// create a multi-list from the options
|
||||||
@@ -731,7 +731,7 @@ void EMSdevice::register_device_value(int8_t tag,
|
|||||||
int8_t numeric_operator,
|
int8_t numeric_operator,
|
||||||
const char * const * name,
|
const char * const * name,
|
||||||
uint8_t uom,
|
uint8_t uom,
|
||||||
const cmd_function_p f) {
|
const cmd_function_p & f) {
|
||||||
add_device_value(tag, value_p, type, nullptr, nullptr, numeric_operator, name, uom, f, 0, 0);
|
add_device_value(tag, value_p, type, nullptr, nullptr, numeric_operator, name, uom, f, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -741,14 +741,14 @@ void EMSdevice::register_device_value(int8_t tag,
|
|||||||
int8_t numeric_operator,
|
int8_t numeric_operator,
|
||||||
const char * const * name,
|
const char * const * name,
|
||||||
uint8_t uom,
|
uint8_t uom,
|
||||||
const cmd_function_p f,
|
const cmd_function_p & f,
|
||||||
int16_t min,
|
int16_t min,
|
||||||
uint32_t max) {
|
uint32_t max) {
|
||||||
add_device_value(tag, value_p, type, nullptr, nullptr, numeric_operator, name, uom, f, min, max);
|
add_device_value(tag, value_p, type, nullptr, nullptr, numeric_operator, name, uom, f, min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
// no options, no function
|
// 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);
|
add_device_value(tag, value_p, type, nullptr, nullptr, 0, name, uom, f, 0, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -758,7 +758,7 @@ void EMSdevice::register_device_value(int8_t tag,
|
|||||||
uint8_t type,
|
uint8_t type,
|
||||||
const char * const * name,
|
const char * const * name,
|
||||||
uint8_t uom,
|
uint8_t uom,
|
||||||
const cmd_function_p f,
|
const cmd_function_p & f,
|
||||||
int16_t min,
|
int16_t min,
|
||||||
uint32_t max) {
|
uint32_t max) {
|
||||||
add_device_value(tag, value_p, type, nullptr, nullptr, 0, name, uom, f, min, max);
|
add_device_value(tag, value_p, type, nullptr, nullptr, 0, name, uom, f, min, max);
|
||||||
@@ -773,7 +773,7 @@ void EMSdevice::register_device_value(int8_t tag,
|
|||||||
const char * const ** options,
|
const char * const ** options,
|
||||||
const char * const * name,
|
const char * const * name,
|
||||||
uint8_t uom,
|
uint8_t uom,
|
||||||
const cmd_function_p f,
|
const cmd_function_p & f,
|
||||||
int16_t min,
|
int16_t min,
|
||||||
uint32_t max) {
|
uint32_t max) {
|
||||||
add_device_value(tag, value_p, type, options, nullptr, 0, name, uom, f, min, max);
|
add_device_value(tag, value_p, type, options, nullptr, 0, name, uom, f, min, max);
|
||||||
@@ -786,7 +786,7 @@ void EMSdevice::register_device_value(int8_t tag,
|
|||||||
const char * const ** options,
|
const char * const ** options,
|
||||||
const char * const * name,
|
const char * const * name,
|
||||||
uint8_t uom,
|
uint8_t uom,
|
||||||
const cmd_function_p f) {
|
const cmd_function_p & f) {
|
||||||
add_device_value(tag, value_p, type, options, nullptr, 0, name, uom, f, 0, 0);
|
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
|
// this is when the mask has it's high bit (0x80) set
|
||||||
// https://github.com/emsesp/EMS-ESP32/issues/891
|
// https://github.com/emsesp/EMS-ESP32/issues/891
|
||||||
EMSESP::webCustomizationService.read([&](WebCustomization & settings) {
|
EMSESP::webCustomizationService.read([&](WebCustomization & settings) {
|
||||||
for (EntityCustomization entityCustomization : settings.entityCustomizations) {
|
for (const auto & entityCustomization : settings.entityCustomizations) {
|
||||||
if (entityCustomization.device_id == device_id()) {
|
if (entityCustomization.device_id == device_id()) {
|
||||||
// entity_ids is a list of all entities with the mask prefixed in the string
|
// 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());
|
uint8_t mask = Helpers::hextoint(entity_id.substr(0, 2).c_str());
|
||||||
if (mask & 0x80) {
|
if (mask & 0x80) {
|
||||||
JsonObject obj = output.add<JsonObject>();
|
JsonObject obj = output.add<JsonObject>();
|
||||||
|
|||||||
+10
-9
@@ -298,7 +298,7 @@ class EMSdevice {
|
|||||||
int8_t numeric_operator,
|
int8_t numeric_operator,
|
||||||
const char * const * name,
|
const char * const * name,
|
||||||
uint8_t uom,
|
uint8_t uom,
|
||||||
const cmd_function_p f,
|
const cmd_function_p & f,
|
||||||
int16_t min,
|
int16_t min,
|
||||||
uint32_t max);
|
uint32_t max);
|
||||||
|
|
||||||
@@ -308,14 +308,14 @@ class EMSdevice {
|
|||||||
const char * const ** options,
|
const char * const ** options,
|
||||||
const char * const * name,
|
const char * const * name,
|
||||||
uint8_t uom,
|
uint8_t uom,
|
||||||
const cmd_function_p f,
|
const cmd_function_p & f,
|
||||||
int16_t min,
|
int16_t min,
|
||||||
uint32_t max);
|
uint32_t max);
|
||||||
|
|
||||||
void erase_device_values();
|
void erase_device_values();
|
||||||
|
|
||||||
void
|
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, const char * const ** options, const char * const * name, uint8_t uom);
|
||||||
|
|
||||||
@@ -325,7 +325,7 @@ class EMSdevice {
|
|||||||
int8_t numeric_operator,
|
int8_t numeric_operator,
|
||||||
const char * const * name,
|
const char * const * name,
|
||||||
uint8_t uom,
|
uint8_t uom,
|
||||||
const cmd_function_p f = nullptr);
|
const cmd_function_p & f = nullptr);
|
||||||
|
|
||||||
void register_device_value(int8_t tag,
|
void register_device_value(int8_t tag,
|
||||||
void * value_p,
|
void * value_p,
|
||||||
@@ -333,7 +333,7 @@ class EMSdevice {
|
|||||||
int8_t numeric_operator,
|
int8_t numeric_operator,
|
||||||
const char * const * name,
|
const char * const * name,
|
||||||
uint8_t uom,
|
uint8_t uom,
|
||||||
const cmd_function_p f,
|
const cmd_function_p & f,
|
||||||
int16_t min,
|
int16_t min,
|
||||||
uint32_t max);
|
uint32_t max);
|
||||||
|
|
||||||
@@ -344,7 +344,7 @@ class EMSdevice {
|
|||||||
const char * const * options_single,
|
const char * const * options_single,
|
||||||
const char * const * name,
|
const char * const * name,
|
||||||
uint8_t uom,
|
uint8_t uom,
|
||||||
const cmd_function_p f = nullptr);
|
const cmd_function_p & f = nullptr);
|
||||||
|
|
||||||
// single list of options, with no translations, with min and max
|
// single list of options, with no translations, with min and max
|
||||||
void register_device_value(int8_t tag,
|
void register_device_value(int8_t tag,
|
||||||
@@ -353,15 +353,16 @@ class EMSdevice {
|
|||||||
const char * const * options_single,
|
const char * const * options_single,
|
||||||
const char * const * name,
|
const char * const * name,
|
||||||
uint8_t uom,
|
uint8_t uom,
|
||||||
const cmd_function_p f,
|
const cmd_function_p & f,
|
||||||
int16_t min,
|
int16_t min,
|
||||||
uint32_t max);
|
uint32_t max);
|
||||||
|
|
||||||
// no options, optional function f
|
// 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
|
// 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, 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;
|
void write_command(const uint16_t type_id, const uint8_t offset, const uint8_t value, const uint16_t validate_typeid) const;
|
||||||
|
|||||||
@@ -192,6 +192,11 @@ class DeviceValue {
|
|||||||
int16_t min; // min range
|
int16_t min; // min range
|
||||||
uint32_t max; // max 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<std::string> custom_fullname_;
|
||||||
|
|
||||||
DeviceValue(uint8_t device_type, // EMSdevice::DeviceType
|
DeviceValue(uint8_t device_type, // EMSdevice::DeviceType
|
||||||
int8_t tag, // DeviceValueTAG::*
|
int8_t tag, // DeviceValueTAG::*
|
||||||
void * value_p, // pointer to variable of any type
|
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_s[];
|
||||||
static const char * const DeviceValueTAG_mqtt[];
|
static const char * const DeviceValueTAG_mqtt[];
|
||||||
static uint8_t NUM_TAGS; // # tags
|
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<std::string> custom_fullname_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}; // namespace emsesp
|
}; // namespace emsesp
|
||||||
|
|||||||
+14
-14
@@ -55,18 +55,18 @@ AsyncWebServer webServer(80);
|
|||||||
|
|
||||||
#if defined(EMSESP_STANDALONE)
|
#if defined(EMSESP_STANDALONE)
|
||||||
FS dummyFS;
|
FS dummyFS;
|
||||||
auto & fsRef = dummyFS;
|
FS * const fsRef = &dummyFS;
|
||||||
#else
|
#else
|
||||||
auto & fsRef = LittleFS;
|
FS * const fsRef = &LittleFS;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ESP32React EMSESP::esp32React(&webServer, &fsRef);
|
ESP32React EMSESP::esp32React(&webServer, fsRef);
|
||||||
WebSettingsService EMSESP::webSettingsService = WebSettingsService(&webServer, &fsRef, EMSESP::esp32React.getSecurityManager());
|
WebSettingsService EMSESP::webSettingsService = WebSettingsService(&webServer, fsRef, EMSESP::esp32React.getSecurityManager());
|
||||||
WebCustomizationService EMSESP::webCustomizationService = WebCustomizationService(&webServer, &fsRef, EMSESP::esp32React.getSecurityManager());
|
WebCustomizationService EMSESP::webCustomizationService = WebCustomizationService(&webServer, fsRef, EMSESP::esp32React.getSecurityManager());
|
||||||
WebSchedulerService EMSESP::webSchedulerService = WebSchedulerService(&webServer, &fsRef, EMSESP::esp32React.getSecurityManager());
|
WebSchedulerService EMSESP::webSchedulerService = WebSchedulerService(&webServer, fsRef, EMSESP::esp32React.getSecurityManager());
|
||||||
WebCommandService EMSESP::webCommandService = WebCommandService(&webServer, &fsRef, EMSESP::esp32React.getSecurityManager());
|
WebCommandService EMSESP::webCommandService = WebCommandService(&webServer, fsRef, EMSESP::esp32React.getSecurityManager());
|
||||||
WebCustomEntityService EMSESP::webCustomEntityService = WebCustomEntityService(&webServer, &fsRef, EMSESP::esp32React.getSecurityManager());
|
WebCustomEntityService EMSESP::webCustomEntityService = WebCustomEntityService(&webServer, fsRef, EMSESP::esp32React.getSecurityManager());
|
||||||
WebModulesService EMSESP::webModulesService = WebModulesService(&webServer, &fsRef, EMSESP::esp32React.getSecurityManager());
|
WebModulesService EMSESP::webModulesService = WebModulesService(&webServer, fsRef, EMSESP::esp32React.getSecurityManager());
|
||||||
|
|
||||||
WebActivityService EMSESP::webActivityService = WebActivityService(&webServer, EMSESP::esp32React.getSecurityManager());
|
WebActivityService EMSESP::webActivityService = WebActivityService(&webServer, EMSESP::esp32React.getSecurityManager());
|
||||||
WebStatusService EMSESP::webStatusService = WebStatusService(&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
|
// clears list of recognized devices, entities and telegrams
|
||||||
void EMSESP::clear_all_devices() {
|
void EMSESP::clear_all_devices() {
|
||||||
for (auto & emsdevice : emsdevices) {
|
for (const auto & emsdevice : emsdevices) {
|
||||||
emsdevice->erase_device_values();
|
emsdevice->erase_device_values();
|
||||||
}
|
}
|
||||||
emsdevices.clear();
|
emsdevices.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// called from EMSdevice/Command whenever an entity or telegram handler is registered.
|
// called from EMSdevice/Command whenever an entity or telegram handler is registered.
|
||||||
// Devices reserve their value/telegram vectors generously (to avoid realloc storms while
|
// Devices reserve their value/telegram vectors generously (to avoid realloc storms while
|
||||||
@@ -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
|
// see if we have a custom device name in our Customizations list, and if so set it
|
||||||
webCustomizationService.read([&](WebCustomization const & settings) {
|
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)) {
|
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);
|
||||||
emsdevices.back()->custom_name(e.custom_name);
|
emsdevices.back()->custom_name(e.custom_name);
|
||||||
|
|||||||
+1
-1
@@ -101,7 +101,7 @@ class Module {}; // forward declaration
|
|||||||
|
|
||||||
// for Command Function callbacks (Command::cmd_function_p). The unified callback takes a JsonObject
|
// for Command Function callbacks (Command::cmd_function_p). The unified callback takes a JsonObject
|
||||||
// output which entity/setter commands ignore.
|
// 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 {
|
namespace emsesp {
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -36,7 +36,7 @@ void Shower::start() {
|
|||||||
Command::add_json(
|
Command::add_json(
|
||||||
EMSdevice::DeviceType::BOILER,
|
EMSdevice::DeviceType::BOILER,
|
||||||
F_(coldshot),
|
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...");
|
LOG_INFO("Forcing coldshot...");
|
||||||
if (shower_state_) {
|
if (shower_state_) {
|
||||||
output["message"] = "OK";
|
output["message"] = "OK";
|
||||||
|
|||||||
+4
-4
@@ -153,10 +153,10 @@ bool System::command_sendmail(const char * value, const int8_t) {
|
|||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
#ifndef EMSESP_STANDALONE
|
#ifndef EMSESP_STANDALONE
|
||||||
WiFiClient * basic_client = new WiFiClient;
|
auto * basic_client = new WiFiClient;
|
||||||
ESP_SSLClient * ssl_client = new ESP_SSLClient;
|
auto * ssl_client = new ESP_SSLClient;
|
||||||
ReadyClient * r_client = new ReadyClient(*ssl_client);
|
auto * r_client = new ReadyClient(*ssl_client);
|
||||||
SMTPClient * smtp = new SMTPClient(*r_client);
|
auto * smtp = new SMTPClient(*r_client);
|
||||||
|
|
||||||
ssl_client->setClient(basic_client);
|
ssl_client->setClient(basic_client);
|
||||||
ssl_client->setInsecure();
|
ssl_client->setInsecure();
|
||||||
|
|||||||
@@ -317,7 +317,7 @@ void WebCustomizationService::customization_entities(AsyncWebServerRequest * req
|
|||||||
|
|
||||||
// add deleted entities from file
|
// add deleted entities from file
|
||||||
read([&](WebCustomization & settings) {
|
read([&](WebCustomization & settings) {
|
||||||
for (EntityCustomization entityCustomization : settings.entityCustomizations) {
|
for (const auto & entityCustomization : settings.entityCustomizations) {
|
||||||
if (entityCustomization.device_id == device_id) {
|
if (entityCustomization.device_id == device_id) {
|
||||||
for (const auto & 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());
|
uint8_t mask = Helpers::hextoint(entity_id.substr(0, 2).c_str());
|
||||||
|
|||||||
Reference in New Issue
Block a user