mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
HA mqtt format multi with v3.6 compatiblity
This commit is contained in:
@@ -374,7 +374,12 @@ const MqttSettings: FC = () => {
|
||||
select
|
||||
>
|
||||
<MenuItem value={0}>{LL.MQTT_ENTITY_FORMAT_0()}</MenuItem>
|
||||
<MenuItem value={3}>{LL.MQTT_ENTITY_FORMAT_1()} (v3.6)</MenuItem>
|
||||
<MenuItem value={3}>
|
||||
{LL.MQTT_ENTITY_FORMAT_1()} (v3.6)
|
||||
</MenuItem>
|
||||
<MenuItem value={4}>
|
||||
{LL.MQTT_ENTITY_FORMAT_2()} (v3.6)
|
||||
</MenuItem>
|
||||
<MenuItem value={1}>{LL.MQTT_ENTITY_FORMAT_1()}</MenuItem>
|
||||
<MenuItem value={2}>{LL.MQTT_ENTITY_FORMAT_2()}</MenuItem>
|
||||
</TextField>
|
||||
|
||||
21
src/mqtt.cpp
21
src/mqtt.cpp
@@ -849,7 +849,8 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
|
||||
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) {
|
||||
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");
|
||||
@@ -861,6 +862,21 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
|
||||
} else {
|
||||
snprintf(uniq_id, sizeof(uniq_id), "%s_%s", device_name, entity_with_tag);
|
||||
}
|
||||
} else if (Mqtt::entity_format() == entityFormat::MULTI_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_%s_ww%s", mqtt_basename_.c_str(), device_name, entity);
|
||||
if (strcmp(entity, "nrgdhw") == 0) { // special case for tp1de #1714
|
||||
snprintf(uniq_id, sizeof(uniq_id), "%s_boiler_nrgww", mqtt_basename_.c_str());
|
||||
}
|
||||
} else if (has_tag && device_type == EMSdevice::DeviceType::WATER && tag >= DeviceValue::DeviceValueTAG::TAG_DHW3) {
|
||||
snprintf(uniq_id, sizeof(uniq_id), "%s_solar_wwc%d_%s", mqtt_basename_.c_str(), 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), "%s_mixer_wwc%d_%s", mqtt_basename_.c_str(), tag - DeviceValue::DeviceValueTAG::TAG_DHW1 + 1, entity);
|
||||
} else {
|
||||
snprintf(uniq_id, sizeof(uniq_id), "%s_%s_%s", mqtt_basename_.c_str(), device_name, entity_with_tag);
|
||||
}
|
||||
} else {
|
||||
// entity_format is 0, the old v3.4 style
|
||||
// take en_name and replace all spaces
|
||||
@@ -868,7 +884,8 @@ 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 && (device_type == EMSdevice::DeviceType::BOILER || device_type == EMSdevice::DeviceType::THERMOSTAT) && tag == DeviceValue::DeviceValueTAG::TAG_DHW1) {
|
||||
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());
|
||||
|
||||
@@ -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, SINGLE_OLD };
|
||||
enum entityFormat : uint8_t { SINGLE_LONG, SINGLE_SHORT, MULTI_SHORT, SINGLE_OLD, MULTI_OLD };
|
||||
|
||||
void loop();
|
||||
void start();
|
||||
|
||||
@@ -1154,13 +1154,18 @@ 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) {
|
||||
} 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;
|
||||
if (mqttSettings.entity_format == 1) {
|
||||
mqttSettings.entity_format = 3; // use old Entity ID format from v3.6
|
||||
return StateUpdateResult::CHANGED;
|
||||
} else if (mqttSettings.entity_format == 2) {
|
||||
mqttSettings.entity_format = 4; // use old Entity ID format from v3.6
|
||||
return StateUpdateResult::CHANGED;
|
||||
}
|
||||
return StateUpdateResult::UNCHANGED;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// Network Settings Wifi tx_power is now using the value * 4.
|
||||
|
||||
Reference in New Issue
Block a user