mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-09 01:09:51 +03:00
HA mqtt compatible setting
This commit is contained in:
22
src/mqtt.cpp
22
src/mqtt.cpp
@@ -847,6 +847,20 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
|
||||
} else if (Mqtt::entity_format() == entityFormat::SINGLE_SHORT) {
|
||||
// shortname, no mqtt base. This is the default version.
|
||||
snprintf(uniq_id, sizeof(uniq_id), "%s_%s", device_name, entity_with_tag);
|
||||
} else if (Mqtt::entity_format() == entityFormat::SINGLE_OLD) {
|
||||
// shortname, remap to 3.6.
|
||||
if (has_tag && (device_type == EMSdevice::DeviceType::BOILER || device_type == EMSdevice::DeviceType::THERMOSTAT) && tag == DeviceValue::DeviceValueTAG::TAG_DHW1) {
|
||||
snprintf(uniq_id, sizeof(uniq_id), "%s_ww%s", device_name, entity);
|
||||
if (strcmp(entity, "nrgdhw") == 0) { // special case for tp1de #1714
|
||||
strcpy(uniq_id, "boiler_nrgww");
|
||||
}
|
||||
} else if (has_tag && device_type == EMSdevice::DeviceType::WATER && tag >= DeviceValue::DeviceValueTAG::TAG_DHW3) {
|
||||
snprintf(uniq_id, sizeof(uniq_id), "solar_wwc%d_%s", tag - DeviceValue::DeviceValueTAG::TAG_DHW1 + 1, entity);
|
||||
} else if (has_tag && device_type == EMSdevice::DeviceType::WATER && tag >= DeviceValue::DeviceValueTAG::TAG_DHW1) {
|
||||
snprintf(uniq_id, sizeof(uniq_id), "mixer_wwc%d_%s", tag - DeviceValue::DeviceValueTAG::TAG_DHW1 + 1, entity);
|
||||
} else {
|
||||
snprintf(uniq_id, sizeof(uniq_id), "%s_%s", device_name, entity_with_tag);
|
||||
}
|
||||
} else {
|
||||
// entity_format is 0, the old v3.4 style
|
||||
// take en_name and replace all spaces
|
||||
@@ -854,7 +868,13 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
|
||||
strlcpy(uniq_s, en_name, sizeof(uniq_s));
|
||||
Helpers::replace_char(uniq_s, ' ', '_');
|
||||
Helpers::replace_char(uniq_s, '+', '2'); //changes 'eco+_switch_off' to 'eco2_switch_off' (HA ignores '+')
|
||||
if (has_tag) {
|
||||
if (has_tag && (device_type == EMSdevice::DeviceType::BOILER || device_type == EMSdevice::DeviceType::THERMOSTAT) && tag == DeviceValue::DeviceValueTAG::TAG_DHW1) {
|
||||
snprintf(uniq_id, sizeof(uniq_id), "%s_%s", device_name, Helpers::toLower(uniq_s).c_str());
|
||||
} else if (has_tag && device_type == EMSdevice::DeviceType::WATER && tag >= DeviceValue::DeviceValueTAG::TAG_DHW3) {
|
||||
snprintf(uniq_id, sizeof(uniq_id), "solar_wwc%d_%s", tag - DeviceValue::DeviceValueTAG::TAG_DHW1 + 1, Helpers::toLower(uniq_s).c_str());
|
||||
} else if (has_tag && device_type == EMSdevice::DeviceType::WATER && tag >= DeviceValue::DeviceValueTAG::TAG_DHW1) {
|
||||
snprintf(uniq_id, sizeof(uniq_id), "mixer_wwc%d_%s", tag - DeviceValue::DeviceValueTAG::TAG_DHW1 + 1, Helpers::toLower(uniq_s).c_str());
|
||||
} else if (has_tag) {
|
||||
snprintf(uniq_id, sizeof(uniq_id), "%s_%s_%s", device_name, DeviceValue::DeviceValueTAG_s[tag][0], Helpers::toLower(uniq_s).c_str());
|
||||
} else {
|
||||
snprintf(uniq_id, sizeof(uniq_id), "%s_%s", device_name, Helpers::toLower(uniq_s).c_str());
|
||||
|
||||
@@ -36,7 +36,7 @@ using mqtt_sub_function_p = std::function<bool(const char * message)>;
|
||||
class Mqtt {
|
||||
public:
|
||||
enum discoveryType : uint8_t { HOMEASSISTANT, DOMOTICZ, DOMOTICZ_LATEST };
|
||||
enum entityFormat : uint8_t { SINGLE_LONG, SINGLE_SHORT, MULTI_SHORT };
|
||||
enum entityFormat : uint8_t { SINGLE_LONG, SINGLE_SHORT, MULTI_SHORT, SINGLE_OLD };
|
||||
|
||||
void loop();
|
||||
void start();
|
||||
|
||||
@@ -1120,7 +1120,7 @@ bool System::check_upgrade(bool factory_settings) {
|
||||
missing_version = (settingsVersion.empty() || (settingsVersion.length() < 5));
|
||||
if (missing_version) {
|
||||
LOG_WARNING("No version information found (%s)", settingsVersion.c_str());
|
||||
settingsVersion = "3.6.4"; // this was the last stable version
|
||||
settingsVersion = "3.5.0"; // this was the last stable version without version info
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1154,6 +1154,13 @@ bool System::check_upgrade(bool factory_settings) {
|
||||
mqttSettings.entity_format = 0; // use old Entity ID format from v3.4
|
||||
return StateUpdateResult::CHANGED;
|
||||
});
|
||||
} else if (settings_version.major()== 3 && settings_version.minor() <= 6) {
|
||||
LOG_INFO("Setting MQTT Entity ID format to v3.6 format");
|
||||
EMSESP::esp8266React.getMqttSettingsService()->update([&](MqttSettings & mqttSettings) {
|
||||
mqttSettings.entity_format = 3; // use old Entity ID format from v3.6
|
||||
return StateUpdateResult::CHANGED;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// Network Settings Wifi tx_power is now using the value * 4.
|
||||
|
||||
@@ -1 +1 @@
|
||||
#define EMSESP_APP_VERSION "3.7.0-dev.4"
|
||||
#define EMSESP_APP_VERSION "3.7.0-dev.5"
|
||||
|
||||
Reference in New Issue
Block a user