1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-24 22:22:22 +01:00

Add select entities and implement template select (#2067)

Co-authored-by: Otto Winter <otto@otto-winter.com>
This commit is contained in:
Jesse Hills
2021-08-02 20:00:51 +12:00
committed by GitHub
parent 69c7cf783e
commit 76991cdcc4
35 changed files with 1053 additions and 0 deletions

View File

@@ -35,6 +35,9 @@
#ifdef USE_NUMBER
#include "esphome/components/number/number.h"
#endif
#ifdef USE_SELECT
#include "esphome/components/select/select.h"
#endif
namespace esphome {
@@ -89,6 +92,10 @@ class Application {
void register_number(number::Number *number) { this->numbers_.push_back(number); }
#endif
#ifdef USE_SELECT
void register_select(select::Select *select) { this->selects_.push_back(select); }
#endif
/// Register the component in this Application instance.
template<class C> C *register_component(C *c) {
static_assert(std::is_base_of<Component, C>::value, "Only Component subclasses can be registered");
@@ -224,6 +231,15 @@ class Application {
return nullptr;
}
#endif
#ifdef USE_SELECT
const std::vector<select::Select *> &get_selects() { return this->selects_; }
select::Select *get_select_by_key(uint32_t key, bool include_internal = false) {
for (auto *obj : this->selects_)
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
return obj;
return nullptr;
}
#endif
Scheduler scheduler;
@@ -264,6 +280,9 @@ class Application {
#ifdef USE_NUMBER
std::vector<number::Number *> numbers_{};
#endif
#ifdef USE_SELECT
std::vector<select::Select *> selects_{};
#endif
std::string name_;
std::string compilation_time_;