Arduino v7

This commit is contained in:
Proddy
2024-01-04 23:43:30 +01:00
parent 13a915e1f4
commit af237c4fc0
213 changed files with 3900 additions and 4479 deletions

View File

@@ -376,7 +376,7 @@ bool TemperatureSensor::command_info(const char * value, const int8_t id, JsonOb
for (const auto & sensor : sensors_) {
char val[10];
if (id == -1) { // show number and id, info command
JsonObject dataSensor = output.createNestedObject(sensor.name());
JsonObject dataSensor = output[sensor.name()].add<JsonObject>();
dataSensor["id"] = sensor.id();
dataSensor["uom"] = EMSdevice::uom_to_string(DeviceValueUOM::DEGREES);
dataSensor["type"] = F_(number);
@@ -490,7 +490,7 @@ void TemperatureSensor::publish_values(const bool force) {
}
}
DynamicJsonDocument doc(150 * num_sensors);
JsonDocument doc;
// used to see if we need to create the [devs] discovery section, as this needs only to be done once for all sensors
bool is_first_ha = true;
@@ -508,7 +508,7 @@ void TemperatureSensor::publish_values(const bool force) {
if (has_value) {
char val[10];
if (Mqtt::is_nested()) {
JsonObject dataSensor = doc.createNestedObject(sensor.id());
JsonObject dataSensor = doc[sensor.id()].add<JsonObject>();
dataSensor["name"] = sensor.name();
dataSensor["temp"] = serialized(Helpers::render_value(val, sensor.temperature_c, 10, EMSESP::system_.fahrenheit() ? 2 : 0));
} else {
@@ -525,7 +525,7 @@ void TemperatureSensor::publish_values(const bool force) {
} else if (!sensor.ha_registered || force) {
LOG_DEBUG("Recreating HA config for sensor ID %s", sensor.id().c_str());
StaticJsonDocument<EMSESP_JSON_SIZE_LARGE> config; // this needs to be large because of all the copying in add_ha_sections_to_doc()
JsonDocument config; // this needs to be large because of all the copying in add_ha_sections_to_doc()
config["dev_cla"] = "temperature";
char stat_t[50];
@@ -566,7 +566,7 @@ void TemperatureSensor::publish_values(const bool force) {
snprintf(name, sizeof(name), "%s", sensor.name().c_str());
config["name"] = name;
Mqtt::add_ha_sections_to_doc("temperature", stat_t, config.as<JsonObject>(), is_first_ha, val_cond);
Mqtt::add_ha_sections_to_doc("temperature", stat_t, config, is_first_ha, val_cond);
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
// use '_' as HA doesn't like '-' in the topic name