mirror of
https://github.com/esphome/esphome.git
synced 2025-11-18 07:45:56 +00:00
Base climate ir (#726)
* add ClimateIR * update climate ir * update class comment * lint * moved to climate_ir * fix include path * use climateir * updates * update include path * lint * fixed variable assigned to itself
This commit is contained in:
committed by
Otto Winter
parent
1242f43769
commit
578e5a0d7a
57
esphome/components/climate_ir/climate_ir.cpp
Normal file
57
esphome/components/climate_ir/climate_ir.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#include "climate_ir.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace climate {
|
||||
|
||||
climate::ClimateTraits ClimateIR::traits() {
|
||||
auto traits = climate::ClimateTraits();
|
||||
traits.set_supports_current_temperature(this->sensor_ != nullptr);
|
||||
traits.set_supports_auto_mode(true);
|
||||
traits.set_supports_cool_mode(this->supports_cool_);
|
||||
traits.set_supports_heat_mode(this->supports_heat_);
|
||||
traits.set_supports_two_point_target_temperature(false);
|
||||
traits.set_supports_away(false);
|
||||
traits.set_visual_min_temperature(this->minimum_temperature_);
|
||||
traits.set_visual_max_temperature(this->maximum_temperature_);
|
||||
traits.set_visual_temperature_step(this->temperature_step_);
|
||||
return traits;
|
||||
}
|
||||
|
||||
void ClimateIR::setup() {
|
||||
if (this->sensor_) {
|
||||
this->sensor_->add_on_state_callback([this](float state) {
|
||||
this->current_temperature = state;
|
||||
// current temperature changed, publish state
|
||||
this->publish_state();
|
||||
});
|
||||
this->current_temperature = this->sensor_->state;
|
||||
} else
|
||||
this->current_temperature = NAN;
|
||||
// restore set points
|
||||
auto restore = this->restore_state_();
|
||||
if (restore.has_value()) {
|
||||
restore->apply(this);
|
||||
} else {
|
||||
// restore from defaults
|
||||
this->mode = climate::CLIMATE_MODE_OFF;
|
||||
// initialize target temperature to some value so that it's not NAN
|
||||
this->target_temperature =
|
||||
roundf(clamp(this->current_temperature, this->minimum_temperature_, this->maximum_temperature_));
|
||||
}
|
||||
// Never send nan to HA
|
||||
if (isnan(this->target_temperature))
|
||||
this->target_temperature = 24;
|
||||
}
|
||||
|
||||
void ClimateIR::control(const climate::ClimateCall &call) {
|
||||
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();
|
||||
|
||||
this->transmit_state();
|
||||
this->publish_state();
|
||||
}
|
||||
|
||||
} // namespace climate
|
||||
} // namespace esphome
|
||||
Reference in New Issue
Block a user