mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-17 13:19:55 +03:00
fix mqtt bool output for analog, scheduler
This commit is contained in:
@@ -675,11 +675,12 @@ void AnalogSensor::publish_values(const bool force) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JsonDocument doc;
|
JsonDocument doc;
|
||||||
|
JsonObject obj = doc.to<JsonObject>();
|
||||||
|
|
||||||
for (auto & sensor : sensors_) {
|
for (auto & sensor : sensors_) {
|
||||||
if (Mqtt::is_nested()) {
|
if (Mqtt::is_nested()) {
|
||||||
char s[10];
|
char s[10];
|
||||||
JsonObject dataSensor = doc[Helpers::smallitoa(s, sensor.gpio())].to<JsonObject>();
|
JsonObject dataSensor = obj[Helpers::smallitoa(s, sensor.gpio())].to<JsonObject>();
|
||||||
dataSensor["name"] = sensor.name();
|
dataSensor["name"] = sensor.name();
|
||||||
#if CONFIG_IDF_TARGET_ESP32
|
#if CONFIG_IDF_TARGET_ESP32
|
||||||
if (sensor.type() == AnalogType::PULSE || (sensor.type() == AnalogType::DIGITAL_OUT && sensor.gpio() != 25 && sensor.gpio() != 26)) {
|
if (sensor.type() == AnalogType::PULSE || (sensor.type() == AnalogType::DIGITAL_OUT && sensor.gpio() != 25 && sensor.gpio() != 26)) {
|
||||||
@@ -691,10 +692,10 @@ void AnalogSensor::publish_values(const bool force) {
|
|||||||
dataSensor["value"] = serialized(Helpers::render_value(s, sensor.value(), 2)); // double
|
dataSensor["value"] = serialized(Helpers::render_value(s, sensor.value(), 2)); // double
|
||||||
}
|
}
|
||||||
} else if (sensor.type() == AnalogType::DIGITAL_IN || sensor.type() == AnalogType::DIGITAL_OUT || sensor.type() == AnalogType::PULSE) {
|
} else if (sensor.type() == AnalogType::DIGITAL_IN || sensor.type() == AnalogType::DIGITAL_OUT || sensor.type() == AnalogType::PULSE) {
|
||||||
Mqtt::add_value_bool(doc.as<JsonObject>(), sensor.name(), sensor.value() != 0);
|
Mqtt::add_value_bool(obj, (const char *)sensor.name(), sensor.value() != 0);
|
||||||
} else {
|
} else {
|
||||||
char s[10];
|
char s[10];
|
||||||
doc[sensor.name()] = serialized(Helpers::render_value(s, sensor.value(), 2));
|
obj[sensor.name()] = serialized(Helpers::render_value(s, sensor.value(), 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// create HA config if hasn't already been done
|
// create HA config if hasn't already been done
|
||||||
@@ -804,7 +805,7 @@ void AnalogSensor::publish_values(const bool force) {
|
|||||||
|
|
||||||
// add default_entity_id
|
// add default_entity_id
|
||||||
std::string topic_str(topic);
|
std::string topic_str(topic);
|
||||||
doc["def_ent_id"] = topic_str.substr(0, topic_str.find("/")) + "." + uniq_s;
|
config["def_ent_id"] = topic_str.substr(0, topic_str.find("/")) + "." + uniq_s;
|
||||||
|
|
||||||
Mqtt::add_ha_avty_section(config.as<JsonObject>(), stat_t, val_cond);
|
Mqtt::add_ha_avty_section(config.as<JsonObject>(), stat_t, val_cond);
|
||||||
|
|
||||||
@@ -814,7 +815,7 @@ void AnalogSensor::publish_values(const bool force) {
|
|||||||
|
|
||||||
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
||||||
snprintf(topic, sizeof(topic), "%s_data", F_(analogsensor));
|
snprintf(topic, sizeof(topic), "%s_data", F_(analogsensor));
|
||||||
Mqtt::queue_publish(topic, doc.as<JsonObject>());
|
Mqtt::queue_publish(topic, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
// called from emsesp.cpp for commands
|
// called from emsesp.cpp for commands
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ bool WebCustomEntityService::command_setvalue(const char * value, const int8_t i
|
|||||||
// if add_uom is true it will add the UOM string to the value
|
// if add_uom is true it will add the UOM string to the value
|
||||||
void WebCustomEntityService::render_value(JsonObject output, CustomEntityItem const & entity, const bool useVal, const bool web, const bool add_uom) {
|
void WebCustomEntityService::render_value(JsonObject output, CustomEntityItem const & entity, const bool useVal, const bool web, const bool add_uom) {
|
||||||
char payload[20];
|
char payload[20];
|
||||||
const char * name = useVal ? "value" : entity.name;
|
const char * name = useVal ? "value" : (const char *)entity.name;
|
||||||
|
|
||||||
switch (entity.value_type) {
|
switch (entity.value_type) {
|
||||||
case DeviceValueType::BOOL:
|
case DeviceValueType::BOOL:
|
||||||
|
|||||||
@@ -235,10 +235,11 @@ void WebSchedulerService::publish(const bool force) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JsonDocument doc;
|
JsonDocument doc;
|
||||||
|
JsonObject output = doc.to<JsonObject>();
|
||||||
bool ha_created = ha_registered_;
|
bool ha_created = ha_registered_;
|
||||||
for (const ScheduleItem & scheduleItem : *scheduleItems_) {
|
for (const ScheduleItem & scheduleItem : *scheduleItems_) {
|
||||||
if (scheduleItem.name[0] != '\0' && !doc[scheduleItem.name].is<JsonVariantConst>()) {
|
if (scheduleItem.name[0] != '\0' && !output[scheduleItem.name].is<JsonVariantConst>()) {
|
||||||
Mqtt::add_value_bool(doc.as<JsonObject>(), scheduleItem.name, scheduleItem.active);
|
Mqtt::add_value_bool(output, (const char *)scheduleItem.name, scheduleItem.active);
|
||||||
|
|
||||||
// create HA config
|
// create HA config
|
||||||
if (Mqtt::ha_enabled() && !ha_registered_) {
|
if (Mqtt::ha_enabled() && !ha_registered_) {
|
||||||
@@ -290,7 +291,7 @@ void WebSchedulerService::publish(const bool force) {
|
|||||||
if (!doc.isNull()) {
|
if (!doc.isNull()) {
|
||||||
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
||||||
snprintf(topic, sizeof(topic), "%s_data", F_(scheduler));
|
snprintf(topic, sizeof(topic), "%s_data", F_(scheduler));
|
||||||
Mqtt::queue_publish(topic, doc.as<JsonObject>());
|
Mqtt::queue_publish(topic, output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user