mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-19 04:33:27 +02:00
[core] Update Entities (#6885)
This commit is contained in:
@@ -69,6 +69,9 @@
|
||||
#ifdef USE_EVENT
|
||||
#include "esphome/components/event/event.h"
|
||||
#endif
|
||||
#ifdef USE_UPDATE
|
||||
#include "esphome/components/update/update_entity.h"
|
||||
#endif
|
||||
|
||||
namespace esphome {
|
||||
|
||||
@@ -178,6 +181,10 @@ class Application {
|
||||
void register_event(event::Event *event) { this->events_.push_back(event); }
|
||||
#endif
|
||||
|
||||
#ifdef USE_UPDATE
|
||||
void register_update(update::UpdateEntity *update) { this->updates_.push_back(update); }
|
||||
#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");
|
||||
@@ -421,6 +428,16 @@ class Application {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_UPDATE
|
||||
const std::vector<update::UpdateEntity *> &get_updates() { return this->updates_; }
|
||||
update::UpdateEntity *get_update_by_key(uint32_t key, bool include_internal = false) {
|
||||
for (auto *obj : this->updates_)
|
||||
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
|
||||
return obj;
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
Scheduler scheduler;
|
||||
|
||||
protected:
|
||||
@@ -495,6 +512,9 @@ class Application {
|
||||
#ifdef USE_ALARM_CONTROL_PANEL
|
||||
std::vector<alarm_control_panel::AlarmControlPanel *> alarm_control_panels_{};
|
||||
#endif
|
||||
#ifdef USE_UPDATE
|
||||
std::vector<update::UpdateEntity *> updates_{};
|
||||
#endif
|
||||
|
||||
std::string name_;
|
||||
std::string friendly_name_;
|
||||
|
||||
@@ -351,6 +351,21 @@ void ComponentIterator::advance() {
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#ifdef USE_UPDATE
|
||||
case IteratorState::UPDATE:
|
||||
if (this->at_ >= App.get_updates().size()) {
|
||||
advance_platform = true;
|
||||
} else {
|
||||
auto *update = App.get_updates()[this->at_];
|
||||
if (update->is_internal() && !this->include_internal_) {
|
||||
success = true;
|
||||
break;
|
||||
} else {
|
||||
success = this->on_update(update);
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case IteratorState::MAX:
|
||||
if (this->on_end()) {
|
||||
|
||||
@@ -86,6 +86,9 @@ class ComponentIterator {
|
||||
#endif
|
||||
#ifdef USE_EVENT
|
||||
virtual bool on_event(event::Event *event) = 0;
|
||||
#endif
|
||||
#ifdef USE_UPDATE
|
||||
virtual bool on_update(update::UpdateEntity *update) = 0;
|
||||
#endif
|
||||
virtual bool on_end();
|
||||
|
||||
@@ -158,6 +161,9 @@ class ComponentIterator {
|
||||
#endif
|
||||
#ifdef USE_EVENT
|
||||
EVENT,
|
||||
#endif
|
||||
#ifdef USE_UPDATE
|
||||
UPDATE,
|
||||
#endif
|
||||
MAX,
|
||||
} state_{IteratorState::NONE};
|
||||
|
||||
@@ -121,6 +121,12 @@ void Controller::setup_controller(bool include_internal) {
|
||||
obj->add_on_event_callback([this, obj](const std::string &event_type) { this->on_event(obj, event_type); });
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_UPDATE
|
||||
for (auto *obj : App.get_updates()) {
|
||||
if (include_internal || !obj->is_internal())
|
||||
obj->add_on_state_callback([this, obj]() { this->on_update(obj); });
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace esphome
|
||||
|
||||
@@ -61,6 +61,9 @@
|
||||
#ifdef USE_EVENT
|
||||
#include "esphome/components/event/event.h"
|
||||
#endif
|
||||
#ifdef USE_UPDATE
|
||||
#include "esphome/components/update/update_entity.h"
|
||||
#endif
|
||||
|
||||
namespace esphome {
|
||||
|
||||
@@ -124,6 +127,9 @@ class Controller {
|
||||
#ifdef USE_EVENT
|
||||
virtual void on_event(event::Event *obj, const std::string &event_type){};
|
||||
#endif
|
||||
#ifdef USE_UPDATE
|
||||
virtual void on_update(update::UpdateEntity *obj){};
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace esphome
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
#define USE_TIME
|
||||
#define USE_TOUCHSCREEN
|
||||
#define USE_UART_DEBUGGER
|
||||
#define USE_UPDATE
|
||||
#define USE_VALVE
|
||||
#define USE_WIFI
|
||||
#define USE_WIFI_AP
|
||||
|
||||
Reference in New Issue
Block a user