mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-26 15:48:28 +02:00
Add select entities and implement template select (#2067)
Co-authored-by: Otto Winter <otto@otto-winter.com>
This commit is contained in:
@@ -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_;
|
||||
|
||||
@@ -59,6 +59,12 @@ void Controller::setup_controller() {
|
||||
obj->add_on_state_callback([this, obj](float state) { this->on_number_update(obj, state); });
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_SELECT
|
||||
for (auto *obj : App.get_selects()) {
|
||||
if (!obj->is_internal())
|
||||
obj->add_on_state_callback([this, obj](const std::string &state) { this->on_select_update(obj, state); });
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace esphome
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#ifdef USE_NUMBER
|
||||
#include "esphome/components/number/number.h"
|
||||
#endif
|
||||
#ifdef USE_SELECT
|
||||
#include "esphome/components/select/select.h"
|
||||
#endif
|
||||
|
||||
namespace esphome {
|
||||
|
||||
@@ -61,6 +64,9 @@ class Controller {
|
||||
#ifdef USE_NUMBER
|
||||
virtual void on_number_update(number::Number *obj, float state){};
|
||||
#endif
|
||||
#ifdef USE_SELECT
|
||||
virtual void on_select_update(select::Select *obj, const std::string &state){};
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace esphome
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#define USE_LIGHT
|
||||
#define USE_CLIMATE
|
||||
#define USE_NUMBER
|
||||
#define USE_SELECT
|
||||
#define USE_MQTT
|
||||
#define USE_POWER_SUPPLY
|
||||
#define USE_HOMEASSISTANT_TIME
|
||||
|
||||
Reference in New Issue
Block a user