Compare commits

...
5 changed files with 11 additions and 32 deletions
+6 -15
View File
@@ -285,12 +285,8 @@ void LD6002BComponent::setup() {
#ifdef USE_SWITCH
if (this->target_display_switch_ != nullptr) {
target_display_controlled = true;
// Nothing reports this switch back, so its restored state is the only state
// there is. Restoring through the switch keeps its inversion in the path:
// the restored value is logical, and driving the switch is what turns it
// into the raw command, the published state and the stream flag.
const bool state = this->target_display_switch_->get_initial_state_with_restore_mode().value_or(true);
this->target_display_switch_->control(state);
// Nothing reports this switch back, so its restored state is the only state there is.
this->target_display_switch_->restore(true);
}
#endif
if (!target_display_controlled) {
@@ -307,10 +303,7 @@ void LD6002BComponent::setup() {
#ifdef USE_SWITCH
if (this->point_cloud_switch_ != nullptr) {
point_cloud_controlled = true;
// The switch owns the stream, so it is also what applies the restored state:
// driving it rather than the module keeps the entity's inversion in the path.
const bool state = this->point_cloud_switch_->get_initial_state_with_restore_mode().value_or(false);
this->point_cloud_switch_->control(state);
this->point_cloud_switch_->restore(false);
}
#endif
if (!point_cloud_controlled) {
@@ -349,11 +342,9 @@ void LD6002BComponent::setup() {
#ifdef USE_SWITCH
bool want_low_power = this->low_power_switch_ != nullptr;
if (want_low_power) {
// The module reports this one back, so the query below confirms what it took.
// Driving the switch applies its inversion; it also marks the restored value
// as reported, so the work mode fallback runs on that until the query lands.
const bool state = this->low_power_switch_->get_initial_state_with_restore_mode().value_or(false);
this->low_power_switch_->control(state);
// The query below confirms what the module took; until it lands, the work mode
// fallback runs on the restored value.
this->low_power_switch_->restore(false);
}
#else
bool want_low_power = false;
@@ -12,13 +12,7 @@ ESPHOME_LOG_TAG(TAG, "modbus_controller.switch");
// Maximum bytes to log in verbose hex output
static constexpr size_t MODBUS_SWITCH_MAX_LOG_BYTES = 64;
void ModbusSwitch::setup() {
optional<bool> initial_state = Switch::get_initial_state_with_restore_mode();
if (initial_state.has_value()) {
// if it has a value, restore_mode is not "DISABLED", therefore act on the switch:
this->control(initial_state.value());
}
}
void ModbusSwitch::setup() { this->restore(); }
void ModbusSwitch::dump_config() { LOG_SWITCH(TAG, "Modbus Controller Switch", this); }
bool ModbusSwitch::assumed_state() { return this->assumed_state_; }
@@ -6,7 +6,7 @@ namespace esphome::output {
ESPHOME_LOG_TAG(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::setup() { this->restore(false); }
void OutputSwitch::write_state(bool state) {
this->output_->set_state(state);
this->publish_state(state);
@@ -13,7 +13,7 @@ ESPHOME_LOG_TAG(TAG, "sendspin.switch");
void SendspinEnabledSwitch::setup() {
// The hub waits for this request, so a restore mode without a state still has to answer.
this->control(this->get_initial_state_with_restore_mode().value_or(true));
this->restore(true);
}
void SendspinEnabledSwitch::dump_config() { LOG_SWITCH("", "Sendspin Enabled Switch", this); }
@@ -28,7 +28,7 @@ void SendspinEnabledSwitch::write_state(bool state) {
void SendspinUnpairedAccessSwitch::setup() {
// The hub holds the client's first start for this, so a restore mode without a state still has to answer.
this->control(this->get_initial_state_with_restore_mode().value_or(true));
this->restore(true);
}
void SendspinUnpairedAccessSwitch::dump_config() { LOG_SWITCH("", "Sendspin Unpaired Access Switch", this); }
@@ -37,13 +37,7 @@ void TemplateSwitch::setup() {
if (!this->f_.has_value())
this->disable_loop();
optional<bool> initial_state = this->get_initial_state_with_restore_mode();
if (initial_state.has_value()) {
ESP_LOGD(TAG, " Restored state %s", ONOFF(initial_state.value()));
// if it has a value, restore_mode is not "DISABLED", therefore act on the switch:
this->control(initial_state.value());
}
this->restore();
}
void TemplateSwitch::dump_config() {
LOG_SWITCH("", "Template Switch", this);