Skip to content

Commit

Permalink
value_info bool format
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDvP committed Apr 24, 2021
1 parent 9036967 commit 018b4af
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/emsdevice.cpp
Expand Up @@ -720,12 +720,29 @@ bool EMSdevice::get_value_info(JsonObject & root, const char * cmd, const int8_t
json["min"] = 0;
json["max"] = divider ? EMS_VALUE_ULONG_NOTSET / divider : EMS_VALUE_ULONG_NOTSET;
break;
case DeviceValueType::BOOL:
case DeviceValueType::BOOL: {
if (Helpers::hasValue(*(uint8_t *)(dv.value_p), EMS_VALUE_BOOL)) {
json["value"] = (bool)(*(uint8_t *)(dv.value_p)) ? true : false;
}
json["type"] = F("boolean");
json["min"] = 0;
json["max"] = 1;
JsonArray enum_ = json.createNestedArray(F("enum"));
if (dv.options_size == 2) {
enum_.add(dv.options[1]);
enum_.add(dv.options[0]);
} else if (Mqtt::bool_format() == BOOL_FORMAT_ONOFF) {
enum_.add("off");
enum_.add("on");
} else if (Mqtt::bool_format() == BOOL_FORMAT_ONOFF_CAP) {
enum_.add("OFF");
enum_.add("ON");
} else {
enum_.add(false);
enum_.add(true);
}
break;
}
case DeviceValueType::TIME:
if (Helpers::hasValue(*(uint32_t *)(dv.value_p))) {
json["value"] = (divider) ? *(uint32_t *)(dv.value_p) / divider : *(uint32_t *)(dv.value_p);
Expand Down

0 comments on commit 018b4af

Please sign in to comment.