mirror of
https://github.com/esphome/esphome.git
synced 2026-10-28 00:42:11 +00:00
[components] Apply inverted when restoring gree, hbridge, lvgl, opentherm and haier_tundra switches (#21544)
This commit is contained in:
1 parent
f21183c160
commit
ba488eab6e
5 files changed
+8
-15
No files matched your search
@@ -5,12 +5,7 @@ namespace esphome::gree {
|
||||
|
||||
ESPHOME_LOG_TAG(TAG, "gree.switch");
|
||||
|
||||
void GreeModeBitSwitch::setup() {
|
||||
auto initial = this->get_initial_state_with_restore_mode();
|
||||
if (initial.has_value()) {
|
||||
this->write_state(*initial);
|
||||
}
|
||||
}
|
||||
void GreeModeBitSwitch::setup() { this->restore(); }
|
||||
|
||||
void GreeModeBitSwitch::dump_config() { log_switch(TAG, " ", this->name_, this); }
|
||||
|
||||
|
||||
@@ -8,9 +8,10 @@ ESPHOME_LOG_TAG(TAG, "haier_tundra.switch");
|
||||
void HaierTundraSwitch::setup() {
|
||||
auto initial = this->get_initial_state_with_restore_mode();
|
||||
if (initial.has_value()) {
|
||||
const bool state = initial.value();
|
||||
this->apply_(state, false);
|
||||
this->publish_state(state);
|
||||
// apply_() and publish_state() take the level, which an inverted switch flips
|
||||
const bool level = *initial != this->is_inverted();
|
||||
this->apply_(level, false);
|
||||
this->publish_state(level);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,6 @@ ESPHOME_LOG_TAG(TAG, "switch.hbridge");
|
||||
|
||||
float HBridgeSwitch::get_setup_priority() const { return setup_priority::HARDWARE; }
|
||||
void HBridgeSwitch::setup() {
|
||||
optional<bool> initial_state = this->get_initial_state_with_restore_mode();
|
||||
|
||||
// Like GPIOSwitch does, set the pin state both before and after pin setup()
|
||||
this->on_pin_->digital_write(false);
|
||||
this->on_pin_->setup();
|
||||
@@ -20,8 +18,7 @@ void HBridgeSwitch::setup() {
|
||||
this->off_pin_->setup();
|
||||
this->off_pin_->digital_write(false);
|
||||
|
||||
if (initial_state.has_value())
|
||||
this->write_state(initial_state.value());
|
||||
this->restore();
|
||||
}
|
||||
|
||||
void HBridgeSwitch::dump_config() {
|
||||
|
||||
@@ -13,7 +13,7 @@ class LVGLSwitch final : public switch_::Switch, public Component {
|
||||
public:
|
||||
LVGLSwitch(std::function<void(bool)> state_lambda) : state_lambda_(std::move(state_lambda)) {}
|
||||
|
||||
void setup() override { this->write_state(this->get_initial_state_with_restore_mode().value_or(false)); }
|
||||
void setup() override { this->restore(false); }
|
||||
|
||||
protected:
|
||||
void write_state(bool value) override { this->state_lambda_(value); }
|
||||
|
||||
@@ -15,7 +15,7 @@ void OpenthermSwitch::setup() {
|
||||
ESP_LOGD(TAG, "Restored state for OpenTherm switch '%s': %d", LOG_STR_ARG(this->get_log_name()), restored.value());
|
||||
state = restored.value();
|
||||
}
|
||||
this->write_state(state);
|
||||
this->control(state);
|
||||
}
|
||||
|
||||
void OpenthermSwitch::dump_config() {
|
||||
|
||||
Reference in new issue
Block a user