mirror of
https://github.com/esphome/esphome.git
synced 2025-10-29 22:24:26 +00:00
Add support for time entities (#6399)
* Add time entities * Add tests * Add myself to datetime codeowners * Fix publishing times with 0 values * Log performing TimeCall * Implement `on_time` trigger * Rename var * Fix initial value for time * Add arg name for clarity * Remove useless checks
This commit is contained in:
@@ -42,6 +42,9 @@
|
||||
#ifdef USE_DATETIME_DATE
|
||||
#include "esphome/components/datetime/date_entity.h"
|
||||
#endif
|
||||
#ifdef USE_DATETIME_TIME
|
||||
#include "esphome/components/datetime/time_entity.h"
|
||||
#endif
|
||||
#ifdef USE_TEXT
|
||||
#include "esphome/components/text/text.h"
|
||||
#endif
|
||||
@@ -128,6 +131,10 @@ class Application {
|
||||
void register_date(datetime::DateEntity *date) { this->dates_.push_back(date); }
|
||||
#endif
|
||||
|
||||
#ifdef USE_DATETIME_TIME
|
||||
void register_time(datetime::TimeEntity *time) { this->times_.push_back(time); }
|
||||
#endif
|
||||
|
||||
#ifdef USE_TEXT
|
||||
void register_text(text::Text *text) { this->texts_.push_back(text); }
|
||||
#endif
|
||||
@@ -305,6 +312,15 @@ class Application {
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_DATETIME_TIME
|
||||
const std::vector<datetime::TimeEntity *> &get_times() { return this->times_; }
|
||||
datetime::TimeEntity *get_time_by_key(uint32_t key, bool include_internal = false) {
|
||||
for (auto *obj : this->times_)
|
||||
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
|
||||
return obj;
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_TEXT
|
||||
const std::vector<text::Text *> &get_texts() { return this->texts_; }
|
||||
text::Text *get_text_by_key(uint32_t key, bool include_internal = false) {
|
||||
@@ -401,6 +417,9 @@ class Application {
|
||||
#ifdef USE_DATETIME_DATE
|
||||
std::vector<datetime::DateEntity *> dates_{};
|
||||
#endif
|
||||
#ifdef USE_DATETIME_TIME
|
||||
std::vector<datetime::TimeEntity *> times_{};
|
||||
#endif
|
||||
#ifdef USE_SELECT
|
||||
std::vector<select::Select *> selects_{};
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user