2019-04-17 12:06:00 +02:00
|
|
|
#include "controller.h"
|
|
|
|
#include "esphome/core/log.h"
|
|
|
|
#include "esphome/core/application.h"
|
|
|
|
|
|
|
|
namespace esphome {
|
|
|
|
|
2021-11-29 16:52:20 +01:00
|
|
|
void Controller::setup_controller(bool include_internal) {
|
2019-04-17 12:06:00 +02:00
|
|
|
#ifdef USE_BINARY_SENSOR
|
|
|
|
for (auto *obj : App.get_binary_sensors()) {
|
2021-11-29 16:52:20 +01:00
|
|
|
if (include_internal || !obj->is_internal())
|
2019-04-17 12:06:00 +02:00
|
|
|
obj->add_on_state_callback([this, obj](bool state) { this->on_binary_sensor_update(obj, state); });
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef USE_FAN
|
|
|
|
for (auto *obj : App.get_fans()) {
|
2021-11-29 16:52:20 +01:00
|
|
|
if (include_internal || !obj->is_internal())
|
2019-04-17 12:06:00 +02:00
|
|
|
obj->add_on_state_callback([this, obj]() { this->on_fan_update(obj); });
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef USE_LIGHT
|
|
|
|
for (auto *obj : App.get_lights()) {
|
2021-11-29 16:52:20 +01:00
|
|
|
if (include_internal || !obj->is_internal())
|
2019-04-17 12:06:00 +02:00
|
|
|
obj->add_new_remote_values_callback([this, obj]() { this->on_light_update(obj); });
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef USE_SENSOR
|
|
|
|
for (auto *obj : App.get_sensors()) {
|
2021-11-29 16:52:20 +01:00
|
|
|
if (include_internal || !obj->is_internal())
|
2019-04-17 12:06:00 +02:00
|
|
|
obj->add_on_state_callback([this, obj](float state) { this->on_sensor_update(obj, state); });
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef USE_SWITCH
|
|
|
|
for (auto *obj : App.get_switches()) {
|
2021-11-29 16:52:20 +01:00
|
|
|
if (include_internal || !obj->is_internal())
|
2019-04-17 12:06:00 +02:00
|
|
|
obj->add_on_state_callback([this, obj](bool state) { this->on_switch_update(obj, state); });
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef USE_COVER
|
|
|
|
for (auto *obj : App.get_covers()) {
|
2021-11-29 16:52:20 +01:00
|
|
|
if (include_internal || !obj->is_internal())
|
2019-04-17 12:06:00 +02:00
|
|
|
obj->add_on_state_callback([this, obj]() { this->on_cover_update(obj); });
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef USE_TEXT_SENSOR
|
|
|
|
for (auto *obj : App.get_text_sensors()) {
|
2021-11-29 16:52:20 +01:00
|
|
|
if (include_internal || !obj->is_internal())
|
2021-06-10 13:04:40 +02:00
|
|
|
obj->add_on_state_callback([this, obj](const std::string &state) { this->on_text_sensor_update(obj, state); });
|
2019-04-17 12:06:00 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef USE_CLIMATE
|
|
|
|
for (auto *obj : App.get_climates()) {
|
2021-11-29 16:52:20 +01:00
|
|
|
if (include_internal || !obj->is_internal())
|
2019-04-17 12:06:00 +02:00
|
|
|
obj->add_on_state_callback([this, obj]() { this->on_climate_update(obj); });
|
|
|
|
}
|
|
|
|
#endif
|
2021-07-12 21:20:12 +02:00
|
|
|
#ifdef USE_NUMBER
|
|
|
|
for (auto *obj : App.get_numbers()) {
|
2021-11-29 16:52:20 +01:00
|
|
|
if (include_internal || !obj->is_internal())
|
2021-07-12 21:20:12 +02:00
|
|
|
obj->add_on_state_callback([this, obj](float state) { this->on_number_update(obj, state); });
|
|
|
|
}
|
|
|
|
#endif
|
2021-08-02 10:00:51 +02:00
|
|
|
#ifdef USE_SELECT
|
|
|
|
for (auto *obj : App.get_selects()) {
|
2022-05-10 06:41:16 +02:00
|
|
|
if (include_internal || !obj->is_internal()) {
|
|
|
|
obj->add_on_state_callback(
|
|
|
|
[this, obj](const std::string &state, size_t index) { this->on_select_update(obj, state, index); });
|
|
|
|
}
|
2021-08-02 10:00:51 +02:00
|
|
|
}
|
|
|
|
#endif
|
2022-02-03 19:24:31 +01:00
|
|
|
#ifdef USE_LOCK
|
|
|
|
for (auto *obj : App.get_locks()) {
|
|
|
|
if (include_internal || !obj->is_internal())
|
|
|
|
obj->add_on_state_callback([this, obj]() { this->on_lock_update(obj); });
|
|
|
|
}
|
|
|
|
#endif
|
2022-06-02 07:00:17 +02:00
|
|
|
#ifdef USE_MEDIA_PLAYER
|
|
|
|
for (auto *obj : App.get_media_players()) {
|
|
|
|
if (include_internal || !obj->is_internal())
|
|
|
|
obj->add_on_state_callback([this, obj]() { this->on_media_player_update(obj); });
|
|
|
|
}
|
|
|
|
#endif
|
2019-04-17 12:06:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace esphome
|