mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
fix mqtt enum in discovery #1280
This commit is contained in:
10
src/mqtt.cpp
10
src/mqtt.cpp
@@ -915,10 +915,20 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
|
|||||||
// for enums, add options
|
// for enums, add options
|
||||||
if (type == DeviceValueType::ENUM) {
|
if (type == DeviceValueType::ENUM) {
|
||||||
JsonArray option_list = doc.createNestedArray("ops"); // options
|
JsonArray option_list = doc.createNestedArray("ops"); // options
|
||||||
|
if (EMSESP::system_.enum_format() == ENUM_FORMAT_INDEX) {
|
||||||
|
// use index numbers
|
||||||
|
for (uint8_t i = 0; i < options_size; i++) {
|
||||||
|
option_list.add(i);
|
||||||
|
}
|
||||||
|
snprintf(sample_val, sizeof(sample_val), "0");
|
||||||
|
} else {
|
||||||
|
// use strings
|
||||||
for (uint8_t i = 0; i < options_size; i++) {
|
for (uint8_t i = 0; i < options_size; i++) {
|
||||||
option_list.add(Helpers::translated_word(options[i]));
|
option_list.add(Helpers::translated_word(options[i]));
|
||||||
}
|
}
|
||||||
snprintf(sample_val, sizeof(sample_val), "'%s'", Helpers::translated_word(options[0]));
|
snprintf(sample_val, sizeof(sample_val), "'%s'", Helpers::translated_word(options[0]));
|
||||||
|
}
|
||||||
|
|
||||||
} else if (type != DeviceValueType::STRING && type != DeviceValueType::BOOL) {
|
} else if (type != DeviceValueType::STRING && type != DeviceValueType::BOOL) {
|
||||||
// Must be Numeric....
|
// Must be Numeric....
|
||||||
doc["mode"] = "box"; // auto, slider or box
|
doc["mode"] = "box"; // auto, slider or box
|
||||||
|
|||||||
Reference in New Issue
Block a user