mirror of
https://github.com/esphome/esphome.git
synced 2025-11-07 18:41:53 +00:00
simplify
This commit is contained in:
@@ -637,13 +637,13 @@ uint16_t APIConnection::try_send_climate_state(EntityBase *entity, APIConnection
|
|||||||
}
|
}
|
||||||
if (traits.get_supports_fan_modes() && climate->fan_mode.has_value())
|
if (traits.get_supports_fan_modes() && climate->fan_mode.has_value())
|
||||||
resp.fan_mode = static_cast<enums::ClimateFanMode>(climate->fan_mode.value());
|
resp.fan_mode = static_cast<enums::ClimateFanMode>(climate->fan_mode.value());
|
||||||
if (!traits.get_supported_custom_fan_modes().empty() && climate->custom_fan_mode != nullptr) {
|
if (!traits.get_supported_custom_fan_modes().empty() && climate->has_custom_fan_mode()) {
|
||||||
resp.set_custom_fan_mode(StringRef(climate->custom_fan_mode));
|
resp.set_custom_fan_mode(StringRef(climate->custom_fan_mode));
|
||||||
}
|
}
|
||||||
if (traits.get_supports_presets() && climate->preset.has_value()) {
|
if (traits.get_supports_presets() && climate->preset.has_value()) {
|
||||||
resp.preset = static_cast<enums::ClimatePreset>(climate->preset.value());
|
resp.preset = static_cast<enums::ClimatePreset>(climate->preset.value());
|
||||||
}
|
}
|
||||||
if (!traits.get_supported_custom_presets().empty() && climate->custom_preset != nullptr) {
|
if (!traits.get_supported_custom_presets().empty() && climate->has_custom_preset()) {
|
||||||
resp.set_custom_preset(StringRef(climate->custom_preset));
|
resp.set_custom_preset(StringRef(climate->custom_preset));
|
||||||
}
|
}
|
||||||
if (traits.get_supports_swing_modes())
|
if (traits.get_supports_swing_modes())
|
||||||
|
|||||||
@@ -216,6 +216,12 @@ class Climate : public EntityBase {
|
|||||||
void set_visual_min_humidity_override(float visual_min_humidity_override);
|
void set_visual_min_humidity_override(float visual_min_humidity_override);
|
||||||
void set_visual_max_humidity_override(float visual_max_humidity_override);
|
void set_visual_max_humidity_override(float visual_max_humidity_override);
|
||||||
|
|
||||||
|
/// Check if a custom fan mode is currently active.
|
||||||
|
bool has_custom_fan_mode() const { return this->custom_fan_mode != nullptr; }
|
||||||
|
|
||||||
|
/// Check if a custom preset is currently active.
|
||||||
|
bool has_custom_preset() const { return this->custom_preset != nullptr; }
|
||||||
|
|
||||||
/// The current temperature of the climate device, as reported from the integration.
|
/// The current temperature of the climate device, as reported from the integration.
|
||||||
float current_temperature{NAN};
|
float current_temperature{NAN};
|
||||||
|
|
||||||
|
|||||||
@@ -1312,7 +1312,7 @@ std::string WebServer::climate_json(climate::Climate *obj, JsonDetail start_conf
|
|||||||
for (climate::ClimatePreset m : traits.get_supported_presets())
|
for (climate::ClimatePreset m : traits.get_supported_presets())
|
||||||
opt.add(PSTR_LOCAL(climate::climate_preset_to_string(m)));
|
opt.add(PSTR_LOCAL(climate::climate_preset_to_string(m)));
|
||||||
}
|
}
|
||||||
if (!traits.get_supported_custom_presets().empty() && obj->custom_preset != nullptr) {
|
if (!traits.get_supported_custom_presets().empty() && obj->has_custom_preset()) {
|
||||||
JsonArray opt = root["custom_presets"].to<JsonArray>();
|
JsonArray opt = root["custom_presets"].to<JsonArray>();
|
||||||
for (auto const &custom_preset : traits.get_supported_custom_presets())
|
for (auto const &custom_preset : traits.get_supported_custom_presets())
|
||||||
opt.add(custom_preset);
|
opt.add(custom_preset);
|
||||||
@@ -1333,13 +1333,13 @@ std::string WebServer::climate_json(climate::Climate *obj, JsonDetail start_conf
|
|||||||
if (traits.get_supports_fan_modes() && obj->fan_mode.has_value()) {
|
if (traits.get_supports_fan_modes() && obj->fan_mode.has_value()) {
|
||||||
root["fan_mode"] = PSTR_LOCAL(climate_fan_mode_to_string(obj->fan_mode.value()));
|
root["fan_mode"] = PSTR_LOCAL(climate_fan_mode_to_string(obj->fan_mode.value()));
|
||||||
}
|
}
|
||||||
if (!traits.get_supported_custom_fan_modes().empty() && obj->custom_fan_mode != nullptr) {
|
if (!traits.get_supported_custom_fan_modes().empty() && obj->has_custom_fan_mode()) {
|
||||||
root["custom_fan_mode"] = obj->custom_fan_mode;
|
root["custom_fan_mode"] = obj->custom_fan_mode;
|
||||||
}
|
}
|
||||||
if (traits.get_supports_presets() && obj->preset.has_value()) {
|
if (traits.get_supports_presets() && obj->preset.has_value()) {
|
||||||
root["preset"] = PSTR_LOCAL(climate_preset_to_string(obj->preset.value()));
|
root["preset"] = PSTR_LOCAL(climate_preset_to_string(obj->preset.value()));
|
||||||
}
|
}
|
||||||
if (!traits.get_supported_custom_presets().empty() && obj->custom_preset != nullptr) {
|
if (!traits.get_supported_custom_presets().empty() && obj->has_custom_preset()) {
|
||||||
root["custom_preset"] = obj->custom_preset;
|
root["custom_preset"] = obj->custom_preset;
|
||||||
}
|
}
|
||||||
if (traits.get_supports_swing_modes()) {
|
if (traits.get_supports_swing_modes()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user