From 8e5b65c2e65a671d369d4f2b723380cc9fad3f11 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 9 Jun 2023 16:38:59 -0500 Subject: [PATCH] loop --- components/ratgdo/light/ratgdo_light_output.cpp | 15 ++++++++------- components/ratgdo/ratgdo.cpp | 4 ++++ components/ratgdo/ratgdo.h | 1 + 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/components/ratgdo/light/ratgdo_light_output.cpp b/components/ratgdo/light/ratgdo_light_output.cpp index bb768d2..7353da8 100644 --- a/components/ratgdo/light/ratgdo_light_output.cpp +++ b/components/ratgdo/light/ratgdo_light_output.cpp @@ -17,18 +17,19 @@ namespace ratgdo { { ESP_LOGD(TAG, "on_light_state: %d", state); if (this->light_state_) { - this->light_state_->current_values.set_state(state == LightState::LIGHT_STATE_ON); - this->light_state_->remote_values.set_state(state == LightState::LIGHT_STATE_ON); - this->light_state_->publish_state(); + set_state(this->light_state_, state); } } + void RATGDOLightOutput::set_state(light::LightState* light_state, esphome::ratgdo::LightState state) + { + light_state->current_values.set_state(is_on); + light_state->remote_values.set_state(is_on); + light_state->publish_state(); + } void RATGDOLightOutput::setup_state(light::LightState* state) { - bool is_on = this->parent_->isLightOn(); this->light_state_ = state; - state->current_values.set_state(is_on); - state->remote_values.set_state(is_on); - state->publish_state(); + this->set_state(state, this->parent_->getLightState()); } LightTraits RATGDOLightOutput::get_traits() { diff --git a/components/ratgdo/ratgdo.cpp b/components/ratgdo/ratgdo.cpp index db198be..1c79078 100644 --- a/components/ratgdo/ratgdo.cpp +++ b/components/ratgdo/ratgdo.cpp @@ -497,6 +497,10 @@ namespace ratgdo { this->children_.push_back(obj); obj->set_parent(this); } + LightState RATGDOComponent::get_light_state() + { + return static_cast(this->lightState); + } } // namespace ratgdo } // namespace esphome diff --git a/components/ratgdo/ratgdo.h b/components/ratgdo/ratgdo.h index 78fb5e8..5df4693 100644 --- a/components/ratgdo/ratgdo.h +++ b/components/ratgdo/ratgdo.h @@ -142,6 +142,7 @@ namespace ratgdo { void sendRollingCodeChanged(); void setRollingCodeCounter(uint32_t counter); void sendCommandAndSaveCounter(cmd command); + LightState RATGDOComponent::get_light_state(); /** Register a child component. */ void register_child(RATGDOClient* obj);