diff --git a/src/emsdevicevalue.h b/src/emsdevicevalue.h index b7630f402..5ea551004 100644 --- a/src/emsdevicevalue.h +++ b/src/emsdevicevalue.h @@ -120,11 +120,10 @@ class DeviceValue { // states of a device value enum DeviceValueState : uint8_t { // low nibble active state of the device value - DV_DEFAULT = 0, // 0 - does not yet have a value - DV_ACTIVE = (1 << 0), // 1 - has a validated real value - DV_HA_CONFIG_CREATED = (1 << 1), // 2 - set if the HA config topic has been created - DV_HA_CLIMATE_NO_RT = (1 << 2), // 4 - climate created without roomTemp - DV_HA_CONFIG_RECREATE = (1 << 3), // 8 - set on reconnect to recreate HA config topic // TODO remove + DV_DEFAULT = 0, // 0 - does not yet have a value + DV_ACTIVE = (1 << 0), // 1 - has a validated real value + DV_HA_CONFIG_CREATED = (1 << 1), // 2 - set if the HA config topic has been created + DV_HA_CLIMATE_NO_RT = (1 << 2), // 4 - climate created without roomTemp // high nibble as mask for exclusions & special functions DV_WEB_EXCLUDE = (1 << 4), // 16 - not shown on web @@ -179,12 +178,8 @@ class DeviceValue { uint16_t max, uint8_t state); - // has values bool hasValue() const; - bool has_tag() const { - return ((tag < DeviceValue::NUM_TAGS) && (tag != DeviceValue::DeviceValueTAG::TAG_NONE) && strlen(DeviceValueTAG_s[tag][0])); - } - + bool has_tag() const; bool get_min_max(int16_t & dv_set_min, uint16_t & dv_set_max); void set_custom_minmax(); diff --git a/src/emsesp.cpp b/src/emsesp.cpp index e831b3509..83cf35f9a 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -541,7 +541,7 @@ void EMSESP::reset_mqtt_ha() { } // create json doc for the devices values and add to MQTT publish queue -// this will also create the HA /config topic +// this will also create the HA /config topic for each device value // generate_values_json is called to build the device value (dv) object array void EMSESP::publish_device_values(uint8_t device_type) { DynamicJsonDocument doc(EMSESP_JSON_SIZE_XXLARGE); @@ -550,24 +550,6 @@ void EMSESP::publish_device_values(uint8_t device_type) { bool nested = (Mqtt::is_nested()); // group by device type - if (Mqtt::ha_enabled()) { - for (const auto & emsdevice : emsdevices) { - if (emsdevice && (emsdevice->device_type() == device_type)) { - // specially for MQTT Discovery - // we may have some RETAINED /config topics that reference fields in the data payloads that no longer exist - // remove them immediately to prevent HA from complaining - // we need to do this first before the data payload is published, and only done once! - // TODO remove - // if (emsdevice->ha_config_firstrun()) { - // emsdevice->ha_config_clear(); - // emsdevice->ha_config_firstrun(false); - // return; - // } else { - // see if we need to delete and /config topics before adding the payloads - emsdevice->mqtt_ha_entity_config_remove(); - } - } - } for (uint8_t tag = DeviceValueTAG::TAG_BOILER_DATA_WW; tag <= DeviceValueTAG::TAG_HS16; tag++) { JsonObject json_hc = json; bool nest_created = false; @@ -586,6 +568,7 @@ void EMSESP::publish_device_values(uint8_t device_type) { need_publish = false; } } + if (need_publish) { if (doc.overflowed()) { LOG_WARNING("MQTT buffer overflow, please use individual topics"); @@ -598,7 +581,6 @@ void EMSESP::publish_device_values(uint8_t device_type) { for (const auto & emsdevice : emsdevices) { if (emsdevice && (emsdevice->device_type() == device_type)) { emsdevice->mqtt_ha_entity_config_create(); - // EMSESP::mqtt_.loop(); // TODO experimental } } } @@ -1073,7 +1055,7 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, const // see: https://github.com/emsesp/EMS-ESP32/issues/103#issuecomment-911717342 and https://github.com/emsesp/EMS-ESP32/issues/624 name = "RF room temperature sensor"; device_type = DeviceType::THERMOSTAT; - } else if (device_id == EMSdevice::EMS_DEVICE_ID_ROOMTHERMOSTAT) { + } else if (device_id == EMSdevice::EMS_DEVICE_ID_ROOMTHERMOSTAT || device_id == EMSdevice::EMS_DEVICE_ID_TADO_OLD) { name = "Generic thermostat"; device_type = DeviceType::THERMOSTAT; flags = DeviceFlags::EMS_DEVICE_FLAG_RC10 | DeviceFlags::EMS_DEVICE_FLAG_NO_WRITE;