esphome/esphome/components/custom_component/custom_component.h
Anthony Uk 5c359856ff
Fixed CustomComponentConstructor::get_component() (#1653)
Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
2021-04-06 13:50:31 +02:00

26 lines
579 B
C++

#pragma once
#include "esphome/core/component.h"
#include "esphome/core/application.h"
namespace esphome {
namespace custom_component {
class CustomComponentConstructor {
public:
CustomComponentConstructor(const std::function<std::vector<Component *>()> &init) {
this->components_ = init();
for (auto *comp : this->components_) {
App.register_component(comp);
}
}
Component *get_component(int i) const { return this->components_[i]; }
protected:
std::vector<Component *> components_;
};
} // namespace custom_component
} // namespace esphome