only publish if MQTT is enabled

This commit is contained in:
Proddy
2023-02-05 10:57:20 +01:00
parent 6c46770330
commit 3a4e6aa852
2 changed files with 19 additions and 3 deletions

View File

@@ -439,7 +439,7 @@ bool DallasSensor::get_value_info(JsonObject & output, const char * cmd, const i
// publish a single sensor to MQTT
void DallasSensor::publish_sensor(const Sensor & sensor) {
if (Mqtt::publish_single()) {
if (Mqtt::ha_enabled() && Mqtt::publish_single()) {
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
if (Mqtt::publish_single2cmd()) {
snprintf(topic, sizeof(topic), "%s/%s", (F_(dallassensor)), sensor.name().c_str());
@@ -469,6 +469,10 @@ void DallasSensor::remove_ha_topic(const std::string & id) {
// send all dallas sensor values as a JSON package to MQTT
void DallasSensor::publish_values(const bool force) {
if (!Mqtt::ha_enabled()) {
return;
}
uint8_t num_sensors = sensors_.size();
if (num_sensors == 0) {