mirror of
https://github.com/esphome/esphome.git
synced 2026-05-31 07:57:40 +08:00
[core] Replace custom esphome::optional with std::optional (#14368)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -63,8 +63,9 @@ void Am43Component::control(const CoverCall &call) {
|
|||||||
ESP_LOGW(TAG, "[%s] Error writing stop command to device, error = %d", this->get_name().c_str(), status);
|
ESP_LOGW(TAG, "[%s] Error writing stop command to device, error = %d", this->get_name().c_str(), status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (call.get_position().has_value()) {
|
auto opt_pos = call.get_position();
|
||||||
auto pos = *call.get_position();
|
if (opt_pos.has_value()) {
|
||||||
|
auto pos = *opt_pos;
|
||||||
|
|
||||||
if (this->invert_position_)
|
if (this->invert_position_)
|
||||||
pos = 1 - pos;
|
pos = 1 - pos;
|
||||||
|
|||||||
@@ -24,8 +24,9 @@ void Anova::loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Anova::control(const ClimateCall &call) {
|
void Anova::control(const ClimateCall &call) {
|
||||||
if (call.get_mode().has_value()) {
|
auto mode_val = call.get_mode();
|
||||||
ClimateMode mode = *call.get_mode();
|
if (mode_val.has_value()) {
|
||||||
|
ClimateMode mode = *mode_val;
|
||||||
AnovaPacket *pkt;
|
AnovaPacket *pkt;
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case climate::CLIMATE_MODE_OFF:
|
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);
|
ESP_LOGW(TAG, "[%s] esp_ble_gattc_write_char failed, status=%d", this->parent_->address_str(), status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (call.get_target_temperature().has_value()) {
|
auto target_temp = call.get_target_temperature();
|
||||||
auto *pkt = this->codec_->get_set_target_temp_request(*call.get_target_temperature());
|
if (target_temp.has_value()) {
|
||||||
|
auto *pkt = this->codec_->get_set_target_temp_request(*target_temp);
|
||||||
auto status =
|
auto status =
|
||||||
esp_ble_gattc_write_char(this->parent_->get_gattc_if(), this->parent_->get_conn_id(), this->char_handle_,
|
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);
|
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;
|
remote_state[11] = 0x1e;
|
||||||
|
|
||||||
// Fan speed
|
// Fan speed
|
||||||
switch (this->fan_mode.value()) {
|
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||||
case climate::CLIMATE_FAN_HIGH:
|
case climate::CLIMATE_FAN_HIGH:
|
||||||
remote_state[4] |= BALLU_FAN_HIGH;
|
remote_state[4] |= BALLU_FAN_HIGH;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -45,17 +45,21 @@ void BangBangClimate::setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BangBangClimate::control(const climate::ClimateCall &call) {
|
void BangBangClimate::control(const climate::ClimateCall &call) {
|
||||||
if (call.get_mode().has_value()) {
|
auto mode = call.get_mode();
|
||||||
this->mode = *call.get_mode();
|
if (mode.has_value()) {
|
||||||
|
this->mode = *mode;
|
||||||
}
|
}
|
||||||
if (call.get_target_temperature_low().has_value()) {
|
auto target_temperature_low = call.get_target_temperature_low();
|
||||||
this->target_temperature_low = *call.get_target_temperature_low();
|
if (target_temperature_low.has_value()) {
|
||||||
|
this->target_temperature_low = *target_temperature_low;
|
||||||
}
|
}
|
||||||
if (call.get_target_temperature_high().has_value()) {
|
auto target_temperature_high = call.get_target_temperature_high();
|
||||||
this->target_temperature_high = *call.get_target_temperature_high();
|
if (target_temperature_high.has_value()) {
|
||||||
|
this->target_temperature_high = *target_temperature_high;
|
||||||
}
|
}
|
||||||
if (call.get_preset().has_value()) {
|
auto preset = call.get_preset();
|
||||||
this->change_away_(*call.get_preset() == climate::CLIMATE_PRESET_AWAY);
|
if (preset.has_value()) {
|
||||||
|
this->change_away_(*preset == climate::CLIMATE_PRESET_AWAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->compute_state_();
|
this->compute_state_();
|
||||||
|
|||||||
@@ -96,8 +96,9 @@ void BedJetClimate::control(const ClimateCall &call) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (call.get_mode().has_value()) {
|
auto mode_opt = call.get_mode();
|
||||||
ClimateMode mode = *call.get_mode();
|
if (mode_opt.has_value()) {
|
||||||
|
ClimateMode mode = *mode_opt;
|
||||||
bool button_result;
|
bool button_result;
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case CLIMATE_MODE_OFF:
|
case CLIMATE_MODE_OFF:
|
||||||
@@ -125,8 +126,9 @@ void BedJetClimate::control(const ClimateCall &call) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (call.get_target_temperature().has_value()) {
|
auto target_temp_opt = call.get_target_temperature();
|
||||||
auto target_temp = *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);
|
auto result = this->parent_->set_target_temp(target_temp);
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
@@ -134,8 +136,9 @@ void BedJetClimate::control(const ClimateCall &call) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (call.get_preset().has_value()) {
|
auto preset_opt = call.get_preset();
|
||||||
ClimatePreset preset = *call.get_preset();
|
if (preset_opt.has_value()) {
|
||||||
|
ClimatePreset preset = *preset_opt;
|
||||||
bool result;
|
bool result;
|
||||||
|
|
||||||
if (preset == CLIMATE_PRESET_BOOST) {
|
if (preset == CLIMATE_PRESET_BOOST) {
|
||||||
@@ -187,10 +190,11 @@ void BedJetClimate::control(const ClimateCall &call) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (call.get_fan_mode().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.
|
// 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.
|
// We can still support a ClimateCall that requests low/med/high, and just translate it to a step increment here.
|
||||||
auto fan_mode = *call.get_fan_mode();
|
auto fan_mode = *fan_mode_opt;
|
||||||
bool result;
|
bool result;
|
||||||
if (fan_mode == CLIMATE_FAN_LOW) {
|
if (fan_mode == CLIMATE_FAN_LOW) {
|
||||||
result = this->parent_->set_fan_speed(20);
|
result = this->parent_->set_fan_speed(20);
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ void BedJetFan::control(const fan::FanCall &call) {
|
|||||||
}
|
}
|
||||||
bool did_change = false;
|
bool did_change = false;
|
||||||
|
|
||||||
if (call.get_state().has_value() && this->state != *call.get_state()) {
|
auto state_opt = call.get_state();
|
||||||
|
if (state_opt.has_value() && this->state != *state_opt) {
|
||||||
// Turning off is easy:
|
// Turning off is easy:
|
||||||
if (this->state && this->parent_->button_off()) {
|
if (this->state && this->parent_->button_off()) {
|
||||||
this->state = false;
|
this->state = false;
|
||||||
@@ -36,8 +37,9 @@ void BedJetFan::control(const fan::FanCall &call) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ignore speed changes if not on or turning on
|
// ignore speed changes if not on or turning on
|
||||||
if (this->state && call.get_speed().has_value()) {
|
auto speed_opt = call.get_speed();
|
||||||
auto speed = *call.get_speed();
|
if (this->state && speed_opt.has_value()) {
|
||||||
|
auto speed = *speed_opt;
|
||||||
if (speed >= 1) {
|
if (speed >= 1) {
|
||||||
this->speed = speed;
|
this->speed = speed;
|
||||||
// Fan.speed is 1-20, but Bedjet expects 0-19, so subtract 1
|
// 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);
|
return fan::FanTraits(this->oscillating_ != nullptr, false, this->direction_ != nullptr, 0);
|
||||||
}
|
}
|
||||||
void BinaryFan::control(const fan::FanCall &call) {
|
void BinaryFan::control(const fan::FanCall &call) {
|
||||||
if (call.get_state().has_value())
|
auto state = call.get_state();
|
||||||
this->state = *call.get_state();
|
if (state.has_value())
|
||||||
if (call.get_oscillating().has_value())
|
this->state = *state;
|
||||||
this->oscillating = *call.get_oscillating();
|
auto oscillating = call.get_oscillating();
|
||||||
if (call.get_direction().has_value())
|
if (oscillating.has_value())
|
||||||
this->direction = *call.get_direction();
|
this->oscillating = *oscillating;
|
||||||
|
auto direction = call.get_direction();
|
||||||
|
if (direction.has_value())
|
||||||
|
this->direction = *direction;
|
||||||
|
|
||||||
this->write_state_();
|
this->write_state_();
|
||||||
this->publish_state();
|
this->publish_state();
|
||||||
|
|||||||
@@ -76,11 +76,12 @@ class BLEPresenceDevice : public binary_sensor::BinarySensorInitiallyOff,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MATCH_BY_IBEACON_UUID:
|
case MATCH_BY_IBEACON_UUID:
|
||||||
if (!device.get_ibeacon().has_value()) {
|
auto maybe_ibeacon = device.get_ibeacon();
|
||||||
|
if (!maybe_ibeacon.has_value()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ibeacon = device.get_ibeacon().value();
|
auto ibeacon = *maybe_ibeacon;
|
||||||
|
|
||||||
if (this->ibeacon_uuid_ != ibeacon.get_uuid()) {
|
if (this->ibeacon_uuid_ != ibeacon.get_uuid()) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -74,11 +74,12 @@ class BLERSSISensor : public sensor::Sensor, public esp32_ble_tracker::ESPBTDevi
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MATCH_BY_IBEACON_UUID:
|
case MATCH_BY_IBEACON_UUID:
|
||||||
if (!device.get_ibeacon().has_value()) {
|
auto maybe_ibeacon = device.get_ibeacon();
|
||||||
|
if (!maybe_ibeacon.has_value()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ibeacon = device.get_ibeacon().value();
|
auto ibeacon = *maybe_ibeacon;
|
||||||
|
|
||||||
if (this->ibeacon_uuid_ != ibeacon.get_uuid()) {
|
if (this->ibeacon_uuid_ != ibeacon.get_uuid()) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -71,16 +71,21 @@ void ClimateIR::setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ClimateIR::control(const climate::ClimateCall &call) {
|
void ClimateIR::control(const climate::ClimateCall &call) {
|
||||||
if (call.get_mode().has_value())
|
auto mode = call.get_mode();
|
||||||
this->mode = *call.get_mode();
|
if (mode.has_value())
|
||||||
if (call.get_target_temperature().has_value())
|
this->mode = *mode;
|
||||||
this->target_temperature = *call.get_target_temperature();
|
auto target_temperature = call.get_target_temperature();
|
||||||
if (call.get_fan_mode().has_value())
|
if (target_temperature.has_value())
|
||||||
this->fan_mode = *call.get_fan_mode();
|
this->target_temperature = *target_temperature;
|
||||||
if (call.get_swing_mode().has_value())
|
auto fan_mode = call.get_fan_mode();
|
||||||
this->swing_mode = *call.get_swing_mode();
|
if (fan_mode.has_value())
|
||||||
if (call.get_preset().has_value())
|
this->fan_mode = fan_mode;
|
||||||
this->preset = *call.get_preset();
|
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->transmit_state();
|
||||||
this->publish_state();
|
this->publish_state();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ void LgIrClimate::transmit_state() {
|
|||||||
if (this->mode == climate::CLIMATE_MODE_OFF) {
|
if (this->mode == climate::CLIMATE_MODE_OFF) {
|
||||||
remote_state |= FAN_AUTO;
|
remote_state |= FAN_AUTO;
|
||||||
} else {
|
} else {
|
||||||
switch (this->fan_mode.value()) {
|
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||||
case climate::CLIMATE_FAN_HIGH:
|
case climate::CLIMATE_FAN_HIGH:
|
||||||
remote_state |= FAN_MAX;
|
remote_state |= FAN_MAX;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ class LgIrClimate : public climate_ir::ClimateIR {
|
|||||||
void control(const climate::ClimateCall &call) override {
|
void control(const climate::ClimateCall &call) override {
|
||||||
this->send_swing_cmd_ = call.get_swing_mode().has_value();
|
this->send_swing_cmd_ = call.get_swing_mode().has_value();
|
||||||
// swing resets after unit powered off
|
// swing resets after unit powered off
|
||||||
if (call.get_mode().has_value() && *call.get_mode() == climate::CLIMATE_MODE_OFF)
|
auto mode = call.get_mode();
|
||||||
|
if (mode.has_value() && *mode == climate::CLIMATE_MODE_OFF)
|
||||||
this->swing_mode = climate::CLIMATE_SWING_OFF;
|
this->swing_mode = climate::CLIMATE_SWING_OFF;
|
||||||
climate_ir::ClimateIR::control(call);
|
climate_ir::ClimateIR::control(call);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ void CoolixClimate::transmit_state() {
|
|||||||
this->fan_mode = climate::CLIMATE_FAN_AUTO;
|
this->fan_mode = climate::CLIMATE_FAN_AUTO;
|
||||||
remote_state |= COOLIX_FAN_MODE_AUTO_DRY;
|
remote_state |= COOLIX_FAN_MODE_AUTO_DRY;
|
||||||
} else {
|
} else {
|
||||||
switch (this->fan_mode.value()) {
|
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||||
case climate::CLIMATE_FAN_HIGH:
|
case climate::CLIMATE_FAN_HIGH:
|
||||||
remote_state |= COOLIX_FAN_MAX;
|
remote_state |= COOLIX_FAN_MAX;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ class CoolixClimate : public climate_ir::ClimateIR {
|
|||||||
void control(const climate::ClimateCall &call) override {
|
void control(const climate::ClimateCall &call) override {
|
||||||
send_swing_cmd_ = call.get_swing_mode().has_value();
|
send_swing_cmd_ = call.get_swing_mode().has_value();
|
||||||
// swing resets after unit powered off
|
// swing resets after unit powered off
|
||||||
if (call.get_mode().has_value() && *call.get_mode() == climate::CLIMATE_MODE_OFF)
|
auto mode = call.get_mode();
|
||||||
|
if (mode.has_value() && *mode == climate::CLIMATE_MODE_OFF)
|
||||||
this->swing_mode = climate::CLIMATE_SWING_OFF;
|
this->swing_mode = climate::CLIMATE_SWING_OFF;
|
||||||
climate_ir::ClimateIR::control(call);
|
climate_ir::ClimateIR::control(call);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,12 +38,15 @@ cover::CoverTraits CopyCover::get_traits() {
|
|||||||
void CopyCover::control(const cover::CoverCall &call) {
|
void CopyCover::control(const cover::CoverCall &call) {
|
||||||
auto call2 = source_->make_call();
|
auto call2 = source_->make_call();
|
||||||
call2.set_stop(call.get_stop());
|
call2.set_stop(call.get_stop());
|
||||||
if (call.get_tilt().has_value())
|
auto tilt = call.get_tilt();
|
||||||
call2.set_tilt(*call.get_tilt());
|
if (tilt.has_value())
|
||||||
if (call.get_position().has_value())
|
call2.set_tilt(*tilt);
|
||||||
call2.set_position(*call.get_position());
|
auto position = call.get_position();
|
||||||
if (call.get_tilt().has_value())
|
if (position.has_value())
|
||||||
call2.set_tilt(*call.get_tilt());
|
call2.set_position(*position);
|
||||||
|
auto tilt2 = call.get_tilt();
|
||||||
|
if (tilt2.has_value())
|
||||||
|
call2.set_tilt(*tilt2);
|
||||||
call2.perform();
|
call2.perform();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,14 +45,18 @@ fan::FanTraits CopyFan::get_traits() {
|
|||||||
|
|
||||||
void CopyFan::control(const fan::FanCall &call) {
|
void CopyFan::control(const fan::FanCall &call) {
|
||||||
auto call2 = source_->make_call();
|
auto call2 = source_->make_call();
|
||||||
if (call.get_state().has_value())
|
auto state = call.get_state();
|
||||||
call2.set_state(*call.get_state());
|
if (state.has_value())
|
||||||
if (call.get_oscillating().has_value())
|
call2.set_state(*state);
|
||||||
call2.set_oscillating(*call.get_oscillating());
|
auto oscillating = call.get_oscillating();
|
||||||
if (call.get_speed().has_value())
|
if (oscillating.has_value())
|
||||||
call2.set_speed(*call.get_speed());
|
call2.set_oscillating(*oscillating);
|
||||||
if (call.get_direction().has_value())
|
auto speed = call.get_speed();
|
||||||
call2.set_direction(*call.get_direction());
|
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())
|
if (call.has_preset_mode())
|
||||||
call2.set_preset_mode(call.get_preset_mode());
|
call2.set_preset_mode(call.get_preset_mode());
|
||||||
call2.perform();
|
call2.perform();
|
||||||
|
|||||||
@@ -11,8 +11,9 @@ void CopySelect::setup() {
|
|||||||
|
|
||||||
traits.set_options(source_->traits.get_options());
|
traits.set_options(source_->traits.get_options());
|
||||||
|
|
||||||
if (source_->has_state())
|
auto idx = this->source_->active_index();
|
||||||
this->publish_state(source_->active_index().value());
|
if (idx.has_value())
|
||||||
|
this->publish_state(*idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CopySelect::dump_config() { LOG_SELECT("", "Copy Select", this); }
|
void CopySelect::dump_config() { LOG_SELECT("", "Copy Select", this); }
|
||||||
|
|||||||
@@ -37,8 +37,9 @@ void CurrentBasedCover::control(const CoverCall &call) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (call.get_position().has_value()) {
|
auto opt_pos = call.get_position();
|
||||||
auto pos = *call.get_position();
|
if (opt_pos.has_value()) {
|
||||||
|
auto pos = *opt_pos;
|
||||||
if (fabsf(this->position - pos) < 0.01) {
|
if (fabsf(this->position - pos) < 0.01) {
|
||||||
// already at target
|
// already at target
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ uint8_t DaikinClimate::operation_mode_() const {
|
|||||||
|
|
||||||
uint16_t DaikinClimate::fan_speed_() const {
|
uint16_t DaikinClimate::fan_speed_() const {
|
||||||
uint16_t fan_speed;
|
uint16_t fan_speed;
|
||||||
switch (this->fan_mode.value()) {
|
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||||
case climate::CLIMATE_FAN_QUIET:
|
case climate::CLIMATE_FAN_QUIET:
|
||||||
fan_speed = DAIKIN_FAN_SILENT << 8;
|
fan_speed = DAIKIN_FAN_SILENT << 8;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ uint8_t DaikinArcClimate::operation_mode_() {
|
|||||||
|
|
||||||
uint16_t DaikinArcClimate::fan_speed_() {
|
uint16_t DaikinArcClimate::fan_speed_() {
|
||||||
uint16_t fan_speed;
|
uint16_t fan_speed;
|
||||||
switch (this->fan_mode.value()) {
|
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||||
case climate::CLIMATE_FAN_LOW:
|
case climate::CLIMATE_FAN_LOW:
|
||||||
fan_speed = DAIKIN_FAN_1 << 8;
|
fan_speed = DAIKIN_FAN_1 << 8;
|
||||||
break;
|
break;
|
||||||
@@ -485,8 +485,9 @@ bool DaikinArcClimate::on_receive(remote_base::RemoteReceiveData data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DaikinArcClimate::control(const climate::ClimateCall &call) {
|
void DaikinArcClimate::control(const climate::ClimateCall &call) {
|
||||||
if (call.get_target_humidity().has_value()) {
|
auto target_humidity = call.get_target_humidity();
|
||||||
this->target_humidity = *call.get_target_humidity();
|
if (target_humidity.has_value()) {
|
||||||
|
this->target_humidity = *target_humidity;
|
||||||
}
|
}
|
||||||
climate_ir::ClimateIR::control(call);
|
climate_ir::ClimateIR::control(call);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ uint8_t DaikinBrcClimate::operation_mode_() {
|
|||||||
|
|
||||||
uint8_t DaikinBrcClimate::fan_speed_swing_() {
|
uint8_t DaikinBrcClimate::fan_speed_swing_() {
|
||||||
uint16_t fan_speed;
|
uint16_t fan_speed;
|
||||||
switch (this->fan_mode.value()) {
|
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||||
case climate::CLIMATE_FAN_LOW:
|
case climate::CLIMATE_FAN_LOW:
|
||||||
fan_speed = DAIKIN_BRC_FAN_1;
|
fan_speed = DAIKIN_BRC_FAN_1;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ void DeepSleepComponent::dump_config_platform_() {}
|
|||||||
bool DeepSleepComponent::prepare_to_sleep_() { return true; }
|
bool DeepSleepComponent::prepare_to_sleep_() { return true; }
|
||||||
|
|
||||||
void DeepSleepComponent::deep_sleep_() {
|
void DeepSleepComponent::deep_sleep_() {
|
||||||
ESP.deepSleep(*this->sleep_duration_); // NOLINT(readability-static-accessed-through-instance)
|
ESP.deepSleep(this->sleep_duration_.value_or(0)); // NOLINT(readability-static-accessed-through-instance)
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace deep_sleep
|
} // namespace deep_sleep
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ uint8_t DelonghiClimate::operation_mode_() {
|
|||||||
|
|
||||||
uint16_t DelonghiClimate::fan_speed_() {
|
uint16_t DelonghiClimate::fan_speed_() {
|
||||||
uint16_t fan_speed;
|
uint16_t fan_speed;
|
||||||
switch (this->fan_mode.value()) {
|
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||||
case climate::CLIMATE_FAN_LOW:
|
case climate::CLIMATE_FAN_LOW:
|
||||||
fan_speed = DELONGHI_FAN_LOW;
|
fan_speed = DELONGHI_FAN_LOW;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -29,10 +29,11 @@ class DemoAlarmControlPanel : public AlarmControlPanel, public Component {
|
|||||||
protected:
|
protected:
|
||||||
void control(const AlarmControlPanelCall &call) override {
|
void control(const AlarmControlPanelCall &call) override {
|
||||||
auto state = call.get_state().value_or(ACP_STATE_DISARMED);
|
auto state = call.get_state().value_or(ACP_STATE_DISARMED);
|
||||||
|
auto code = call.get_code();
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case ACP_STATE_ARMED_AWAY:
|
case ACP_STATE_ARMED_AWAY:
|
||||||
if (this->get_requires_code_to_arm() && call.get_code().has_value()) {
|
if (this->get_requires_code_to_arm() && code.has_value()) {
|
||||||
if (call.get_code().value() != "1234") {
|
if (*code != "1234") {
|
||||||
this->status_momentary_error("invalid_code", 5000);
|
this->status_momentary_error("invalid_code", 5000);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -40,8 +41,8 @@ class DemoAlarmControlPanel : public AlarmControlPanel, public Component {
|
|||||||
this->publish_state(ACP_STATE_ARMED_AWAY);
|
this->publish_state(ACP_STATE_ARMED_AWAY);
|
||||||
break;
|
break;
|
||||||
case ACP_STATE_DISARMED:
|
case ACP_STATE_DISARMED:
|
||||||
if (this->get_requires_code() && call.get_code().has_value()) {
|
if (this->get_requires_code() && code.has_value()) {
|
||||||
if (call.get_code().value() != "1234") {
|
if (*code != "1234") {
|
||||||
this->status_momentary_error("invalid_code", 5000);
|
this->status_momentary_error("invalid_code", 5000);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,33 +45,31 @@ class DemoClimate : public climate::Climate, public Component {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void control(const climate::ClimateCall &call) override {
|
void control(const climate::ClimateCall &call) override {
|
||||||
if (call.get_mode().has_value()) {
|
auto mode = call.get_mode();
|
||||||
this->mode = *call.get_mode();
|
if (mode.has_value())
|
||||||
}
|
this->mode = *mode;
|
||||||
if (call.get_target_temperature().has_value()) {
|
auto target_temperature = call.get_target_temperature();
|
||||||
this->target_temperature = *call.get_target_temperature();
|
if (target_temperature.has_value())
|
||||||
}
|
this->target_temperature = *target_temperature;
|
||||||
if (call.get_target_temperature_low().has_value()) {
|
auto target_temperature_low = call.get_target_temperature_low();
|
||||||
this->target_temperature_low = *call.get_target_temperature_low();
|
if (target_temperature_low.has_value())
|
||||||
}
|
this->target_temperature_low = *target_temperature_low;
|
||||||
if (call.get_target_temperature_high().has_value()) {
|
auto target_temperature_high = call.get_target_temperature_high();
|
||||||
this->target_temperature_high = *call.get_target_temperature_high();
|
if (target_temperature_high.has_value())
|
||||||
}
|
this->target_temperature_high = *target_temperature_high;
|
||||||
if (call.get_fan_mode().has_value()) {
|
auto fan_mode = call.get_fan_mode();
|
||||||
this->set_fan_mode_(*call.get_fan_mode());
|
if (fan_mode.has_value())
|
||||||
}
|
this->set_fan_mode_(*fan_mode);
|
||||||
if (call.get_swing_mode().has_value()) {
|
auto swing_mode = call.get_swing_mode();
|
||||||
this->swing_mode = *call.get_swing_mode();
|
if (swing_mode.has_value())
|
||||||
}
|
this->swing_mode = *swing_mode;
|
||||||
if (call.has_custom_fan_mode()) {
|
if (call.has_custom_fan_mode())
|
||||||
this->set_custom_fan_mode_(call.get_custom_fan_mode());
|
this->set_custom_fan_mode_(call.get_custom_fan_mode());
|
||||||
}
|
auto preset = call.get_preset();
|
||||||
if (call.get_preset().has_value()) {
|
if (preset.has_value())
|
||||||
this->set_preset_(*call.get_preset());
|
this->set_preset_(*preset);
|
||||||
}
|
if (call.has_custom_preset())
|
||||||
if (call.has_custom_preset()) {
|
|
||||||
this->set_custom_preset_(call.get_custom_preset());
|
this->set_custom_preset_(call.get_custom_preset());
|
||||||
}
|
|
||||||
this->publish_state();
|
this->publish_state();
|
||||||
}
|
}
|
||||||
climate::ClimateTraits traits() override {
|
climate::ClimateTraits traits() override {
|
||||||
|
|||||||
@@ -38,8 +38,9 @@ class DemoCover : public cover::Cover, public Component {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void control(const cover::CoverCall &call) override {
|
void control(const cover::CoverCall &call) override {
|
||||||
if (call.get_position().has_value()) {
|
auto pos = call.get_position();
|
||||||
float target = *call.get_position();
|
if (pos.has_value()) {
|
||||||
|
float target = *pos;
|
||||||
this->current_operation =
|
this->current_operation =
|
||||||
target > this->position ? cover::COVER_OPERATION_OPENING : cover::COVER_OPERATION_CLOSING;
|
target > this->position ? cover::COVER_OPERATION_OPENING : cover::COVER_OPERATION_CLOSING;
|
||||||
|
|
||||||
@@ -49,8 +50,9 @@ class DemoCover : public cover::Cover, public Component {
|
|||||||
this->publish_state();
|
this->publish_state();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (call.get_tilt().has_value()) {
|
auto tilt = call.get_tilt();
|
||||||
this->tilt = *call.get_tilt();
|
if (tilt.has_value()) {
|
||||||
|
this->tilt = *tilt;
|
||||||
}
|
}
|
||||||
if (call.get_stop()) {
|
if (call.get_stop()) {
|
||||||
this->cancel_timeout("move");
|
this->cancel_timeout("move");
|
||||||
|
|||||||
@@ -47,14 +47,18 @@ class DemoFan : public fan::Fan, public Component {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void control(const fan::FanCall &call) override {
|
void control(const fan::FanCall &call) override {
|
||||||
if (call.get_state().has_value())
|
auto state = call.get_state();
|
||||||
this->state = *call.get_state();
|
if (state.has_value())
|
||||||
if (call.get_oscillating().has_value())
|
this->state = *state;
|
||||||
this->oscillating = *call.get_oscillating();
|
auto oscillating = call.get_oscillating();
|
||||||
if (call.get_speed().has_value())
|
if (oscillating.has_value())
|
||||||
this->speed = *call.get_speed();
|
this->oscillating = *oscillating;
|
||||||
if (call.get_direction().has_value())
|
auto speed = call.get_speed();
|
||||||
this->direction = *call.get_direction();
|
if (speed.has_value())
|
||||||
|
this->speed = *speed;
|
||||||
|
auto direction = call.get_direction();
|
||||||
|
if (direction.has_value())
|
||||||
|
this->direction = *direction;
|
||||||
|
|
||||||
this->publish_state();
|
this->publish_state();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,9 @@ namespace demo {
|
|||||||
class DemoLock : public lock::Lock {
|
class DemoLock : public lock::Lock {
|
||||||
protected:
|
protected:
|
||||||
void control(const lock::LockCall &call) override {
|
void control(const lock::LockCall &call) override {
|
||||||
auto state = *call.get_state();
|
auto state = call.get_state();
|
||||||
this->publish_state(state);
|
if (state.has_value())
|
||||||
|
this->publish_state(*state);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -26,12 +26,15 @@ class DemoValve : public valve::Valve {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void control(const valve::ValveCall &call) override {
|
void control(const valve::ValveCall &call) override {
|
||||||
if (call.get_position().has_value()) {
|
auto pos = call.get_position();
|
||||||
this->position = *call.get_position();
|
if (pos.has_value()) {
|
||||||
|
this->position = *pos;
|
||||||
this->publish_state();
|
this->publish_state();
|
||||||
return;
|
return;
|
||||||
} else if (call.get_toggle().has_value()) {
|
}
|
||||||
if (call.get_toggle().value()) {
|
auto toggle = call.get_toggle();
|
||||||
|
if (toggle.has_value()) {
|
||||||
|
if (*toggle) {
|
||||||
if (this->position == valve::VALVE_OPEN) {
|
if (this->position == valve::VALVE_OPEN) {
|
||||||
this->position = valve::VALVE_CLOSED;
|
this->position = valve::VALVE_CLOSED;
|
||||||
this->publish_state();
|
this->publish_state();
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ uint8_t EmmetiClimate::set_mode_() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t EmmetiClimate::set_fan_speed_() {
|
uint8_t EmmetiClimate::set_fan_speed_() {
|
||||||
switch (this->fan_mode.value()) {
|
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||||
case climate::CLIMATE_FAN_LOW:
|
case climate::CLIMATE_FAN_LOW:
|
||||||
return EMMETI_FAN_1;
|
return EMMETI_FAN_1;
|
||||||
case climate::CLIMATE_FAN_MEDIUM:
|
case climate::CLIMATE_FAN_MEDIUM:
|
||||||
|
|||||||
@@ -37,8 +37,9 @@ void EndstopCover::control(const CoverCall &call) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (call.get_position().has_value()) {
|
auto opt_pos = call.get_position();
|
||||||
auto pos = *call.get_position();
|
if (opt_pos.has_value()) {
|
||||||
|
auto pos = *opt_pos;
|
||||||
if (pos == this->position) {
|
if (pos == this->position) {
|
||||||
// already at target
|
// already at target
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ class ESPBTDevice {
|
|||||||
for (auto &it : this->manufacturer_datas_) {
|
for (auto &it : this->manufacturer_datas_) {
|
||||||
auto res = ESPBLEiBeacon::from_manufacturer_data(it);
|
auto res = ESPBLEiBeacon::from_manufacturer_data(it);
|
||||||
if (res.has_value())
|
if (res.has_value())
|
||||||
return *res;
|
return res;
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,7 +162,8 @@ void ESP32RMTLEDStripLightOutput::set_led_params(uint32_t bit0_high, uint32_t bi
|
|||||||
void ESP32RMTLEDStripLightOutput::write_state(light::LightState *state) {
|
void ESP32RMTLEDStripLightOutput::write_state(light::LightState *state) {
|
||||||
// protect from refreshing too often
|
// protect from refreshing too often
|
||||||
uint32_t now = micros();
|
uint32_t now = micros();
|
||||||
if (*this->max_refresh_rate_ != 0 && (now - this->last_refresh_) < *this->max_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
|
// try again next loop iteration, so that this change won't get lost
|
||||||
this->schedule_show();
|
this->schedule_show();
|
||||||
return;
|
return;
|
||||||
@@ -301,7 +302,7 @@ void ESP32RMTLEDStripLightOutput::dump_config() {
|
|||||||
" RGB Order: %s\n"
|
" RGB Order: %s\n"
|
||||||
" Max refresh rate: %" PRIu32 "\n"
|
" Max refresh rate: %" PRIu32 "\n"
|
||||||
" Number of LEDs: %u",
|
" Number of LEDs: %u",
|
||||||
rgb_order, *this->max_refresh_rate_, this->num_leds_);
|
rgb_order, this->max_refresh_rate_.value_or(0), this->num_leds_);
|
||||||
}
|
}
|
||||||
|
|
||||||
float ESP32RMTLEDStripLightOutput::get_setup_priority() const { return setup_priority::HARDWARE; }
|
float ESP32RMTLEDStripLightOutput::get_setup_priority() const { return setup_priority::HARDWARE; }
|
||||||
|
|||||||
@@ -21,12 +21,13 @@ void FastLEDLightOutput::dump_config() {
|
|||||||
"FastLED light:\n"
|
"FastLED light:\n"
|
||||||
" Num LEDs: %u\n"
|
" Num LEDs: %u\n"
|
||||||
" Max refresh rate: %u",
|
" Max refresh rate: %u",
|
||||||
this->num_leds_, *this->max_refresh_rate_);
|
this->num_leds_, this->max_refresh_rate_.value_or(0));
|
||||||
}
|
}
|
||||||
void FastLEDLightOutput::write_state(light::LightState *state) {
|
void FastLEDLightOutput::write_state(light::LightState *state) {
|
||||||
// protect from refreshing too often
|
// protect from refreshing too often
|
||||||
uint32_t now = micros();
|
uint32_t now = micros();
|
||||||
if (*this->max_refresh_rate_ != 0 && (now - this->last_refresh_) < *this->max_refresh_rate_) {
|
uint32_t max_rate = this->max_refresh_rate_.value_or(0);
|
||||||
|
if (max_rate != 0 && (now - this->last_refresh_) < max_rate) {
|
||||||
// try again next loop iteration, so that this change won't get lost
|
// try again next loop iteration, so that this change won't get lost
|
||||||
this->schedule_show();
|
this->schedule_show();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -269,9 +269,12 @@ void FeedbackCover::control(const CoverCall &call) {
|
|||||||
this->start_direction_(COVER_OPERATION_CLOSING);
|
this->start_direction_(COVER_OPERATION_CLOSING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (call.get_position().has_value()) {
|
} else {
|
||||||
|
auto pos_opt = call.get_position();
|
||||||
|
if (!pos_opt.has_value())
|
||||||
|
return;
|
||||||
// go to position action
|
// go to position action
|
||||||
auto pos = *call.get_position();
|
auto pos = *pos_opt;
|
||||||
if (pos == this->position) {
|
if (pos == this->position) {
|
||||||
// already at target,
|
// already at target,
|
||||||
|
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ void FujitsuGeneralClimate::transmit_state() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set fan
|
// Set fan
|
||||||
switch (this->fan_mode.value()) {
|
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||||
case climate::CLIMATE_FAN_HIGH:
|
case climate::CLIMATE_FAN_HIGH:
|
||||||
SET_NIBBLE(remote_state, FUJITSU_GENERAL_FAN_NIBBLE, FUJITSU_GENERAL_FAN_HIGH);
|
SET_NIBBLE(remote_state, FUJITSU_GENERAL_FAN_NIBBLE, FUJITSU_GENERAL_FAN_HIGH);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ uint8_t GreeClimate::operation_mode_() {
|
|||||||
uint8_t GreeClimate::fan_speed_() {
|
uint8_t GreeClimate::fan_speed_() {
|
||||||
// YX1FF has 4 fan speeds -- we treat low as quiet and turbo as high
|
// YX1FF has 4 fan speeds -- we treat low as quiet and turbo as high
|
||||||
if (this->model_ == GREE_YX1FF) {
|
if (this->model_ == GREE_YX1FF) {
|
||||||
switch (this->fan_mode.value()) {
|
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||||
case climate::CLIMATE_FAN_QUIET:
|
case climate::CLIMATE_FAN_QUIET:
|
||||||
return GREE_FAN_1;
|
return GREE_FAN_1;
|
||||||
case climate::CLIMATE_FAN_LOW:
|
case climate::CLIMATE_FAN_LOW:
|
||||||
@@ -195,7 +195,7 @@ uint8_t GreeClimate::fan_speed_() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (this->fan_mode.value()) {
|
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||||
case climate::CLIMATE_FAN_LOW:
|
case climate::CLIMATE_FAN_LOW:
|
||||||
return GREE_FAN_1;
|
return GREE_FAN_1;
|
||||||
case climate::CLIMATE_FAN_MEDIUM:
|
case climate::CLIMATE_FAN_MEDIUM:
|
||||||
@@ -235,7 +235,7 @@ uint8_t GreeClimate::temperature_() {
|
|||||||
uint8_t GreeClimate::preset_() {
|
uint8_t GreeClimate::preset_() {
|
||||||
// YX1FF has sleep preset
|
// YX1FF has sleep preset
|
||||||
if (this->model_ == GREE_YX1FF) {
|
if (this->model_ == GREE_YX1FF) {
|
||||||
switch (this->preset.value()) {
|
switch (this->preset.value_or(climate::CLIMATE_PRESET_NONE)) {
|
||||||
case climate::CLIMATE_PRESET_NONE:
|
case climate::CLIMATE_PRESET_NONE:
|
||||||
return GREE_PRESET_NONE;
|
return GREE_PRESET_NONE;
|
||||||
case climate::CLIMATE_PRESET_SLEEP:
|
case climate::CLIMATE_PRESET_SLEEP:
|
||||||
|
|||||||
@@ -893,7 +893,8 @@ haier_protocol::HandlerError HonClimate::process_status_message_(const uint8_t *
|
|||||||
} else {
|
} else {
|
||||||
this->preset = CLIMATE_PRESET_NONE;
|
this->preset = CLIMATE_PRESET_NONE;
|
||||||
}
|
}
|
||||||
should_publish = should_publish || (!old_preset.has_value()) || (old_preset.value() != this->preset.value());
|
should_publish = should_publish || (!old_preset.has_value()) ||
|
||||||
|
(old_preset.value_or(CLIMATE_PRESET_NONE) != this->preset.value_or(CLIMATE_PRESET_NONE));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// Target temperature
|
// Target temperature
|
||||||
@@ -936,7 +937,8 @@ haier_protocol::HandlerError HonClimate::process_status_message_(const uint8_t *
|
|||||||
this->fan_mode = CLIMATE_FAN_HIGH;
|
this->fan_mode = CLIMATE_FAN_HIGH;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
should_publish = should_publish || (!old_fan_mode.has_value()) || (old_fan_mode.value() != fan_mode.value());
|
should_publish = should_publish || (!old_fan_mode.has_value()) ||
|
||||||
|
(old_fan_mode.value_or(CLIMATE_FAN_ON) != this->fan_mode.value_or(CLIMATE_FAN_ON));
|
||||||
}
|
}
|
||||||
// Display status
|
// Display status
|
||||||
// should be before "Climate mode" because it is changing this->mode
|
// should be before "Climate mode" because it is changing this->mode
|
||||||
@@ -1301,7 +1303,8 @@ void HonClimate::clear_control_messages_queue_() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool HonClimate::prepare_pending_action() {
|
bool HonClimate::prepare_pending_action() {
|
||||||
switch (this->action_request_.value().action) {
|
auto &action_request = this->action_request_.value(); // NOLINT(bugprone-unchecked-optional-access)
|
||||||
|
switch (action_request.action) {
|
||||||
case ActionRequest::START_SELF_CLEAN:
|
case ActionRequest::START_SELF_CLEAN:
|
||||||
if (this->control_method_ == HonControlMethod::SET_GROUP_PARAMETERS) {
|
if (this->control_method_ == HonControlMethod::SET_GROUP_PARAMETERS) {
|
||||||
uint8_t control_out_buffer[haier_protocol::MAX_FRAME_SIZE];
|
uint8_t control_out_buffer[haier_protocol::MAX_FRAME_SIZE];
|
||||||
@@ -1315,12 +1318,12 @@ bool HonClimate::prepare_pending_action() {
|
|||||||
out_data->ac_power = 1;
|
out_data->ac_power = 1;
|
||||||
out_data->ac_mode = (uint8_t) hon_protocol::ConditioningMode::DRY;
|
out_data->ac_mode = (uint8_t) hon_protocol::ConditioningMode::DRY;
|
||||||
out_data->light_status = 0;
|
out_data->light_status = 0;
|
||||||
this->action_request_.value().message = haier_protocol::HaierMessage(
|
action_request.message = haier_protocol::HaierMessage(
|
||||||
haier_protocol::FrameType::CONTROL, (uint16_t) hon_protocol::SubcommandsControl::SET_GROUP_PARAMETERS,
|
haier_protocol::FrameType::CONTROL, (uint16_t) hon_protocol::SubcommandsControl::SET_GROUP_PARAMETERS,
|
||||||
control_out_buffer, this->real_control_packet_size_);
|
control_out_buffer, this->real_control_packet_size_);
|
||||||
return true;
|
return true;
|
||||||
} else if (this->control_method_ == HonControlMethod::SET_SINGLE_PARAMETER) {
|
} else if (this->control_method_ == HonControlMethod::SET_SINGLE_PARAMETER) {
|
||||||
this->action_request_.value().message =
|
action_request.message =
|
||||||
haier_protocol::HaierMessage(haier_protocol::FrameType::CONTROL,
|
haier_protocol::HaierMessage(haier_protocol::FrameType::CONTROL,
|
||||||
(uint16_t) hon_protocol::SubcommandsControl::SET_SINGLE_PARAMETER +
|
(uint16_t) hon_protocol::SubcommandsControl::SET_SINGLE_PARAMETER +
|
||||||
(uint8_t) hon_protocol::DataParameters::SELF_CLEANING,
|
(uint8_t) hon_protocol::DataParameters::SELF_CLEANING,
|
||||||
@@ -1343,7 +1346,7 @@ bool HonClimate::prepare_pending_action() {
|
|||||||
out_data->ac_power = 1;
|
out_data->ac_power = 1;
|
||||||
out_data->ac_mode = (uint8_t) hon_protocol::ConditioningMode::DRY;
|
out_data->ac_mode = (uint8_t) hon_protocol::ConditioningMode::DRY;
|
||||||
out_data->light_status = 0;
|
out_data->light_status = 0;
|
||||||
this->action_request_.value().message = haier_protocol::HaierMessage(
|
action_request.message = haier_protocol::HaierMessage(
|
||||||
haier_protocol::FrameType::CONTROL, (uint16_t) hon_protocol::SubcommandsControl::SET_GROUP_PARAMETERS,
|
haier_protocol::FrameType::CONTROL, (uint16_t) hon_protocol::SubcommandsControl::SET_GROUP_PARAMETERS,
|
||||||
control_out_buffer, this->real_control_packet_size_);
|
control_out_buffer, this->real_control_packet_size_);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -402,7 +402,8 @@ haier_protocol::HandlerError Smartair2Climate::process_status_message_(const uin
|
|||||||
} else {
|
} else {
|
||||||
this->preset = CLIMATE_PRESET_NONE;
|
this->preset = CLIMATE_PRESET_NONE;
|
||||||
}
|
}
|
||||||
should_publish = should_publish || (!old_preset.has_value()) || (old_preset.value() != this->preset.value());
|
should_publish = should_publish || (!old_preset.has_value()) ||
|
||||||
|
(old_preset.value_or(CLIMATE_PRESET_NONE) != this->preset.value_or(CLIMATE_PRESET_NONE));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// Target temperature
|
// Target temperature
|
||||||
@@ -446,7 +447,8 @@ haier_protocol::HandlerError Smartair2Climate::process_status_message_(const uin
|
|||||||
this->fan_mode = CLIMATE_FAN_HIGH;
|
this->fan_mode = CLIMATE_FAN_HIGH;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
should_publish = should_publish || (!old_fan_mode.has_value()) || (old_fan_mode.value() != fan_mode.value());
|
should_publish = should_publish || (!old_fan_mode.has_value()) ||
|
||||||
|
(old_fan_mode.value_or(CLIMATE_FAN_ON) != this->fan_mode.value_or(CLIMATE_FAN_ON));
|
||||||
}
|
}
|
||||||
// Display status
|
// Display status
|
||||||
// should be before "Climate mode" because it is changing this->mode
|
// 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) {
|
void HBridgeFan::control(const fan::FanCall &call) {
|
||||||
if (call.get_state().has_value())
|
auto call_state = call.get_state();
|
||||||
this->state = *call.get_state();
|
if (call_state.has_value())
|
||||||
if (call.get_speed().has_value())
|
this->state = *call_state;
|
||||||
this->speed = *call.get_speed();
|
auto call_speed = call.get_speed();
|
||||||
if (call.get_oscillating().has_value())
|
if (call_speed.has_value())
|
||||||
this->oscillating = *call.get_oscillating();
|
this->speed = *call_speed;
|
||||||
if (call.get_direction().has_value())
|
auto call_oscillating = call.get_oscillating();
|
||||||
this->direction = *call.get_direction();
|
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->apply_preset_mode_(call);
|
||||||
|
|
||||||
this->write_state_();
|
this->write_state_();
|
||||||
|
|||||||
@@ -171,9 +171,12 @@ void HE60rCover::control(const CoverCall &call) {
|
|||||||
} else {
|
} else {
|
||||||
this->toggles_needed_++;
|
this->toggles_needed_++;
|
||||||
}
|
}
|
||||||
} else if (call.get_position().has_value()) {
|
} else {
|
||||||
|
auto pos_opt = call.get_position();
|
||||||
|
if (!pos_opt.has_value())
|
||||||
|
return;
|
||||||
// go to position action
|
// go to position action
|
||||||
auto pos = *call.get_position();
|
auto pos = *pos_opt;
|
||||||
// are we at the target?
|
// are we at the target?
|
||||||
if (pos == this->position) {
|
if (pos == this->position) {
|
||||||
this->start_direction_(COVER_OPERATION_IDLE);
|
this->start_direction_(COVER_OPERATION_IDLE);
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ void HitachiClimate::transmit_state() {
|
|||||||
|
|
||||||
set_temp_(static_cast<uint8_t>(this->target_temperature));
|
set_temp_(static_cast<uint8_t>(this->target_temperature));
|
||||||
|
|
||||||
switch (this->fan_mode.value()) {
|
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||||
case climate::CLIMATE_FAN_LOW:
|
case climate::CLIMATE_FAN_LOW:
|
||||||
set_fan_(HITACHI_AC344_FAN_LOW);
|
set_fan_(HITACHI_AC344_FAN_LOW);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ void HitachiClimate::transmit_state() {
|
|||||||
|
|
||||||
set_temp_(static_cast<uint8_t>(this->target_temperature));
|
set_temp_(static_cast<uint8_t>(this->target_temperature));
|
||||||
|
|
||||||
switch (this->fan_mode.value()) {
|
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||||
case climate::CLIMATE_FAN_LOW:
|
case climate::CLIMATE_FAN_LOW:
|
||||||
set_fan_(HITACHI_AC424_FAN_LOW);
|
set_fan_(HITACHI_AC424_FAN_LOW);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -11,17 +11,18 @@ static const char *const TAG = "audio";
|
|||||||
|
|
||||||
void I2SAudioMediaPlayer::control(const media_player::MediaPlayerCall &call) {
|
void I2SAudioMediaPlayer::control(const media_player::MediaPlayerCall &call) {
|
||||||
media_player::MediaPlayerState play_state = media_player::MEDIA_PLAYER_STATE_PLAYING;
|
media_player::MediaPlayerState play_state = media_player::MEDIA_PLAYER_STATE_PLAYING;
|
||||||
if (call.get_announcement().has_value()) {
|
auto announcement = call.get_announcement();
|
||||||
play_state = call.get_announcement().value() ? media_player::MEDIA_PLAYER_STATE_ANNOUNCING
|
if (announcement.has_value()) {
|
||||||
: media_player::MEDIA_PLAYER_STATE_PLAYING;
|
play_state = *announcement ? media_player::MEDIA_PLAYER_STATE_ANNOUNCING : media_player::MEDIA_PLAYER_STATE_PLAYING;
|
||||||
}
|
}
|
||||||
if (call.get_media_url().has_value()) {
|
auto media_url = call.get_media_url();
|
||||||
this->current_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->i2s_state_ != I2S_STATE_STOPPED && this->audio_ != nullptr) {
|
||||||
if (this->audio_->isRunning()) {
|
if (this->audio_->isRunning()) {
|
||||||
this->audio_->stopSong();
|
this->audio_->stopSong();
|
||||||
}
|
}
|
||||||
this->audio_->connecttohost(this->current_url_.value().c_str());
|
this->audio_->connecttohost(media_url->c_str());
|
||||||
this->state = play_state;
|
this->state = play_state;
|
||||||
} else {
|
} else {
|
||||||
this->start();
|
this->start();
|
||||||
@@ -32,13 +33,15 @@ void I2SAudioMediaPlayer::control(const media_player::MediaPlayerCall &call) {
|
|||||||
this->is_announcement_ = true;
|
this->is_announcement_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (call.get_volume().has_value()) {
|
auto vol = call.get_volume();
|
||||||
this->volume = call.get_volume().value();
|
if (vol.has_value()) {
|
||||||
|
this->volume = *vol;
|
||||||
this->set_volume_(volume);
|
this->set_volume_(volume);
|
||||||
this->unmute_();
|
this->unmute_();
|
||||||
}
|
}
|
||||||
if (call.get_command().has_value()) {
|
auto cmd = call.get_command();
|
||||||
switch (call.get_command().value()) {
|
if (cmd.has_value()) {
|
||||||
|
switch (*cmd) {
|
||||||
case media_player::MEDIA_PLAYER_COMMAND_MUTE:
|
case media_player::MEDIA_PLAYER_COMMAND_MUTE:
|
||||||
this->mute_();
|
this->mute_();
|
||||||
break;
|
break;
|
||||||
@@ -67,7 +70,7 @@ void I2SAudioMediaPlayer::control(const media_player::MediaPlayerCall &call) {
|
|||||||
if (this->i2s_state_ != I2S_STATE_RUNNING) {
|
if (this->i2s_state_ != I2S_STATE_RUNNING) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch (call.get_command().value()) {
|
switch (*cmd) {
|
||||||
case media_player::MEDIA_PLAYER_COMMAND_PLAY:
|
case media_player::MEDIA_PLAYER_COMMAND_PLAY:
|
||||||
if (!this->audio_->isRunning())
|
if (!this->audio_->isRunning())
|
||||||
this->audio_->pauseResume();
|
this->audio_->pauseResume();
|
||||||
|
|||||||
@@ -90,8 +90,9 @@ void Infrared::control(const InfraredCall &call) {
|
|||||||
auto *transmit_data = transmit_call.get_data();
|
auto *transmit_data = transmit_call.get_data();
|
||||||
|
|
||||||
// Set carrier frequency
|
// Set carrier frequency
|
||||||
if (call.get_carrier_frequency().has_value()) {
|
auto freq = call.get_carrier_frequency();
|
||||||
transmit_data->set_carrier_frequency(call.get_carrier_frequency().value());
|
if (freq.has_value()) {
|
||||||
|
transmit_data->set_carrier_frequency(*freq);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set timings based on format
|
// Set timings based on format
|
||||||
|
|||||||
@@ -56,7 +56,8 @@ optional<uint8_t> ledc_bit_depth_for_frequency(float frequency) {
|
|||||||
|
|
||||||
esp_err_t configure_timer_frequency(ledc_mode_t speed_mode, ledc_timer_t timer_num, ledc_channel_t chan_num,
|
esp_err_t configure_timer_frequency(ledc_mode_t speed_mode, ledc_timer_t timer_num, ledc_channel_t chan_num,
|
||||||
uint8_t channel, uint8_t &bit_depth, float frequency) {
|
uint8_t channel, uint8_t &bit_depth, float frequency) {
|
||||||
bit_depth = *ledc_bit_depth_for_frequency(frequency);
|
auto bit_depth_opt = ledc_bit_depth_for_frequency(frequency);
|
||||||
|
bit_depth = bit_depth_opt.value_or(0);
|
||||||
if (bit_depth < 1) {
|
if (bit_depth < 1) {
|
||||||
ESP_LOGE(TAG, "Frequency %f can't be achieved with any bit depth", frequency);
|
ESP_LOGE(TAG, "Frequency %f can't be achieved with any bit depth", frequency);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,9 @@ void Mcp4461Component::setup() {
|
|||||||
// save WP/WL status
|
// save WP/WL status
|
||||||
this->update_write_protection_status_();
|
this->update_write_protection_status_();
|
||||||
for (uint8_t i = 0; i < 8; i++) {
|
for (uint8_t i = 0; i < 8; i++) {
|
||||||
if (this->reg_[i].initial_value.has_value()) {
|
auto init_val = this->reg_[i].initial_value;
|
||||||
uint16_t initial_state = static_cast<uint16_t>(*this->reg_[i].initial_value * 256.0f);
|
if (init_val.has_value()) {
|
||||||
|
uint16_t initial_state = static_cast<uint16_t>(*init_val * 256.0f);
|
||||||
this->write_wiper_level_(i, initial_state);
|
this->write_wiper_level_(i, initial_state);
|
||||||
}
|
}
|
||||||
if (this->reg_[i].enabled) {
|
if (this->reg_[i].enabled) {
|
||||||
|
|||||||
@@ -56,20 +56,25 @@ void AirConditioner::on_status_change() {
|
|||||||
|
|
||||||
void AirConditioner::control(const ClimateCall &call) {
|
void AirConditioner::control(const ClimateCall &call) {
|
||||||
dudanov::midea::ac::Control ctrl{};
|
dudanov::midea::ac::Control ctrl{};
|
||||||
if (call.get_target_temperature().has_value())
|
auto target_temp_val = call.get_target_temperature();
|
||||||
ctrl.targetTemp = call.get_target_temperature().value();
|
if (target_temp_val.has_value())
|
||||||
if (call.get_swing_mode().has_value())
|
ctrl.targetTemp = *target_temp_val;
|
||||||
ctrl.swingMode = Converters::to_midea_swing_mode(call.get_swing_mode().value());
|
auto swing_mode_val = call.get_swing_mode();
|
||||||
if (call.get_mode().has_value())
|
if (swing_mode_val.has_value())
|
||||||
ctrl.mode = Converters::to_midea_mode(call.get_mode().value());
|
ctrl.swingMode = Converters::to_midea_swing_mode(*swing_mode_val);
|
||||||
if (call.get_preset().has_value()) {
|
auto mode_val = call.get_mode();
|
||||||
ctrl.preset = Converters::to_midea_preset(call.get_preset().value());
|
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()) {
|
} else if (call.has_custom_preset()) {
|
||||||
// get_custom_preset() returns StringRef pointing to null-terminated string literals from codegen
|
// 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());
|
ctrl.preset = Converters::to_midea_preset(call.get_custom_preset().c_str());
|
||||||
}
|
}
|
||||||
if (call.get_fan_mode().has_value()) {
|
auto fan_mode_val = call.get_fan_mode();
|
||||||
ctrl.fanMode = Converters::to_midea_fan_mode(call.get_fan_mode().value());
|
if (fan_mode_val.has_value()) {
|
||||||
|
ctrl.fanMode = Converters::to_midea_fan_mode(*fan_mode_val);
|
||||||
} else if (call.has_custom_fan_mode()) {
|
} else if (call.has_custom_fan_mode()) {
|
||||||
// get_custom_fan_mode() returns StringRef pointing to null-terminated string literals from codegen
|
// 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());
|
ctrl.fanMode = Converters::to_midea_fan_mode(call.get_custom_fan_mode().c_str());
|
||||||
|
|||||||
@@ -114,15 +114,20 @@ void MideaIR::control(const climate::ClimateCall &call) {
|
|||||||
if (call.get_mode() == climate::CLIMATE_MODE_OFF) {
|
if (call.get_mode() == climate::CLIMATE_MODE_OFF) {
|
||||||
this->swing_mode = climate::CLIMATE_SWING_OFF;
|
this->swing_mode = climate::CLIMATE_SWING_OFF;
|
||||||
this->preset = climate::CLIMATE_PRESET_NONE;
|
this->preset = climate::CLIMATE_PRESET_NONE;
|
||||||
} else if (call.get_swing_mode().has_value() && ((*call.get_swing_mode() == climate::CLIMATE_SWING_OFF &&
|
} else {
|
||||||
this->swing_mode == climate::CLIMATE_SWING_VERTICAL) ||
|
auto swing = call.get_swing_mode();
|
||||||
(*call.get_swing_mode() == climate::CLIMATE_SWING_VERTICAL &&
|
if (swing.has_value() &&
|
||||||
this->swing_mode == climate::CLIMATE_SWING_OFF))) {
|
((*swing == climate::CLIMATE_SWING_OFF && this->swing_mode == climate::CLIMATE_SWING_VERTICAL) ||
|
||||||
this->swing_ = true;
|
(*swing == climate::CLIMATE_SWING_VERTICAL && this->swing_mode == climate::CLIMATE_SWING_OFF))) {
|
||||||
} else if (call.get_preset().has_value() &&
|
this->swing_ = true;
|
||||||
((*call.get_preset() == climate::CLIMATE_PRESET_NONE && this->preset == climate::CLIMATE_PRESET_BOOST) ||
|
} else {
|
||||||
(*call.get_preset() == climate::CLIMATE_PRESET_BOOST && this->preset == climate::CLIMATE_PRESET_NONE))) {
|
auto preset = call.get_preset();
|
||||||
this->boost_ = true;
|
if (preset.has_value() &&
|
||||||
|
((*preset == climate::CLIMATE_PRESET_NONE && this->preset == climate::CLIMATE_PRESET_BOOST) ||
|
||||||
|
(*preset == climate::CLIMATE_PRESET_BOOST && this->preset == climate::CLIMATE_PRESET_NONE))) {
|
||||||
|
this->boost_ = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
climate_ir::ClimateIR::control(call);
|
climate_ir::ClimateIR::control(call);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ void MitsubishiClimate::transmit_state() {
|
|||||||
// For 5Level: Low = 1, Middle = 2, Medium = 3, High = 4
|
// For 5Level: Low = 1, Middle = 2, Medium = 3, High = 4
|
||||||
// For 4Level + Quiet: Low = 1, Middle = 2, Medium = 3, High = 4, Quiet = 5
|
// For 4Level + Quiet: Low = 1, Middle = 2, Medium = 3, High = 4, Quiet = 5
|
||||||
|
|
||||||
switch (this->fan_mode.value()) {
|
switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) {
|
||||||
case climate::CLIMATE_FAN_LOW:
|
case climate::CLIMATE_FAN_LOW:
|
||||||
remote_state[9] = 1;
|
remote_state[9] = 1;
|
||||||
break;
|
break;
|
||||||
@@ -209,7 +209,8 @@ void MitsubishiClimate::transmit_state() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_LOGD(TAG, "fan: %02x state: %02x", this->fan_mode.value(), remote_state[9]);
|
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
|
// Vertical Vane
|
||||||
switch (this->swing_mode) {
|
switch (this->swing_mode) {
|
||||||
@@ -227,7 +228,7 @@ void MitsubishiClimate::transmit_state() {
|
|||||||
ESP_LOGD(TAG, "default_vertical_direction_: %02X", this->default_vertical_direction_);
|
ESP_LOGD(TAG, "default_vertical_direction_: %02X", this->default_vertical_direction_);
|
||||||
|
|
||||||
// Special modes
|
// Special modes
|
||||||
switch (this->preset.value()) {
|
switch (this->preset.value_or(climate::CLIMATE_PRESET_NONE)) {
|
||||||
case climate::CLIMATE_PRESET_ECO:
|
case climate::CLIMATE_PRESET_ECO:
|
||||||
remote_state[6] = MITSUBISHI_MODE_COOL | MITSUBISHI_OTHERWISE;
|
remote_state[6] = MITSUBISHI_MODE_COOL | MITSUBISHI_OTHERWISE;
|
||||||
remote_state[8] = (remote_state[8] & ~7) | MITSUBISHI_MODE_A_COOL;
|
remote_state[8] = (remote_state[8] & ~7) | MITSUBISHI_MODE_A_COOL;
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user