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

Add Number entities (from Home Assistant) (#1971)

Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl>
This commit is contained in:
Jesse Hills
2021-07-13 07:20:12 +12:00
committed by GitHub
parent 1f5c79bd17
commit dd37a4e04c
36 changed files with 1206 additions and 0 deletions

View File

@@ -32,6 +32,9 @@
#ifdef USE_COVER
#include "esphome/components/cover/cover.h"
#endif
#ifdef USE_NUMBER
#include "esphome/components/number/number.h"
#endif
namespace esphome {
@@ -82,6 +85,10 @@ class Application {
void register_light(light::LightState *light) { this->lights_.push_back(light); }
#endif
#ifdef USE_NUMBER
void register_number(number::Number *number) { this->numbers_.push_back(number); }
#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");
@@ -208,6 +215,15 @@ class Application {
return nullptr;
}
#endif
#ifdef USE_NUMBER
const std::vector<number::Number *> &get_numbers() { return this->numbers_; }
number::Number *get_number_by_key(uint32_t key, bool include_internal = false) {
for (auto *obj : this->numbers_)
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
return obj;
return nullptr;
}
#endif
Scheduler scheduler;
@@ -245,6 +261,9 @@ class Application {
#ifdef USE_LIGHT
std::vector<light::LightState *> lights_{};
#endif
#ifdef USE_NUMBER
std::vector<number::Number *> numbers_{};
#endif
std::string name_;
std::string compilation_time_;