diff --git a/esphome/components/ebus/ebus_component.cpp b/esphome/components/ebus/ebus_component.cpp index 13bf0a3a66..5fd391cb71 100644 --- a/esphome/components/ebus/ebus_component.cpp +++ b/esphome/components/ebus/ebus_component.cpp @@ -45,8 +45,6 @@ void EbusComponent::set_command_queue_size(uint8_t command_queue_size) { this->command_queue_size_ = command_queue_size; } -void EbusComponent::add_receiver(EbusReceiver *receiver) { this->receivers_.push_back(receiver); } - void EbusComponent::setup_queues_() { this->history_queue_ = xQueueCreate(this->history_queue_size_, sizeof(Telegram)); this->command_queue_ = xQueueCreate(this->command_queue_size_, sizeof(Telegram)); @@ -72,8 +70,8 @@ void EbusComponent::setup_ebus_() { this->ebus_->add_send_response_handler([&](Telegram &telegram) { std::vector reply = {}; - for (auto const &receiver : this->receivers_) { - reply = receiver->reply(telegram); + for (auto const &item : this->items_) { + reply = item->reply(telegram); if (reply.size() != 0) { break; } @@ -157,8 +155,8 @@ void EbusComponent::handle_message_(Telegram &telegram) { return; } - for (auto const &receiver : this->receivers_) { - receiver->process_received(telegram); + for (auto const &item : this->items_) { + item->process_received(telegram); } } diff --git a/esphome/components/ebus/ebus_component.h b/esphome/components/ebus/ebus_component.h index 6a7682ecfc..4d11f3c70b 100644 --- a/esphome/components/ebus/ebus_component.h +++ b/esphome/components/ebus/ebus_component.h @@ -20,16 +20,7 @@ static const char *const TAG = "ebus"; class EbusComponent; -class EbusReceiver { - public: - virtual void process_received(Telegram) = 0; - std::vector reply(Telegram telegram) { - std::vector reply = {0xe3, 'E', 'S', 'P', 'H', 'M', 0x12, 0x34, 0x56, 0x78}; - return reply; - }; -}; - -class EbusItem : public EbusReceiver, public Component { +class EbusItem : public Component { public: void dump_config() override; @@ -40,6 +31,11 @@ class EbusItem : public EbusReceiver, public Component { void set_payload(const std::vector &payload) { this->payload_ = payload; } void set_response_read_position(uint8_t response_position) { this->response_position_ = response_position; } + virtual void process_received(Telegram) { } + virtual std::vector reply(Telegram telegram) { + std::vector reply = {0xe3, 'E', 'S', 'P', 'H', 'M', 0x12, 0x34, 0x56, 0x78}; + return reply; + }; virtual optional prepare_command(); // TODO: refactor these @@ -72,10 +68,8 @@ class EbusComponent : public PollingComponent { void set_history_queue_size(uint8_t /*history_queue_size*/); void set_command_queue_size(uint8_t /*command_queue_size*/); - void add_receiver(EbusReceiver * /*receiver*/); void add_item(EbusItem *item) { this->items_.push_back(item); - this->add_receiver(item); }; void update() override; @@ -96,7 +90,6 @@ class EbusComponent : public PollingComponent { #endif std::list items_; - std::list receivers_; std::unique_ptr ebus_;