analogsensor default name fix

This commit is contained in:
MichaelDvP
2024-07-25 14:32:55 +02:00
parent 51d323a41d
commit babf112a7a
2 changed files with 11 additions and 14 deletions

View File

@@ -339,7 +339,7 @@ void AnalogSensor::loop() {
// update analog information name and offset
// a type value of -1 is used to delete the sensor
bool AnalogSensor::update(uint8_t gpio, const std::string & name, double offset, double factor, uint8_t uom, int8_t type, bool deleted) {
bool AnalogSensor::update(uint8_t gpio, std::string & name, double offset, double factor, uint8_t uom, int8_t type, bool deleted) {
// first see if we can find the sensor in our customization list
bool found_sensor = false;
EMSESP::webCustomizationService.update([&](WebCustomization & settings) {
@@ -347,6 +347,11 @@ bool AnalogSensor::update(uint8_t gpio, const std::string & name, double offset,
if (AnalogCustomization.type == AnalogType::COUNTER || AnalogCustomization.type >= AnalogType::DIGITAL_OUT) {
Command::erase_command(EMSdevice::DeviceType::ANALOGSENSOR, AnalogCustomization.name.c_str());
}
if (name.empty()) {
char n[20];
snprintf(n, sizeof(n), "%s_%02d", FL_(AnalogTypeName)[type], gpio);
name = n;
}
if (AnalogCustomization.gpio == gpio) {
found_sensor = true; // found the record
// see if it's marked for deletion
@@ -756,16 +761,6 @@ AnalogSensor::Sensor::Sensor(const uint8_t gpio, const std::string & name, const
value_ = 0; // init value to 0 always
}
// returns name of the analog sensor or creates one if its empty
std::string AnalogSensor::Sensor::name() const {
if (name_.empty()) {
char name[20];
snprintf(name, sizeof(name), "%s_%02d", FL_(AnalogTypeName)[type_], gpio_);
return name;
}
return name_;
}
// set the dig_out/counter/DAC/PWM value, id is gpio-no
bool AnalogSensor::command_setvalue(const char * value, const int8_t gpio) {
float val;