don't include disabled analog sensors in dashboard

This commit is contained in:
proddy
2024-10-13 00:09:54 +01:00
parent 4ca7da684e
commit ed11260ffa
2 changed files with 6 additions and 2 deletions

View File

@@ -153,7 +153,11 @@ class AnalogSensor {
return (!sensors_.empty()); return (!sensors_.empty());
} }
size_t count_entities() const { size_t count_entities(bool count_disabled = false) const {
if (count_disabled) {
// count number of items in sensors_ where type is not set to disabled
return std::count_if(sensors_.begin(), sensors_.end(), [](const Sensor & sensor) { return sensor.type() != AnalogSensor::AnalogType::NOTUSED; });
}
return sensors_.size(); return sensors_.size();
} }

View File

@@ -408,7 +408,7 @@ void WebDataService::dashboard_data(AsyncWebServerRequest * request) {
JsonArray nodes = obj["nodes"].to<JsonArray>(); JsonArray nodes = obj["nodes"].to<JsonArray>();
uint8_t count = 0; uint8_t count = 0;
for (const auto & sensor : EMSESP::analogsensor_.sensors()) { for (const auto & sensor : EMSESP::analogsensor_.sensors()) {
if (sensor.type() != AnalogSensor::AnalogType::NOTUSED) { if (sensor.type() != AnalogSensor::AnalogType::NOTUSED) { // ignore disabled
JsonObject node = nodes.add<JsonObject>(); JsonObject node = nodes.add<JsonObject>();
node["id"] = (EMSdevice::DeviceTypeUniqueID::ANALOGSENSOR_UID * 100) + count++; node["id"] = (EMSdevice::DeviceTypeUniqueID::ANALOGSENSOR_UID * 100) + count++;