expand all sites

This commit is contained in:
J. Nick Koston
2026-03-03 13:30:27 -10:00
parent 92cd08aa38
commit d74a8ea385
34 changed files with 251 additions and 154 deletions
+2 -1
View File
@@ -63,7 +63,8 @@ void Am43Component::control(const CoverCall &call) {
ESP_LOGW(TAG, "[%s] Error writing stop command to device, error = %d", this->get_name().c_str(), status);
}
}
if (auto opt_pos = call.get_position(); opt_pos.has_value()) {
auto opt_pos = call.get_position();
if (opt_pos.has_value()) {
auto pos = *opt_pos;
if (this->invert_position_)
+6 -4
View File
@@ -24,8 +24,9 @@ void Anova::loop() {
}
void Anova::control(const ClimateCall &call) {
if (auto val = call.get_mode(); val.has_value()) {
ClimateMode mode = *val;
auto mode_val = call.get_mode();
if (mode_val.has_value()) {
ClimateMode mode = *mode_val;
AnovaPacket *pkt;
switch (mode) {
case climate::CLIMATE_MODE_OFF:
@@ -45,8 +46,9 @@ void Anova::control(const ClimateCall &call) {
ESP_LOGW(TAG, "[%s] esp_ble_gattc_write_char failed, status=%d", this->parent_->address_str(), status);
}
}
if (auto val = call.get_target_temperature(); val.has_value()) {
auto *pkt = this->codec_->get_set_target_temp_request(*val);
auto target_temp = call.get_target_temperature();
if (target_temp.has_value()) {
auto *pkt = this->codec_->get_set_target_temp_request(*target_temp);
auto status =
esp_ble_gattc_write_char(this->parent_->get_gattc_if(), this->parent_->get_conn_id(), this->char_handle_,
pkt->length, pkt->data, ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE);
@@ -45,17 +45,21 @@ void BangBangClimate::setup() {
}
void BangBangClimate::control(const climate::ClimateCall &call) {
if (auto val = call.get_mode(); val.has_value()) {
this->mode = *val;
auto mode = call.get_mode();
if (mode.has_value()) {
this->mode = *mode;
}
if (auto val = call.get_target_temperature_low(); val.has_value()) {
this->target_temperature_low = *val;
auto target_temperature_low = call.get_target_temperature_low();
if (target_temperature_low.has_value()) {
this->target_temperature_low = *target_temperature_low;
}
if (auto val = call.get_target_temperature_high(); val.has_value()) {
this->target_temperature_high = *val;
auto target_temperature_high = call.get_target_temperature_high();
if (target_temperature_high.has_value()) {
this->target_temperature_high = *target_temperature_high;
}
if (auto val = call.get_preset(); val.has_value()) {
this->change_away_(*val == climate::CLIMATE_PRESET_AWAY);
auto preset = call.get_preset();
if (preset.has_value()) {
this->change_away_(*preset == climate::CLIMATE_PRESET_AWAY);
}
this->compute_state_();
@@ -96,8 +96,9 @@ void BedJetClimate::control(const ClimateCall &call) {
return;
}
if (auto val = call.get_mode(); val.has_value()) {
ClimateMode mode = *val;
auto mode_opt = call.get_mode();
if (mode_opt.has_value()) {
ClimateMode mode = *mode_opt;
bool button_result;
switch (mode) {
case CLIMATE_MODE_OFF:
@@ -125,8 +126,9 @@ void BedJetClimate::control(const ClimateCall &call) {
}
}
if (auto val = call.get_target_temperature(); val.has_value()) {
auto target_temp = *val;
auto target_temp_opt = call.get_target_temperature();
if (target_temp_opt.has_value()) {
auto target_temp = *target_temp_opt;
auto result = this->parent_->set_target_temp(target_temp);
if (result) {
@@ -134,8 +136,9 @@ void BedJetClimate::control(const ClimateCall &call) {
}
}
if (auto val = call.get_preset(); val.has_value()) {
ClimatePreset preset = *val;
auto preset_opt = call.get_preset();
if (preset_opt.has_value()) {
ClimatePreset preset = *preset_opt;
bool result;
if (preset == CLIMATE_PRESET_BOOST) {
@@ -187,10 +190,11 @@ void BedJetClimate::control(const ClimateCall &call) {
}
}
if (auto val = call.get_fan_mode(); val.has_value()) {
auto fan_mode_opt = call.get_fan_mode();
if (fan_mode_opt.has_value()) {
// Climate fan mode only supports low/med/high, but the BedJet supports 5-100% increments.
// We can still support a ClimateCall that requests low/med/high, and just translate it to a step increment here.
auto fan_mode = *val;
auto fan_mode = *fan_mode_opt;
bool result;
if (fan_mode == CLIMATE_FAN_LOW) {
result = this->parent_->set_fan_speed(20);
+5 -3
View File
@@ -19,7 +19,8 @@ void BedJetFan::control(const fan::FanCall &call) {
}
bool did_change = false;
if (auto val = call.get_state(); val.has_value() && this->state != *val) {
auto state_opt = call.get_state();
if (state_opt.has_value() && this->state != *state_opt) {
// Turning off is easy:
if (this->state && this->parent_->button_off()) {
this->state = false;
@@ -36,8 +37,9 @@ void BedJetFan::control(const fan::FanCall &call) {
}
// ignore speed changes if not on or turning on
if (auto val = call.get_speed(); this->state && val.has_value()) {
auto speed = *val;
auto speed_opt = call.get_speed();
if (this->state && speed_opt.has_value()) {
auto speed = *speed_opt;
if (speed >= 1) {
this->speed = speed;
// Fan.speed is 1-20, but Bedjet expects 0-19, so subtract 1
+9 -6
View File
@@ -18,12 +18,15 @@ fan::FanTraits BinaryFan::get_traits() {
return fan::FanTraits(this->oscillating_ != nullptr, false, this->direction_ != nullptr, 0);
}
void BinaryFan::control(const fan::FanCall &call) {
if (auto val = call.get_state(); val.has_value())
this->state = *val;
if (auto val = call.get_oscillating(); val.has_value())
this->oscillating = *val;
if (auto val = call.get_direction(); val.has_value())
this->direction = *val;
auto state = call.get_state();
if (state.has_value())
this->state = *state;
auto oscillating = call.get_oscillating();
if (oscillating.has_value())
this->oscillating = *oscillating;
auto direction = call.get_direction();
if (direction.has_value())
this->direction = *direction;
this->write_state_();
this->publish_state();
+15 -10
View File
@@ -71,16 +71,21 @@ void ClimateIR::setup() {
}
void ClimateIR::control(const climate::ClimateCall &call) {
if (auto val = call.get_mode(); val.has_value())
this->mode = *val;
if (auto val = call.get_target_temperature(); val.has_value())
this->target_temperature = *val;
if (auto val = call.get_fan_mode(); val.has_value())
this->fan_mode = val;
if (auto val = call.get_swing_mode(); val.has_value())
this->swing_mode = *val;
if (auto val = call.get_preset(); val.has_value())
this->preset = val;
auto mode = call.get_mode();
if (mode.has_value())
this->mode = *mode;
auto target_temperature = call.get_target_temperature();
if (target_temperature.has_value())
this->target_temperature = *target_temperature;
auto fan_mode = call.get_fan_mode();
if (fan_mode.has_value())
this->fan_mode = fan_mode;
auto swing_mode = call.get_swing_mode();
if (swing_mode.has_value())
this->swing_mode = *swing_mode;
auto preset = call.get_preset();
if (preset.has_value())
this->preset = preset;
this->transmit_state();
this->publish_state();
}
+9 -6
View File
@@ -38,12 +38,15 @@ cover::CoverTraits CopyCover::get_traits() {
void CopyCover::control(const cover::CoverCall &call) {
auto call2 = source_->make_call();
call2.set_stop(call.get_stop());
if (auto val = call.get_tilt(); val.has_value())
call2.set_tilt(*val);
if (auto val = call.get_position(); val.has_value())
call2.set_position(*val);
if (auto val = call.get_tilt(); val.has_value())
call2.set_tilt(*val);
auto tilt = call.get_tilt();
if (tilt.has_value())
call2.set_tilt(*tilt);
auto position = call.get_position();
if (position.has_value())
call2.set_position(*position);
auto tilt2 = call.get_tilt();
if (tilt2.has_value())
call2.set_tilt(*tilt2);
call2.perform();
}
+12 -8
View File
@@ -45,14 +45,18 @@ fan::FanTraits CopyFan::get_traits() {
void CopyFan::control(const fan::FanCall &call) {
auto call2 = source_->make_call();
if (auto val = call.get_state(); val.has_value())
call2.set_state(*val);
if (auto val = call.get_oscillating(); val.has_value())
call2.set_oscillating(*val);
if (auto val = call.get_speed(); val.has_value())
call2.set_speed(*val);
if (auto val = call.get_direction(); val.has_value())
call2.set_direction(*val);
auto state = call.get_state();
if (state.has_value())
call2.set_state(*state);
auto oscillating = call.get_oscillating();
if (oscillating.has_value())
call2.set_oscillating(*oscillating);
auto speed = call.get_speed();
if (speed.has_value())
call2.set_speed(*speed);
auto direction = call.get_direction();
if (direction.has_value())
call2.set_direction(*direction);
if (call.has_preset_mode())
call2.set_preset_mode(call.get_preset_mode());
call2.perform();
@@ -11,7 +11,8 @@ void CopySelect::setup() {
traits.set_options(source_->traits.get_options());
if (auto idx = this->source_->active_index(); idx.has_value())
auto idx = this->source_->active_index();
if (idx.has_value())
this->publish_state(*idx);
}
@@ -37,7 +37,8 @@ void CurrentBasedCover::control(const CoverCall &call) {
}
}
}
if (auto opt_pos = call.get_position(); opt_pos.has_value()) {
auto opt_pos = call.get_position();
if (opt_pos.has_value()) {
auto pos = *opt_pos;
if (fabsf(this->position - pos) < 0.01) {
// already at target
+3 -2
View File
@@ -485,8 +485,9 @@ bool DaikinArcClimate::on_receive(remote_base::RemoteReceiveData data) {
}
void DaikinArcClimate::control(const climate::ClimateCall &call) {
if (auto val = call.get_target_humidity(); val.has_value()) {
this->target_humidity = *val;
auto target_humidity = call.get_target_humidity();
if (target_humidity.has_value()) {
this->target_humidity = *target_humidity;
}
climate_ir::ClimateIR::control(call);
}
+2 -1
View File
@@ -37,7 +37,8 @@ void EndstopCover::control(const CoverCall &call) {
}
}
}
if (auto opt_pos = call.get_position(); opt_pos.has_value()) {
auto opt_pos = call.get_position();
if (opt_pos.has_value()) {
auto pos = *opt_pos;
if (pos == this->position) {
// already at target
@@ -269,7 +269,10 @@ void FeedbackCover::control(const CoverCall &call) {
this->start_direction_(COVER_OPERATION_CLOSING);
}
}
} else if (auto pos_opt = call.get_position(); pos_opt.has_value()) {
} else {
auto pos_opt = call.get_position();
if (!pos_opt.has_value())
return;
// go to position action
auto pos = *pos_opt;
if (pos == this->position) {
+12 -8
View File
@@ -49,14 +49,18 @@ void HBridgeFan::dump_config() {
}
void HBridgeFan::control(const fan::FanCall &call) {
if (auto val = call.get_state(); val.has_value())
this->state = *val;
if (auto val = call.get_speed(); val.has_value())
this->speed = *val;
if (auto val = call.get_oscillating(); val.has_value())
this->oscillating = *val;
if (auto val = call.get_direction(); val.has_value())
this->direction = *val;
auto call_state = call.get_state();
if (call_state.has_value())
this->state = *call_state;
auto call_speed = call.get_speed();
if (call_speed.has_value())
this->speed = *call_speed;
auto call_oscillating = call.get_oscillating();
if (call_oscillating.has_value())
this->oscillating = *call_oscillating;
auto call_direction = call.get_direction();
if (call_direction.has_value())
this->direction = *call_direction;
this->apply_preset_mode_(call);
this->write_state_();
+4 -1
View File
@@ -171,7 +171,10 @@ void HE60rCover::control(const CoverCall &call) {
} else {
this->toggles_needed_++;
}
} else if (auto pos_opt = call.get_position(); pos_opt.has_value()) {
} else {
auto pos_opt = call.get_position();
if (!pos_opt.has_value())
return;
// go to position action
auto pos = *pos_opt;
// are we at the target?
@@ -11,10 +11,12 @@ static const char *const TAG = "audio";
void I2SAudioMediaPlayer::control(const media_player::MediaPlayerCall &call) {
media_player::MediaPlayerState play_state = media_player::MEDIA_PLAYER_STATE_PLAYING;
if (auto announcement = call.get_announcement(); announcement.has_value()) {
auto announcement = call.get_announcement();
if (announcement.has_value()) {
play_state = *announcement ? media_player::MEDIA_PLAYER_STATE_ANNOUNCING : media_player::MEDIA_PLAYER_STATE_PLAYING;
}
if (auto media_url = call.get_media_url(); media_url.has_value()) {
auto media_url = call.get_media_url();
if (media_url.has_value()) {
this->current_url_ = media_url;
if (this->i2s_state_ != I2S_STATE_STOPPED && this->audio_ != nullptr) {
if (this->audio_->isRunning()) {
@@ -31,12 +33,14 @@ void I2SAudioMediaPlayer::control(const media_player::MediaPlayerCall &call) {
this->is_announcement_ = true;
}
if (auto vol = call.get_volume(); vol.has_value()) {
auto vol = call.get_volume();
if (vol.has_value()) {
this->volume = *vol;
this->set_volume_(volume);
this->unmute_();
}
if (auto cmd = call.get_command(); cmd.has_value()) {
auto cmd = call.get_command();
if (cmd.has_value()) {
switch (*cmd) {
case media_player::MEDIA_PLAYER_COMMAND_MUTE:
this->mute_();
+2 -1
View File
@@ -90,7 +90,8 @@ void Infrared::control(const InfraredCall &call) {
auto *transmit_data = transmit_call.get_data();
// Set carrier frequency
if (auto freq = call.get_carrier_frequency(); freq.has_value()) {
auto freq = call.get_carrier_frequency();
if (freq.has_value()) {
transmit_data->set_carrier_frequency(*freq);
}
+2 -1
View File
@@ -19,7 +19,8 @@ void Mcp4461Component::setup() {
// save WP/WL status
this->update_write_protection_status_();
for (uint8_t i = 0; i < 8; i++) {
if (auto init_val = this->reg_[i].initial_value; init_val.has_value()) {
auto init_val = this->reg_[i].initial_value;
if (init_val.has_value()) {
uint16_t initial_state = static_cast<uint16_t>(*init_val * 256.0f);
this->write_wiper_level_(i, initial_state);
}
+15 -10
View File
@@ -56,20 +56,25 @@ void AirConditioner::on_status_change() {
void AirConditioner::control(const ClimateCall &call) {
dudanov::midea::ac::Control ctrl{};
if (auto val = call.get_target_temperature(); val.has_value())
ctrl.targetTemp = *val;
if (auto val = call.get_swing_mode(); val.has_value())
ctrl.swingMode = Converters::to_midea_swing_mode(*val);
if (auto val = call.get_mode(); val.has_value())
ctrl.mode = Converters::to_midea_mode(*val);
if (auto val = call.get_preset(); val.has_value()) {
ctrl.preset = Converters::to_midea_preset(*val);
auto target_temp_val = call.get_target_temperature();
if (target_temp_val.has_value())
ctrl.targetTemp = *target_temp_val;
auto swing_mode_val = call.get_swing_mode();
if (swing_mode_val.has_value())
ctrl.swingMode = Converters::to_midea_swing_mode(*swing_mode_val);
auto mode_val = call.get_mode();
if (mode_val.has_value())
ctrl.mode = Converters::to_midea_mode(*mode_val);
auto preset_val = call.get_preset();
if (preset_val.has_value()) {
ctrl.preset = Converters::to_midea_preset(*preset_val);
} else if (call.has_custom_preset()) {
// get_custom_preset() returns StringRef pointing to null-terminated string literals from codegen
ctrl.preset = Converters::to_midea_preset(call.get_custom_preset().c_str());
}
if (auto val = call.get_fan_mode(); val.has_value()) {
ctrl.fanMode = Converters::to_midea_fan_mode(*val);
auto fan_mode_val = call.get_fan_mode();
if (fan_mode_val.has_value()) {
ctrl.fanMode = Converters::to_midea_fan_mode(*fan_mode_val);
} else if (call.has_custom_fan_mode()) {
// get_custom_fan_mode() returns StringRef pointing to null-terminated string literals from codegen
ctrl.fanMode = Converters::to_midea_fan_mode(call.get_custom_fan_mode().c_str());
+6 -4
View File
@@ -41,10 +41,12 @@ void PIDClimate::setup() {
}
}
void PIDClimate::control(const climate::ClimateCall &call) {
if (auto val = call.get_mode(); val.has_value())
this->mode = *val;
if (auto val = call.get_target_temperature(); val.has_value())
this->target_temperature = *val;
auto call_mode = call.get_mode();
if (call_mode.has_value())
this->mode = *call_mode;
auto call_target = call.get_target_temperature();
if (call_target.has_value())
this->target_temperature = *call_target;
// If switching to off mode, set output immediately
if (this->mode == climate::CLIMATE_MODE_OFF)
@@ -495,17 +495,20 @@ void SpeakerMediaPlayer::control(const media_player::MediaPlayerCall &call) {
MediaCallCommand media_command;
if (auto ann = call.get_announcement(); this->single_pipeline_() || (ann.has_value() && *ann)) {
auto ann = call.get_announcement();
if (this->single_pipeline_() || (ann.has_value() && *ann)) {
media_command.announce = true;
} else {
media_command.announce = false;
}
if (auto media_url = call.get_media_url(); media_url.has_value()) {
auto media_url = call.get_media_url();
if (media_url.has_value()) {
media_command.url =
new std::string(*media_url); // Must be manually deleted after receiving media_command from a queue
if (auto cmd = call.get_command(); cmd.has_value()) {
auto cmd = call.get_command();
if (cmd.has_value()) {
if (*cmd == media_player::MEDIA_PLAYER_COMMAND_ENQUEUE) {
media_command.enqueue = true;
}
@@ -515,14 +518,16 @@ void SpeakerMediaPlayer::control(const media_player::MediaPlayerCall &call) {
return;
}
if (auto vol = call.get_volume(); vol.has_value()) {
auto vol = call.get_volume();
if (vol.has_value()) {
media_command.volume = vol;
// Wait 0 ticks for queue to be free, volume sets aren't that important!
xQueueSend(this->media_control_command_queue_, &media_command, 0);
return;
}
if (auto cmd = call.get_command(); cmd.has_value()) {
auto cmd = call.get_command();
if (cmd.has_value()) {
media_command.command = cmd;
TickType_t ticks_to_wait = portMAX_DELAY;
if ((*cmd == media_player::MEDIA_PLAYER_COMMAND_VOLUME_UP) ||
+12 -8
View File
@@ -21,14 +21,18 @@ void SpeedFan::setup() {
void SpeedFan::dump_config() { LOG_FAN("", "Speed Fan", this); }
void SpeedFan::control(const fan::FanCall &call) {
if (auto val = call.get_state(); val.has_value())
this->state = *val;
if (auto val = call.get_speed(); val.has_value())
this->speed = *val;
if (auto val = call.get_oscillating(); val.has_value())
this->oscillating = *val;
if (auto val = call.get_direction(); val.has_value())
this->direction = *val;
auto call_state = call.get_state();
if (call_state.has_value())
this->state = *call_state;
auto call_speed = call.get_speed();
if (call_speed.has_value())
this->speed = *call_speed;
auto call_oscillating = call.get_oscillating();
if (call_oscillating.has_value())
this->oscillating = *call_oscillating;
auto call_direction = call.get_direction();
if (call_direction.has_value())
this->direction = *call_direction;
this->apply_preset_mode_(call);
this->write_state_();
+2 -1
View File
@@ -1193,7 +1193,8 @@ switch_::Switch *Sprinkler::valve_switch(const size_t valve_number) {
switch_::Switch *Sprinkler::valve_pump_switch(const size_t valve_number) {
if (this->is_a_valid_valve(valve_number)) {
if (auto idx = this->valve_[valve_number].pump_switch_index; idx.has_value()) {
auto idx = this->valve_[valve_number].pump_switch_index;
if (idx.has_value()) {
return this->pump_[*idx];
}
}
@@ -74,7 +74,8 @@ void TemplateCover::control(const CoverCall &call) {
this->prev_command_trigger_ = &this->toggle_trigger_;
this->publish_state();
}
if (auto pos_val = call.get_position(); pos_val.has_value()) {
auto pos_val = call.get_position();
if (pos_val.has_value()) {
auto pos = *pos_val;
this->stop_prev_trigger_();
@@ -93,7 +94,8 @@ void TemplateCover::control(const CoverCall &call) {
}
}
if (auto tilt_val = call.get_tilt(); tilt_val.has_value()) {
auto tilt_val = call.get_tilt();
if (tilt_val.has_value()) {
auto tilt = *tilt_val;
this->tilt_trigger_.trigger(tilt);
@@ -20,14 +20,18 @@ void TemplateFan::setup() {
void TemplateFan::dump_config() { LOG_FAN("", "Template Fan", this); }
void TemplateFan::control(const fan::FanCall &call) {
if (auto val = call.get_state(); val.has_value())
this->state = *val;
if (auto val = call.get_speed(); val.has_value() && (this->speed_count_ > 0))
this->speed = *val;
if (auto val = call.get_oscillating(); val.has_value() && this->has_oscillating_)
this->oscillating = *val;
if (auto val = call.get_direction(); val.has_value() && this->has_direction_)
this->direction = *val;
auto call_state = call.get_state();
if (call_state.has_value())
this->state = *call_state;
auto call_speed = call.get_speed();
if (call_speed.has_value() && (this->speed_count_ > 0))
this->speed = *call_speed;
auto call_oscillating = call.get_oscillating();
if (call_oscillating.has_value() && this->has_oscillating_)
this->oscillating = *call_oscillating;
auto call_direction = call.get_direction();
if (call_direction.has_value() && this->has_direction_)
this->direction = *call_direction;
this->apply_preset_mode_(call);
this->publish_state();
@@ -77,7 +77,8 @@ void TemplateValve::control(const ValveCall &call) {
this->prev_command_trigger_ = &this->toggle_trigger_;
this->publish_state();
}
if (auto pos_val = call.get_position(); pos_val.has_value()) {
auto pos_val = call.get_position();
if (pos_val.has_value()) {
auto pos = *pos_val;
this->stop_prev_trigger_();
@@ -101,9 +101,10 @@ water_heater::WaterHeaterCallInternal TemplateWaterHeater::make_call() {
}
void TemplateWaterHeater::control(const water_heater::WaterHeaterCall &call) {
if (auto val = call.get_mode(); val.has_value()) {
auto mode_val = call.get_mode();
if (mode_val.has_value()) {
if (this->optimistic_) {
this->mode_ = *val;
this->mode_ = *mode_val;
}
}
if (!std::isnan(call.get_target_temperature())) {
@@ -112,14 +113,16 @@ void TemplateWaterHeater::control(const water_heater::WaterHeaterCall &call) {
}
}
if (auto val = call.get_away(); val.has_value()) {
auto away_val = call.get_away();
if (away_val.has_value()) {
if (this->optimistic_) {
this->set_state_flag_(water_heater::WATER_HEATER_STATE_AWAY, *val);
this->set_state_flag_(water_heater::WATER_HEATER_STATE_AWAY, *away_val);
}
}
if (auto val = call.get_on(); val.has_value()) {
auto on_val = call.get_on();
if (on_val.has_value()) {
if (this->optimistic_) {
this->set_state_flag_(water_heater::WATER_HEATER_STATE_ON, *val);
this->set_state_flag_(water_heater::WATER_HEATER_STATE_ON, *on_val);
}
}
@@ -211,12 +211,13 @@ void ThermostatClimate::validate_target_humidity() {
void ThermostatClimate::control(const climate::ClimateCall &call) {
bool target_temperature_high_changed = false;
if (auto val = call.get_preset(); val.has_value()) {
auto preset = call.get_preset();
if (preset.has_value()) {
// setup_complete_ blocks modifying/resetting the temps immediately after boot
if (this->setup_complete_) {
this->change_preset_(*val);
this->change_preset_(*preset);
} else {
this->preset = val;
this->preset = preset;
}
}
if (call.has_custom_preset()) {
@@ -229,34 +230,41 @@ void ThermostatClimate::control(const climate::ClimateCall &call) {
}
}
if (auto val = call.get_mode(); val.has_value()) {
this->mode = *val;
auto mode = call.get_mode();
if (mode.has_value()) {
this->mode = *mode;
}
if (auto val = call.get_fan_mode(); val.has_value()) {
this->fan_mode = val;
auto fan_mode = call.get_fan_mode();
if (fan_mode.has_value()) {
this->fan_mode = fan_mode;
}
if (auto val = call.get_swing_mode(); val.has_value()) {
this->swing_mode = *val;
auto swing_mode = call.get_swing_mode();
if (swing_mode.has_value()) {
this->swing_mode = *swing_mode;
}
if (this->supports_two_points_) {
if (auto val = call.get_target_temperature_low(); val.has_value()) {
this->target_temperature_low = *val;
auto target_temp_low = call.get_target_temperature_low();
if (target_temp_low.has_value()) {
this->target_temperature_low = *target_temp_low;
}
if (auto val = call.get_target_temperature_high(); val.has_value()) {
target_temperature_high_changed = this->target_temperature_high != *val;
this->target_temperature_high = *val;
auto target_temp_high = call.get_target_temperature_high();
if (target_temp_high.has_value()) {
target_temperature_high_changed = this->target_temperature_high != *target_temp_high;
this->target_temperature_high = *target_temp_high;
}
// ensure the two set points are valid and adjust one of them if necessary
this->validate_target_temperatures(target_temperature_high_changed ||
(this->prev_mode_ == climate::CLIMATE_MODE_COOL));
} else {
if (auto val = call.get_target_temperature(); val.has_value()) {
this->target_temperature = *val;
auto target_temp = call.get_target_temperature();
if (target_temp.has_value()) {
this->target_temperature = *target_temp;
this->validate_target_temperature();
}
}
if (auto val = call.get_target_humidity(); val.has_value()) {
this->target_humidity = *val;
auto target_humidity = call.get_target_humidity();
if (target_humidity.has_value()) {
this->target_humidity = *target_humidity;
this->validate_target_humidity();
}
// make any changes happen
@@ -79,7 +79,8 @@ void TimeBasedCover::control(const CoverCall &call) {
}
}
}
if (auto pos_val = call.get_position(); pos_val.has_value()) {
auto pos_val = call.get_position();
if (pos_val.has_value()) {
auto pos = *pos_val;
if (pos == this->position) {
// already at target
@@ -66,7 +66,8 @@ void Tormatic::control(const cover::CoverCall &call) {
return;
}
if (auto pos_val = call.get_position(); pos_val.has_value()) {
auto pos_val = call.get_position();
if (pos_val.has_value()) {
auto pos = *pos_val;
this->control_position_(pos);
return;
@@ -7,7 +7,8 @@ namespace tuya {
static const char *const TAG = "tuya.climate";
void TuyaClimate::setup() {
if (auto switch_id = this->switch_id_; switch_id.has_value()) {
auto switch_id = this->switch_id_;
if (switch_id.has_value()) {
this->parent_->register_listener(*switch_id, [this](const TuyaDatapoint &datapoint) {
ESP_LOGV(TAG, "MCU reported switch is: %s", ONOFF(datapoint.value_bool));
this->mode = climate::CLIMATE_MODE_OFF;
@@ -32,7 +33,8 @@ void TuyaClimate::setup() {
this->cooling_state_pin_->setup();
this->cooling_state_ = this->cooling_state_pin_->digital_read();
}
if (auto active_state_id = this->active_state_id_; active_state_id.has_value()) {
auto active_state_id = this->active_state_id_;
if (active_state_id.has_value()) {
this->parent_->register_listener(*active_state_id, [this](const TuyaDatapoint &datapoint) {
ESP_LOGV(TAG, "MCU reported active state is: %u", datapoint.value_enum);
this->active_state_ = datapoint.value_enum;
@@ -40,7 +42,8 @@ void TuyaClimate::setup() {
this->publish_state();
});
}
if (auto target_temp_id = this->target_temperature_id_; target_temp_id.has_value()) {
auto target_temp_id = this->target_temperature_id_;
if (target_temp_id.has_value()) {
this->parent_->register_listener(*target_temp_id, [this](const TuyaDatapoint &datapoint) {
this->manual_temperature_ = datapoint.value_int * this->target_temperature_multiplier_;
if (this->reports_fahrenheit_) {
@@ -53,7 +56,8 @@ void TuyaClimate::setup() {
this->publish_state();
});
}
if (auto current_temp_id = this->current_temperature_id_; current_temp_id.has_value()) {
auto current_temp_id = this->current_temperature_id_;
if (current_temp_id.has_value()) {
this->parent_->register_listener(*current_temp_id, [this](const TuyaDatapoint &datapoint) {
this->current_temperature = datapoint.value_int * this->current_temperature_multiplier_;
if (this->reports_fahrenheit_) {
@@ -65,7 +69,8 @@ void TuyaClimate::setup() {
this->publish_state();
});
}
if (auto eco_id = this->eco_id_; eco_id.has_value()) {
auto eco_id = this->eco_id_;
if (eco_id.has_value()) {
this->parent_->register_listener(*eco_id, [this](const TuyaDatapoint &datapoint) {
// Whether data type is BOOL or ENUM, it will still be a 1 or a 0, so the functions below are valid in both cases
this->eco_ = datapoint.value_bool;
@@ -76,7 +81,8 @@ void TuyaClimate::setup() {
this->publish_state();
});
}
if (auto sleep_id = this->sleep_id_; sleep_id.has_value()) {
auto sleep_id = this->sleep_id_;
if (sleep_id.has_value()) {
this->parent_->register_listener(*sleep_id, [this](const TuyaDatapoint &datapoint) {
this->sleep_ = datapoint.value_bool;
ESP_LOGV(TAG, "MCU reported sleep is: %s", ONOFF(this->sleep_));
@@ -85,7 +91,8 @@ void TuyaClimate::setup() {
this->publish_state();
});
}
if (auto swing_vert_id = this->swing_vertical_id_; swing_vert_id.has_value()) {
auto swing_vert_id = this->swing_vertical_id_;
if (swing_vert_id.has_value()) {
this->parent_->register_listener(*swing_vert_id, [this](const TuyaDatapoint &datapoint) {
this->swing_vertical_ = datapoint.value_bool;
ESP_LOGV(TAG, "MCU reported vertical swing is: %s", ONOFF(datapoint.value_bool));
@@ -94,7 +101,8 @@ void TuyaClimate::setup() {
});
}
if (auto swing_horiz_id = this->swing_horizontal_id_; swing_horiz_id.has_value()) {
auto swing_horiz_id = this->swing_horizontal_id_;
if (swing_horiz_id.has_value()) {
this->parent_->register_listener(*swing_horiz_id, [this](const TuyaDatapoint &datapoint) {
this->swing_horizontal_ = datapoint.value_bool;
ESP_LOGV(TAG, "MCU reported horizontal swing is: %s", ONOFF(datapoint.value_bool));
@@ -103,7 +111,8 @@ void TuyaClimate::setup() {
});
}
if (auto fan_speed_id = this->fan_speed_id_; fan_speed_id.has_value()) {
auto fan_speed_id = this->fan_speed_id_;
if (fan_speed_id.has_value()) {
this->parent_->register_listener(*fan_speed_id, [this](const TuyaDatapoint &datapoint) {
ESP_LOGV(TAG, "MCU reported Fan Speed Mode is: %u", datapoint.value_enum);
this->fan_state_ = datapoint.value_enum;
@@ -42,7 +42,8 @@ climate::ClimateTraits UponorSmatrixClimate::traits() {
}
void UponorSmatrixClimate::control(const climate::ClimateCall &call) {
if (auto val = call.get_target_temperature(); val.has_value()) {
auto val = call.get_target_temperature();
if (val.has_value()) {
uint16_t temp = celsius_to_raw(*val);
if (this->preset == climate::CLIMATE_PRESET_ECO) {
// During ECO mode, the thermostat automatically substracts the setback value from the setpoint,
+6 -4
View File
@@ -120,10 +120,12 @@ void YashimaClimate::setup() {
}
void YashimaClimate::control(const climate::ClimateCall &call) {
if (auto val = call.get_mode(); val.has_value())
this->mode = *val;
if (auto val = call.get_target_temperature(); val.has_value())
this->target_temperature = *val;
auto call_mode = call.get_mode();
if (call_mode.has_value())
this->mode = *call_mode;
auto call_target = call.get_target_temperature();
if (call_target.has_value())
this->target_temperature = *call_target;
this->transmit_state_();
this->publish_state();