Allow specifying target and current visual steps for climate (#4440)

* Allow specifying target and current visual steps for climate

* Fixes

* format

* format
This commit is contained in:
Jesse Hills
2023-02-21 11:22:43 +13:00
committed by GitHub
parent 50fbbf2d3b
commit 0e1d018ce3
11 changed files with 111 additions and 40 deletions
+7 -6
View File
@@ -62,7 +62,7 @@ void MQTTClimateComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryCo
// max_temp
root[MQTT_MAX_TEMP] = traits.get_visual_max_temperature();
// temp_step
root["temp_step"] = traits.get_visual_temperature_step();
root["temp_step"] = traits.get_visual_target_temperature_step();
// temperature units are always coerced to Celsius internally
root[MQTT_TEMPERATURE_UNIT] = "C";
@@ -281,21 +281,22 @@ bool MQTTClimateComponent::publish_state_() {
bool success = true;
if (!this->publish(this->get_mode_state_topic(), mode_s))
success = false;
int8_t accuracy = traits.get_temperature_accuracy_decimals();
int8_t target_accuracy = traits.get_target_temperature_accuracy_decimals();
int8_t current_accuracy = traits.get_current_temperature_accuracy_decimals();
if (traits.get_supports_current_temperature() && !std::isnan(this->device_->current_temperature)) {
std::string payload = value_accuracy_to_string(this->device_->current_temperature, accuracy);
std::string payload = value_accuracy_to_string(this->device_->current_temperature, current_accuracy);
if (!this->publish(this->get_current_temperature_state_topic(), payload))
success = false;
}
if (traits.get_supports_two_point_target_temperature()) {
std::string payload = value_accuracy_to_string(this->device_->target_temperature_low, accuracy);
std::string payload = value_accuracy_to_string(this->device_->target_temperature_low, target_accuracy);
if (!this->publish(this->get_target_temperature_low_state_topic(), payload))
success = false;
payload = value_accuracy_to_string(this->device_->target_temperature_high, accuracy);
payload = value_accuracy_to_string(this->device_->target_temperature_high, target_accuracy);
if (!this->publish(this->get_target_temperature_high_state_topic(), payload))
success = false;
} else {
std::string payload = value_accuracy_to_string(this->device_->target_temperature, accuracy);
std::string payload = value_accuracy_to_string(this->device_->target_temperature, target_accuracy);
if (!this->publish(this->get_target_temperature_state_topic(), payload))
success = false;
}