mirror of
https://github.com/esphome/esphome.git
synced 2026-02-23 17:58:23 -07:00
[mqtt] add missing precision in HA autodiscovery (#14010)
This commit is contained in:
@@ -243,6 +243,7 @@
|
||||
X(MQTT_STATE_VALUE_TEMPLATE, "stat_val_tpl", "state_value_template") \
|
||||
X(MQTT_STEP, "step", "step") \
|
||||
X(MQTT_SUBTYPE, "stype", "subtype") \
|
||||
X(MQTT_SUGGESTED_DISPLAY_PRECISION, "sug_dsp_prc", "suggested_display_precision") \
|
||||
X(MQTT_SUPPORTED_COLOR_MODES, "sup_clrm", "supported_color_modes") \
|
||||
X(MQTT_SUPPORTED_FEATURES, "sup_feat", "supported_features") \
|
||||
X(MQTT_SWING_MODE_COMMAND_TEMPLATE, "swing_mode_cmd_tpl", "swing_mode_command_template") \
|
||||
|
||||
@@ -49,6 +49,10 @@ void MQTTSensorComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryCon
|
||||
root[MQTT_DEVICE_CLASS] = device_class;
|
||||
}
|
||||
|
||||
if (this->sensor_->has_accuracy_decimals()) {
|
||||
root[MQTT_SUGGESTED_DISPLAY_PRECISION] = this->sensor_->get_accuracy_decimals();
|
||||
}
|
||||
|
||||
const auto unit_of_measurement = this->sensor_->get_unit_of_measurement_ref();
|
||||
if (!unit_of_measurement.empty()) {
|
||||
root[MQTT_UNIT_OF_MEASUREMENT] = unit_of_measurement;
|
||||
|
||||
@@ -48,6 +48,8 @@ class Sensor : public EntityBase, public EntityBase_DeviceClass, public EntityBa
|
||||
int8_t get_accuracy_decimals();
|
||||
/// Manually set the accuracy in decimals.
|
||||
void set_accuracy_decimals(int8_t accuracy_decimals);
|
||||
/// Check if the accuracy in decimals has been manually set.
|
||||
bool has_accuracy_decimals() const { return this->sensor_flags_.has_accuracy_override; }
|
||||
|
||||
/// Get the state class, using the manual override if set.
|
||||
StateClass get_state_class();
|
||||
|
||||
Reference in New Issue
Block a user