add dallassensors to api-info

This commit is contained in:
MichaelDvP
2021-04-30 15:15:54 +02:00
parent 4f98b4bb21
commit ee5b1b8c34
3 changed files with 38 additions and 4 deletions

View File

@@ -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;
} }

View File

@@ -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;
} }

View File

@@ -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;
} }