mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
rename add_name() to update(). show offset in log msg
This commit is contained in:
@@ -188,7 +188,7 @@ void DallasSensor::loop() {
|
||||
scancnt_ = 0;
|
||||
} else if (scancnt_ == SCAN_START + 1) { // startup
|
||||
firstscan_ = sensors_.size();
|
||||
LOG_DEBUG(F("Adding %d dallassensor(s) from first scan"), firstscan_);
|
||||
LOG_DEBUG(F("Adding %d dallas sensor(s) from first scan"), firstscan_);
|
||||
} else if ((scancnt_ <= 0) && (firstscan_ != sensors_.size())) { // check 2 times for no change of sensor #
|
||||
scancnt_ = SCAN_START;
|
||||
sensors_.clear(); // restart scaning and clear to get correct numbering
|
||||
@@ -327,7 +327,7 @@ std::string DallasSensor::Sensor::to_string(const bool name) const {
|
||||
|
||||
int16_t DallasSensor::Sensor::offset() const {
|
||||
std::string str = id_string();
|
||||
int16_t offset = 0;
|
||||
int16_t offset = 0; // default value
|
||||
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) {
|
||||
@@ -339,7 +339,8 @@ int16_t DallasSensor::Sensor::offset() const {
|
||||
return offset;
|
||||
}
|
||||
|
||||
bool DallasSensor::add_name(const char * idstr, const char * name, int16_t offset) {
|
||||
// update dallas information like name and offset
|
||||
bool DallasSensor::update(const char * idstr, const char * name, int16_t offset) {
|
||||
bool ok = false;
|
||||
char id[20];
|
||||
strlcpy(id, idstr, sizeof(id));
|
||||
@@ -351,6 +352,7 @@ bool DallasSensor::add_name(const char * idstr, const char * name, int16_t offse
|
||||
strlcpy(id, sensors_[no].id_string().c_str(), sizeof(id));
|
||||
}
|
||||
}
|
||||
|
||||
// check valid id
|
||||
if (strlen(id) != 17 || id[2] != '-' || id[7] != '-' || id[12] != '-') {
|
||||
LOG_WARNING(F("Invalid sensor id: %s"), id);
|
||||
@@ -366,27 +368,31 @@ bool DallasSensor::add_name(const char * idstr, const char * name, int16_t offse
|
||||
settings.sensor[i].id = "";
|
||||
settings.sensor[i].name = "";
|
||||
settings.sensor[i].offset = 0;
|
||||
LOG_INFO(F("Deleting entry of sensor %s"), id);
|
||||
LOG_INFO(F("Deleting entry for 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);
|
||||
char result[10];
|
||||
LOG_INFO(F("Renaming sensor ID %s to %s with offset %s"), id, name, Helpers::render_value(result, offset, 10));
|
||||
}
|
||||
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);
|
||||
char result[10];
|
||||
LOG_INFO(F("Renaming sensor ID %s to %s with offset %s"), id, name, Helpers::render_value(result, offset, 10));
|
||||
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;
|
||||
@@ -399,12 +405,13 @@ bool DallasSensor::add_name(const char * idstr, const char * name, int16_t offse
|
||||
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);
|
||||
LOG_INFO(F("Renaming sensor %s to %s"), id, name);
|
||||
ok = true;
|
||||
return StateUpdateResult::CHANGED;
|
||||
}
|
||||
}
|
||||
LOG_ERROR(F("List full, remove one sensorname first"));
|
||||
|
||||
LOG_ERROR(F("List full, remove a sensor first"));
|
||||
return StateUpdateResult::UNCHANGED;
|
||||
},
|
||||
"local");
|
||||
|
||||
Reference in New Issue
Block a user