remove OriginID from state service

This commit is contained in:
Proddy
2024-02-12 11:22:07 +01:00
parent 65cf8005a4
commit 1f7c968d0d
20 changed files with 302 additions and 366 deletions

View File

@@ -302,31 +302,29 @@ bool TemperatureSensor::update(const std::string & id, const std::string & name,
sensor.set_offset(offset);
// store the new name and offset in our configuration
EMSESP::webCustomizationService.update(
[&](WebCustomization & settings) {
// look it up to see if it exists
bool found = false;
for (auto & SensorCustomization : settings.sensorCustomizations) {
if (SensorCustomization.id == id) {
SensorCustomization.name = name;
SensorCustomization.offset = offset;
found = true;
LOG_DEBUG("Customizing existing sensor ID %s", id.c_str());
break;
}
EMSESP::webCustomizationService.update([&](WebCustomization & settings) {
// look it up to see if it exists
bool found = false;
for (auto & SensorCustomization : settings.sensorCustomizations) {
if (SensorCustomization.id == id) {
SensorCustomization.name = name;
SensorCustomization.offset = offset;
found = true;
LOG_DEBUG("Customizing existing sensor ID %s", id.c_str());
break;
}
if (!found) {
SensorCustomization newSensor = SensorCustomization();
newSensor.id = id;
newSensor.name = name;
newSensor.offset = offset;
settings.sensorCustomizations.push_back(newSensor);
LOG_DEBUG("Adding new customization for sensor ID %s", id.c_str());
}
sensor.ha_registered = false; // it's changed so we may need to recreate the HA config
return StateUpdateResult::CHANGED;
},
"local");
}
if (!found) {
SensorCustomization newSensor = SensorCustomization();
newSensor.id = id;
newSensor.name = name;
newSensor.offset = offset;
settings.sensorCustomizations.push_back(newSensor);
LOG_DEBUG("Adding new customization for sensor ID %s", id.c_str());
}
sensor.ha_registered = false; // it's changed so we may need to recreate the HA config
return StateUpdateResult::CHANGED;
});
return true;
}
}