replace lambda [&] with [this]

This commit is contained in:
Proddy
2024-02-13 15:19:06 +01:00
parent 16779064f4
commit a7d0259b30
12 changed files with 38 additions and 38 deletions

View File

@@ -65,7 +65,7 @@ ESP8266React::ESP8266React(AsyncWebServer * server, FS * fs)
void ESP8266React::begin() {
_networkSettingsService.begin();
_networkSettingsService.read([&](NetworkSettings & networkSettings) {
_networkSettingsService.read([this](NetworkSettings & networkSettings) {
DefaultHeaders & defaultHeaders = DefaultHeaders::Instance();
if (networkSettings.enableCORS) {
defaultHeaders.addHeader("Access-Control-Allow-Origin", networkSettings.CORSOrigin);

View File

@@ -40,7 +40,7 @@ class FSPersistence {
void enableUpdateHandler() {
if (!_updateHandlerId) {
_updateHandlerId = _statefulService->addUpdateHandler([&]() { writeToFS(); });
_updateHandlerId = _statefulService->addUpdateHandler([this] { writeToFS(); });
}
}

View File

@@ -37,7 +37,7 @@ void AnalogSensor::start() {
Command::add(
EMSdevice::DeviceType::ANALOGSENSOR,
F_(setvalue),
[&](const char * value, const int8_t id) { return command_setvalue(value, id); },
[this](const char * value, const int8_t id) { return command_setvalue(value, id); },
FL_(setiovalue_cmd),
CommandFlag::ADMIN_ONLY);
@@ -48,7 +48,7 @@ void AnalogSensor::start() {
// load settings from the customization file, sorts them and initializes the GPIOs
void AnalogSensor::reload() {
EMSESP::webSettingsService.read([&](WebSettings & settings) { analog_enabled_ = settings.analog_enabled; });
EMSESP::webSettingsService.read([this](WebSettings & settings) { analog_enabled_ = settings.analog_enabled; });
#if defined(EMSESP_STANDALONE)
analog_enabled_ = true; // for local offline testing
@@ -63,7 +63,7 @@ void AnalogSensor::reload() {
}
// load the list of analog sensors from the customization service
// and store them locally and then activate them
EMSESP::webCustomizationService.read([&](WebCustomization & settings) {
EMSESP::webCustomizationService.read([this](WebCustomization & settings) {
auto it = sensors_.begin();
for (auto & sensor_ : sensors_) {
// update existing sensors

View File

@@ -604,7 +604,7 @@ void EMSESPShell::display_banner() {
println();
// set console name
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) { console_hostname_ = networkSettings.hostname.c_str(); });
EMSESP::esp8266React.getNetworkSettingsService()->read([this](NetworkSettings & networkSettings) { console_hostname_ = networkSettings.hostname.c_str(); });
if (console_hostname_.empty()) {
console_hostname_ = "ems-esp";
}

View File

@@ -1118,7 +1118,7 @@ void Boiler::check_active() {
// check forceheatingoff option
if (!Helpers::hasValue(forceHeatingOff_, EMS_VALUE_BOOL)) {
EMSESP::webSettingsService.read([&](WebSettings & settings) { forceHeatingOff_ = settings.boiler_heatingoff ? EMS_VALUE_BOOL_ON : 0; });
EMSESP::webSettingsService.read([this](WebSettings & settings) { forceHeatingOff_ = settings.boiler_heatingoff ? EMS_VALUE_BOOL_ON : 0; });
has_update(&forceHeatingOff_);
}
static uint32_t lastSendHeatingOff = 0;

View File

@@ -554,7 +554,7 @@ void Solar::process_SM10Monitor(std::shared_ptr<const Telegram> telegram) {
has_update(solarPumpMod_, solarpumpmod);
if (!Helpers::hasValue(maxFlow_)) {
EMSESP::webSettingsService.read([&](WebSettings & settings) { maxFlow_ = settings.solar_maxflow; });
EMSESP::webSettingsService.read([this](WebSettings & settings) { maxFlow_ = settings.solar_maxflow; });
has_update(&maxFlow_);
}
@@ -1047,7 +1047,7 @@ bool Solar::set_SM10MaxFlow(const char * value, const int8_t id) {
return false;
}
maxFlow_ = (flow * 10);
EMSESP::webSettingsService.update([&](WebSettings & settings) {
EMSESP::webSettingsService.update([this](WebSettings & settings) {
settings.solar_maxflow = maxFlow_;
return StateUpdateResult::CHANGED;
});

View File

@@ -195,9 +195,9 @@ void Mqtt::show_mqtt(uuid::console::Shell & shell) {
for (const auto & mqtt_subfunction : mqtt_subfunctions_) {
shell.printfln(" %s/%s", Mqtt::base().c_str(), mqtt_subfunction.topic_.c_str());
}
shell.println();
shell.println();
shell.println();
}
#if defined(EMSESP_TEST)
@@ -451,6 +451,7 @@ void Mqtt::on_disconnect(espMqttClientTypes::DisconnectReason reason) {
return;
}
connecting_ = false;
if (reason == espMqttClientTypes::DisconnectReason::TCP_DISCONNECTED) {
LOG_WARNING("MQTT disconnected: TCP");
} else if (reason == espMqttClientTypes::DisconnectReason::MQTT_UNACCEPTABLE_PROTOCOL_VERSION) {
@@ -468,6 +469,7 @@ void Mqtt::on_disconnect(espMqttClientTypes::DisconnectReason reason) {
} else {
LOG_WARNING("MQTT disconnected: code %d", reason);
}
mqttClient_->clearQueue(true);
}

View File

@@ -25,7 +25,7 @@ uuid::log::Logger Shower::logger_{F_(shower), uuid::log::Facility::CONSOLE};
static bool force_coldshot = false;
void Shower::start() {
EMSESP::webSettingsService.read([&](WebSettings & settings) {
EMSESP::webSettingsService.read([this](WebSettings & settings) {
shower_timer_ = settings.shower_timer;
shower_alert_ = settings.shower_alert;
shower_alert_trigger_ = settings.shower_alert_trigger * 60000; // convert from minutes
@@ -35,7 +35,7 @@ void Shower::start() {
Command::add(
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";

View File

@@ -202,7 +202,7 @@ bool System::command_syslog_level(const char * value, const int8_t id) {
if (Helpers::value2enum(value, s, FL_(list_syslog_level))) {
bool changed = false;
EMSESP::webSettingsService.update(
[&](WebSettings & settings) {
[this](WebSettings & settings) {
if (settings.syslog_level != (int8_t)s - 1) {
settings.syslog_level = (int8_t)s - 1;
changed = true;
@@ -295,7 +295,7 @@ void System::format(uuid::console::Shell & shell) {
}
void System::syslog_init() {
EMSESP::webSettingsService.read([&](WebSettings & settings) {
EMSESP::webSettingsService.read([this](WebSettings & settings) {
syslog_enabled_ = settings.syslog_enabled;
syslog_level_ = settings.syslog_level;
syslog_mark_interval_ = settings.syslog_mark_interval;
@@ -349,7 +349,7 @@ void System::syslog_init() {
// read some specific system settings to store locally for faster access
void System::reload_settings() {
EMSESP::webSettingsService.read([&](WebSettings & settings) {
EMSESP::webSettingsService.read([this](WebSettings & settings) {
version_ = settings.version;
pbutton_gpio_ = settings.pbutton_gpio;
@@ -427,7 +427,7 @@ void System::start() {
refreshHeapMem(); // refresh free heap and max alloc heap
#endif
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
EMSESP::esp8266React.getNetworkSettingsService()->read([this](NetworkSettings & networkSettings) {
hostname(networkSettings.hostname.c_str()); // sets the hostname
});
@@ -1080,15 +1080,13 @@ bool System::check_upgrade(bool factory_settings) {
version::Semver200_version settings_version(settingsVersion);
#if defined(EMSESP_DEBUG)
if (!missing_version) {
LOG_INFO("Checking version (settings file is v%d.%d.%d-%s)...",
settings_version.major(),
settings_version.minor(),
settings_version.patch(),
settings_version.prerelease().c_str());
LOG_DEBUG("Checking version upgrade (settings file is v%d.%d.%d-%s)",
settings_version.major(),
settings_version.minor(),
settings_version.patch(),
settings_version.prerelease().c_str());
}
#endif
if (factory_settings) {
return false; // fresh install, do nothing
@@ -1106,14 +1104,14 @@ bool System::check_upgrade(bool factory_settings) {
// if we're coming from 3.4.4 or 3.5.0b14 which had no version stored then we need to apply new settings
if (missing_version) {
LOG_INFO("Setting MQTT Entity ID format to v3.4 format");
EMSESP::esp8266React.getMqttSettingsService()->update([&](MqttSettings & mqttSettings) {
EMSESP::esp8266React.getMqttSettingsService()->update([this](MqttSettings & mqttSettings) {
mqttSettings.entity_format = 0; // use old Entity ID format from v3.4
return StateUpdateResult::CHANGED;
});
}
// Network Settings Wifi tx_power is now using the value * 4.
EMSESP::esp8266React.getNetworkSettingsService()->update([&](NetworkSettings & networkSettings) {
EMSESP::esp8266React.getNetworkSettingsService()->update([this](NetworkSettings & networkSettings) {
if (networkSettings.tx_power == 20) {
networkSettings.tx_power = WIFI_POWER_19_5dBm; // use 19.5 as we don't have 20 anymore
LOG_INFO("Setting WiFi TX Power to Auto");
@@ -1132,7 +1130,7 @@ bool System::check_upgrade(bool factory_settings) {
// if we did a change, set the new version and reboot
if (save_version) {
EMSESP::webSettingsService.update([&](WebSettings & settings) {
EMSESP::webSettingsService.update([this](WebSettings & settings) {
settings.version = EMSESP_APP_VERSION;
return StateUpdateResult::CHANGED;
});

View File

@@ -243,7 +243,7 @@ void RxService::add_empty(const uint8_t src, const uint8_t dest, const uint16_t
// send out request to EMS bus for all devices
void TxService::start() {
// grab the bus ID and tx_mode
EMSESP::webSettingsService.read([&](WebSettings & settings) {
EMSESP::webSettingsService.read([this](WebSettings & settings) {
ems_bus_id(settings.ems_bus_id);
tx_mode(settings.tx_mode);
});

View File

@@ -53,7 +53,7 @@ void TemperatureSensor::start() {
// load settings
void TemperatureSensor::reload() {
// load the service settings
EMSESP::webSettingsService.read([&](WebSettings & settings) {
EMSESP::webSettingsService.read([this](WebSettings & settings) {
dallas_gpio_ = settings.dallas_gpio;
parasite_ = settings.dallas_parasite;
});
@@ -604,7 +604,7 @@ std::string TemperatureSensor::Sensor::name() const {
// look up in customization service for a specific sensor
// and set the name and offset from that entry if it exists
bool TemperatureSensor::Sensor::apply_customization() {
EMSESP::webCustomizationService.read([&](WebCustomization & settings) {
EMSESP::webCustomizationService.read([this](WebCustomization & settings) {
auto sensors = settings.sensorCustomizations;
if (!sensors.empty()) {
for (const auto & sensor : sensors) {

View File

@@ -128,7 +128,7 @@ StateUpdateResult WebCustomEntity::update(JsonObject root, WebCustomEntity & web
// set value by api command
bool WebCustomEntityService::command_setvalue(const char * value, const std::string name) {
EMSESP::webCustomEntityService.read([&](WebCustomEntity & webEntity) { customEntityItems = &webEntity.customEntityItems; });
EMSESP::webCustomEntityService.read([this](WebCustomEntity & webEntity) { customEntityItems = &webEntity.customEntityItems; });
for (CustomEntityItem & entityItem : *customEntityItems) {
if (Helpers::toLower(entityItem.name) == Helpers::toLower(name)) {
if (entityItem.ram == 1) {
@@ -251,7 +251,7 @@ void WebCustomEntityService::show_values(JsonObject output) {
// process json output for info/commands and value_info
bool WebCustomEntityService::get_value_info(JsonObject output, const char * cmd) {
EMSESP::webCustomEntityService.read([&](WebCustomEntity & webEntity) { customEntityItems = &webEntity.customEntityItems; });
EMSESP::webCustomEntityService.read([this](WebCustomEntity & webEntity) { customEntityItems = &webEntity.customEntityItems; });
// if it's commands...
if (Helpers::toLower(cmd) == F_(commands)) {
@@ -365,7 +365,7 @@ void WebCustomEntityService::publish(const bool force) {
return;
}
EMSESP::webCustomEntityService.read([&](WebCustomEntity & webEntity) { customEntityItems = &webEntity.customEntityItems; });
EMSESP::webCustomEntityService.read([this](WebCustomEntity & webEntity) { customEntityItems = &webEntity.customEntityItems; });
if (customEntityItems->size() == 0) {
return;
}
@@ -456,7 +456,7 @@ void WebCustomEntityService::publish(const bool force) {
// count only entities with valid value or command to show in dashboard
uint8_t WebCustomEntityService::count_entities() {
EMSESP::webCustomEntityService.read([&](WebCustomEntity & webEntity) { customEntityItems = &webEntity.customEntityItems; });
EMSESP::webCustomEntityService.read([this](WebCustomEntity & webEntity) { customEntityItems = &webEntity.customEntityItems; });
if (customEntityItems->size() == 0) {
return 0;
}
@@ -473,7 +473,7 @@ uint8_t WebCustomEntityService::count_entities() {
}
uint8_t WebCustomEntityService::has_commands() {
EMSESP::webCustomEntityService.read([&](WebCustomEntity & webEntity) { customEntityItems = &webEntity.customEntityItems; });
EMSESP::webCustomEntityService.read([this](WebCustomEntity & webEntity) { customEntityItems = &webEntity.customEntityItems; });
uint8_t count = 0;
for (const CustomEntityItem & entity : *customEntityItems) {
count += entity.writeable ? 1 : 0;
@@ -484,7 +484,7 @@ uint8_t WebCustomEntityService::has_commands() {
// send to dashboard, msgpack don't like serialized, use number
void WebCustomEntityService::generate_value_web(JsonObject output) {
EMSESP::webCustomEntityService.read([&](WebCustomEntity & webEntity) { customEntityItems = &webEntity.customEntityItems; });
EMSESP::webCustomEntityService.read([this](WebCustomEntity & webEntity) { customEntityItems = &webEntity.customEntityItems; });
output["label"] = (std::string) "Custom Entities";
JsonArray data = output["data"].to<JsonArray>();
@@ -556,7 +556,7 @@ void WebCustomEntityService::generate_value_web(JsonObject output) {
// fetch telegram, called from emsesp::fetch
void WebCustomEntityService::fetch() {
EMSESP::webCustomEntityService.read([&](WebCustomEntity & webEntity) { customEntityItems = &webEntity.customEntityItems; });
EMSESP::webCustomEntityService.read([this](WebCustomEntity & webEntity) { customEntityItems = &webEntity.customEntityItems; });
const uint8_t len[] = {1, 1, 1, 2, 2, 3, 3};
for (auto & entity : *customEntityItems) {
@@ -582,7 +582,7 @@ void WebCustomEntityService::fetch() {
// called on process telegram, read from telegram
bool WebCustomEntityService::get_value(std::shared_ptr<const Telegram> telegram) {
bool has_change = false;
EMSESP::webCustomEntityService.read([&](WebCustomEntity & webEntity) { customEntityItems = &webEntity.customEntityItems; });
EMSESP::webCustomEntityService.read([this](WebCustomEntity & webEntity) { customEntityItems = &webEntity.customEntityItems; });
// read-length of BOOL, INT, UINT, SHORT, USHORT, ULONG, TIME
const uint8_t len[] = {1, 1, 1, 2, 2, 3, 3};
for (auto & entity : *customEntityItems) {
@@ -626,7 +626,7 @@ bool WebCustomEntityService::get_value(std::shared_ptr<const Telegram> telegram)
// hard coded tests
#ifdef EMSESP_TEST
void WebCustomEntityService::test() {
update([&](WebCustomEntity & webCustomEntity) {
update([this](WebCustomEntity & webCustomEntity) {
webCustomEntity.customEntityItems.clear();
// test 1
auto entityItem = CustomEntityItem();