mirror of
https://github.com/esphome/esphome.git
synced 2026-07-10 08:55:36 +00:00
Merge remote-tracking branch 'origin/std-optional' into integration
This commit is contained in:
@@ -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_)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -47,7 +47,7 @@ void BalluClimate::transmit_state() {
|
||||
remote_state[11] = 0x1e;
|
||||
|
||||
// Fan speed
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||
case climate::CLIMATE_FAN_HIGH:
|
||||
remote_state[4] |= BALLU_FAN_HIGH;
|
||||
break;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ void LgIrClimate::transmit_state() {
|
||||
if (this->mode == climate::CLIMATE_MODE_OFF) {
|
||||
remote_state |= FAN_AUTO;
|
||||
} else {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||
case climate::CLIMATE_FAN_HIGH:
|
||||
remote_state |= FAN_MAX;
|
||||
break;
|
||||
|
||||
@@ -83,7 +83,7 @@ void CoolixClimate::transmit_state() {
|
||||
this->fan_mode = climate::CLIMATE_FAN_AUTO;
|
||||
remote_state |= COOLIX_FAN_MODE_AUTO_DRY;
|
||||
} else {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||
case climate::CLIMATE_FAN_HIGH:
|
||||
remote_state |= COOLIX_FAN_MAX;
|
||||
break;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -94,7 +94,7 @@ uint8_t DaikinClimate::operation_mode_() const {
|
||||
|
||||
uint16_t DaikinClimate::fan_speed_() const {
|
||||
uint16_t fan_speed;
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||
case climate::CLIMATE_FAN_QUIET:
|
||||
fan_speed = DAIKIN_FAN_SILENT << 8;
|
||||
break;
|
||||
|
||||
@@ -176,7 +176,7 @@ uint8_t DaikinArcClimate::operation_mode_() {
|
||||
|
||||
uint16_t DaikinArcClimate::fan_speed_() {
|
||||
uint16_t fan_speed;
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||
case climate::CLIMATE_FAN_LOW:
|
||||
fan_speed = DAIKIN_FAN_1 << 8;
|
||||
break;
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ uint8_t DaikinBrcClimate::operation_mode_() {
|
||||
|
||||
uint8_t DaikinBrcClimate::fan_speed_swing_() {
|
||||
uint16_t fan_speed;
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||
case climate::CLIMATE_FAN_LOW:
|
||||
fan_speed = DAIKIN_BRC_FAN_1;
|
||||
break;
|
||||
|
||||
@@ -64,7 +64,7 @@ uint8_t DelonghiClimate::operation_mode_() {
|
||||
|
||||
uint16_t DelonghiClimate::fan_speed_() {
|
||||
uint16_t fan_speed;
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||
case climate::CLIMATE_FAN_LOW:
|
||||
fan_speed = DELONGHI_FAN_LOW;
|
||||
break;
|
||||
|
||||
@@ -28,7 +28,7 @@ uint8_t EmmetiClimate::set_mode_() {
|
||||
}
|
||||
|
||||
uint8_t EmmetiClimate::set_fan_speed_() {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||
case climate::CLIMATE_FAN_LOW:
|
||||
return EMMETI_FAN_1;
|
||||
case climate::CLIMATE_FAN_MEDIUM:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -162,7 +162,8 @@ void ESP32RMTLEDStripLightOutput::set_led_params(uint32_t bit0_high, uint32_t bi
|
||||
void ESP32RMTLEDStripLightOutput::write_state(light::LightState *state) {
|
||||
// protect from refreshing too often
|
||||
uint32_t now = micros();
|
||||
if (auto rate = this->max_refresh_rate_.value_or(0); rate != 0 && (now - this->last_refresh_) < rate) {
|
||||
auto rate = this->max_refresh_rate_.value_or(0);
|
||||
if (rate != 0 && (now - this->last_refresh_) < rate) {
|
||||
// try again next loop iteration, so that this change won't get lost
|
||||
this->schedule_show();
|
||||
return;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -141,7 +141,7 @@ void FujitsuGeneralClimate::transmit_state() {
|
||||
}
|
||||
|
||||
// Set fan
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||
case climate::CLIMATE_FAN_HIGH:
|
||||
SET_NIBBLE(remote_state, FUJITSU_GENERAL_FAN_NIBBLE, FUJITSU_GENERAL_FAN_HIGH);
|
||||
break;
|
||||
|
||||
@@ -180,7 +180,7 @@ uint8_t GreeClimate::operation_mode_() {
|
||||
uint8_t GreeClimate::fan_speed_() {
|
||||
// YX1FF has 4 fan speeds -- we treat low as quiet and turbo as high
|
||||
if (this->model_ == GREE_YX1FF) {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||
case climate::CLIMATE_FAN_QUIET:
|
||||
return GREE_FAN_1;
|
||||
case climate::CLIMATE_FAN_LOW:
|
||||
@@ -195,7 +195,7 @@ uint8_t GreeClimate::fan_speed_() {
|
||||
}
|
||||
}
|
||||
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||
case climate::CLIMATE_FAN_LOW:
|
||||
return GREE_FAN_1;
|
||||
case climate::CLIMATE_FAN_MEDIUM:
|
||||
|
||||
@@ -938,7 +938,7 @@ haier_protocol::HandlerError HonClimate::process_status_message_(const uint8_t *
|
||||
break;
|
||||
}
|
||||
should_publish = should_publish || (!old_fan_mode.has_value()) ||
|
||||
(old_fan_mode.value_or(CLIMATE_FAN_AUTO) != this->fan_mode.value_or(CLIMATE_FAN_AUTO));
|
||||
(old_fan_mode.value_or(CLIMATE_FAN_ON) != this->fan_mode.value_or(CLIMATE_FAN_ON));
|
||||
}
|
||||
// Display status
|
||||
// should be before "Climate mode" because it is changing this->mode
|
||||
|
||||
@@ -448,7 +448,7 @@ haier_protocol::HandlerError Smartair2Climate::process_status_message_(const uin
|
||||
break;
|
||||
}
|
||||
should_publish = should_publish || (!old_fan_mode.has_value()) ||
|
||||
(old_fan_mode.value_or(CLIMATE_FAN_AUTO) != this->fan_mode.value_or(CLIMATE_FAN_AUTO));
|
||||
(old_fan_mode.value_or(CLIMATE_FAN_ON) != this->fan_mode.value_or(CLIMATE_FAN_ON));
|
||||
}
|
||||
// Display status
|
||||
// should be before "Climate mode" because it is changing this->mode
|
||||
|
||||
@@ -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_();
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -187,7 +187,7 @@ void HeatpumpIRClimate::transmit_state() {
|
||||
swing_h_cmd = HDIR_SWING;
|
||||
}
|
||||
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||
case climate::CLIMATE_FAN_LOW:
|
||||
fan_speed_cmd = FAN_2;
|
||||
break;
|
||||
|
||||
@@ -175,7 +175,7 @@ void HitachiClimate::transmit_state() {
|
||||
|
||||
set_temp_(static_cast<uint8_t>(this->target_temperature));
|
||||
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||
case climate::CLIMATE_FAN_LOW:
|
||||
set_fan_(HITACHI_AC344_FAN_LOW);
|
||||
break;
|
||||
|
||||
@@ -176,7 +176,7 @@ void HitachiClimate::transmit_state() {
|
||||
|
||||
set_temp_(static_cast<uint8_t>(this->target_temperature));
|
||||
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||
case climate::CLIMATE_FAN_LOW:
|
||||
set_fan_(HITACHI_AC424_FAN_LOW);
|
||||
break;
|
||||
|
||||
@@ -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_();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -180,7 +180,7 @@ void MitsubishiClimate::transmit_state() {
|
||||
// For 5Level: Low = 1, Middle = 2, Medium = 3, High = 4
|
||||
// For 4Level + Quiet: Low = 1, Middle = 2, Medium = 3, High = 4, Quiet = 5
|
||||
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||
case climate::CLIMATE_FAN_LOW:
|
||||
remote_state[9] = 1;
|
||||
break;
|
||||
@@ -209,7 +209,7 @@ void MitsubishiClimate::transmit_state() {
|
||||
break;
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, "fan: %02x state: %02x", static_cast<uint8_t>(this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)),
|
||||
ESP_LOGD(TAG, "fan: %02x state: %02x", static_cast<uint8_t>(this->fan_mode.value_or(climate::CLIMATE_FAN_ON)),
|
||||
remote_state[9]);
|
||||
|
||||
// Vertical Vane
|
||||
|
||||
@@ -71,7 +71,7 @@ void NoblexClimate::transmit_state() {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||
case climate::CLIMATE_FAN_LOW:
|
||||
remote_state[0] |= (IRNoblexFan::IR_NOBLEX_FAN_LOW << 2);
|
||||
break;
|
||||
|
||||
@@ -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) ||
|
||||
|
||||
@@ -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_();
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ void Tcl112Climate::transmit_state() {
|
||||
|
||||
// Set fan
|
||||
uint8_t selected_fan;
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||
case climate::CLIMATE_FAN_HIGH:
|
||||
selected_fan = TCL112_FAN_HIGH;
|
||||
break;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -502,7 +502,7 @@ void ToshibaClimate::transmit_generic_() {
|
||||
}
|
||||
|
||||
uint8_t fan;
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||
case climate::CLIMATE_FAN_QUIET:
|
||||
fan = TOSHIBA_FAN_SPEED_QUIET;
|
||||
break;
|
||||
@@ -567,7 +567,7 @@ void ToshibaClimate::transmit_rac_pt1411hwru_() {
|
||||
message[2] = RAC_PT1411HWRU_NO_FAN.code1;
|
||||
message[7] = RAC_PT1411HWRU_NO_FAN.code2;
|
||||
} else {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||
case climate::CLIMATE_FAN_LOW:
|
||||
message[2] = RAC_PT1411HWRU_FAN_LOW.code1;
|
||||
message[7] = RAC_PT1411HWRU_FAN_LOW.code2;
|
||||
@@ -811,12 +811,12 @@ void ToshibaClimate::transmit_ras_2819t_() {
|
||||
uint8_t temp_code = get_ras_2819t_temp_code(temperature);
|
||||
|
||||
// Get fan speed encoding for rc_code_1
|
||||
climate::ClimateFanMode effective_fan_mode = this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO);
|
||||
climate::ClimateFanMode effective_fan_mode = this->fan_mode.value_or(climate::CLIMATE_FAN_ON);
|
||||
|
||||
// Dry mode only supports AUTO fan speed
|
||||
if (this->mode == climate::CLIMATE_MODE_DRY) {
|
||||
effective_fan_mode = climate::CLIMATE_FAN_AUTO;
|
||||
if (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO) != climate::CLIMATE_FAN_AUTO) {
|
||||
if (this->fan_mode.value_or(climate::CLIMATE_FAN_ON) != climate::CLIMATE_FAN_AUTO) {
|
||||
ESP_LOGW(TAG, "Dry mode only supports AUTO fan speed, forcing AUTO");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -139,27 +148,34 @@ void TuyaClimate::loop() {
|
||||
}
|
||||
|
||||
void TuyaClimate::control(const climate::ClimateCall &call) {
|
||||
if (auto mode = call.get_mode(); mode.has_value()) {
|
||||
auto mode = call.get_mode();
|
||||
if (mode.has_value()) {
|
||||
const bool switch_state = *mode != climate::CLIMATE_MODE_OFF;
|
||||
ESP_LOGV(TAG, "Setting switch: %s", ONOFF(switch_state));
|
||||
if (auto id = this->switch_id_; id.has_value()) {
|
||||
this->parent_->set_boolean_datapoint_value(*id, switch_state);
|
||||
auto switch_dp_id = this->switch_id_;
|
||||
if (switch_dp_id.has_value()) {
|
||||
this->parent_->set_boolean_datapoint_value(*switch_dp_id, switch_state);
|
||||
}
|
||||
const climate::ClimateMode new_mode = *mode;
|
||||
|
||||
if (auto id = this->active_state_id_; id.has_value()) {
|
||||
auto active_state_dp_id = this->active_state_id_;
|
||||
if (active_state_dp_id.has_value()) {
|
||||
if (new_mode == climate::CLIMATE_MODE_HEAT && this->supports_heat_) {
|
||||
if (auto val = this->active_state_heating_value_; val.has_value())
|
||||
this->parent_->set_enum_datapoint_value(*id, *val);
|
||||
auto heating_val = this->active_state_heating_value_;
|
||||
if (heating_val.has_value())
|
||||
this->parent_->set_enum_datapoint_value(*active_state_dp_id, *heating_val);
|
||||
} else if (new_mode == climate::CLIMATE_MODE_COOL && this->supports_cool_) {
|
||||
if (auto val = this->active_state_cooling_value_; val.has_value())
|
||||
this->parent_->set_enum_datapoint_value(*id, *val);
|
||||
auto cooling_val = this->active_state_cooling_value_;
|
||||
if (cooling_val.has_value())
|
||||
this->parent_->set_enum_datapoint_value(*active_state_dp_id, *cooling_val);
|
||||
} else if (new_mode == climate::CLIMATE_MODE_DRY) {
|
||||
if (auto val = this->active_state_drying_value_; val.has_value())
|
||||
this->parent_->set_enum_datapoint_value(*id, *val);
|
||||
auto drying_val = this->active_state_drying_value_;
|
||||
if (drying_val.has_value())
|
||||
this->parent_->set_enum_datapoint_value(*active_state_dp_id, *drying_val);
|
||||
} else if (new_mode == climate::CLIMATE_MODE_FAN_ONLY) {
|
||||
if (auto val = this->active_state_fanonly_value_; val.has_value())
|
||||
this->parent_->set_enum_datapoint_value(*id, *val);
|
||||
auto fanonly_val = this->active_state_fanonly_value_;
|
||||
if (fanonly_val.has_value())
|
||||
this->parent_->set_enum_datapoint_value(*active_state_dp_id, *fanonly_val);
|
||||
}
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Active state (mode) datapoint not configured");
|
||||
@@ -169,33 +185,38 @@ void TuyaClimate::control(const climate::ClimateCall &call) {
|
||||
control_swing_mode_(call);
|
||||
control_fan_mode_(call);
|
||||
|
||||
if (auto target_temp = call.get_target_temperature(); target_temp.has_value()) {
|
||||
auto target_temp = call.get_target_temperature();
|
||||
if (target_temp.has_value()) {
|
||||
float target_temperature = *target_temp;
|
||||
if (this->reports_fahrenheit_)
|
||||
target_temperature = (target_temperature * 9 / 5) + 32;
|
||||
|
||||
ESP_LOGV(TAG, "Setting target temperature: %.1f", target_temperature);
|
||||
if (auto id = this->target_temperature_id_; id.has_value()) {
|
||||
this->parent_->set_integer_datapoint_value(*id,
|
||||
auto target_temp_dp_id = this->target_temperature_id_;
|
||||
if (target_temp_dp_id.has_value()) {
|
||||
this->parent_->set_integer_datapoint_value(*target_temp_dp_id,
|
||||
(int) (target_temperature / this->target_temperature_multiplier_));
|
||||
}
|
||||
}
|
||||
|
||||
if (auto preset_val = call.get_preset(); preset_val.has_value()) {
|
||||
auto preset_val = call.get_preset();
|
||||
if (preset_val.has_value()) {
|
||||
const climate::ClimatePreset preset = *preset_val;
|
||||
if (auto id = this->eco_id_; id.has_value()) {
|
||||
auto eco_dp_id = this->eco_id_;
|
||||
if (eco_dp_id.has_value()) {
|
||||
const bool eco = preset == climate::CLIMATE_PRESET_ECO;
|
||||
ESP_LOGV(TAG, "Setting eco: %s", ONOFF(eco));
|
||||
if (this->eco_type_ == TuyaDatapointType::ENUM) {
|
||||
this->parent_->set_enum_datapoint_value(*id, eco);
|
||||
this->parent_->set_enum_datapoint_value(*eco_dp_id, eco);
|
||||
} else {
|
||||
this->parent_->set_boolean_datapoint_value(*id, eco);
|
||||
this->parent_->set_boolean_datapoint_value(*eco_dp_id, eco);
|
||||
}
|
||||
}
|
||||
if (auto id = this->sleep_id_; id.has_value()) {
|
||||
auto sleep_dp_id = this->sleep_id_;
|
||||
if (sleep_dp_id.has_value()) {
|
||||
const bool sleep = preset == climate::CLIMATE_PRESET_SLEEP;
|
||||
ESP_LOGV(TAG, "Setting sleep: %s", ONOFF(sleep));
|
||||
this->parent_->set_boolean_datapoint_value(*id, sleep);
|
||||
this->parent_->set_boolean_datapoint_value(*sleep_dp_id, sleep);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -204,7 +225,8 @@ void TuyaClimate::control_swing_mode_(const climate::ClimateCall &call) {
|
||||
bool vertical_swing_changed = false;
|
||||
bool horizontal_swing_changed = false;
|
||||
|
||||
if (auto swing_mode_val = call.get_swing_mode(); swing_mode_val.has_value()) {
|
||||
auto swing_mode_val = call.get_swing_mode();
|
||||
if (swing_mode_val.has_value()) {
|
||||
const auto swing_mode = *swing_mode_val;
|
||||
|
||||
switch (swing_mode) {
|
||||
@@ -249,14 +271,16 @@ void TuyaClimate::control_swing_mode_(const climate::ClimateCall &call) {
|
||||
}
|
||||
}
|
||||
|
||||
if (auto id = this->swing_vertical_id_; vertical_swing_changed && id.has_value()) {
|
||||
auto vert_dp_id = this->swing_vertical_id_;
|
||||
if (vertical_swing_changed && vert_dp_id.has_value()) {
|
||||
ESP_LOGV(TAG, "Setting vertical swing: %s", ONOFF(swing_vertical_));
|
||||
this->parent_->set_boolean_datapoint_value(*id, swing_vertical_);
|
||||
this->parent_->set_boolean_datapoint_value(*vert_dp_id, swing_vertical_);
|
||||
}
|
||||
|
||||
if (auto id = this->swing_horizontal_id_; horizontal_swing_changed && id.has_value()) {
|
||||
auto horiz_dp_id = this->swing_horizontal_id_;
|
||||
if (horizontal_swing_changed && horiz_dp_id.has_value()) {
|
||||
ESP_LOGV(TAG, "Setting horizontal swing: %s", ONOFF(swing_horizontal_));
|
||||
this->parent_->set_boolean_datapoint_value(*id, swing_horizontal_);
|
||||
this->parent_->set_boolean_datapoint_value(*horiz_dp_id, swing_horizontal_);
|
||||
}
|
||||
|
||||
// Publish the state after updating the swing mode
|
||||
@@ -264,7 +288,8 @@ void TuyaClimate::control_swing_mode_(const climate::ClimateCall &call) {
|
||||
}
|
||||
|
||||
void TuyaClimate::control_fan_mode_(const climate::ClimateCall &call) {
|
||||
if (auto fan_mode_val = call.get_fan_mode(); fan_mode_val.has_value()) {
|
||||
auto fan_mode_val = call.get_fan_mode();
|
||||
if (fan_mode_val.has_value()) {
|
||||
climate::ClimateFanMode fan_mode = *fan_mode_val;
|
||||
|
||||
uint8_t tuya_fan_speed;
|
||||
@@ -289,8 +314,9 @@ void TuyaClimate::control_fan_mode_(const climate::ClimateCall &call) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (auto id = this->fan_speed_id_; id.has_value()) {
|
||||
this->parent_->set_enum_datapoint_value(*id, tuya_fan_speed);
|
||||
auto fan_speed_dp_id = this->fan_speed_id_;
|
||||
if (fan_speed_dp_id.has_value()) {
|
||||
this->parent_->set_enum_datapoint_value(*fan_speed_dp_id, tuya_fan_speed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -345,31 +371,39 @@ climate::ClimateTraits TuyaClimate::traits() {
|
||||
|
||||
void TuyaClimate::dump_config() {
|
||||
LOG_CLIMATE("", "Tuya Climate", this);
|
||||
if (auto id = this->switch_id_; id.has_value()) {
|
||||
ESP_LOGCONFIG(TAG, " Switch has datapoint ID %u", *id);
|
||||
auto switch_dp_id = this->switch_id_;
|
||||
if (switch_dp_id.has_value()) {
|
||||
ESP_LOGCONFIG(TAG, " Switch has datapoint ID %u", *switch_dp_id);
|
||||
}
|
||||
if (auto id = this->active_state_id_; id.has_value()) {
|
||||
ESP_LOGCONFIG(TAG, " Active state has datapoint ID %u", *id);
|
||||
auto active_state_dp_id = this->active_state_id_;
|
||||
if (active_state_dp_id.has_value()) {
|
||||
ESP_LOGCONFIG(TAG, " Active state has datapoint ID %u", *active_state_dp_id);
|
||||
}
|
||||
if (auto id = this->target_temperature_id_; id.has_value()) {
|
||||
ESP_LOGCONFIG(TAG, " Target Temperature has datapoint ID %u", *id);
|
||||
auto target_temp_dp_id = this->target_temperature_id_;
|
||||
if (target_temp_dp_id.has_value()) {
|
||||
ESP_LOGCONFIG(TAG, " Target Temperature has datapoint ID %u", *target_temp_dp_id);
|
||||
}
|
||||
if (auto id = this->current_temperature_id_; id.has_value()) {
|
||||
ESP_LOGCONFIG(TAG, " Current Temperature has datapoint ID %u", *id);
|
||||
auto current_temp_dp_id = this->current_temperature_id_;
|
||||
if (current_temp_dp_id.has_value()) {
|
||||
ESP_LOGCONFIG(TAG, " Current Temperature has datapoint ID %u", *current_temp_dp_id);
|
||||
}
|
||||
LOG_PIN(" Heating State Pin: ", this->heating_state_pin_);
|
||||
LOG_PIN(" Cooling State Pin: ", this->cooling_state_pin_);
|
||||
if (auto id = this->eco_id_; id.has_value()) {
|
||||
ESP_LOGCONFIG(TAG, " Eco has datapoint ID %u", *id);
|
||||
auto eco_dp_id = this->eco_id_;
|
||||
if (eco_dp_id.has_value()) {
|
||||
ESP_LOGCONFIG(TAG, " Eco has datapoint ID %u", *eco_dp_id);
|
||||
}
|
||||
if (auto id = this->sleep_id_; id.has_value()) {
|
||||
ESP_LOGCONFIG(TAG, " Sleep has datapoint ID %u", *id);
|
||||
auto sleep_dp_id = this->sleep_id_;
|
||||
if (sleep_dp_id.has_value()) {
|
||||
ESP_LOGCONFIG(TAG, " Sleep has datapoint ID %u", *sleep_dp_id);
|
||||
}
|
||||
if (auto id = this->swing_vertical_id_; id.has_value()) {
|
||||
ESP_LOGCONFIG(TAG, " Swing Vertical has datapoint ID %u", *id);
|
||||
auto swing_vert_dp_id = this->swing_vertical_id_;
|
||||
if (swing_vert_dp_id.has_value()) {
|
||||
ESP_LOGCONFIG(TAG, " Swing Vertical has datapoint ID %u", *swing_vert_dp_id);
|
||||
}
|
||||
if (auto id = this->swing_horizontal_id_; id.has_value()) {
|
||||
ESP_LOGCONFIG(TAG, " Swing Horizontal has datapoint ID %u", *id);
|
||||
auto swing_horiz_dp_id = this->swing_horizontal_id_;
|
||||
if (swing_horiz_dp_id.has_value()) {
|
||||
ESP_LOGCONFIG(TAG, " Swing Horizontal has datapoint ID %u", *swing_horiz_dp_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,8 @@ void TuyaCover::control(const cover::CoverCall &call) {
|
||||
this->parent_->force_set_integer_datapoint_value(*this->position_id_, position_int);
|
||||
}
|
||||
}
|
||||
if (auto pos_opt = call.get_position(); pos_opt.has_value()) {
|
||||
auto pos_opt = call.get_position();
|
||||
if (pos_opt.has_value()) {
|
||||
auto pos = *pos_opt;
|
||||
if (this->control_id_.has_value() && (pos == COVER_OPEN || pos == COVER_CLOSED)) {
|
||||
if (pos == COVER_OPEN) {
|
||||
|
||||
@@ -7,7 +7,8 @@ namespace tuya {
|
||||
static const char *const TAG = "tuya.fan";
|
||||
|
||||
void TuyaFan::setup() {
|
||||
if (auto speed_id = this->speed_id_; speed_id.has_value()) {
|
||||
auto speed_id = this->speed_id_;
|
||||
if (speed_id.has_value()) {
|
||||
this->parent_->register_listener(*speed_id, [this](const TuyaDatapoint &datapoint) {
|
||||
if (datapoint.type == TuyaDatapointType::ENUM) {
|
||||
ESP_LOGV(TAG, "MCU reported speed of: %d", datapoint.value_enum);
|
||||
@@ -25,14 +26,16 @@ void TuyaFan::setup() {
|
||||
this->speed_type_ = datapoint.type;
|
||||
});
|
||||
}
|
||||
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->state = datapoint.value_bool;
|
||||
this->publish_state();
|
||||
});
|
||||
}
|
||||
if (auto oscillation_id = this->oscillation_id_; oscillation_id.has_value()) {
|
||||
auto oscillation_id = this->oscillation_id_;
|
||||
if (oscillation_id.has_value()) {
|
||||
this->parent_->register_listener(*oscillation_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
|
||||
// scenarios
|
||||
@@ -43,7 +46,8 @@ void TuyaFan::setup() {
|
||||
this->oscillation_type_ = datapoint.type;
|
||||
});
|
||||
}
|
||||
if (auto direction_id = this->direction_id_; direction_id.has_value()) {
|
||||
auto direction_id = this->direction_id_;
|
||||
if (direction_id.has_value()) {
|
||||
this->parent_->register_listener(*direction_id, [this](const TuyaDatapoint &datapoint) {
|
||||
ESP_LOGD(TAG, "MCU reported reverse direction is: %s", ONOFF(datapoint.value_bool));
|
||||
this->direction = datapoint.value_bool ? fan::FanDirection::REVERSE : fan::FanDirection::FORWARD;
|
||||
@@ -60,17 +64,21 @@ void TuyaFan::setup() {
|
||||
|
||||
void TuyaFan::dump_config() {
|
||||
LOG_FAN("", "Tuya Fan", this);
|
||||
if (auto id = this->speed_id_; id.has_value()) {
|
||||
ESP_LOGCONFIG(TAG, " Speed has datapoint ID %u", *id);
|
||||
auto speed_dp_id = this->speed_id_;
|
||||
if (speed_dp_id.has_value()) {
|
||||
ESP_LOGCONFIG(TAG, " Speed has datapoint ID %u", *speed_dp_id);
|
||||
}
|
||||
if (auto id = this->switch_id_; id.has_value()) {
|
||||
ESP_LOGCONFIG(TAG, " Switch has datapoint ID %u", *id);
|
||||
auto switch_dp_id = this->switch_id_;
|
||||
if (switch_dp_id.has_value()) {
|
||||
ESP_LOGCONFIG(TAG, " Switch has datapoint ID %u", *switch_dp_id);
|
||||
}
|
||||
if (auto id = this->oscillation_id_; id.has_value()) {
|
||||
ESP_LOGCONFIG(TAG, " Oscillation has datapoint ID %u", *id);
|
||||
auto oscillation_dp_id = this->oscillation_id_;
|
||||
if (oscillation_dp_id.has_value()) {
|
||||
ESP_LOGCONFIG(TAG, " Oscillation has datapoint ID %u", *oscillation_dp_id);
|
||||
}
|
||||
if (auto id = this->direction_id_; id.has_value()) {
|
||||
ESP_LOGCONFIG(TAG, " Direction has datapoint ID %u", *id);
|
||||
auto direction_dp_id = this->direction_id_;
|
||||
if (direction_dp_id.has_value()) {
|
||||
ESP_LOGCONFIG(TAG, " Direction has datapoint ID %u", *direction_dp_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,13 +88,17 @@ fan::FanTraits TuyaFan::get_traits() {
|
||||
}
|
||||
|
||||
void TuyaFan::control(const fan::FanCall &call) {
|
||||
if (auto switch_id = this->switch_id_; switch_id.has_value()) {
|
||||
if (auto state = call.get_state(); state.has_value()) {
|
||||
auto switch_id = this->switch_id_;
|
||||
if (switch_id.has_value()) {
|
||||
auto state = call.get_state();
|
||||
if (state.has_value()) {
|
||||
this->parent_->set_boolean_datapoint_value(*switch_id, *state);
|
||||
}
|
||||
}
|
||||
if (auto osc_id = this->oscillation_id_; osc_id.has_value()) {
|
||||
if (auto oscillating = call.get_oscillating(); oscillating.has_value()) {
|
||||
auto osc_id = this->oscillation_id_;
|
||||
if (osc_id.has_value()) {
|
||||
auto oscillating = call.get_oscillating();
|
||||
if (oscillating.has_value()) {
|
||||
if (this->oscillation_type_ == TuyaDatapointType::ENUM) {
|
||||
this->parent_->set_enum_datapoint_value(*osc_id, *oscillating);
|
||||
} else if (this->oscillation_type_ == TuyaDatapointType::BOOLEAN) {
|
||||
@@ -94,14 +106,18 @@ void TuyaFan::control(const fan::FanCall &call) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (auto dir_id = this->direction_id_; dir_id.has_value()) {
|
||||
if (auto direction = call.get_direction(); direction.has_value()) {
|
||||
auto dir_id = this->direction_id_;
|
||||
if (dir_id.has_value()) {
|
||||
auto direction = call.get_direction();
|
||||
if (direction.has_value()) {
|
||||
bool enable = *direction == fan::FanDirection::REVERSE;
|
||||
this->parent_->set_enum_datapoint_value(*dir_id, enable);
|
||||
}
|
||||
}
|
||||
if (auto spd_id = this->speed_id_; spd_id.has_value()) {
|
||||
if (auto speed = call.get_speed(); speed.has_value()) {
|
||||
auto spd_id = this->speed_id_;
|
||||
if (spd_id.has_value()) {
|
||||
auto speed = call.get_speed();
|
||||
if (speed.has_value()) {
|
||||
if (this->speed_type_ == TuyaDatapointType::ENUM) {
|
||||
this->parent_->set_enum_datapoint_value(*spd_id, *speed - 1);
|
||||
} else if (this->speed_type_ == TuyaDatapointType::INTEGER) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -82,7 +82,7 @@ void WhirlpoolClimate::transmit_state() {
|
||||
remote_state[3] |= (uint8_t) (temp - this->temperature_min_()) << 4;
|
||||
|
||||
// Fan speed
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||
case climate::CLIMATE_FAN_HIGH:
|
||||
remote_state[2] |= WHIRLPOOL_FAN_HIGH;
|
||||
break;
|
||||
|
||||
@@ -69,7 +69,7 @@ void Whynter::transmit_state() {
|
||||
}
|
||||
mode_before_ = this->mode;
|
||||
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||
case climate::CLIMATE_FAN_LOW:
|
||||
remote_state |= FAN_LOW;
|
||||
break;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -55,7 +55,7 @@ void ZHLT01Climate::transmit_state() {
|
||||
ir_message[7] |= AC1_FAN_SILENT;
|
||||
break;
|
||||
default:
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) {
|
||||
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||
case climate::CLIMATE_FAN_LOW:
|
||||
ir_message[7] |= AC1_FAN1;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user