mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-09 01:09:51 +03:00
MQTT Formatting payload (nested vs single) is a pull-down option
This commit is contained in:
@@ -145,7 +145,7 @@
|
||||
#endif
|
||||
|
||||
#ifndef EMSESP_DEFAULT_NESTED_FORMAT
|
||||
#define EMSESP_DEFAULT_NESTED_FORMAT true
|
||||
#define EMSESP_DEFAULT_NESTED_FORMAT 1
|
||||
#endif
|
||||
|
||||
#ifndef EMSESP_DEFAULT_SUBSCRIBE_FORMAT
|
||||
|
||||
@@ -376,7 +376,7 @@ void Thermostat::register_mqtt_ha_config_hc(uint8_t hc_num) {
|
||||
doc["~"] = Mqtt::base(); // ems-esp
|
||||
|
||||
char topic_t[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
||||
if (Mqtt::nested_format()) {
|
||||
if (Mqtt::nested_format() == 1) {
|
||||
snprintf_P(topic_t, sizeof(topic_t), PSTR("~/%s"), Mqtt::tag_to_topic(EMSdevice::DeviceType::THERMOSTAT, DeviceValueTAG::TAG_NONE).c_str());
|
||||
|
||||
char mode_str_tpl[40];
|
||||
@@ -1148,7 +1148,7 @@ bool Thermostat::set_building(const char * value, const int8_t id) {
|
||||
if ((model() == EMS_DEVICE_FLAG_RC300) || (model() == EMS_DEVICE_FLAG_RC100)) {
|
||||
if (Helpers::value2enum(value, bd, FL_(enum_ibaBuildingType))) {
|
||||
LOG_INFO(F("Setting building to %s"), value);
|
||||
write_command(0x240, 9, bd , 0x240);
|
||||
write_command(0x240, 9, bd, 0x240);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -435,7 +435,7 @@ void EMSESP::publish_device_values(uint8_t device_type) {
|
||||
JsonObject json = doc.to<JsonObject>();
|
||||
bool need_publish = false;
|
||||
|
||||
bool nested = Mqtt::nested_format();
|
||||
uint8_t nested = Mqtt::nested_format();
|
||||
|
||||
// group by device type
|
||||
for (const auto & emsdevice : emsdevices) {
|
||||
|
||||
@@ -39,7 +39,7 @@ uint8_t Mqtt::dallas_format_;
|
||||
uint8_t Mqtt::bool_format_;
|
||||
uint8_t Mqtt::ha_climate_format_;
|
||||
bool Mqtt::ha_enabled_;
|
||||
bool Mqtt::nested_format_;
|
||||
uint8_t Mqtt::nested_format_;
|
||||
uint8_t Mqtt::subscribe_format_;
|
||||
|
||||
std::deque<Mqtt::QueuedMqttMessage> Mqtt::mqtt_messages_;
|
||||
@@ -898,7 +898,7 @@ void Mqtt::publish_mqtt_ha_sensor(uint8_t type, // EMSdevice
|
||||
DynamicJsonDocument doc(EMSESP_JSON_SIZE_HA_CONFIG);
|
||||
|
||||
bool have_tag = !EMSdevice::tag_to_string(tag).empty() && (device_type != EMSdevice::DeviceType::BOILER); // ignore boiler
|
||||
bool is_nested = nested_format_ || (device_type == EMSdevice::DeviceType::BOILER); // boiler never uses nested
|
||||
bool is_nested = (nested_format_ == 1) || (device_type == EMSdevice::DeviceType::BOILER); // boiler never uses nested
|
||||
|
||||
// create entity by add the tag if present, seperating with a .
|
||||
char new_entity[50];
|
||||
@@ -1005,7 +1005,7 @@ const std::string Mqtt::tag_to_topic(uint8_t device_type, uint8_t tag) {
|
||||
}
|
||||
|
||||
// if there is a tag add it
|
||||
if ((EMSdevice::tag_to_mqtt(tag).empty()) || (nested_format_ && (device_type != EMSdevice::DeviceType::BOILER))) {
|
||||
if ((EMSdevice::tag_to_mqtt(tag).empty()) || ((nested_format_ == 1) && (device_type != EMSdevice::DeviceType::BOILER))) {
|
||||
return EMSdevice::device_type_2_device_name(device_type) + "_data";
|
||||
} else {
|
||||
return EMSdevice::device_type_2_device_name(device_type) + "_data_" + EMSdevice::tag_to_mqtt(tag);
|
||||
|
||||
@@ -158,11 +158,11 @@ class Mqtt {
|
||||
return bool_format_;
|
||||
}
|
||||
|
||||
static bool nested_format() {
|
||||
static uint8_t nested_format() {
|
||||
return nested_format_;
|
||||
}
|
||||
|
||||
static void nested_format(bool nested_format) {
|
||||
static void nested_format(uint8_t nested_format) {
|
||||
nested_format_ = nested_format;
|
||||
}
|
||||
|
||||
@@ -274,7 +274,7 @@ class Mqtt {
|
||||
static uint8_t bool_format_;
|
||||
static uint8_t ha_climate_format_;
|
||||
static bool ha_enabled_;
|
||||
static bool nested_format_;
|
||||
static uint8_t nested_format_;
|
||||
static uint8_t subscribe_format_;
|
||||
};
|
||||
|
||||
|
||||
@@ -376,7 +376,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) {
|
||||
if (command == "boiler") {
|
||||
shell.printfln(F("Testing boiler..."));
|
||||
Mqtt::ha_enabled(false);
|
||||
Mqtt::nested_format(true);
|
||||
Mqtt::nested_format(1);
|
||||
|
||||
run_test("boiler");
|
||||
shell.invoke_command("show devices");
|
||||
@@ -414,8 +414,8 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) {
|
||||
if (command == "ha") {
|
||||
shell.printfln(F("Testing HA discovery"));
|
||||
Mqtt::ha_enabled(true);
|
||||
// Mqtt::nested_format(true);
|
||||
Mqtt::nested_format(false);
|
||||
// Mqtt::nested_format(1);
|
||||
Mqtt::nested_format(2);
|
||||
|
||||
// run_test("boiler");
|
||||
run_test("thermostat");
|
||||
@@ -436,11 +436,11 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) {
|
||||
run_test("mixer");
|
||||
|
||||
// first with nested
|
||||
Mqtt::nested_format(true);
|
||||
Mqtt::nested_format(1);
|
||||
shell.invoke_command("call system publish");
|
||||
|
||||
// then without nested
|
||||
Mqtt::nested_format(false);
|
||||
Mqtt::nested_format(2);
|
||||
shell.invoke_command("call system publish");
|
||||
shell.invoke_command("show mqtt");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user