mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
merge multiple_instances with entity_format
This commit is contained in:
@@ -170,6 +170,7 @@ const MqttSettingsForm: FC = () => {
|
|||||||
control={<Checkbox name="mqtt_retain" checked={data.mqtt_retain} onChange={updateFormValue} />}
|
control={<Checkbox name="mqtt_retain" checked={data.mqtt_retain} onChange={updateFormValue} />}
|
||||||
label={LL.MQTT_RETAIN_FLAG()}
|
label={LL.MQTT_RETAIN_FLAG()}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Typography sx={{ pt: 2 }} variant="h6" color="primary">
|
<Typography sx={{ pt: 2 }} variant="h6" color="primary">
|
||||||
{LL.FORMATTING()}
|
{LL.FORMATTING()}
|
||||||
</Typography>
|
</Typography>
|
||||||
@@ -214,34 +215,15 @@ const MqttSettingsForm: FC = () => {
|
|||||||
<Grid container spacing={1} direction="row" justifyContent="flex-start" alignItems="flex-start">
|
<Grid container spacing={1} direction="row" justifyContent="flex-start" alignItems="flex-start">
|
||||||
<Grid item>
|
<Grid item>
|
||||||
<BlockFormControlLabel
|
<BlockFormControlLabel
|
||||||
sx={{ pb: 2 }}
|
sx={{ pb: 1 }}
|
||||||
control={<Checkbox name="ha_enabled" checked={data.ha_enabled} onChange={updateFormValue} />}
|
control={<Checkbox name="ha_enabled" checked={data.ha_enabled} onChange={updateFormValue} />}
|
||||||
label={LL.MQTT_PUBLISH_TEXT_3()}
|
label={LL.MQTT_PUBLISH_TEXT_3()}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
{data.ha_enabled && (
|
{data.ha_enabled && (
|
||||||
<>
|
<>
|
||||||
|
<Grid container spacing={1} direction="row" justifyContent="flex-start" alignItems="flex-start">
|
||||||
<Grid item>
|
<Grid item>
|
||||||
<BlockFormControlLabel
|
|
||||||
control={
|
|
||||||
<Checkbox
|
|
||||||
name="multiple_instances"
|
|
||||||
checked={data.multiple_instances}
|
|
||||||
onChange={updateFormValue}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
label={LL.MQTT_MULTIPLE_INSTANCES()}
|
|
||||||
/>
|
|
||||||
</Grid>
|
|
||||||
<Grid item>
|
|
||||||
<BlockFormControlLabel
|
|
||||||
control={
|
|
||||||
<Checkbox name="entity_fullname" checked={data.entity_fullname} onChange={updateFormValue} />
|
|
||||||
}
|
|
||||||
label={LL.MQTT_ENTITY_FULLNAME()}
|
|
||||||
/>
|
|
||||||
</Grid>
|
|
||||||
<Grid item sx={{ pb: 3 }}>
|
|
||||||
<ValidatedTextField
|
<ValidatedTextField
|
||||||
name="discovery_prefix"
|
name="discovery_prefix"
|
||||||
label={LL.MQTT_PUBLISH_TEXT_4()}
|
label={LL.MQTT_PUBLISH_TEXT_4()}
|
||||||
@@ -249,14 +231,30 @@ const MqttSettingsForm: FC = () => {
|
|||||||
variant="outlined"
|
variant="outlined"
|
||||||
value={data.discovery_prefix}
|
value={data.discovery_prefix}
|
||||||
onChange={updateFormValue}
|
onChange={updateFormValue}
|
||||||
size="small"
|
margin="normal"
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
<Grid item>
|
||||||
|
<ValidatedTextField
|
||||||
|
name="multiple_instances"
|
||||||
|
label={LL.MQTT_ENTITY_FORMAT()}
|
||||||
|
value={data.multiple_instances}
|
||||||
|
fullWidth
|
||||||
|
variant="outlined"
|
||||||
|
onChange={updateFormValue}
|
||||||
|
margin="normal"
|
||||||
|
select
|
||||||
|
>
|
||||||
|
<MenuItem value="false">{LL.MQTT_ENTITY_FORMAT_0()}</MenuItem>
|
||||||
|
<MenuItem value="true">{LL.MQTT_ENTITY_FORMAT_1()}</MenuItem>
|
||||||
|
</ValidatedTextField>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Grid>
|
</Grid>
|
||||||
)}
|
)}
|
||||||
<Typography variant="h6" color="primary">
|
<Typography sx={{ pt: 2 }} variant="h6" color="primary">
|
||||||
{LL.MQTT_PUBLISH_INTERVALS()} (0=auto)
|
{LL.MQTT_PUBLISH_INTERVALS()} (0=auto)
|
||||||
</Typography>
|
</Typography>
|
||||||
<Grid container spacing={1} direction="row" justifyContent="flex-start" alignItems="flex-start">
|
<Grid container spacing={1} direction="row" justifyContent="flex-start" alignItems="flex-start">
|
||||||
|
|||||||
@@ -249,8 +249,9 @@ const de: Translation = {
|
|||||||
MQTT_INT_HEARTBEAT: 'Heartbeat',
|
MQTT_INT_HEARTBEAT: 'Heartbeat',
|
||||||
MQTT_QUEUE: 'MQTT Queue',
|
MQTT_QUEUE: 'MQTT Queue',
|
||||||
DEFAULT: 'Standard',
|
DEFAULT: 'Standard',
|
||||||
MQTT_MULTIPLE_INSTANCES: 'Erlaube EMS-ESP Mehrfachinstanzen',
|
MQTT_ENTITY_FORMAT: 'Entity ID format',
|
||||||
MQTT_ENTITY_FULLNAME: 'Use v3.4 style Entity IDs',
|
MQTT_ENTITY_FORMAT_0: 'Single instance, long name',
|
||||||
|
MQTT_ENTITY_FORMAT_1: 'Multiple instances, short name',
|
||||||
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',
|
||||||
|
|||||||
@@ -248,8 +248,9 @@ const en: Translation = {
|
|||||||
MQTT_INT_HEARTBEAT: 'Heartbeat',
|
MQTT_INT_HEARTBEAT: 'Heartbeat',
|
||||||
MQTT_QUEUE: 'MQTT Queue',
|
MQTT_QUEUE: 'MQTT Queue',
|
||||||
DEFAULT: 'Default',
|
DEFAULT: 'Default',
|
||||||
MQTT_MULTIPLE_INSTANCES: 'Enable Multiple Instances of EMS-ESP',
|
MQTT_ENTITY_FORMAT: 'Entity ID format',
|
||||||
MQTT_ENTITY_FULLNAME: 'Use v3.4 style Entity IDs',
|
MQTT_ENTITY_FORMAT_0: 'Single instance, long name',
|
||||||
|
MQTT_ENTITY_FORMAT_1: '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',
|
||||||
|
|||||||
@@ -248,8 +248,9 @@ const nl: Translation = {
|
|||||||
MQTT_INT_HEARTBEAT: 'Heartbeat',
|
MQTT_INT_HEARTBEAT: 'Heartbeat',
|
||||||
MQTT_QUEUE: 'MQTT Queue',
|
MQTT_QUEUE: 'MQTT Queue',
|
||||||
DEFAULT: 'Default',
|
DEFAULT: 'Default',
|
||||||
MQTT_MULTIPLE_INSTANCES: 'Enable Multiple Instances of EMS-ESP',
|
MQTT_ENTITY_FORMAT: 'Entity ID format',
|
||||||
MQTT_ENTITY_FULLNAME: 'Use v3.4 style Entity IDs',
|
MQTT_ENTITY_FORMAT_0: 'Single instance, long name',
|
||||||
|
MQTT_ENTITY_FORMAT_1: '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',
|
||||||
|
|||||||
@@ -248,8 +248,9 @@ const no: Translation = {
|
|||||||
MQTT_INT_HEARTBEAT: 'Heartbeat',
|
MQTT_INT_HEARTBEAT: 'Heartbeat',
|
||||||
MQTT_QUEUE: 'MQTT Queue',
|
MQTT_QUEUE: 'MQTT Queue',
|
||||||
DEFAULT: 'Standard',
|
DEFAULT: 'Standard',
|
||||||
MQTT_MULTIPLE_INSTANCES: 'Enable Multiple Instances of EMS-ESP',
|
MQTT_ENTITY_FORMAT: 'Entity ID format',
|
||||||
MQTT_ENTITY_FULLNAME: 'Use v3.4 style Entity IDs',
|
MQTT_ENTITY_FORMAT_0: 'Single instance, long name',
|
||||||
|
MQTT_ENTITY_FORMAT_1: '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',
|
||||||
|
|||||||
@@ -248,8 +248,9 @@ const pl: BaseTranslation = {
|
|||||||
MQTT_INT_HEARTBEAT: 'Heartbeat',
|
MQTT_INT_HEARTBEAT: 'Heartbeat',
|
||||||
MQTT_QUEUE: 'Kolejka MQTT',
|
MQTT_QUEUE: 'Kolejka MQTT',
|
||||||
DEFAULT: '{{Pozostałe|Domyślna|}}',
|
DEFAULT: '{{Pozostałe|Domyślna|}}',
|
||||||
MQTT_MULTIPLE_INSTANCES: 'Enable Multiple Instances of EMS-ESP',
|
MQTT_ENTITY_FORMAT: 'Entity ID format',
|
||||||
MQTT_ENTITY_FULLNAME: 'Use v3.4 style Entity IDs',
|
MQTT_ENTITY_FORMAT_0: 'Single instance, long name',
|
||||||
|
MQTT_ENTITY_FORMAT_1: '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',
|
||||||
|
|||||||
@@ -248,8 +248,9 @@ const se: Translation = {
|
|||||||
MQTT_INT_HEARTBEAT: 'Heartbeat',
|
MQTT_INT_HEARTBEAT: 'Heartbeat',
|
||||||
MQTT_QUEUE: 'MQTT Queue',
|
MQTT_QUEUE: 'MQTT Queue',
|
||||||
DEFAULT: 'Standard',
|
DEFAULT: 'Standard',
|
||||||
MQTT_MULTIPLE_INSTANCES: 'Enable Multiple Instances of EMS-ESP',
|
MQTT_ENTITY_FORMAT: 'Entity ID format',
|
||||||
MQTT_ENTITY_FULLNAME: 'Use v3.4 style Entity IDs',
|
MQTT_ENTITY_FORMAT_0: 'Single instance, long name',
|
||||||
|
MQTT_ENTITY_FORMAT_1: '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',
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ export interface MqttSettings {
|
|||||||
keep_alive: number;
|
keep_alive: number;
|
||||||
clean_session: boolean;
|
clean_session: boolean;
|
||||||
multiple_instances: boolean;
|
multiple_instances: boolean;
|
||||||
entity_fullname: boolean;
|
|
||||||
publish_time_boiler: number;
|
publish_time_boiler: number;
|
||||||
publish_time_thermostat: number;
|
publish_time_thermostat: number;
|
||||||
publish_time_solar: number;
|
publish_time_solar: number;
|
||||||
|
|||||||
@@ -155,7 +155,6 @@ void MqttSettings::read(MqttSettings & settings, JsonObject & root) {
|
|||||||
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["multiple_instances"] = settings.multiple_instances;
|
||||||
root["entity_fullname"] = settings.entity_fullname;
|
|
||||||
|
|
||||||
// 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;
|
||||||
@@ -189,7 +188,6 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting
|
|||||||
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.multiple_instances = root["multiple_instances"] | FACTORY_MQTT_MULTIPLE_INSTANCES;
|
||||||
newSettings.entity_fullname = root["entity_fullname"] | FACTORY_MQTT_ENTITY_FULLNAME;
|
|
||||||
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;
|
||||||
|
|
||||||
|
|||||||
@@ -61,10 +61,6 @@ static String generateClientId() {
|
|||||||
#define FACTORY_MQTT_MULTIPLE_INSTANCES false
|
#define FACTORY_MQTT_MULTIPLE_INSTANCES false
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FACTORY_MQTT_ENTITY_FULLNAME
|
|
||||||
#define FACTORY_MQTT_ENTITY_FULLNAME false
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class MqttSettings {
|
class MqttSettings {
|
||||||
public:
|
public:
|
||||||
// host and port - if enabled
|
// host and port - if enabled
|
||||||
@@ -86,9 +82,6 @@ class MqttSettings {
|
|||||||
// multiple instances
|
// multiple instances
|
||||||
bool multiple_instances;
|
bool multiple_instances;
|
||||||
|
|
||||||
// use v3.4 entity fullnames in Discovery
|
|
||||||
bool entity_fullname;
|
|
||||||
|
|
||||||
// proddy EMS-ESP specific
|
// proddy EMS-ESP specific
|
||||||
String base;
|
String base;
|
||||||
uint16_t publish_time_boiler;
|
uint16_t publish_time_boiler;
|
||||||
|
|||||||
@@ -82,7 +82,6 @@ class DummySettings {
|
|||||||
uint16_t keepAlive = 60;
|
uint16_t keepAlive = 60;
|
||||||
bool cleanSession = false;
|
bool cleanSession = false;
|
||||||
bool multiple_instances = false;
|
bool multiple_instances = false;
|
||||||
bool entity_fullname = false;
|
|
||||||
|
|
||||||
uint16_t publish_time_boiler = 10;
|
uint16_t publish_time_boiler = 10;
|
||||||
uint16_t publish_time_thermostat = 10;
|
uint16_t publish_time_thermostat = 10;
|
||||||
|
|||||||
@@ -224,7 +224,6 @@ mqtt_settings = {
|
|||||||
keep_alive: 60,
|
keep_alive: 60,
|
||||||
clean_session: true,
|
clean_session: true,
|
||||||
multiple_instances: false,
|
multiple_instances: false,
|
||||||
entity_fullname: false,
|
|
||||||
publish_time_boiler: 10,
|
publish_time_boiler: 10,
|
||||||
publish_time_thermostat: 10,
|
publish_time_thermostat: 10,
|
||||||
publish_time_solar: 10,
|
publish_time_solar: 10,
|
||||||
|
|||||||
16
src/mqtt.cpp
16
src/mqtt.cpp
@@ -39,7 +39,6 @@ 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_;
|
bool Mqtt::multiple_instances_;
|
||||||
bool Mqtt::entity_fullname_;
|
|
||||||
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_;
|
||||||
@@ -432,7 +431,6 @@ void Mqtt::load_settings() {
|
|||||||
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;
|
multiple_instances_ = mqttSettings.multiple_instances;
|
||||||
entity_fullname_ = mqttSettings.entity_fullname;
|
|
||||||
|
|
||||||
// convert to milliseconds
|
// convert to milliseconds
|
||||||
publish_time_boiler_ = mqttSettings.publish_time_boiler * 1000;
|
publish_time_boiler_ = mqttSettings.publish_time_boiler * 1000;
|
||||||
@@ -993,18 +991,12 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
|
|||||||
|
|
||||||
// build unique identifier which will be used in the topic, also used as object_id
|
// build unique identifier which will be used in the topic, also used as object_id
|
||||||
char uniq_id[70];
|
char uniq_id[70];
|
||||||
char entityid[50];
|
|
||||||
if (Mqtt::entity_fullname()) {
|
|
||||||
strlcpy(entityid, en_name, sizeof(entityid)); // old v3.4 style
|
|
||||||
} else {
|
|
||||||
strlcpy(entityid, entity_with_tag, sizeof(entityid));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Mqtt::multiple_instances()) {
|
if (Mqtt::multiple_instances()) {
|
||||||
// prefix base name to each uniq_id
|
// 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, entityid);
|
snprintf(uniq_id, sizeof(uniq_id), "%s_%s_%s", mqtt_basename_.c_str(), device_name, entity_with_tag);
|
||||||
} else {
|
} else {
|
||||||
snprintf(uniq_id, sizeof(uniq_id), "%s_%s", device_name, entityid);
|
// old v3.4 style
|
||||||
|
snprintf(uniq_id, sizeof(uniq_id), "%s_%s", device_name, en_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// build a config topic that will be prefix onto a HA type (e.g. number, switch)
|
// build a config topic that will be prefix onto a HA type (e.g. number, switch)
|
||||||
|
|||||||
@@ -185,10 +185,6 @@ class Mqtt {
|
|||||||
return multiple_instances_;
|
return multiple_instances_;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool entity_fullname() {
|
|
||||||
return entity_fullname_;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void nested_format(uint8_t nested_format) {
|
static void nested_format(uint8_t nested_format) {
|
||||||
nested_format_ = nested_format;
|
nested_format_ = nested_format;
|
||||||
}
|
}
|
||||||
@@ -327,7 +323,6 @@ class Mqtt {
|
|||||||
static bool ha_enabled_;
|
static bool ha_enabled_;
|
||||||
static uint8_t nested_format_;
|
static uint8_t nested_format_;
|
||||||
static bool multiple_instances_;
|
static bool multiple_instances_;
|
||||||
static bool entity_fullname_;
|
|
||||||
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_;
|
||||||
|
|||||||
@@ -1153,7 +1153,6 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp
|
|||||||
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["multiple instances"] = settings.multiple_instances;
|
||||||
node["entity fullname"] = settings.entity_fullname;
|
|
||||||
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