diff --git a/src/console.cpp b/src/console.cpp index 76183aef6..d1c1309fe 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -711,47 +711,46 @@ void Console::load_system_commands(unsigned int context) { }); }); - EMSESPShell::commands - ->add_command(context, - CommandFlags::ADMIN, - flash_string_vector{F_(sensorname)}, - flash_string_vector{F_(sensorid_optional), F_(name_optional), F_(offset_optional)}, - [](Shell & shell, const std::vector & arguments) { - if (arguments.size() == 0) { - EMSESP::webSettingsService.read([&](WebSettings & settings) { - for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) { - if (!settings.sensor[i].id.isEmpty()) { - shell.print(settings.sensor[i].id); - shell.print(" : "); - shell.print(settings.sensor[i].name); - shell.print(" : "); - char buf[10]; - shell.println(Helpers::render_value(buf, settings.sensor[i].offset, 10)); - } - } - }); - return; - } - if (arguments.size() == 1) { - EMSESP::dallassensor_.add_name(arguments.front().c_str(), "", 0); - // shell.println(EMSESP::dallassensor_.get_name(arguments.front().c_str())); - return; - } - int16_t offset = 0; - float val; - if (arguments.size() == 2) { - if (Helpers::value2float(arguments.back().c_str(), val)) { - offset = (10 * val); - EMSESP::dallassensor_.add_name(arguments.front().c_str(), "", offset); - return; - } - } else if (arguments.size() == 3) { - if (Helpers::value2float(arguments.back().c_str(), val)) { - offset = (10 * val); - } - } - EMSESP::dallassensor_.add_name(arguments.front().c_str(), arguments[1].c_str(), offset); - }); + EMSESPShell::commands->add_command(context, + CommandFlags::ADMIN, + flash_string_vector{F_(sensorname)}, + flash_string_vector{F_(sensorid_optional), F_(name_optional), F_(offset_optional)}, + [](Shell & shell, const std::vector & arguments) { + if (arguments.size() == 0) { + EMSESP::webSettingsService.read([&](WebSettings & settings) { + for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) { + if (!settings.sensor[i].id.isEmpty()) { + shell.print(settings.sensor[i].id); + shell.print(" : "); + shell.print(settings.sensor[i].name); + shell.print(" : "); + char buf[10]; + shell.println(Helpers::render_value(buf, settings.sensor[i].offset, 10)); + } + } + }); + return; + } + if (arguments.size() == 1) { + EMSESP::dallassensor_.add_name(arguments.front().c_str(), "", 0); + // shell.println(EMSESP::dallassensor_.get_name(arguments.front().c_str())); + return; + } + int16_t offset = 0; + float val; + if (arguments.size() == 2) { + if (Helpers::value2float(arguments.back().c_str(), val)) { + offset = (10 * val); + EMSESP::dallassensor_.add_name(arguments.front().c_str(), "", offset); + return; + } + } else if (arguments.size() == 3) { + if (Helpers::value2float(arguments.back().c_str(), val)) { + offset = (10 * val); + } + } + EMSESP::dallassensor_.add_name(arguments.front().c_str(), arguments[1].c_str(), offset); + }); EMSESPShell::commands ->add_command(context, diff --git a/src/dallassensor.cpp b/src/dallassensor.cpp index ae78d39a5..f4db8d0d9 100644 --- a/src/dallassensor.cpp +++ b/src/dallassensor.cpp @@ -315,12 +315,12 @@ std::string DallasSensor::Sensor::to_string(const bool name) const { EMSESP::webSettingsService.read([&](WebSettings & settings) { if (settings.dallas_format == Dallas_Format::NAME || name) { for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) { - if (strcmp(settings.sensor[i].id.c_str(), str.c_str()) == 0) { + if (strcmp(settings.sensor[i].id.c_str(), str.c_str()) == 0) { str = settings.sensor[i].name.c_str(); } } } - }); + }); return str; } @@ -330,7 +330,7 @@ int16_t DallasSensor::Sensor::offset() const { int16_t offset = 0; EMSESP::webSettingsService.read([&](WebSettings & settings) { for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) { - if (strcmp(settings.sensor[i].id.c_str(), str.c_str()) == 0) { + if (strcmp(settings.sensor[i].id.c_str(), str.c_str()) == 0) { offset = settings.sensor[i].offset; } } @@ -352,60 +352,62 @@ bool DallasSensor::add_name(const char * idstr, const char * name, int16_t offse } } // check valid id - if (strlen(id) != 17 || id[2] != '-' || id[7] != '-' || id[12] !='-') { + if (strlen(id) != 17 || id[2] != '-' || id[7] != '-' || id[12] != '-') { LOG_WARNING(F("Invalid sensor id: %s"), id); return ok; } - EMSESP::webSettingsService.update([&](WebSettings & settings) { - // check for new name of stored id - for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) { - if (strcmp(id, settings.sensor[i].id.c_str()) == 0) { - if (strlen(name) == 0 && offset == 0) { // delete entry if name and offset is empty - settings.sensor[i].id = ""; - settings.sensor[i].name = ""; - settings.sensor[i].offset = 0; - LOG_INFO(F("Deleting entry of sensor %s"), id); - } else { + EMSESP::webSettingsService.update( + [&](WebSettings & settings) { + // check for new name of stored id + for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) { + if (strcmp(id, settings.sensor[i].id.c_str()) == 0) { + if (strlen(name) == 0 && offset == 0) { // delete entry if name and offset is empty + settings.sensor[i].id = ""; + settings.sensor[i].name = ""; + settings.sensor[i].offset = 0; + LOG_INFO(F("Deleting entry of sensor %s"), id); + } else { + settings.sensor[i].name = (strlen(name) == 0) ? id : name; + settings.sensor[i].offset = offset; + LOG_INFO(F("Setting name of sensor %s to %s"), id, name); + } + ok = true; + return StateUpdateResult::CHANGED; + } + } + // check for free place + for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) { + if (settings.sensor[i].id.isEmpty()) { + settings.sensor[i].id = id; settings.sensor[i].name = (strlen(name) == 0) ? id : name; settings.sensor[i].offset = offset; LOG_INFO(F("Setting name of sensor %s to %s"), id, name); - } - ok = true; - return StateUpdateResult::CHANGED; - } - } - // check for free place - for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) { - if (settings.sensor[i].id.isEmpty()) { - settings.sensor[i].id = id; - settings.sensor[i].name = (strlen(name) == 0) ? id : name; - settings.sensor[i].offset = offset; - LOG_INFO(F("Setting name of sensor %s to %s"), id, name); - ok = true; - return StateUpdateResult::CHANGED; - } - } - // check if there is a unused id and overwrite it - for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) { - bool found = false; - for (const auto & sensor : sensors_) { - if (strcmp(sensor.id_string().c_str(), settings.sensor[i].id.c_str()) == 0) { - found = true; + ok = true; + return StateUpdateResult::CHANGED; } } - if (!found) { - settings.sensor[i].id = id; - settings.sensor[i].name = (strlen(name) == 0) ? id : name; - settings.sensor[i].offset = offset; - LOG_INFO(F("Setting name of sensor %s to %s"), id, name); - ok = true; - return StateUpdateResult::CHANGED; + // check if there is a unused id and overwrite it + for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) { + bool found = false; + for (const auto & sensor : sensors_) { + if (strcmp(sensor.id_string().c_str(), settings.sensor[i].id.c_str()) == 0) { + found = true; + } + } + if (!found) { + settings.sensor[i].id = id; + settings.sensor[i].name = (strlen(name) == 0) ? id : name; + settings.sensor[i].offset = offset; + LOG_INFO(F("Setting name of sensor %s to %s"), id, name); + ok = true; + return StateUpdateResult::CHANGED; + } } - } - LOG_ERROR(F("List full, remove one sensorname first")); - return StateUpdateResult::UNCHANGED; - }, "local"); + LOG_ERROR(F("List full, remove one sensorname first")); + return StateUpdateResult::UNCHANGED; + }, + "local"); return ok; } diff --git a/src/devices/boiler.cpp b/src/devices/boiler.cpp index 3ad94e705..b5e216e66 100644 --- a/src/devices/boiler.cpp +++ b/src/devices/boiler.cpp @@ -85,8 +85,13 @@ Boiler::Boiler(uint8_t device_type, int8_t device_id, uint8_t product_id, const register_telegram_type(0x48F, F("HpOutdoor"), false, MAKE_PF_CB(process_HpOutdoor)); } // MQTT commands for boiler topic - register_device_value( - TAG_BOILER_DATA, &wWTapActivated_, DeviceValueType::BOOL, nullptr, FL_(wwtapactivated), DeviceValueUOM::BOOLEAN, MAKE_CF_CB(set_tapwarmwater_activated)); + register_device_value(TAG_BOILER_DATA, + &wWTapActivated_, + DeviceValueType::BOOL, + nullptr, + FL_(wwtapactivated), + DeviceValueUOM::BOOLEAN, + MAKE_CF_CB(set_tapwarmwater_activated)); register_device_value(TAG_BOILER_DATA, &dummy8u_, DeviceValueType::CMD, FL_(enum_reset), FL_(reset), DeviceValueUOM::LIST, MAKE_CF_CB(set_reset)); // add values @@ -143,20 +148,10 @@ Boiler::Boiler(uint8_t device_type, int8_t device_id, uint8_t product_id, const FL_(maintenanceType), DeviceValueUOM::LIST, MAKE_CF_CB(set_maintenance)); - register_device_value(TAG_BOILER_DATA, - &maintenanceTime_, - DeviceValueType::USHORT, - nullptr, - FL_(maintenanceTime), - DeviceValueUOM::HOURS, - MAKE_CF_CB(set_maintenancetime)); - register_device_value(TAG_BOILER_DATA, - &maintenanceDate_, - DeviceValueType::TEXT, - nullptr, - FL_(maintenanceDate), - DeviceValueUOM::NONE, - MAKE_CF_CB(set_maintenancedate)); + register_device_value( + TAG_BOILER_DATA, &maintenanceTime_, DeviceValueType::USHORT, nullptr, FL_(maintenanceTime), DeviceValueUOM::HOURS, MAKE_CF_CB(set_maintenancetime)); + register_device_value( + TAG_BOILER_DATA, &maintenanceDate_, DeviceValueType::TEXT, nullptr, FL_(maintenanceDate), DeviceValueUOM::NONE, MAKE_CF_CB(set_maintenancedate)); // heatpump info if (model() == EMS_DEVICE_FLAG_HEATPUMP) { register_device_value(TAG_BOILER_DATA, &upTimeControl_, DeviceValueType::TIME, FL_(div60), FL_(upTimeControl), DeviceValueUOM::MINUTES); @@ -305,7 +300,7 @@ void Boiler::check_active(const bool force) { // check if we can use tapactivated in flow systems if ((wWType_ == 1) && !Helpers::hasValue(wWTapActivated_, EMS_VALUE_BOOL)) { - wWTapActivated_= 1; + wWTapActivated_ = 1; } // check if tap water is active, bits 1 and 4 must be set @@ -1160,7 +1155,7 @@ bool Boiler::set_tapwarmwater_activated(const char * value, const int8_t id) { message_data[1] = 0x00; // burner output 0% message_data[3] = 0x64; // boiler pump capacity 100% message_data[4] = 0xFF; // 3-way valve hot water only - wWTapActivated_= 0; + wWTapActivated_ = 0; } else { // get out of test mode. Send all zeros. // telegram: 0B 08 1D 00 00 diff --git a/src/devices/thermostat.cpp b/src/devices/thermostat.cpp index 3a8d1de30..03425e53e 100644 --- a/src/devices/thermostat.cpp +++ b/src/devices/thermostat.cpp @@ -1105,9 +1105,9 @@ void Thermostat::process_RCErrorMessage(std::shared_ptr telegram if (telegram->message_data[4] & 0x80) { // valid date char code[3]; uint16_t codeNo = EMS_VALUE_USHORT_NOTSET; - code[0] = telegram->message_data[0]; - code[1] = telegram->message_data[1]; - code[2] = 0; + code[0] = telegram->message_data[0]; + code[1] = telegram->message_data[1]; + code[2] = 0; telegram->read_value(codeNo, 2); uint16_t year = (telegram->message_data[4] & 0x7F) + 2000; uint8_t month = telegram->message_data[5]; diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index 99bfe7b30..0adefa2c6 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -582,7 +582,7 @@ void EMSdevice::generate_values_json_web(JsonObject & json) { } // handle commands without value - else if(dv.type == DeviceValueType::CMD) { + else if (dv.type == DeviceValueType::CMD) { obj = data.createNestedObject(); obj["v"] = ""; } @@ -881,7 +881,7 @@ bool EMSdevice::generate_values_json(JsonObject & root, const uint8_t tag_filter } else { json[name] = (uint8_t)(*(uint8_t *)(dv.value_p)) ? 1 : 0; } - has_value = true; + has_value = true; } // handle TEXT strings diff --git a/src/locale_EN.h b/src/locale_EN.h index 2671619c4..ebfe70655 100644 --- a/src/locale_EN.h +++ b/src/locale_EN.h @@ -175,8 +175,8 @@ MAKE_PSTR(w, "W") MAKE_PSTR(kb, "KB") MAKE_PSTR(seconds, "seconds") MAKE_PSTR(dbm, "dBm") -MAKE_PSTR(num, " ") // this is hack so HA renders numbers correctly -MAKE_PSTR(bool, " ") // this is hack so HA renders numbers correctly +MAKE_PSTR(num, " ") // this is hack so HA renders numbers correctly +MAKE_PSTR(bool, " ") // this is hack so HA renders numbers correctly MAKE_PSTR(blank, " ") // this is hack so HA renders numbers correctly // TAG mapping - maps to DeviceValueTAG_s in emsdevice.cpp diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 1ae9f60d7..a5db4a438 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -55,7 +55,6 @@ uuid::log::Logger Mqtt::logger_{F_(mqtt), uuid::log::Facility::DAEMON}; // subscribe to an MQTT topic, and store the associated callback function // only if it already hasn't been added void Mqtt::subscribe(const uint8_t device_type, const std::string & topic, mqtt_subfunction_p cb) { - // check if we already have the topic subscribed, if so don't add it again if (!mqtt_subfunctions_.empty()) { for (auto & mqtt_subfunction : mqtt_subfunctions_) { diff --git a/src/web/WebDevicesService.cpp b/src/web/WebDevicesService.cpp index 8577aa539..fbc822bfe 100644 --- a/src/web/WebDevicesService.cpp +++ b/src/web/WebDevicesService.cpp @@ -28,7 +28,7 @@ WebDevicesService::WebDevicesService(AsyncWebServer * server, SecurityManager * , _writevalue_dataHandler(WRITE_VALUE_SERVICE_PATH, securityManager->wrapCallback(std::bind(&WebDevicesService::write_value, this, _1, _2), AuthenticationPredicates::IS_ADMIN)) , _writesensor_dataHandler(WRITE_SENSOR_SERVICE_PATH, - securityManager->wrapCallback(std::bind(&WebDevicesService::write_sensor, this, _1, _2), AuthenticationPredicates::IS_ADMIN)) { + securityManager->wrapCallback(std::bind(&WebDevicesService::write_sensor, this, _1, _2), AuthenticationPredicates::IS_ADMIN)) { server->on(EMSESP_DEVICES_SERVICE_PATH, HTTP_GET, securityManager->wrapRequest(std::bind(&WebDevicesService::all_devices, this, _1), AuthenticationPredicates::IS_AUTHENTICATED)); @@ -178,7 +178,7 @@ void WebDevicesService::write_sensor(AsyncWebServerRequest * request, JsonVarian } } ok = EMSESP::dallassensor_.add_name(nostr, name, offset); - } + } } AsyncWebServerResponse * response = request->beginResponse(ok ? 200 : 204); diff --git a/src/web/WebLogService.h b/src/web/WebLogService.h index c45c7213a..9c4329f28 100644 --- a/src/web/WebLogService.h +++ b/src/web/WebLogService.h @@ -75,7 +75,7 @@ class WebLogService : public uuid::log::Handler { unsigned long log_message_id_ = 0; // The next identifier to use for queued log messages unsigned long log_message_id_tail_ = 0; // last event shown on the screen after fetch std::list log_messages_; // Queued log messages, in the order they were received - time_t time_offset_ = 0; + time_t time_offset_ = 0; }; } // namespace emsesp diff --git a/src/web/WebSettingsService.h b/src/web/WebSettingsService.h index f35c54079..2f8730f3f 100644 --- a/src/web/WebSettingsService.h +++ b/src/web/WebSettingsService.h @@ -33,7 +33,7 @@ namespace emsesp { enum { BOOL_FORMAT_ONOFF = 1, BOOL_FORMAT_ONOFF_CAP, BOOL_FORMAT_TRUEFALSE, BOOL_FORMAT_10 }; // matches Web UI settings -enum { ENUM_FORMAT_TEXT = 1, ENUM_FORMAT_NUMBER }; // matches Web UI settings +enum { ENUM_FORMAT_TEXT = 1, ENUM_FORMAT_NUMBER }; // matches Web UI settings class WebSettings { public: @@ -66,9 +66,9 @@ class WebSettings { uint8_t enum_format; struct { - String id; - String name; - int16_t offset; + String id; + String name; + int16_t offset; } sensor[NUM_SENSOR_NAMES]; static void read(WebSettings & settings, JsonObject & root);