Skip to content

Commit

Permalink
fix mqtt enum in discovery #1280
Browse files Browse the repository at this point in the history
  • Loading branch information
proddy committed Sep 8, 2023
1 parent 6db5058 commit 98e2951
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,10 +915,20 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
// for enums, add options
if (type == DeviceValueType::ENUM) {
JsonArray option_list = doc.createNestedArray("ops"); // options
for (uint8_t i = 0; i < options_size; i++) {
option_list.add(Helpers::translated_word(options[i]));
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++) {
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) {
// Must be Numeric....
doc["mode"] = "box"; // auto, slider or box
Expand Down

0 comments on commit 98e2951

Please sign in to comment.