diff --git a/components/ratgdo/macros.h b/components/ratgdo/macros.h index e948dac..14bea5b 100644 --- a/components/ratgdo/macros.h +++ b/components/ratgdo/macros.h @@ -126,34 +126,4 @@ namespace detail { } \ } -#define SUM_TYPE_UNION_MEMBER0(type, var) type var; -#define SUM_TYPE_UNION_MEMBER(name, tuple) SUM_TYPE_UNION_MEMBER0 tuple -#define SUM_TYPE_ENUM_MEMBER0(type, var) var, -#define SUM_TYPE_ENUM_MEMBER(name, tuple) SUM_TYPE_ENUM_MEMBER0 tuple - -#define SUM_TYPE_CONSTRUCTOR0(name, type, val) \ - name(type&& arg) \ - : tag(Tag::val) \ - { \ - value.val = std::move(arg); \ - } -#define SUM_TYPE_CONSTRUCTOR(name, tuple) SUM_TYPE_CONSTRUCTOR0 LPAREN name, TUPLE tuple) - -#define SUM_TYPE(name, ...) \ - class name { \ - public: \ - union { \ - FOR_EACH(SUM_TYPE_UNION_MEMBER, name, __VA_ARGS__) \ - } value; \ - enum class Tag { \ - void_, \ - FOR_EACH(SUM_TYPE_ENUM_MEMBER, name, __VA_ARGS__) \ - } tag; \ - \ - name() \ - : tag(Tag::void_) \ - { \ - } \ - FOR_EACH(SUM_TYPE_CONSTRUCTOR, name, __VA_ARGS__) \ - }; diff --git a/components/ratgdo/protocol.h b/components/ratgdo/protocol.h index 6f42c5c..c38a5df 100644 --- a/components/ratgdo/protocol.h +++ b/components/ratgdo/protocol.h @@ -16,18 +16,6 @@ class RATGDOComponent; namespace protocol { - struct QueryStatus { - }; - struct QueryOpenings { - }; - - // a poor man's sum-type, because C++ - SUM_TYPE(Args, - (QueryStatus, query_status), - (QueryOpenings, query_openings), ) - - SUM_TYPE(Result, ) - class Protocol { public: virtual void setup(RATGDOComponent* ratgdo, Scheduler* scheduler, InternalGPIOPin* rx_pin, InternalGPIOPin* tx_pin); @@ -42,7 +30,8 @@ namespace protocol { virtual void lock_action(LockAction action); virtual void door_action(DoorAction action); - virtual protocol::Result call(protocol::Args args); + virtual void query_status() {} + virtual void query_openings() {} }; } diff --git a/components/ratgdo/ratgdo.cpp b/components/ratgdo/ratgdo.cpp index 2826eda..38069ac 100644 --- a/components/ratgdo/ratgdo.cpp +++ b/components/ratgdo/ratgdo.cpp @@ -295,16 +295,11 @@ void RATGDOComponent::set_distance_measurement(int16_t distance) this->last_distance_measurement = distance; } -Result RATGDOComponent::call_protocol(Args args) -{ - return this->protocol_->call(args); -} - -void RATGDOComponent::query_status() { this->protocol_->call(QueryStatus { }); } +void RATGDOComponent::query_status() { this->protocol_->query_status(); } void RATGDOComponent::query_openings() { - this->protocol_->call(QueryOpenings { }); + this->protocol_->query_openings(); } void RATGDOComponent::sync() diff --git a/components/ratgdo/ratgdo.h b/components/ratgdo/ratgdo.h index 0af6ed5..cd84295 100644 --- a/components/ratgdo/ratgdo.h +++ b/components/ratgdo/ratgdo.h @@ -35,8 +35,7 @@ typedef Parented RATGDOClient; const float DOOR_POSITION_UNKNOWN = -1.0; const float DOOR_DELTA_UNKNOWN = -2.0; -using protocol::Args; -using protocol::Result; + class RATGDOComponent : public Component { public: @@ -83,7 +82,7 @@ public: void set_output_gdo_pin(InternalGPIOPin* pin) { this->output_gdo_pin_ = pin; } void set_input_gdo_pin(InternalGPIOPin* pin) { this->input_gdo_pin_ = pin; } - Result call_protocol(Args args); + void received(const DoorState door_state); void received(const LightState light_state); diff --git a/components/ratgdo/secplus2.cpp b/components/ratgdo/secplus2.cpp index 9081adb..fdf0320 100644 --- a/components/ratgdo/secplus2.cpp +++ b/components/ratgdo/secplus2.cpp @@ -192,16 +192,7 @@ namespace secplus2 { this->door_command(action); } - Result Secplus2::call(Args args) - { - using Tag = Args::Tag; - if (args.tag == Tag::query_status) { - this->send_command(CommandType::GET_STATUS); - } else if (args.tag == Tag::query_openings) { - this->send_command(CommandType::GET_OPENINGS); - } - return { }; - } + void Secplus2::door_command(DoorAction action) { diff --git a/components/ratgdo/secplus2.h b/components/ratgdo/secplus2.h index abe6328..5b8f492 100644 --- a/components/ratgdo/secplus2.h +++ b/components/ratgdo/secplus2.h @@ -81,7 +81,8 @@ namespace secplus2 { void lock_action(LockAction action); void door_action(DoorAction action); - Result call(Args args); + void query_status() override; + void query_openings() override; protected: void increment_rolling_code_counter(int delta = 1); @@ -114,8 +115,7 @@ namespace secplus2 { void door_command(DoorAction action); - void query_status(); - void query_openings(); + void print_packet(const esphome::LogString* prefix, const WirePacket& packet) const; optional decode_packet(const WirePacket& packet) const;