@@ -455,7 +455,7 @@ void EMSdevice::register_device_value(uint8_t tag,
455
455
};
456
456
}
457
457
458
- devicevalues_.emplace_back (device_type_, tag, value_p, type, options, options_size, short_name, full_name, uom, has_cmd);
458
+ devicevalues_.emplace_back (device_type_, tag, value_p, type, options, options_size, short_name, full_name, uom, 0 , has_cmd);
459
459
}
460
460
461
461
void EMSdevice::register_device_value (uint8_t tag, void * value_p, uint8_t type, const __FlashStringHelper * const * options, const __FlashStringHelper * const * name, uint8_t uom, cmdfunction_p f) {
@@ -617,11 +617,12 @@ bool EMSdevice::generate_values_json_web(JsonObject & json) {
617
617
// return false if empty
618
618
// this is used to create both the MQTT payloads and Console messages (console = true)
619
619
bool EMSdevice::generate_values_json (JsonObject & root, const uint8_t tag_filter, const bool nested, const bool console) {
620
- bool has_value = false ; // to see if we've added a value. it's faster than doing a json.size() at the end
621
- uint8_t old_tag = 255 ; // NAN
622
- JsonObject json = root;
620
+ bool has_values = false ; // to see if we've added a value. it's faster than doing a json.size() at the end
621
+ uint8_t old_tag = 255 ; // NAN
622
+ JsonObject json = root;
623
623
624
- for (const auto & dv : devicevalues_) {
624
+ for (auto & dv : devicevalues_) {
625
+ bool has_value = false ;
625
626
// only show if tag is either empty (TAG_NONE) or matches a value
626
627
// and don't show if full_name is empty unless we're outputing for mqtt payloads
627
628
// for nested we use all values
@@ -753,20 +754,24 @@ bool EMSdevice::generate_values_json(JsonObject & root, const uint8_t tag_filter
753
754
}
754
755
}
755
756
}
757
+ dv.ha |= has_value ? DeviceValueHA::HA_VALUE : DeviceValueHA::HA_NONE;
758
+ has_values |= has_value;
756
759
}
757
760
758
- return has_value ;
761
+ return has_values ;
759
762
}
760
763
761
764
// create the Home Assistant configs for each value
762
- // this is called when an MQTT publish is done via an EMS Device, and only done once
765
+ // this is called when an MQTT publish is done via an EMS Device
763
766
void EMSdevice::publish_mqtt_ha_sensor () {
764
- for (const auto & dv : devicevalues_) {
765
- Mqtt::publish_mqtt_ha_sensor (dv.type , dv.tag , dv.full_name , device_type_, dv.short_name , dv.uom );
767
+ for (auto & dv : devicevalues_) {
768
+ if (dv.ha == DeviceValueHA::HA_VALUE) {
769
+ Mqtt::publish_mqtt_ha_sensor (dv.type , dv.tag , dv.full_name , device_type_, dv.short_name , dv.uom );
770
+ dv.ha |= DeviceValueHA::HA_DONE;
771
+ }
766
772
}
767
-
768
- bool ok = publish_ha_config ();
769
- ha_config_done (ok); // see if it worked
773
+ // bool ok = publish_ha_config();
774
+ // ha_config_done(ok); // see if it worked
770
775
}
771
776
772
777
// return the name of the telegram type
0 commit comments