is_system fixes

This commit is contained in:
proddy
2025-11-10 11:28:49 +01:00
parent 32474d10ce
commit 12e8d64ec2

View File

@@ -160,9 +160,11 @@ void TemperatureSensor::loop() {
}
// add new sensor. this will create the id string, empty name and offset
if (!found && (sensors_.size() < (MAX_SENSORS - 1))) {
LOG_DEBUG("Adding new sensor for %s", Sensor(addr).id().c_str());
sensors_.emplace_back(addr);
sensors_.back().read = true;
changed_ = true;
sensors_.back().set_is_system(false);
changed_ = true;
// look in the customization service for an optional alias or offset for that particular sensor
sensors_.back().apply_customization();
sensors_.back().temperature_c = t + sensors_.back().offset();
@@ -189,7 +191,6 @@ void TemperatureSensor::loop() {
bus_.depower();
}
// check for missing sensors after some samples
// but don't do this if running in test mode where we simulate sensors
if (++scancnt_ > SCAN_MAX) {
for (auto & sensor : sensors_) {
if (!sensor.read) {
@@ -329,6 +330,7 @@ bool TemperatureSensor::update(const std::string & id, const std::string & name,
sensor.set_name(name);
sensor.set_offset(offset);
sensor.set_is_system(is_system);
// store the new name and offset in our configuration
EMSESP::webCustomizationService.update([&id, &name, &offset, &is_system, &sensor](WebCustomization & settings) {
@@ -425,6 +427,7 @@ void TemperatureSensor::get_value_json(JsonObject output, const Sensor & sensor)
output["readable"] = true;
output["writeable"] = false;
output["visible"] = true;
output["is_system"] = sensor.is_system();
}
// publish a single sensor to MQTT
@@ -610,6 +613,7 @@ bool TemperatureSensor::Sensor::apply_customization() {
LOG_DEBUG("Loading customization for temperature sensor %s", sensor.id.c_str());
set_name(sensor.name);
set_offset(sensor.offset);
set_is_system(sensor.is_system);
return true;
}
}