mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 00:39:50 +03:00
only publish MQTT if MQTT is enabled
This commit is contained in:
@@ -290,6 +290,7 @@ void EMSESP::show_sensor_values(uuid::console::Shell & shell) {
|
||||
|
||||
// MQTT publish everything, immediately
|
||||
void EMSESP::publish_all() {
|
||||
if (Mqtt::connected()) {
|
||||
publish_device_values(EMSdevice::DeviceType::BOILER);
|
||||
publish_device_values(EMSdevice::DeviceType::THERMOSTAT);
|
||||
publish_device_values(EMSdevice::DeviceType::SOLAR);
|
||||
@@ -298,19 +299,17 @@ void EMSESP::publish_all() {
|
||||
publish_sensor_values(true);
|
||||
system_.send_heartbeat();
|
||||
}
|
||||
}
|
||||
|
||||
void EMSESP::publish_device_values(uint8_t device_type) {
|
||||
if (Mqtt::connected()) {
|
||||
for (const auto & emsdevice : emsdevices) {
|
||||
if (emsdevice && (emsdevice->device_type() == device_type)) {
|
||||
emsdevice->publish_values();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EMSESP::publish_other_values() {
|
||||
if (Mqtt::connected()) {
|
||||
for (const auto & emsdevice : emsdevices) {
|
||||
if (emsdevice && (emsdevice->device_type() != EMSdevice::DeviceType::BOILER) && (emsdevice->device_type() != EMSdevice::DeviceType::THERMOSTAT)
|
||||
&& (emsdevice->device_type() != EMSdevice::DeviceType::SOLAR) && (emsdevice->device_type() != EMSdevice::DeviceType::MIXING)) {
|
||||
@@ -318,18 +317,19 @@ void EMSESP::publish_other_values() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EMSESP::publish_sensor_values(const bool force) {
|
||||
if (Mqtt::connected()) {
|
||||
if (sensor_.updated_values() || force) {
|
||||
sensor_.publish_values();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MQTT publish a telegram as raw data
|
||||
void EMSESP::publish_response(std::shared_ptr<const Telegram> telegram) {
|
||||
if (!Mqtt::connected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
StaticJsonDocument<EMSESP_MAX_JSON_SIZE_SMALL> doc;
|
||||
|
||||
char buffer[100];
|
||||
@@ -553,8 +553,8 @@ bool EMSESP::process_telegram(std::shared_ptr<const Telegram> telegram) {
|
||||
if (emsdevice) {
|
||||
if (emsdevice->is_device_id(telegram->src)) {
|
||||
found = emsdevice->handle_telegram(telegram);
|
||||
// check to see if we need to follow up after the telegram has been processed
|
||||
if (found) {
|
||||
// if we correctly processes the telegram follow up with sending it via MQTT if needed
|
||||
if (found && Mqtt::connected()) {
|
||||
if ((mqtt_.get_publish_onchange(emsdevice->device_type()) && emsdevice->updated_values()) || telegram->type_id == publish_id_) {
|
||||
if (telegram->type_id == publish_id_) {
|
||||
publish_id_ = 0;
|
||||
|
||||
Reference in New Issue
Block a user