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
+19
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_;
+6
View File
@@ -53,6 +53,12 @@ void Controller::setup_controller() {
obj->add_on_state_callback([this, obj]() { this->on_climate_update(obj); });
}
#endif
#ifdef USE_NUMBER
for (auto *obj : App.get_numbers()) {
if (!obj->is_internal())
obj->add_on_state_callback([this, obj](float state) { this->on_number_update(obj, state); });
}
#endif
}
} // namespace esphome
+6
View File
@@ -25,6 +25,9 @@
#ifdef USE_CLIMATE
#include "esphome/components/climate/climate.h"
#endif
#ifdef USE_NUMBER
#include "esphome/components/number/number.h"
#endif
namespace esphome {
@@ -55,6 +58,9 @@ class Controller {
#ifdef USE_CLIMATE
virtual void on_climate_update(climate::Climate *obj){};
#endif
#ifdef USE_NUMBER
virtual void on_number_update(number::Number *obj, float state){};
#endif
};
} // namespace esphome
+1
View File
@@ -13,6 +13,7 @@
#define USE_COVER
#define USE_LIGHT
#define USE_CLIMATE
#define USE_NUMBER
#define USE_MQTT
#define USE_POWER_SUPPLY
#define USE_HOMEASSISTANT_TIME