mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
Merge branch 'dev' of https://github.com/emsesp/EMS-ESP32 into dev
This commit is contained in:
@@ -236,17 +236,18 @@ const MqttSettingsForm: FC = () => {
|
|||||||
</Grid>
|
</Grid>
|
||||||
<Grid item>
|
<Grid item>
|
||||||
<ValidatedTextField
|
<ValidatedTextField
|
||||||
name="multiple_instances"
|
name="entity_format"
|
||||||
label={LL.MQTT_ENTITY_FORMAT()}
|
label={LL.MQTT_ENTITY_FORMAT()}
|
||||||
value={data.multiple_instances}
|
value={data.entity_format}
|
||||||
fullWidth
|
fullWidth
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={updateFormValue}
|
onChange={updateFormValue}
|
||||||
margin="normal"
|
margin="normal"
|
||||||
select
|
select
|
||||||
>
|
>
|
||||||
<MenuItem value={false as any}>{LL.MQTT_ENTITY_FORMAT_0()}</MenuItem>
|
<MenuItem value={0}>{LL.MQTT_ENTITY_FORMAT_0()}</MenuItem>
|
||||||
<MenuItem value={true as any}>{LL.MQTT_ENTITY_FORMAT_1()}</MenuItem>
|
<MenuItem value={1}>{LL.MQTT_ENTITY_FORMAT_1()}</MenuItem>
|
||||||
|
<MenuItem value={2}>{LL.MQTT_ENTITY_FORMAT_2()}</MenuItem>
|
||||||
</ValidatedTextField>
|
</ValidatedTextField>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@@ -250,8 +250,9 @@ const de: Translation = {
|
|||||||
MQTT_QUEUE: 'MQTT Queue',
|
MQTT_QUEUE: 'MQTT Queue',
|
||||||
DEFAULT: 'Standard',
|
DEFAULT: 'Standard',
|
||||||
MQTT_ENTITY_FORMAT: 'Entitäts-ID Format',
|
MQTT_ENTITY_FORMAT: 'Entitäts-ID Format',
|
||||||
MQTT_ENTITY_FORMAT_0: 'Einzelinstanz, Langname (veraltet)',
|
MQTT_ENTITY_FORMAT_0: 'Einzelinstanz, Langname (v3.4)',
|
||||||
MQTT_ENTITY_FORMAT_1: 'Mehrfachinstanzen, MQTT-Namen',
|
MQTT_ENTITY_FORMAT_1: 'Einzelinstanz, MQTT-Namen',
|
||||||
|
MQTT_ENTITY_FORMAT_2: 'Mehrfachinstanzen, MQTT-Namen',
|
||||||
MQTT_CLEAN_SESSION: 'Setze `Clean Session`',
|
MQTT_CLEAN_SESSION: 'Setze `Clean Session`',
|
||||||
MQTT_RETAIN_FLAG: 'Setze `Retain flag` immer',
|
MQTT_RETAIN_FLAG: 'Setze `Retain flag` immer',
|
||||||
INACTIVE: 'Inaktiv',
|
INACTIVE: 'Inaktiv',
|
||||||
|
|||||||
@@ -249,8 +249,9 @@ const en: Translation = {
|
|||||||
MQTT_QUEUE: 'MQTT Queue',
|
MQTT_QUEUE: 'MQTT Queue',
|
||||||
DEFAULT: 'Default',
|
DEFAULT: 'Default',
|
||||||
MQTT_ENTITY_FORMAT: 'Entity ID format',
|
MQTT_ENTITY_FORMAT: 'Entity ID format',
|
||||||
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (depreciated)',
|
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)',
|
||||||
MQTT_ENTITY_FORMAT_1: 'Multiple instances, short name',
|
MQTT_ENTITY_FORMAT_1: 'Single instance, short name',
|
||||||
|
MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name',
|
||||||
MQTT_CLEAN_SESSION: 'Set Clean Session',
|
MQTT_CLEAN_SESSION: 'Set Clean Session',
|
||||||
MQTT_RETAIN_FLAG: 'Always set Retain flag',
|
MQTT_RETAIN_FLAG: 'Always set Retain flag',
|
||||||
INACTIVE: 'Inactive',
|
INACTIVE: 'Inactive',
|
||||||
|
|||||||
@@ -249,8 +249,9 @@ const fr: Translation = {
|
|||||||
MQTT_QUEUE: 'Queue MQTT',
|
MQTT_QUEUE: 'Queue MQTT',
|
||||||
DEFAULT: 'Défaut',
|
DEFAULT: 'Défaut',
|
||||||
MQTT_ENTITY_FORMAT: 'Entity ID format',
|
MQTT_ENTITY_FORMAT: 'Entity ID format',
|
||||||
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (depreciated)',
|
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)',
|
||||||
MQTT_ENTITY_FORMAT_1: 'Multiple instances, short name',
|
MQTT_ENTITY_FORMAT_1: 'Single instance, short name',
|
||||||
|
MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name',
|
||||||
MQTT_CLEAN_SESSION: 'Flag Clean Session',
|
MQTT_CLEAN_SESSION: 'Flag Clean Session',
|
||||||
MQTT_RETAIN_FLAG: 'Toujours activer le Retain Flag',
|
MQTT_RETAIN_FLAG: 'Toujours activer le Retain Flag',
|
||||||
INACTIVE: 'Inactif',
|
INACTIVE: 'Inactif',
|
||||||
|
|||||||
@@ -249,8 +249,9 @@ const nl: Translation = {
|
|||||||
MQTT_QUEUE: 'MQTT Queue',
|
MQTT_QUEUE: 'MQTT Queue',
|
||||||
DEFAULT: 'Default',
|
DEFAULT: 'Default',
|
||||||
MQTT_ENTITY_FORMAT: 'Entity ID format',
|
MQTT_ENTITY_FORMAT: 'Entity ID format',
|
||||||
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (depreciated)',
|
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)',
|
||||||
MQTT_ENTITY_FORMAT_1: 'Multiple instances, short name',
|
MQTT_ENTITY_FORMAT_1: 'Single instance, short name',
|
||||||
|
MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name',
|
||||||
MQTT_CLEAN_SESSION: 'Clean Session aan',
|
MQTT_CLEAN_SESSION: 'Clean Session aan',
|
||||||
MQTT_RETAIN_FLAG: 'Retain flag aan',
|
MQTT_RETAIN_FLAG: 'Retain flag aan',
|
||||||
INACTIVE: 'Inactief',
|
INACTIVE: 'Inactief',
|
||||||
|
|||||||
@@ -249,8 +249,9 @@ const no: Translation = {
|
|||||||
MQTT_QUEUE: 'MQTT Queue',
|
MQTT_QUEUE: 'MQTT Queue',
|
||||||
DEFAULT: 'Standard',
|
DEFAULT: 'Standard',
|
||||||
MQTT_ENTITY_FORMAT: 'Entity ID format',
|
MQTT_ENTITY_FORMAT: 'Entity ID format',
|
||||||
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (depreciated)',
|
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)',
|
||||||
MQTT_ENTITY_FORMAT_1: 'Multiple instances, short name',
|
MQTT_ENTITY_FORMAT_1: 'Single instance, short name',
|
||||||
|
MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name',
|
||||||
MQTT_CLEAN_SESSION: 'Benytt Clean Session',
|
MQTT_CLEAN_SESSION: 'Benytt Clean Session',
|
||||||
MQTT_RETAIN_FLAG: 'Alltid sett Retain flag',
|
MQTT_RETAIN_FLAG: 'Alltid sett Retain flag',
|
||||||
INACTIVE: 'Innaktiv',
|
INACTIVE: 'Innaktiv',
|
||||||
|
|||||||
@@ -249,8 +249,9 @@ const pl: BaseTranslation = {
|
|||||||
MQTT_QUEUE: 'Kolejka MQTT',
|
MQTT_QUEUE: 'Kolejka MQTT',
|
||||||
DEFAULT: '{{Pozostałe|Domyślna|}}',
|
DEFAULT: '{{Pozostałe|Domyślna|}}',
|
||||||
MQTT_ENTITY_FORMAT: 'Entity ID format',
|
MQTT_ENTITY_FORMAT: 'Entity ID format',
|
||||||
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (depreciated)',
|
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)',
|
||||||
MQTT_ENTITY_FORMAT_1: 'Multiple instances, short name',
|
MQTT_ENTITY_FORMAT_1: 'Single instance, short name',
|
||||||
|
MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name',
|
||||||
MQTT_CLEAN_SESSION: 'Ustawiaj flagę "Clean session"',
|
MQTT_CLEAN_SESSION: 'Ustawiaj flagę "Clean session"',
|
||||||
MQTT_RETAIN_FLAG: 'Ustawiaj flagę "Retain"',
|
MQTT_RETAIN_FLAG: 'Ustawiaj flagę "Retain"',
|
||||||
INACTIVE: 'nieaktywny',
|
INACTIVE: 'nieaktywny',
|
||||||
|
|||||||
@@ -249,8 +249,9 @@ const se: Translation = {
|
|||||||
MQTT_QUEUE: 'MQTT Queue',
|
MQTT_QUEUE: 'MQTT Queue',
|
||||||
DEFAULT: 'Standard',
|
DEFAULT: 'Standard',
|
||||||
MQTT_ENTITY_FORMAT: 'Entity ID format',
|
MQTT_ENTITY_FORMAT: 'Entity ID format',
|
||||||
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (depreciated)',
|
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)',
|
||||||
MQTT_ENTITY_FORMAT_1: 'Multiple instances, short name',
|
MQTT_ENTITY_FORMAT_1: 'Single instance, short name',
|
||||||
|
MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name',
|
||||||
MQTT_CLEAN_SESSION: 'Använd "Clean Session"-flaggan',
|
MQTT_CLEAN_SESSION: 'Använd "Clean Session"-flaggan',
|
||||||
MQTT_RETAIN_FLAG: 'Använd "Always Retain"-flaggan',
|
MQTT_RETAIN_FLAG: 'Använd "Always Retain"-flaggan',
|
||||||
INACTIVE: 'Inaktiv',
|
INACTIVE: 'Inaktiv',
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export interface MqttSettings {
|
|||||||
client_id: string;
|
client_id: string;
|
||||||
keep_alive: number;
|
keep_alive: number;
|
||||||
clean_session: boolean;
|
clean_session: boolean;
|
||||||
multiple_instances: boolean;
|
entity_format: number;
|
||||||
publish_time_boiler: number;
|
publish_time_boiler: number;
|
||||||
publish_time_thermostat: number;
|
publish_time_thermostat: number;
|
||||||
publish_time_solar: number;
|
publish_time_solar: number;
|
||||||
|
|||||||
@@ -145,16 +145,16 @@ void MqttSettingsService::configureMqtt() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MqttSettings::read(MqttSettings & settings, JsonObject & root) {
|
void MqttSettings::read(MqttSettings & settings, JsonObject & root) {
|
||||||
root["enabled"] = settings.enabled;
|
root["enabled"] = settings.enabled;
|
||||||
root["host"] = settings.host;
|
root["host"] = settings.host;
|
||||||
root["port"] = settings.port;
|
root["port"] = settings.port;
|
||||||
root["base"] = settings.base;
|
root["base"] = settings.base;
|
||||||
root["username"] = settings.username;
|
root["username"] = settings.username;
|
||||||
root["password"] = settings.password;
|
root["password"] = settings.password;
|
||||||
root["client_id"] = settings.clientId;
|
root["client_id"] = settings.clientId;
|
||||||
root["keep_alive"] = settings.keepAlive;
|
root["keep_alive"] = settings.keepAlive;
|
||||||
root["clean_session"] = settings.cleanSession;
|
root["clean_session"] = settings.cleanSession;
|
||||||
root["multiple_instances"] = settings.multiple_instances;
|
root["entity_format"] = settings.entity_format;
|
||||||
|
|
||||||
// added by proddy for EMS-ESP
|
// added by proddy for EMS-ESP
|
||||||
root["publish_time_boiler"] = settings.publish_time_boiler;
|
root["publish_time_boiler"] = settings.publish_time_boiler;
|
||||||
@@ -178,18 +178,18 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting
|
|||||||
MqttSettings newSettings = {};
|
MqttSettings newSettings = {};
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
|
|
||||||
newSettings.enabled = root["enabled"] | FACTORY_MQTT_ENABLED;
|
newSettings.enabled = root["enabled"] | FACTORY_MQTT_ENABLED;
|
||||||
newSettings.host = root["host"] | FACTORY_MQTT_HOST;
|
newSettings.host = root["host"] | FACTORY_MQTT_HOST;
|
||||||
newSettings.port = root["port"] | FACTORY_MQTT_PORT;
|
newSettings.port = root["port"] | FACTORY_MQTT_PORT;
|
||||||
newSettings.base = root["base"] | FACTORY_MQTT_BASE;
|
newSettings.base = root["base"] | FACTORY_MQTT_BASE;
|
||||||
newSettings.username = root["username"] | FACTORY_MQTT_USERNAME;
|
newSettings.username = root["username"] | FACTORY_MQTT_USERNAME;
|
||||||
newSettings.password = root["password"] | FACTORY_MQTT_PASSWORD;
|
newSettings.password = root["password"] | FACTORY_MQTT_PASSWORD;
|
||||||
newSettings.clientId = root["client_id"] | FACTORY_MQTT_CLIENT_ID;
|
newSettings.clientId = root["client_id"] | FACTORY_MQTT_CLIENT_ID;
|
||||||
newSettings.keepAlive = root["keep_alive"] | FACTORY_MQTT_KEEP_ALIVE;
|
newSettings.keepAlive = root["keep_alive"] | FACTORY_MQTT_KEEP_ALIVE;
|
||||||
newSettings.cleanSession = root["clean_session"] | FACTORY_MQTT_CLEAN_SESSION;
|
newSettings.cleanSession = root["clean_session"] | FACTORY_MQTT_CLEAN_SESSION;
|
||||||
newSettings.multiple_instances = root["multiple_instances"] | FACTORY_MQTT_MULTIPLE_INSTANCES;
|
newSettings.entity_format = root["entity_format"] | FACTORY_MQTT_ENTITY_FORMAT;
|
||||||
newSettings.mqtt_qos = root["mqtt_qos"] | EMSESP_DEFAULT_MQTT_QOS;
|
newSettings.mqtt_qos = root["mqtt_qos"] | EMSESP_DEFAULT_MQTT_QOS;
|
||||||
newSettings.mqtt_retain = root["mqtt_retain"] | EMSESP_DEFAULT_MQTT_RETAIN;
|
newSettings.mqtt_retain = root["mqtt_retain"] | EMSESP_DEFAULT_MQTT_RETAIN;
|
||||||
|
|
||||||
newSettings.publish_time_boiler = root["publish_time_boiler"] | EMSESP_DEFAULT_PUBLISH_TIME;
|
newSettings.publish_time_boiler = root["publish_time_boiler"] | EMSESP_DEFAULT_PUBLISH_TIME;
|
||||||
newSettings.publish_time_thermostat = root["publish_time_thermostat"] | EMSESP_DEFAULT_PUBLISH_TIME;
|
newSettings.publish_time_thermostat = root["publish_time_thermostat"] | EMSESP_DEFAULT_PUBLISH_TIME;
|
||||||
@@ -223,7 +223,7 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting
|
|||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newSettings.multiple_instances != settings.multiple_instances) {
|
if (newSettings.entity_format != settings.entity_format) {
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,8 +57,8 @@ static String generateClientId() {
|
|||||||
#define FACTORY_MQTT_MAX_TOPIC_LENGTH 128
|
#define FACTORY_MQTT_MAX_TOPIC_LENGTH 128
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FACTORY_MQTT_MULTIPLE_INSTANCES
|
#ifndef FACTORY_MQTT_ENTITY_FORMAT
|
||||||
#define FACTORY_MQTT_MULTIPLE_INSTANCES true
|
#define FACTORY_MQTT_ENTITY_FORMAT 1 // use shortnames
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class MqttSettings {
|
class MqttSettings {
|
||||||
@@ -80,7 +80,7 @@ class MqttSettings {
|
|||||||
bool cleanSession;
|
bool cleanSession;
|
||||||
|
|
||||||
// multiple instances
|
// multiple instances
|
||||||
bool multiple_instances;
|
uint8_t entity_format;
|
||||||
|
|
||||||
// proddy EMS-ESP specific
|
// proddy EMS-ESP specific
|
||||||
String base;
|
String base;
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ class DummySettings {
|
|||||||
String username = "";
|
String username = "";
|
||||||
uint16_t keepAlive = 60;
|
uint16_t keepAlive = 60;
|
||||||
bool cleanSession = false;
|
bool cleanSession = false;
|
||||||
bool multiple_instances = false;
|
uint8_t entity_format = 1;
|
||||||
|
|
||||||
uint16_t publish_time_boiler = 10;
|
uint16_t publish_time_boiler = 10;
|
||||||
uint16_t publish_time_thermostat = 10;
|
uint16_t publish_time_thermostat = 10;
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ mqtt_settings = {
|
|||||||
client_id: 'ems-esp',
|
client_id: 'ems-esp',
|
||||||
keep_alive: 60,
|
keep_alive: 60,
|
||||||
clean_session: true,
|
clean_session: true,
|
||||||
multiple_instances: true,
|
entity_format: 1,
|
||||||
publish_time_boiler: 10,
|
publish_time_boiler: 10,
|
||||||
publish_time_thermostat: 10,
|
publish_time_thermostat: 10,
|
||||||
publish_time_solar: 10,
|
publish_time_solar: 10,
|
||||||
|
|||||||
@@ -452,7 +452,7 @@ void AnalogSensor::publish_values(const bool force) {
|
|||||||
config["val_tpl"] = str;
|
config["val_tpl"] = str;
|
||||||
|
|
||||||
char uniq_s[70];
|
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());
|
snprintf(uniq_s, sizeof(uniq_s), "%s_analogsensor_%d", Mqtt::basename().c_str(), sensor.gpio());
|
||||||
} else {
|
} else {
|
||||||
snprintf(uniq_s, sizeof(uniq_s), "analogsensor_%d", sensor.gpio());
|
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;
|
config["val_tpl"] = str;
|
||||||
|
|
||||||
char uniq_s[70];
|
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());
|
snprintf(uniq_s, sizeof(uniq_s), "%s_dallassensor_%s", Mqtt::basename().c_str(), sensor.id().c_str());
|
||||||
} else {
|
} else {
|
||||||
snprintf(uniq_s, sizeof(uniq_s), "dallassensor_%s", sensor.id().c_str());
|
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_other_;
|
||||||
uint32_t Mqtt::publish_time_heartbeat_;
|
uint32_t Mqtt::publish_time_heartbeat_;
|
||||||
bool Mqtt::mqtt_enabled_;
|
bool Mqtt::mqtt_enabled_;
|
||||||
bool Mqtt::multiple_instances_;
|
uint8_t Mqtt::entity_format_;
|
||||||
bool Mqtt::ha_enabled_;
|
bool Mqtt::ha_enabled_;
|
||||||
uint8_t Mqtt::nested_format_;
|
uint8_t Mqtt::nested_format_;
|
||||||
std::string Mqtt::discovery_prefix_;
|
std::string Mqtt::discovery_prefix_;
|
||||||
@@ -430,7 +430,7 @@ void Mqtt::load_settings() {
|
|||||||
publish_single2cmd_ = mqttSettings.publish_single2cmd;
|
publish_single2cmd_ = mqttSettings.publish_single2cmd;
|
||||||
send_response_ = mqttSettings.send_response;
|
send_response_ = mqttSettings.send_response;
|
||||||
discovery_prefix_ = mqttSettings.discovery_prefix.c_str();
|
discovery_prefix_ = mqttSettings.discovery_prefix.c_str();
|
||||||
multiple_instances_ = mqttSettings.multiple_instances;
|
entity_format_ = mqttSettings.entity_format;
|
||||||
|
|
||||||
// convert to milliseconds
|
// convert to milliseconds
|
||||||
publish_time_boiler_ = mqttSettings.publish_time_boiler * 1000;
|
publish_time_boiler_ = mqttSettings.publish_time_boiler * 1000;
|
||||||
@@ -609,7 +609,7 @@ void Mqtt::ha_status() {
|
|||||||
StaticJsonDocument<EMSESP_JSON_SIZE_HA_CONFIG> doc;
|
StaticJsonDocument<EMSESP_JSON_SIZE_HA_CONFIG> doc;
|
||||||
|
|
||||||
char uniq[70];
|
char uniq[70];
|
||||||
if (Mqtt::multiple_instances()) {
|
if (Mqtt::entity_format() == 2) {
|
||||||
snprintf(uniq, sizeof(uniq), "%s_system_status", mqtt_basename_.c_str());
|
snprintf(uniq, sizeof(uniq), "%s_system_status", mqtt_basename_.c_str());
|
||||||
} else {
|
} else {
|
||||||
strcpy(uniq, "system_status");
|
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
|
// build unique identifier also used as object_id and becomes the Entity ID in HA
|
||||||
char uniq_id[70];
|
char uniq_id[70];
|
||||||
if (Mqtt::multiple_instances()) {
|
if (Mqtt::entity_format() == 2) {
|
||||||
// prefix base name to each uniq_id and use the shortname
|
// 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);
|
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 {
|
} else {
|
||||||
|
// entity_format is 0
|
||||||
// old v3.4 style
|
// old v3.4 style
|
||||||
// take en_name and replace all spaces and lowercase it
|
// take en_name and replace all spaces and lowercase it
|
||||||
char uniq_s[40];
|
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);
|
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
|
snprintf(uniq_id_s, sizeof(uniq_id_s), "%s_thermostat_hc%d", mqtt_basename_.c_str(), hc_num); // add basename
|
||||||
} else {
|
} else {
|
||||||
snprintf(uniq_id_s, sizeof(uniq_id_s), "thermostat_hc%d", hc_num); // backward compatible with v3.4
|
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;
|
return nested_format_ == NestedFormat::NESTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool multiple_instances() {
|
static uint8_t entity_format() {
|
||||||
return multiple_instances_;
|
return entity_format_;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void nested_format(uint8_t nested_format) {
|
static void nested_format(uint8_t nested_format) {
|
||||||
@@ -322,7 +322,7 @@ class Mqtt {
|
|||||||
static bool mqtt_enabled_;
|
static bool mqtt_enabled_;
|
||||||
static bool ha_enabled_;
|
static bool ha_enabled_;
|
||||||
static uint8_t nested_format_;
|
static uint8_t nested_format_;
|
||||||
static bool multiple_instances_;
|
static uint8_t entity_format_;
|
||||||
static std::string discovery_prefix_;
|
static std::string discovery_prefix_;
|
||||||
static bool publish_single_;
|
static bool publish_single_;
|
||||||
static bool publish_single2cmd_;
|
static bool publish_single2cmd_;
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ void Shower::set_shower_state(bool state, bool force) {
|
|||||||
doc["name"] = "Shower Active";
|
doc["name"] = "Shower Active";
|
||||||
|
|
||||||
char str[70];
|
char str[70];
|
||||||
if (Mqtt::multiple_instances()) {
|
if (Mqtt::entity_format() == 2) {
|
||||||
snprintf(str, sizeof(str), "%s_shower_active", Mqtt::basename().c_str());
|
snprintf(str, sizeof(str), "%s_shower_active", Mqtt::basename().c_str());
|
||||||
} else {
|
} else {
|
||||||
snprintf(str, sizeof(str), "shower_active"); // v3.4 compatible
|
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["client id"] = settings.clientId;
|
||||||
node["keep alive"] = settings.keepAlive;
|
node["keep alive"] = settings.keepAlive;
|
||||||
node["clean session"] = settings.cleanSession;
|
node["clean session"] = settings.cleanSession;
|
||||||
node["multiple instances"] = settings.multiple_instances;
|
node["entity format"] = settings.entity_format;
|
||||||
node["base"] = settings.base;
|
node["base"] = settings.base;
|
||||||
node["discovery prefix"] = settings.discovery_prefix;
|
node["discovery prefix"] = settings.discovery_prefix;
|
||||||
node["nested format"] = settings.nested_format;
|
node["nested format"] = settings.nested_format;
|
||||||
|
|||||||
Reference in New Issue
Block a user