mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
add dallassensors to api-info
This commit is contained in:
@@ -308,12 +308,20 @@ bool DallasSensor::command_info(const char * value, const int8_t id, JsonObject
|
|||||||
for (const auto & sensor : sensors_) {
|
for (const auto & sensor : sensors_) {
|
||||||
char sensorID[10]; // sensor{1-n}
|
char sensorID[10]; // sensor{1-n}
|
||||||
snprintf_P(sensorID, 10, PSTR("sensor%d"), i++);
|
snprintf_P(sensorID, 10, PSTR("sensor%d"), i++);
|
||||||
|
if (id == 0) {
|
||||||
|
if (Mqtt::dallas_format() == Mqtt::Dallas_Format::SENSORID && Helpers::hasValue(sensor.temperature_c)) {
|
||||||
|
json[sensor.to_string()] = (float)(sensor.temperature_c) / 10;
|
||||||
|
} else if (Helpers::hasValue(sensor.temperature_c)) {
|
||||||
|
json[sensorID] = (float)(sensor.temperature_c) / 10;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
JsonObject dataSensor = json.createNestedObject(sensorID);
|
JsonObject dataSensor = json.createNestedObject(sensorID);
|
||||||
dataSensor["id"] = sensor.to_string();
|
dataSensor["id"] = sensor.to_string();
|
||||||
if (Helpers::hasValue(sensor.temperature_c)) {
|
if (Helpers::hasValue(sensor.temperature_c)) {
|
||||||
dataSensor["temp"] = (float)(sensor.temperature_c) / 10;
|
dataSensor["temp"] = (float)(sensor.temperature_c) / 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -553,6 +553,27 @@ bool EMSESP::get_device_value_info(JsonObject & root, const char * cmd, const in
|
|||||||
return emsdevice->get_value_info(root, cmd, id);
|
return emsdevice->get_value_info(root, cmd, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (devicetype == DeviceType::DALLASSENSOR) {
|
||||||
|
uint8_t i = 1;
|
||||||
|
for (const auto & sensor : EMSESP::sensor_devices()) {
|
||||||
|
char sensorID[10];
|
||||||
|
snprintf_P(sensorID, 10, PSTR("sensor%d"), i++);
|
||||||
|
if ((strcmp(cmd, sensorID) == 0) || (strcmp(cmd, Helpers::toLower(sensor.to_string()).c_str()) == 0)) {
|
||||||
|
root["name"] = sensor.to_string();
|
||||||
|
if (Helpers::hasValue(sensor.temperature_c)) {
|
||||||
|
root["value"] = (float)(sensor.temperature_c) / 10;
|
||||||
|
}
|
||||||
|
root["type"] = F_(number);
|
||||||
|
root["min"] = -55;
|
||||||
|
root["max"] = 125;
|
||||||
|
root["unit"] = EMSdevice::uom_to_string(DeviceValueUOM::DEGREES);
|
||||||
|
root["writeable"] = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -921,6 +921,11 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & json
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (EMSESP::sensor_devices().size()) {
|
||||||
|
JsonObject obj = devices2.createNestedObject();
|
||||||
|
obj["type"] = F("Dallassensor");
|
||||||
|
obj["name"] = F("Dallassensor");
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user