mirror of
https://github.com/esphome/esphome.git
synced 2025-09-26 07:02:21 +01:00
Event entity support (#6451)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
@@ -63,6 +63,9 @@
|
||||
#ifdef USE_ALARM_CONTROL_PANEL
|
||||
#include "esphome/components/alarm_control_panel/alarm_control_panel.h"
|
||||
#endif
|
||||
#ifdef USE_EVENT
|
||||
#include "esphome/components/event/event.h"
|
||||
#endif
|
||||
|
||||
namespace esphome {
|
||||
|
||||
@@ -164,6 +167,10 @@ class Application {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_EVENT
|
||||
void register_event(event::Event *event) { this->events_.push_back(event); }
|
||||
#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");
|
||||
@@ -386,6 +393,16 @@ class Application {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_EVENT
|
||||
const std::vector<event::Event *> &get_events() { return this->events_; }
|
||||
event::Event *get_event_by_key(uint32_t key, bool include_internal = false) {
|
||||
for (auto *obj : this->events_)
|
||||
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
|
||||
return obj;
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
Scheduler scheduler;
|
||||
|
||||
protected:
|
||||
@@ -409,6 +426,9 @@ class Application {
|
||||
#ifdef USE_BUTTON
|
||||
std::vector<button::Button *> buttons_{};
|
||||
#endif
|
||||
#ifdef USE_EVENT
|
||||
std::vector<event::Event *> events_{};
|
||||
#endif
|
||||
#ifdef USE_SENSOR
|
||||
std::vector<sensor::Sensor *> sensors_{};
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user