#759 add option to enable multiple instances to keep backward compatibllity with v3.4

This commit is contained in:
proddy
2022-12-05 21:33:10 +01:00
parent fd04f8be5a
commit 1af1a1863a
6 changed files with 53 additions and 24 deletions

View File

@@ -451,7 +451,12 @@ void AnalogSensor::publish_values(const bool force) {
}
config["val_tpl"] = str;
snprintf(str, sizeof(str), "%s_analogsensor_%d", Mqtt::basename().c_str(), sensor.gpio());
if (Mqtt::multiple_instances()) {
snprintf(str, sizeof(str), "%s_analogsensor_%d", Mqtt::basename().c_str(), sensor.gpio());
} else {
snprintf(str, sizeof(str), "analogsensor_%d", sensor.gpio());
}
config["object_id"] = str;
config["uniq_id"] = str; // same as object_id