offset to new dallas, remove sensors if disabled

This commit is contained in:
MichaelDvP
2022-08-30 17:36:03 +02:00
parent be4f49e96d
commit e79115d719
2 changed files with 11 additions and 7 deletions

View File

@@ -60,7 +60,10 @@ void AnalogSensor::reload() {
#if defined(EMSESP_STANDALONE)
analog_enabled_ = true; // for local offline testing
#endif
if (!analog_enabled_) {
sensors_.clear();
return;
}
// load the list of analog sensors from the customization service
// and store them locally and then activate them
EMSESP::webCustomizationService.read([&](WebCustomization & settings) {

View File

@@ -36,6 +36,7 @@ void DallasSensor::start() {
reload();
if (!dallas_gpio_) {
sensors_.clear();
return; // disabled if dallas gpio is 0
}
@@ -152,10 +153,10 @@ void DallasSensor::loop() {
if (sensor.internal_id() == get_id(addr)) {
t += sensor.offset();
if (t != sensor.temperature_c) {
sensor.temperature_c = t;
publish_sensor(sensor);
changed_ |= true;
}
sensor.temperature_c = t;
sensor.read = true;
found = true;
break;
@@ -164,11 +165,11 @@ void DallasSensor::loop() {
// add new sensor. this will create the id string, empty name and offset
if (!found && (sensors_.size() < (MAX_SENSORS - 1))) {
sensors_.emplace_back(addr);
sensors_.back().temperature_c = t + sensors_.back().offset();
sensors_.back().read = true;
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();
publish_sensor(sensors_.back()); // call publish single
// sort the sensors based on name
// std::sort(sensors_.begin(), sensors_.end(), [](const Sensor & a, const Sensor & b) { return a.name() < b.name(); });