From 4652dded4e4ae2741d8e320c81c86a8012a3062c Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 7 Jun 2023 20:46:44 -0500 Subject: [PATCH] cleanups --- components/ratgdo/light/ratgdo_light_output.cpp | 8 ++++++++ components/ratgdo/light/ratgdo_light_output.h | 2 +- components/ratgdo/ratgdo.cpp | 5 +++++ components/ratgdo/ratgdo.h | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/components/ratgdo/light/ratgdo_light_output.cpp b/components/ratgdo/light/ratgdo_light_output.cpp index b67f783..bb768d2 100644 --- a/components/ratgdo/light/ratgdo_light_output.cpp +++ b/components/ratgdo/light/ratgdo_light_output.cpp @@ -22,6 +22,14 @@ namespace ratgdo { this->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(); + } LightTraits RATGDOLightOutput::get_traits() { auto traits = LightTraits(); diff --git a/components/ratgdo/light/ratgdo_light_output.h b/components/ratgdo/light/ratgdo_light_output.h index 06c74b0..8b57f5d 100644 --- a/components/ratgdo/light/ratgdo_light_output.h +++ b/components/ratgdo/light/ratgdo_light_output.h @@ -14,7 +14,7 @@ namespace ratgdo { void dump_config() override; light::LightTraits get_traits() override; void write_state(light::LightState* state) override; - void setup_state(light::LightState* state) override { this->light_state_ = state; } + void setup_state(light::LightState* state) override; light::LightState* get_state() { return this->light_state_; } void on_light_state(esphome::ratgdo::LightState state) override; diff --git a/components/ratgdo/ratgdo.cpp b/components/ratgdo/ratgdo.cpp index 962a460..503ba66 100644 --- a/components/ratgdo/ratgdo.cpp +++ b/components/ratgdo/ratgdo.cpp @@ -583,6 +583,11 @@ namespace ratgdo { sendCommandAndSaveCounter(Commands::DOOR2); } + bool RATGDOComonent::isLightOn() + { + return this->lightState == LightState::LIGHT_STATE_ON; + } + void RATGDOComponent::lightOn() { if (this->lightState == LightState::LIGHT_STATE_ON) { diff --git a/components/ratgdo/ratgdo.h b/components/ratgdo/ratgdo.h index 1c41b1b..eae89fe 100644 --- a/components/ratgdo/ratgdo.h +++ b/components/ratgdo/ratgdo.h @@ -115,6 +115,7 @@ namespace ratgdo { void toggleLight(); void lightOn(); void lightOff(); + bool isLightOn(); void sendLightStatus(); void toggleLock();