Skip to content

Commit b28865a

Browse files
committed
use only espMqttClient queue
1 parent d2ff44e commit b28865a

File tree

5 files changed

+125
-363
lines changed

5 files changed

+125
-363
lines changed

lib/espMqttClient/src/MqttClient.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -707,9 +707,7 @@ uint16_t MqttClient::getQueue() const {
707707
espMqttClientInternals::Outbox<OutgoingPacket>::Iterator it = _outbox.front();
708708
uint16_t count = 0;
709709
while (it) {
710-
if (it.get()->packet.packetType() == PacketType.PUBLISH) {
711-
++count;
712-
}
710+
++count;
713711
++it;
714712
}
715713
EMC_SEMAPHORE_GIVE();

src/emsdevice.cpp

+12-9
Original file line numberDiff line numberDiff line change
@@ -1689,23 +1689,26 @@ void EMSdevice::mqtt_ha_entity_config_create() {
16891689
for (auto & dv : devicevalues_) {
16901690
if (!strcmp(dv.short_name, FL_(haclimate)[0]) && !dv.has_state(DeviceValueState::DV_API_MQTT_EXCLUDE) && dv.has_state(DeviceValueState::DV_ACTIVE)) {
16911691
if (*(int8_t *)(dv.value_p) == 1 && (!dv.has_state(DeviceValueState::DV_HA_CONFIG_CREATED) || dv.has_state(DeviceValueState::DV_HA_CLIMATE_NO_RT))) {
1692-
dv.remove_state(DeviceValueState::DV_HA_CLIMATE_NO_RT);
1693-
dv.add_state(DeviceValueState::DV_HA_CONFIG_CREATED);
1694-
Mqtt::publish_ha_climate_config(dv.tag, true, false, dv.min, dv.max); // roomTemp
1692+
if (Mqtt::publish_ha_climate_config(dv.tag, true, false, dv.min, dv.max)) { // roomTemp
1693+
dv.remove_state(DeviceValueState::DV_HA_CLIMATE_NO_RT);
1694+
dv.add_state(DeviceValueState::DV_HA_CONFIG_CREATED);
1695+
}
16951696
} else if (*(int8_t *)(dv.value_p) == 0
16961697
&& (!dv.has_state(DeviceValueState::DV_HA_CONFIG_CREATED) || !dv.has_state(DeviceValueState::DV_HA_CLIMATE_NO_RT))) {
1697-
dv.add_state(DeviceValueState::DV_HA_CLIMATE_NO_RT);
1698-
dv.add_state(DeviceValueState::DV_HA_CONFIG_CREATED);
1699-
Mqtt::publish_ha_climate_config(dv.tag, false, false, dv.min, dv.max); // no roomTemp
1698+
if (Mqtt::publish_ha_climate_config(dv.tag, false, false, dv.min, dv.max)) { // no roomTemp
1699+
dv.add_state(DeviceValueState::DV_HA_CLIMATE_NO_RT);
1700+
dv.add_state(DeviceValueState::DV_HA_CONFIG_CREATED);
1701+
}
17001702
}
17011703
}
17021704

17031705
if (!dv.has_state(DeviceValueState::DV_HA_CONFIG_CREATED) && (dv.type != DeviceValueType::CMD) && dv.has_state(DeviceValueState::DV_ACTIVE)
17041706
&& !dv.has_state(DeviceValueState::DV_API_MQTT_EXCLUDE)) {
17051707
// create_device_config is only done once for the EMS device. It can added to any entity, so we take the first
1706-
Mqtt::publish_ha_sensor_config(dv, name(), brand_to_char(), false, create_device_config);
1707-
dv.add_state(DeviceValueState::DV_HA_CONFIG_CREATED);
1708-
create_device_config = false; // only create the main config once
1708+
if (Mqtt::publish_ha_sensor_config(dv, name(), brand_to_char(), false, create_device_config)) {
1709+
dv.add_state(DeviceValueState::DV_HA_CONFIG_CREATED);
1710+
create_device_config = false; // only create the main config once
1711+
}
17091712
#ifndef EMSESP_STANDALONE
17101713
// always create minimum one config
17111714
if (ESP.getMaxAllocHeap() < (6 * 1024) || (!emsesp::EMSESP::system_.PSram() && ESP.getFreeHeap() < (65 * 1024))) {

src/emsesp.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ void EMSESP::publish_all_loop() {
493493
}
494494

495495
// wait for free queue before sending next message, HA-messages are also queued
496-
if (!Mqtt::is_empty()) {
496+
if (Mqtt::publish_queued() > 0) {
497497
return;
498498
}
499499

0 commit comments

Comments
 (0)