mirror of
https://github.com/esphome/esphome.git
synced 2026-09-30 16:30:22 +00:00
Add integration test for deprecated ClimateTraits compat layer
This commit is contained in:
@@ -0,0 +1 @@
|
||||
"""Legacy climate component — tests deprecated ClimateTraits setters backward compat."""
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
"""Legacy climate platform that uses deprecated ClimateTraits setters."""
|
||||
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import climate
|
||||
import esphome.config_validation as cv
|
||||
|
||||
legacy_climate_ns = cg.esphome_ns.namespace("legacy_climate_test")
|
||||
LegacyClimate = legacy_climate_ns.class_("LegacyClimate", climate.Climate, cg.Component)
|
||||
|
||||
CONFIG_SCHEMA = climate.climate_schema(LegacyClimate).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
var = await climate.new_climate(config)
|
||||
await cg.register_component(var, config)
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/climate/climate.h"
|
||||
#include "esphome/core/component.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace legacy_climate_test {
|
||||
|
||||
/// Test climate that uses the DEPRECATED ClimateTraits setters for custom modes.
|
||||
/// This validates backward compatibility for external components that haven't migrated.
|
||||
class LegacyClimate : public climate::Climate, public Component {
|
||||
public:
|
||||
void setup() override {
|
||||
this->mode = climate::CLIMATE_MODE_OFF;
|
||||
this->target_temperature = 22.0f;
|
||||
this->current_temperature = 20.0f;
|
||||
this->publish_state();
|
||||
}
|
||||
|
||||
float get_setup_priority() const override { return setup_priority::LATE; }
|
||||
|
||||
protected:
|
||||
climate::ClimateTraits traits() override {
|
||||
auto traits = climate::ClimateTraits();
|
||||
traits.add_feature_flags(climate::CLIMATE_SUPPORTS_CURRENT_TEMPERATURE);
|
||||
traits.set_supported_modes({climate::CLIMATE_MODE_OFF, climate::CLIMATE_MODE_HEAT, climate::CLIMATE_MODE_COOL});
|
||||
traits.set_visual_min_temperature(16.0f);
|
||||
traits.set_visual_max_temperature(30.0f);
|
||||
traits.set_visual_temperature_step(0.5f);
|
||||
|
||||
// DEPRECATED API: setting custom modes directly on ClimateTraits.
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
traits.set_supported_custom_fan_modes({"Turbo", "Silent", "Auto"});
|
||||
traits.set_supported_custom_presets({"Eco Mode", "Night Mode"});
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
return traits;
|
||||
}
|
||||
|
||||
void control(const climate::ClimateCall &call) override {
|
||||
if (call.get_mode().has_value()) {
|
||||
this->mode = *call.get_mode();
|
||||
}
|
||||
if (call.get_target_temperature().has_value()) {
|
||||
this->target_temperature = *call.get_target_temperature();
|
||||
}
|
||||
if (call.get_custom_fan_mode() != nullptr) {
|
||||
this->set_custom_fan_mode_(call.get_custom_fan_mode());
|
||||
}
|
||||
if (call.get_custom_preset() != nullptr) {
|
||||
this->set_custom_preset_(call.get_custom_preset());
|
||||
}
|
||||
this->publish_state();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace legacy_climate_test
|
||||
} // namespace esphome
|
||||
Reference in New Issue
Block a user