diff --git a/components/ratgdo/number/ratgdo_number.cpp b/components/ratgdo/number/ratgdo_number.cpp index 0f85055..318f647 100644 --- a/components/ratgdo/number/ratgdo_number.cpp +++ b/components/ratgdo/number/ratgdo_number.cpp @@ -5,6 +5,9 @@ namespace esphome { namespace ratgdo { + using protocol::SetRollingCodeCounter; + using protocol::SetClientID; + float normalize_client_id(float client_id) { uint32_t int_value = static_cast(client_id); @@ -84,6 +87,9 @@ namespace ratgdo { void RATGDONumber::update_state(float value) { + if (value == this->state) { + return; + } this->pref_.save(&value); this->publish_state(value); } @@ -91,14 +97,14 @@ namespace ratgdo { void RATGDONumber::control(float value) { if (this->number_type_ == RATGDO_ROLLING_CODE_COUNTER) { - this->parent_->set_rolling_code_counter(value); + this->parent_->call_protocol(SetRollingCodeCounter{static_cast(value)}); } else if (this->number_type_ == RATGDO_OPENING_DURATION) { this->parent_->set_opening_duration(value); } else if (this->number_type_ == RATGDO_CLOSING_DURATION) { this->parent_->set_closing_duration(value); } else if (this->number_type_ == RATGDO_CLIENT_ID) { value = normalize_client_id(value); - this->parent_->set_client_id(value); + this->parent_->call_protocol(SetClientID{static_cast(value)}); } this->update_state(value); } diff --git a/components/ratgdo/ratgdo.cpp b/components/ratgdo/ratgdo.cpp index f98cf99..0413c6e 100644 --- a/components/ratgdo/ratgdo.cpp +++ b/components/ratgdo/ratgdo.cpp @@ -312,16 +312,9 @@ namespace ratgdo { this->closing_duration = duration; } - void RATGDOComponent::set_rolling_code_counter(uint32_t counter) + Result RATGDOComponent::call_protocol(Args args) { - - ESP_LOGV(TAG, "Set rolling code counter to %d", counter); - this->protocol_->call(SetRollingCodeCounter{counter}); - } - - void RATGDOComponent::set_client_id(uint64_t client_id) - { - this->protocol_->call(SetClientID{client_id}); + return this->protocol_->call(args); } /*************************** OBSTRUCTION DETECTION ***************************/ diff --git a/components/ratgdo/ratgdo.h b/components/ratgdo/ratgdo.h index 2a6fa76..92fe116 100644 --- a/components/ratgdo/ratgdo.h +++ b/components/ratgdo/ratgdo.h @@ -43,8 +43,12 @@ namespace ratgdo { } }; + using protocol::Args; + using protocol::Result; + class RATGDOComponent : public Component { public: + void setup() override; void loop() override; void dump_config() override; @@ -88,9 +92,7 @@ namespace ratgdo { void set_input_gdo_pin(InternalGPIOPin* pin) { this->input_gdo_pin_ = pin; } void set_input_obst_pin(InternalGPIOPin* pin) { this->input_obst_pin_ = pin; } - // security+2.0 specific - void set_rolling_code_counter(uint32_t code); - void set_client_id(uint64_t client_id); + Result call_protocol(Args args); void received(const DoorState door_state); void received(const LightState light_state);