ESPHome  2022.6.3
custom_component.h
Go to the documentation of this file.
1 #pragma once
2 
5 
6 namespace esphome {
7 namespace custom_component {
8 
10  public:
11  CustomComponentConstructor(const std::function<std::vector<Component *>()> &init) {
12  this->components_ = init();
13 
14  for (auto *comp : this->components_) {
15  App.register_component(comp);
16  }
17  }
18 
19  Component *get_component(int i) const { return this->components_[i]; }
20 
21  protected:
22  std::vector<Component *> components_;
23 };
24 
25 } // namespace custom_component
26 } // namespace esphome
C * register_component(C *c)
Register the component in this Application instance.
Definition: application.h:122
Application App
Global storage of Application pointer - only one Application can exist.
Definition: a4988.cpp:4
CustomComponentConstructor(const std::function< std::vector< Component *>()> &init)
void init()
Definition: core.cpp:85