mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-01-29 10:09:11 +03:00
replace disabled sensor gpio (99) with code logic
This commit is contained in:
@@ -157,12 +157,13 @@ void AnalogSensor::reload(bool get_nvs) {
|
||||
if (!found) {
|
||||
// check if the GPIO is valid before registering. If not, force set the sensor to disabled, but don't remove it
|
||||
// should only trigger if uploading a customization file with invalid gpios.
|
||||
AnalogType type = static_cast<AnalogType>(sensor.type);
|
||||
if (!EMSESP::system_.is_valid_gpio(sensor.gpio)) {
|
||||
LOG_WARNING("Bad GPIO %d for Sensor %s. Disabling.", sensor.gpio, sensor.name.c_str());
|
||||
sensors_.emplace_back(99, sensor.name, sensor.offset, sensor.factor, sensor.uom, sensor.type, sensor.is_system);
|
||||
} else {
|
||||
sensors_.emplace_back(sensor.gpio, sensor.name, sensor.offset, sensor.factor, sensor.uom, sensor.type, sensor.is_system);
|
||||
type = AnalogType::NOTUSED;
|
||||
}
|
||||
sensors_.emplace_back(sensor.gpio, sensor.name, sensor.offset, sensor.factor, sensor.uom, type, sensor.is_system);
|
||||
|
||||
sensors_.back().ha_registered = false; // this will trigger recreate of the HA config
|
||||
if (sensor.type == AnalogType::COUNTER || sensor.type >= AnalogType::DIGITAL_OUT) {
|
||||
sensors_.back().set_value(sensor.offset);
|
||||
|
||||
@@ -146,7 +146,7 @@ void WebDataService::sensor_data(AsyncWebServerRequest * request) {
|
||||
obj["t"] = sensor.type();
|
||||
obj["s"] = sensor.is_system();
|
||||
|
||||
if (sensor.type() != AnalogSensor::AnalogType::NOTUSED && sensor.gpio() != 99) {
|
||||
if (sensor.type() != AnalogSensor::AnalogType::NOTUSED) {
|
||||
obj["v"] = Helpers::transformNumFloat(sensor.value()); // is optional and is a float
|
||||
} else {
|
||||
obj["v"] = 0; // must have a value for web sorting to work
|
||||
@@ -436,7 +436,7 @@ void WebDataService::dashboard_data(AsyncWebServerRequest * request) {
|
||||
uint8_t count = 0;
|
||||
for (const auto & sensor : EMSESP::analogsensor_.sensors()) {
|
||||
// ignore system and disabled sensors
|
||||
if (sensor.is_system() || sensor.type() == AnalogSensor::AnalogType::NOTUSED || sensor.gpio() == 99) {
|
||||
if (sensor.is_system() || sensor.type() == AnalogSensor::AnalogType::NOTUSED) {
|
||||
continue;
|
||||
}
|
||||
JsonObject node = nodes.add<JsonObject>();
|
||||
|
||||
Reference in New Issue
Block a user