mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-09 01:09:51 +03:00
Merge branch 'dev' of https://github.com/emsesp/EMS-ESP32 into dev
This commit is contained in:
@@ -452,7 +452,7 @@ void AnalogSensor::publish_values(const bool force) {
|
||||
config["val_tpl"] = str;
|
||||
|
||||
char uniq_s[70];
|
||||
if (Mqtt::multiple_instances()) {
|
||||
if (Mqtt::entity_format() == 2) {
|
||||
snprintf(uniq_s, sizeof(uniq_s), "%s_analogsensor_%d", Mqtt::basename().c_str(), sensor.gpio());
|
||||
} else {
|
||||
snprintf(uniq_s, sizeof(uniq_s), "analogsensor_%d", sensor.gpio());
|
||||
|
||||
@@ -519,7 +519,7 @@ void DallasSensor::publish_values(const bool force) {
|
||||
config["val_tpl"] = str;
|
||||
|
||||
char uniq_s[70];
|
||||
if (Mqtt::multiple_instances()) {
|
||||
if (Mqtt::entity_format() == 2) {
|
||||
snprintf(uniq_s, sizeof(uniq_s), "%s_dallassensor_%s", Mqtt::basename().c_str(), sensor.id().c_str());
|
||||
} else {
|
||||
snprintf(uniq_s, sizeof(uniq_s), "dallassensor_%s", sensor.id().c_str());
|
||||
|
||||
14
src/mqtt.cpp
14
src/mqtt.cpp
@@ -38,7 +38,7 @@ uint32_t Mqtt::publish_time_sensor_;
|
||||
uint32_t Mqtt::publish_time_other_;
|
||||
uint32_t Mqtt::publish_time_heartbeat_;
|
||||
bool Mqtt::mqtt_enabled_;
|
||||
bool Mqtt::multiple_instances_;
|
||||
uint8_t Mqtt::entity_format_;
|
||||
bool Mqtt::ha_enabled_;
|
||||
uint8_t Mqtt::nested_format_;
|
||||
std::string Mqtt::discovery_prefix_;
|
||||
@@ -430,7 +430,7 @@ void Mqtt::load_settings() {
|
||||
publish_single2cmd_ = mqttSettings.publish_single2cmd;
|
||||
send_response_ = mqttSettings.send_response;
|
||||
discovery_prefix_ = mqttSettings.discovery_prefix.c_str();
|
||||
multiple_instances_ = mqttSettings.multiple_instances;
|
||||
entity_format_ = mqttSettings.entity_format;
|
||||
|
||||
// convert to milliseconds
|
||||
publish_time_boiler_ = mqttSettings.publish_time_boiler * 1000;
|
||||
@@ -609,7 +609,7 @@ void Mqtt::ha_status() {
|
||||
StaticJsonDocument<EMSESP_JSON_SIZE_HA_CONFIG> doc;
|
||||
|
||||
char uniq[70];
|
||||
if (Mqtt::multiple_instances()) {
|
||||
if (Mqtt::entity_format() == 2) {
|
||||
snprintf(uniq, sizeof(uniq), "%s_system_status", mqtt_basename_.c_str());
|
||||
} else {
|
||||
strcpy(uniq, "system_status");
|
||||
@@ -991,10 +991,14 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
|
||||
|
||||
// build unique identifier also used as object_id and becomes the Entity ID in HA
|
||||
char uniq_id[70];
|
||||
if (Mqtt::multiple_instances()) {
|
||||
if (Mqtt::entity_format() == 2) {
|
||||
// prefix base name to each uniq_id and use the shortname
|
||||
snprintf(uniq_id, sizeof(uniq_id), "%s_%s_%s", mqtt_basename_.c_str(), device_name, entity_with_tag);
|
||||
} else if (Mqtt::entity_format() == 1) {
|
||||
// shortname, no mqtt base
|
||||
snprintf(uniq_id, sizeof(uniq_id), "%s_%s", device_name, entity_with_tag);
|
||||
} else {
|
||||
// entity_format is 0
|
||||
// old v3.4 style
|
||||
// take en_name and replace all spaces and lowercase it
|
||||
char uniq_s[40];
|
||||
@@ -1308,7 +1312,7 @@ void Mqtt::publish_ha_climate_config(const uint8_t tag, const bool has_roomtemp,
|
||||
|
||||
snprintf(name_s, sizeof(name_s), "Hc%d", hc_num);
|
||||
|
||||
if (Mqtt::multiple_instances()) {
|
||||
if (Mqtt::entity_format() == 2) {
|
||||
snprintf(uniq_id_s, sizeof(uniq_id_s), "%s_thermostat_hc%d", mqtt_basename_.c_str(), hc_num); // add basename
|
||||
} else {
|
||||
snprintf(uniq_id_s, sizeof(uniq_id_s), "thermostat_hc%d", hc_num); // backward compatible with v3.4
|
||||
|
||||
@@ -181,8 +181,8 @@ class Mqtt {
|
||||
return nested_format_ == NestedFormat::NESTED;
|
||||
}
|
||||
|
||||
static bool multiple_instances() {
|
||||
return multiple_instances_;
|
||||
static uint8_t entity_format() {
|
||||
return entity_format_;
|
||||
}
|
||||
|
||||
static void nested_format(uint8_t nested_format) {
|
||||
@@ -322,7 +322,7 @@ class Mqtt {
|
||||
static bool mqtt_enabled_;
|
||||
static bool ha_enabled_;
|
||||
static uint8_t nested_format_;
|
||||
static bool multiple_instances_;
|
||||
static uint8_t entity_format_;
|
||||
static std::string discovery_prefix_;
|
||||
static bool publish_single_;
|
||||
static bool publish_single2cmd_;
|
||||
|
||||
@@ -155,7 +155,7 @@ void Shower::set_shower_state(bool state, bool force) {
|
||||
doc["name"] = "Shower Active";
|
||||
|
||||
char str[70];
|
||||
if (Mqtt::multiple_instances()) {
|
||||
if (Mqtt::entity_format() == 2) {
|
||||
snprintf(str, sizeof(str), "%s_shower_active", Mqtt::basename().c_str());
|
||||
} else {
|
||||
snprintf(str, sizeof(str), "shower_active"); // v3.4 compatible
|
||||
|
||||
@@ -1152,7 +1152,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp
|
||||
node["client id"] = settings.clientId;
|
||||
node["keep alive"] = settings.keepAlive;
|
||||
node["clean session"] = settings.cleanSession;
|
||||
node["multiple instances"] = settings.multiple_instances;
|
||||
node["entity format"] = settings.entity_format;
|
||||
node["base"] = settings.base;
|
||||
node["discovery prefix"] = settings.discovery_prefix;
|
||||
node["nested format"] = settings.nested_format;
|
||||
|
||||
Reference in New Issue
Block a user