mirror of
https://github.com/esphome/esphome.git
synced 2026-09-18 02:28:42 +00:00
[output] Use BinaryOutput::set_state() instead of hand written turn_on/turn_off branches (#19366)
This commit is contained in:
@@ -17,11 +17,7 @@ class BinaryLightOutput final : public light::LightOutput {
|
||||
void write_state(light::LightState *state) override {
|
||||
bool binary;
|
||||
state->current_values_as_binary(&binary);
|
||||
if (binary) {
|
||||
this->output_->turn_on();
|
||||
} else {
|
||||
this->output_->turn_off();
|
||||
}
|
||||
this->output_->set_state(binary);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
@@ -208,11 +208,7 @@ void ImprovBLEComponent::set_status_indicator_state_(bool state) {
|
||||
if (this->status_indicator_state_ == state)
|
||||
return;
|
||||
this->status_indicator_state_ = state;
|
||||
if (state) {
|
||||
this->status_indicator_->turn_on();
|
||||
} else {
|
||||
this->status_indicator_->turn_off();
|
||||
}
|
||||
this->status_indicator_->set_state(state);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -38,14 +38,6 @@ float Mcp4461Wiper::update_state() {
|
||||
return this->state_;
|
||||
}
|
||||
|
||||
void Mcp4461Wiper::set_state(bool state) {
|
||||
if (state) {
|
||||
this->turn_on();
|
||||
} else {
|
||||
this->turn_off();
|
||||
}
|
||||
}
|
||||
|
||||
void Mcp4461Wiper::turn_on() { this->parent_->enable_wiper_(this->wiper_); }
|
||||
|
||||
void Mcp4461Wiper::turn_off() { this->parent_->disable_wiper_(this->wiper_); }
|
||||
|
||||
@@ -13,9 +13,6 @@ class Mcp4461Wiper final : public output::FloatOutput, public Parented<Mcp4461Co
|
||||
/// @brief Set level of wiper
|
||||
/// @param[in] state - The desired float level in range 0-1.0
|
||||
void set_level(float state);
|
||||
/// @brief Enables/Disables current output using bool parameter
|
||||
/// @param[in] state boolean var representing desired state (true=ON, false=OFF)
|
||||
void set_state(bool state) override;
|
||||
/// @brief Enables current output
|
||||
void turn_on() override;
|
||||
/// @brief Disables current output
|
||||
|
||||
@@ -8,11 +8,7 @@ static const char *const TAG = "output.switch";
|
||||
void OutputSwitch::dump_config() { LOG_SWITCH("", "Output Switch", this); }
|
||||
void OutputSwitch::setup() { this->control(this->get_initial_state_with_restore_mode().value_or(false)); }
|
||||
void OutputSwitch::write_state(bool state) {
|
||||
if (state) {
|
||||
this->output_->turn_on();
|
||||
} else {
|
||||
this->output_->turn_off();
|
||||
}
|
||||
this->output_->set_state(state);
|
||||
this->publish_state(state);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user