mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
offset to new dallas, remove sensors if disabled
This commit is contained in:
@@ -60,7 +60,10 @@ void AnalogSensor::reload() {
|
|||||||
#if defined(EMSESP_STANDALONE)
|
#if defined(EMSESP_STANDALONE)
|
||||||
analog_enabled_ = true; // for local offline testing
|
analog_enabled_ = true; // for local offline testing
|
||||||
#endif
|
#endif
|
||||||
|
if (!analog_enabled_) {
|
||||||
|
sensors_.clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
// load the list of analog sensors from the customization service
|
// load the list of analog sensors from the customization service
|
||||||
// and store them locally and then activate them
|
// and store them locally and then activate them
|
||||||
EMSESP::webCustomizationService.read([&](WebCustomization & settings) {
|
EMSESP::webCustomizationService.read([&](WebCustomization & settings) {
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ void DallasSensor::start() {
|
|||||||
reload();
|
reload();
|
||||||
|
|
||||||
if (!dallas_gpio_) {
|
if (!dallas_gpio_) {
|
||||||
|
sensors_.clear();
|
||||||
return; // disabled if dallas gpio is 0
|
return; // disabled if dallas gpio is 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,10 +153,10 @@ void DallasSensor::loop() {
|
|||||||
if (sensor.internal_id() == get_id(addr)) {
|
if (sensor.internal_id() == get_id(addr)) {
|
||||||
t += sensor.offset();
|
t += sensor.offset();
|
||||||
if (t != sensor.temperature_c) {
|
if (t != sensor.temperature_c) {
|
||||||
|
sensor.temperature_c = t;
|
||||||
publish_sensor(sensor);
|
publish_sensor(sensor);
|
||||||
changed_ |= true;
|
changed_ |= true;
|
||||||
}
|
}
|
||||||
sensor.temperature_c = t;
|
|
||||||
sensor.read = true;
|
sensor.read = true;
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
@@ -164,11 +165,11 @@ void DallasSensor::loop() {
|
|||||||
// add new sensor. this will create the id string, empty name and offset
|
// add new sensor. this will create the id string, empty name and offset
|
||||||
if (!found && (sensors_.size() < (MAX_SENSORS - 1))) {
|
if (!found && (sensors_.size() < (MAX_SENSORS - 1))) {
|
||||||
sensors_.emplace_back(addr);
|
sensors_.emplace_back(addr);
|
||||||
sensors_.back().temperature_c = t + sensors_.back().offset();
|
|
||||||
sensors_.back().read = true;
|
sensors_.back().read = true;
|
||||||
changed_ = true;
|
changed_ = true;
|
||||||
// look in the customization service for an optional alias or offset for that particular sensor
|
// look in the customization service for an optional alias or offset for that particular sensor
|
||||||
sensors_.back().apply_customization();
|
sensors_.back().apply_customization();
|
||||||
|
sensors_.back().temperature_c = t + sensors_.back().offset();
|
||||||
publish_sensor(sensors_.back()); // call publish single
|
publish_sensor(sensors_.back()); // call publish single
|
||||||
// sort the sensors based on name
|
// sort the sensors based on name
|
||||||
// std::sort(sensors_.begin(), sensors_.end(), [](const Sensor & a, const Sensor & b) { return a.name() < b.name(); });
|
// std::sort(sensors_.begin(), sensors_.end(), [](const Sensor & a, const Sensor & b) { return a.name() < b.name(); });
|
||||||
|
|||||||
Reference in New Issue
Block a user