mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-09-13 13:44:10 +00:00
do not rebuild all HA configs on a mqtt reconnect, limit by heap
This commit is contained in:
@@ -111,6 +111,12 @@ void AnalogSensor::start(const bool factory_settings) {
|
||||
Mqtt::subscribe(EMSdevice::DeviceType::ANALOGSENSOR, topic, nullptr); // use empty function callback
|
||||
}
|
||||
|
||||
void AnalogSensor::ha_reset() {
|
||||
for (const auto & sensor : sensors_) {
|
||||
remove_ha_topic(sensor.type(), sensor.gpio());
|
||||
}
|
||||
}
|
||||
|
||||
// load settings from the customization file, sorts them and initializes the GPIOs
|
||||
void AnalogSensor::reload(bool get_nvs) {
|
||||
exclude_types_.clear();
|
||||
|
||||
@@ -144,6 +144,7 @@ class AnalogSensor {
|
||||
void publish_values(const bool force);
|
||||
void reload(bool get_nvs = false);
|
||||
bool updated_values();
|
||||
void ha_reset();
|
||||
|
||||
// return back reference to the sensor list, used by other classes
|
||||
const std::vector<Sensor, AllocatorPSRAM<Sensor>> & sensors() const {
|
||||
|
||||
@@ -2207,7 +2207,7 @@ void EMSdevice::mqtt_ha_entity_config_create() {
|
||||
|
||||
#ifndef EMSESP_STANDALONE
|
||||
// always create minimum one config
|
||||
if (count && (heap_caps_get_free_size(MALLOC_CAP_8BIT) < 65 * 1024)) { // checks free Heap+PSRAM
|
||||
if (count && (heap_caps_get_free_size(MALLOC_CAP_INTERNAL) < 65 * 1024)) { // checks free Heap
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
+2
-2
@@ -657,8 +657,8 @@ void EMSESP::reset_mqtt_ha() {
|
||||
}
|
||||
|
||||
// force the re-creating of the temperature and analog sensor topics (for HA)
|
||||
temperaturesensor_.reload();
|
||||
analogsensor_.reload();
|
||||
temperaturesensor_.ha_reset();
|
||||
analogsensor_.ha_reset();
|
||||
|
||||
// rebuild MQTT HA config topics for shower, custom entities and scheduler
|
||||
shower_.ha_reset();
|
||||
|
||||
@@ -352,6 +352,7 @@ void Mqtt::reset_mqtt() {
|
||||
mqttClient_->disconnect(true); // force a disconnect
|
||||
}
|
||||
load_settings(); // reload MQTT settings
|
||||
connectcount_ = 0;
|
||||
}
|
||||
|
||||
// load the settings from service
|
||||
@@ -512,6 +513,7 @@ void Mqtt::on_connect() {
|
||||
connecting_ = true;
|
||||
queuecount_ = mqttClient_->queueSize();
|
||||
|
||||
if (connectcount_ == 0) { // only on first connect and after reconfigure, HA messages are reain
|
||||
if (ha_enabled_) {
|
||||
queue_unsubscribe_message(discovery_prefix_ + "/+/" + Mqtt::basename() + "/#");
|
||||
EMSESP::reset_mqtt_ha(); // re-create all HA devices if there are any
|
||||
@@ -524,6 +526,7 @@ void Mqtt::on_connect() {
|
||||
// disable HA, wait 5 minutes (to allow the broker to send all), than reenable HA again.
|
||||
queue_subscribe_message(discovery_prefix_ + "/+/" + Mqtt::basename() + "/#");
|
||||
}
|
||||
}
|
||||
|
||||
// re-subscribe to all custom registered MQTT topics
|
||||
resubscribe();
|
||||
|
||||
@@ -45,17 +45,20 @@ void TemperatureSensor::start(const bool factory_settings) {
|
||||
Mqtt::subscribe(EMSdevice::DeviceType::TEMPERATURESENSOR, topic, nullptr); // use empty function callback
|
||||
}
|
||||
|
||||
void TemperatureSensor::ha_reset() {
|
||||
for (auto & sensor : sensors_) {
|
||||
remove_ha_topic(sensor.id());
|
||||
sensor.ha_registered = false; // force HA configs to be re-created
|
||||
}
|
||||
}
|
||||
|
||||
// load settings
|
||||
void TemperatureSensor::reload() {
|
||||
EMSESP::webSettingsService.read([&](WebSettings const & settings) {
|
||||
dallas_gpio_ = settings.dallas_gpio;
|
||||
parasite_ = settings.dallas_parasite;
|
||||
});
|
||||
|
||||
for (auto & sensor : sensors_) {
|
||||
remove_ha_topic(sensor.id());
|
||||
sensor.ha_registered = false; // force HA configs to be re-created
|
||||
}
|
||||
ha_reset();
|
||||
}
|
||||
|
||||
void TemperatureSensor::loop() {
|
||||
|
||||
@@ -93,6 +93,7 @@ class TemperatureSensor {
|
||||
void publish_sensor(const Sensor & sensor);
|
||||
void publish_values(const bool force);
|
||||
void reload();
|
||||
void ha_reset();
|
||||
bool updated_values();
|
||||
bool get_value_info(JsonObject output, const char * cmd, const int8_t id = -1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user