mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
optimistic only for writable values
This commit is contained in:
@@ -682,7 +682,7 @@ void AnalogSensor::publish_values(const bool force) {
|
|||||||
|
|
||||||
Mqtt::add_ha_sections_to_doc("analog", stat_t, config, !is_ha_device_created, val_cond);
|
Mqtt::add_ha_sections_to_doc("analog", stat_t, config, !is_ha_device_created, val_cond);
|
||||||
|
|
||||||
if (Mqtt::ha_optimistic()) {
|
if (Mqtt::ha_optimistic() && config["cmd_t"].is<const char*>()) {
|
||||||
config["optimistic"] = true;
|
config["optimistic"] = true;
|
||||||
}
|
}
|
||||||
sensor.ha_registered = Mqtt::queue_ha(topic, config.as<JsonObject>());
|
sensor.ha_registered = Mqtt::queue_ha(topic, config.as<JsonObject>());
|
||||||
|
|||||||
@@ -1116,7 +1116,7 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
|
|||||||
|
|
||||||
doc["dev"] = dev_json;
|
doc["dev"] = dev_json;
|
||||||
|
|
||||||
if (ha_optimistic_) {
|
if (ha_optimistic_ && has_cmd) {
|
||||||
doc["optimistic"] = true;
|
doc["optimistic"] = true;
|
||||||
}
|
}
|
||||||
return queue_ha(topic, doc.as<JsonObject>());
|
return queue_ha(topic, doc.as<JsonObject>());
|
||||||
@@ -1406,7 +1406,7 @@ void Mqtt::add_ha_sections_to_doc(const char * name,
|
|||||||
|
|
||||||
// make local copy of state, as the pointer will get derefenced
|
// make local copy of state, as the pointer will get derefenced
|
||||||
char state[50];
|
char state[50];
|
||||||
strcpy(state, state_t);
|
strlcpy(state, state_t, sizeof(state));
|
||||||
|
|
||||||
// skip conditional Jinja2 templates if not home assistant
|
// skip conditional Jinja2 templates if not home assistant
|
||||||
if (discovery_type() == discoveryType::HOMEASSISTANT) {
|
if (discovery_type() == discoveryType::HOMEASSISTANT) {
|
||||||
|
|||||||
@@ -452,7 +452,7 @@ void WebCustomEntityService::publish(const bool force) {
|
|||||||
|
|
||||||
Mqtt::add_ha_sections_to_doc(F_(custom), stat_t, config, !ha_created, val_cond);
|
Mqtt::add_ha_sections_to_doc(F_(custom), stat_t, config, !ha_created, val_cond);
|
||||||
|
|
||||||
if (Mqtt::ha_optimistic()) {
|
if (Mqtt::ha_optimistic() && (entityItem.writeable || entityItem.ram > 0)) {
|
||||||
config["optimistic"] = true;
|
config["optimistic"] = true;
|
||||||
}
|
}
|
||||||
ha_created |= Mqtt::queue_ha(topic, config.as<JsonObject>());
|
ha_created |= Mqtt::queue_ha(topic, config.as<JsonObject>());
|
||||||
|
|||||||
Reference in New Issue
Block a user