Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/emsesp/EMS-ESP32 into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDvP committed Dec 18, 2022
2 parents eb30c1e + 17cbd26 commit d70b5d7
Show file tree
Hide file tree
Showing 19 changed files with 71 additions and 59 deletions.
9 changes: 5 additions & 4 deletions interface/src/framework/mqtt/MqttSettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,17 +236,18 @@ const MqttSettingsForm: FC = () => {
</Grid>
<Grid item>
<ValidatedTextField
name="multiple_instances"
name="entity_format"
label={LL.MQTT_ENTITY_FORMAT()}
value={data.multiple_instances}
value={data.entity_format}
fullWidth
variant="outlined"
onChange={updateFormValue}
margin="normal"
select
>
<MenuItem value={false as any}>{LL.MQTT_ENTITY_FORMAT_0()}</MenuItem>
<MenuItem value={true as any}>{LL.MQTT_ENTITY_FORMAT_1()}</MenuItem>
<MenuItem value={0}>{LL.MQTT_ENTITY_FORMAT_0()}</MenuItem>
<MenuItem value={1}>{LL.MQTT_ENTITY_FORMAT_1()}</MenuItem>
<MenuItem value={2}>{LL.MQTT_ENTITY_FORMAT_2()}</MenuItem>
</ValidatedTextField>
</Grid>
</Grid>
Expand Down
5 changes: 3 additions & 2 deletions interface/src/i18n/de/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,9 @@ const de: Translation = {
MQTT_QUEUE: 'MQTT Queue',
DEFAULT: 'Standard',
MQTT_ENTITY_FORMAT: 'Entitäts-ID Format',
MQTT_ENTITY_FORMAT_0: 'Einzelinstanz, Langname (veraltet)',
MQTT_ENTITY_FORMAT_1: 'Mehrfachinstanzen, MQTT-Namen',
MQTT_ENTITY_FORMAT_0: 'Einzelinstanz, Langname (v3.4)',
MQTT_ENTITY_FORMAT_1: 'Einzelinstanz, MQTT-Namen',
MQTT_ENTITY_FORMAT_2: 'Mehrfachinstanzen, MQTT-Namen',
MQTT_CLEAN_SESSION: 'Setze `Clean Session`',
MQTT_RETAIN_FLAG: 'Setze `Retain flag` immer',
INACTIVE: 'Inaktiv',
Expand Down
5 changes: 3 additions & 2 deletions interface/src/i18n/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,9 @@ const en: Translation = {
MQTT_QUEUE: 'MQTT Queue',
DEFAULT: 'Default',
MQTT_ENTITY_FORMAT: 'Entity ID format',
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (depreciated)',
MQTT_ENTITY_FORMAT_1: 'Multiple instances, short name',
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)',
MQTT_ENTITY_FORMAT_1: 'Single instance, short name',
MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name',
MQTT_CLEAN_SESSION: 'Set Clean Session',
MQTT_RETAIN_FLAG: 'Always set Retain flag',
INACTIVE: 'Inactive',
Expand Down
5 changes: 3 additions & 2 deletions interface/src/i18n/fr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,9 @@ const fr: Translation = {
MQTT_QUEUE: 'Queue MQTT',
DEFAULT: 'Défaut',
MQTT_ENTITY_FORMAT: 'Entity ID format',
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (depreciated)',
MQTT_ENTITY_FORMAT_1: 'Multiple instances, short name',
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)',
MQTT_ENTITY_FORMAT_1: 'Single instance, short name',
MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name',
MQTT_CLEAN_SESSION: 'Flag Clean Session',
MQTT_RETAIN_FLAG: 'Toujours activer le Retain Flag',
INACTIVE: 'Inactif',
Expand Down
5 changes: 3 additions & 2 deletions interface/src/i18n/nl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,9 @@ const nl: Translation = {
MQTT_QUEUE: 'MQTT Queue',
DEFAULT: 'Default',
MQTT_ENTITY_FORMAT: 'Entity ID format',
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (depreciated)',
MQTT_ENTITY_FORMAT_1: 'Multiple instances, short name',
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)',
MQTT_ENTITY_FORMAT_1: 'Single instance, short name',
MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name',
MQTT_CLEAN_SESSION: 'Clean Session aan',
MQTT_RETAIN_FLAG: 'Retain flag aan',
INACTIVE: 'Inactief',
Expand Down
5 changes: 3 additions & 2 deletions interface/src/i18n/no/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,9 @@ const no: Translation = {
MQTT_QUEUE: 'MQTT Queue',
DEFAULT: 'Standard',
MQTT_ENTITY_FORMAT: 'Entity ID format',
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (depreciated)',
MQTT_ENTITY_FORMAT_1: 'Multiple instances, short name',
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)',
MQTT_ENTITY_FORMAT_1: 'Single instance, short name',
MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name',
MQTT_CLEAN_SESSION: 'Benytt Clean Session',
MQTT_RETAIN_FLAG: 'Alltid sett Retain flag',
INACTIVE: 'Innaktiv',
Expand Down
5 changes: 3 additions & 2 deletions interface/src/i18n/pl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,9 @@ const pl: BaseTranslation = {
MQTT_QUEUE: 'Kolejka MQTT',
DEFAULT: '{{Pozostałe|Domyślna|}}',
MQTT_ENTITY_FORMAT: 'Entity ID format',
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (depreciated)',
MQTT_ENTITY_FORMAT_1: 'Multiple instances, short name',
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)',
MQTT_ENTITY_FORMAT_1: 'Single instance, short name',
MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name',
MQTT_CLEAN_SESSION: 'Ustawiaj flagę "Clean session"',
MQTT_RETAIN_FLAG: 'Ustawiaj flagę "Retain"',
INACTIVE: 'nieaktywny',
Expand Down
5 changes: 3 additions & 2 deletions interface/src/i18n/se/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,9 @@ const se: Translation = {
MQTT_QUEUE: 'MQTT Queue',
DEFAULT: 'Standard',
MQTT_ENTITY_FORMAT: 'Entity ID format',
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (depreciated)',
MQTT_ENTITY_FORMAT_1: 'Multiple instances, short name',
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)',
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_RETAIN_FLAG: 'Använd "Always Retain"-flaggan',
INACTIVE: 'Inaktiv',
Expand Down
2 changes: 1 addition & 1 deletion interface/src/types/mqtt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface MqttSettings {
client_id: string;
keep_alive: number;
clean_session: boolean;
multiple_instances: boolean;
entity_format: number;
publish_time_boiler: number;
publish_time_thermostat: number;
publish_time_solar: number;
Expand Down
46 changes: 23 additions & 23 deletions lib/framework/MqttSettingsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,16 @@ void MqttSettingsService::configureMqtt() {
}

void MqttSettings::read(MqttSettings & settings, JsonObject & root) {
root["enabled"] = settings.enabled;
root["host"] = settings.host;
root["port"] = settings.port;
root["base"] = settings.base;
root["username"] = settings.username;
root["password"] = settings.password;
root["client_id"] = settings.clientId;
root["keep_alive"] = settings.keepAlive;
root["clean_session"] = settings.cleanSession;
root["multiple_instances"] = settings.multiple_instances;
root["enabled"] = settings.enabled;
root["host"] = settings.host;
root["port"] = settings.port;
root["base"] = settings.base;
root["username"] = settings.username;
root["password"] = settings.password;
root["client_id"] = settings.clientId;
root["keep_alive"] = settings.keepAlive;
root["clean_session"] = settings.cleanSession;
root["entity_format"] = settings.entity_format;

// added by proddy for EMS-ESP
root["publish_time_boiler"] = settings.publish_time_boiler;
Expand All @@ -178,18 +178,18 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting
MqttSettings newSettings = {};
bool changed = false;

newSettings.enabled = root["enabled"] | FACTORY_MQTT_ENABLED;
newSettings.host = root["host"] | FACTORY_MQTT_HOST;
newSettings.port = root["port"] | FACTORY_MQTT_PORT;
newSettings.base = root["base"] | FACTORY_MQTT_BASE;
newSettings.username = root["username"] | FACTORY_MQTT_USERNAME;
newSettings.password = root["password"] | FACTORY_MQTT_PASSWORD;
newSettings.clientId = root["client_id"] | FACTORY_MQTT_CLIENT_ID;
newSettings.keepAlive = root["keep_alive"] | FACTORY_MQTT_KEEP_ALIVE;
newSettings.cleanSession = root["clean_session"] | FACTORY_MQTT_CLEAN_SESSION;
newSettings.multiple_instances = root["multiple_instances"] | FACTORY_MQTT_MULTIPLE_INSTANCES;
newSettings.mqtt_qos = root["mqtt_qos"] | EMSESP_DEFAULT_MQTT_QOS;
newSettings.mqtt_retain = root["mqtt_retain"] | EMSESP_DEFAULT_MQTT_RETAIN;
newSettings.enabled = root["enabled"] | FACTORY_MQTT_ENABLED;
newSettings.host = root["host"] | FACTORY_MQTT_HOST;
newSettings.port = root["port"] | FACTORY_MQTT_PORT;
newSettings.base = root["base"] | FACTORY_MQTT_BASE;
newSettings.username = root["username"] | FACTORY_MQTT_USERNAME;
newSettings.password = root["password"] | FACTORY_MQTT_PASSWORD;
newSettings.clientId = root["client_id"] | FACTORY_MQTT_CLIENT_ID;
newSettings.keepAlive = root["keep_alive"] | FACTORY_MQTT_KEEP_ALIVE;
newSettings.cleanSession = root["clean_session"] | FACTORY_MQTT_CLEAN_SESSION;
newSettings.entity_format = root["entity_format"] | FACTORY_MQTT_ENTITY_FORMAT;
newSettings.mqtt_qos = root["mqtt_qos"] | EMSESP_DEFAULT_MQTT_QOS;
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_thermostat = root["publish_time_thermostat"] | EMSESP_DEFAULT_PUBLISH_TIME;
Expand Down Expand Up @@ -223,7 +223,7 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting
changed = true;
}

if (newSettings.multiple_instances != settings.multiple_instances) {
if (newSettings.entity_format != settings.entity_format) {
changed = true;
}

Expand Down
6 changes: 3 additions & 3 deletions lib/framework/MqttSettingsService.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ static String generateClientId() {
#define FACTORY_MQTT_MAX_TOPIC_LENGTH 128
#endif

#ifndef FACTORY_MQTT_MULTIPLE_INSTANCES
#define FACTORY_MQTT_MULTIPLE_INSTANCES true
#ifndef FACTORY_MQTT_ENTITY_FORMAT
#define FACTORY_MQTT_ENTITY_FORMAT 1 // use shortnames
#endif

class MqttSettings {
Expand All @@ -80,7 +80,7 @@ class MqttSettings {
bool cleanSession;

// multiple instances
bool multiple_instances;
uint8_t entity_format;

// proddy EMS-ESP specific
String base;
Expand Down
2 changes: 1 addition & 1 deletion lib_standalone/ESP8266React.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class DummySettings {
String username = "";
uint16_t keepAlive = 60;
bool cleanSession = false;
bool multiple_instances = false;
uint8_t entity_format = 1;

uint16_t publish_time_boiler = 10;
uint16_t publish_time_thermostat = 10;
Expand Down
2 changes: 1 addition & 1 deletion mock-api/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ mqtt_settings = {
client_id: 'ems-esp',
keep_alive: 60,
clean_session: true,
multiple_instances: true,
entity_format: 1,
publish_time_boiler: 10,
publish_time_thermostat: 10,
publish_time_solar: 10,
Expand Down
2 changes: 1 addition & 1 deletion src/analogsensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/dallassensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
14 changes: 9 additions & 5 deletions src/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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_;
Expand Down
2 changes: 1 addition & 1 deletion src/shower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d70b5d7

Please sign in to comment.