diff --git a/esphome/components/alarm_control_panel/alarm_control_panel.cpp b/esphome/components/alarm_control_panel/alarm_control_panel.cpp index baa7094a8a5..febd00f2c5c 100644 --- a/esphome/components/alarm_control_panel/alarm_control_panel.cpp +++ b/esphome/components/alarm_control_panel/alarm_control_panel.cpp @@ -1,4 +1,5 @@ #include +#include "esphome/core/defines.h" #include "alarm_control_panel.h" #include "esphome/core/controller_registry.h" @@ -34,7 +35,7 @@ void AlarmControlPanel::publish_state(AlarmControlPanelState state) { LOG_STR_ARG(alarm_control_panel_state_to_string(prev_state))); this->current_state_ = state; this->state_callback_.call(); -#ifdef USE_ALARM_CONTROL_PANEL +#if defined(USE_ALARM_CONTROL_PANEL) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_alarm_control_panel_update(this); #endif if (state == ACP_STATE_TRIGGERED) { diff --git a/esphome/components/binary_sensor/binary_sensor.cpp b/esphome/components/binary_sensor/binary_sensor.cpp index 7c35ebe116a..220ed685db0 100644 --- a/esphome/components/binary_sensor/binary_sensor.cpp +++ b/esphome/components/binary_sensor/binary_sensor.cpp @@ -1,4 +1,5 @@ #include "binary_sensor.h" +#include "esphome/core/defines.h" #include "esphome/core/controller_registry.h" #include "esphome/core/log.h" @@ -38,7 +39,7 @@ void BinarySensor::send_state_internal(bool new_state) { // Note that set_state_ de-dups and will only trigger callbacks if the state has actually changed if (this->set_state_(new_state)) { ESP_LOGD(TAG, "'%s': New state is %s", this->get_name().c_str(), ONOFF(new_state)); -#ifdef USE_BINARY_SENSOR +#if defined(USE_BINARY_SENSOR) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_binary_sensor_update(this); #endif } diff --git a/esphome/components/climate/climate.cpp b/esphome/components/climate/climate.cpp index 0576674f3a9..82b75660bae 100644 --- a/esphome/components/climate/climate.cpp +++ b/esphome/components/climate/climate.cpp @@ -1,4 +1,5 @@ #include "climate.h" +#include "esphome/core/defines.h" #include "esphome/core/controller_registry.h" #include "esphome/core/macros.h" @@ -464,7 +465,7 @@ void Climate::publish_state() { // Send state to frontend this->state_callback_.call(*this); -#ifdef USE_CLIMATE +#if defined(USE_CLIMATE) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_climate_update(this); #endif // Save state diff --git a/esphome/components/cover/cover.cpp b/esphome/components/cover/cover.cpp index 4542f0300ee..ab800a87499 100644 --- a/esphome/components/cover/cover.cpp +++ b/esphome/components/cover/cover.cpp @@ -1,4 +1,5 @@ #include "cover.h" +#include "esphome/core/defines.h" #include #include "esphome/core/controller_registry.h" #include "esphome/core/log.h" @@ -170,7 +171,7 @@ void Cover::publish_state(bool save) { ESP_LOGD(TAG, " Current Operation: %s", cover_operation_to_str(this->current_operation)); this->state_callback_.call(); -#ifdef USE_COVER +#if defined(USE_COVER) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_cover_update(this); #endif diff --git a/esphome/components/datetime/date_entity.cpp b/esphome/components/datetime/date_entity.cpp index d5c63f5e0b6..2c2775ecf40 100644 --- a/esphome/components/datetime/date_entity.cpp +++ b/esphome/components/datetime/date_entity.cpp @@ -1,4 +1,5 @@ #include "date_entity.h" +#include "esphome/core/defines.h" #include "esphome/core/controller_registry.h" #ifdef USE_DATETIME_DATE @@ -32,7 +33,7 @@ void DateEntity::publish_state() { this->set_has_state(true); ESP_LOGD(TAG, "'%s': Sending date %d-%d-%d", this->get_name().c_str(), this->year_, this->month_, this->day_); this->state_callback_.call(); -#ifdef USE_DATETIME_DATE +#if defined(USE_DATETIME_DATE) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_date_update(this); #endif } diff --git a/esphome/components/datetime/datetime_entity.cpp b/esphome/components/datetime/datetime_entity.cpp index 56f4e3f7af9..8606a47fa72 100644 --- a/esphome/components/datetime/datetime_entity.cpp +++ b/esphome/components/datetime/datetime_entity.cpp @@ -1,4 +1,5 @@ #include "datetime_entity.h" +#include "esphome/core/defines.h" #include "esphome/core/controller_registry.h" #ifdef USE_DATETIME_DATETIME @@ -48,7 +49,7 @@ void DateTimeEntity::publish_state() { ESP_LOGD(TAG, "'%s': Sending datetime %04u-%02u-%02u %02d:%02d:%02d", this->get_name().c_str(), this->year_, this->month_, this->day_, this->hour_, this->minute_, this->second_); this->state_callback_.call(); -#ifdef USE_DATETIME_DATETIME +#if defined(USE_DATETIME_DATETIME) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_datetime_update(this); #endif } diff --git a/esphome/components/datetime/time_entity.cpp b/esphome/components/datetime/time_entity.cpp index f06f9621779..469be077eab 100644 --- a/esphome/components/datetime/time_entity.cpp +++ b/esphome/components/datetime/time_entity.cpp @@ -1,4 +1,5 @@ #include "time_entity.h" +#include "esphome/core/defines.h" #include "esphome/core/controller_registry.h" #ifdef USE_DATETIME_TIME @@ -29,7 +30,7 @@ void TimeEntity::publish_state() { ESP_LOGD(TAG, "'%s': Sending time %02d:%02d:%02d", this->get_name().c_str(), this->hour_, this->minute_, this->second_); this->state_callback_.call(); -#ifdef USE_DATETIME_TIME +#if defined(USE_DATETIME_TIME) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_time_update(this); #endif } diff --git a/esphome/components/event/event.cpp b/esphome/components/event/event.cpp index ffc3cdaa39a..4c74a113885 100644 --- a/esphome/components/event/event.cpp +++ b/esphome/components/event/event.cpp @@ -1,4 +1,5 @@ #include "event.h" +#include "esphome/core/defines.h" #include "esphome/core/controller_registry.h" #include "esphome/core/log.h" @@ -23,7 +24,7 @@ void Event::trigger(const std::string &event_type) { this->last_event_type_ = found; ESP_LOGD(TAG, "'%s' Triggered event '%s'", this->get_name().c_str(), this->last_event_type_); this->event_callback_.call(event_type); -#ifdef USE_EVENT +#if defined(USE_EVENT) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_event(this); #endif } diff --git a/esphome/components/fan/fan.cpp b/esphome/components/fan/fan.cpp index ee1962bf60a..d37825a6513 100644 --- a/esphome/components/fan/fan.cpp +++ b/esphome/components/fan/fan.cpp @@ -1,4 +1,5 @@ #include "fan.h" +#include "esphome/core/defines.h" #include "esphome/core/controller_registry.h" #include "esphome/core/log.h" @@ -182,7 +183,7 @@ void Fan::publish_state() { ESP_LOGD(TAG, " Preset Mode: %s", preset); } this->state_callback_.call(); -#ifdef USE_FAN +#if defined(USE_FAN) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_fan_update(this); #endif this->save_state_(); diff --git a/esphome/components/light/light_state.cpp b/esphome/components/light/light_state.cpp index 0f6695d968b..8b53044554a 100644 --- a/esphome/components/light/light_state.cpp +++ b/esphome/components/light/light_state.cpp @@ -1,4 +1,5 @@ #include "esphome/core/controller_registry.h" +#include "esphome/core/defines.h" #include "esphome/core/log.h" #include "light_output.h" @@ -140,7 +141,7 @@ float LightState::get_setup_priority() const { return setup_priority::HARDWARE - void LightState::publish_state() { this->remote_values_callback_.call(); -#ifdef USE_LIGHT +#if defined(USE_LIGHT) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_light_update(this); #endif } diff --git a/esphome/components/lock/lock.cpp b/esphome/components/lock/lock.cpp index 2cbef07ca60..54fefe8745e 100644 --- a/esphome/components/lock/lock.cpp +++ b/esphome/components/lock/lock.cpp @@ -1,4 +1,5 @@ #include "lock.h" +#include "esphome/core/defines.h" #include "esphome/core/controller_registry.h" #include "esphome/core/log.h" @@ -54,7 +55,7 @@ void Lock::publish_state(LockState state) { this->rtc_.save(&this->state); ESP_LOGD(TAG, "'%s': Sending state %s", this->name_.c_str(), lock_state_to_string(state)); this->state_callback_.call(); -#ifdef USE_LOCK +#if defined(USE_LOCK) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_lock_update(this); #endif } diff --git a/esphome/components/media_player/media_player.cpp b/esphome/components/media_player/media_player.cpp index 878dcfe6f16..b46ec39d302 100644 --- a/esphome/components/media_player/media_player.cpp +++ b/esphome/components/media_player/media_player.cpp @@ -1,4 +1,5 @@ #include "media_player.h" +#include "esphome/core/defines.h" #include "esphome/core/controller_registry.h" #include "esphome/core/log.h" @@ -150,7 +151,7 @@ void MediaPlayer::add_on_state_callback(std::function &&callback) { void MediaPlayer::publish_state() { this->state_callback_.call(); -#ifdef USE_MEDIA_PLAYER +#if defined(USE_MEDIA_PLAYER) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_media_player_update(this); #endif } diff --git a/esphome/components/number/number.cpp b/esphome/components/number/number.cpp index 35e59ebdabf..f12e0e9e1e1 100644 --- a/esphome/components/number/number.cpp +++ b/esphome/components/number/number.cpp @@ -1,4 +1,5 @@ #include "number.h" +#include "esphome/core/defines.h" #include "esphome/core/controller_registry.h" #include "esphome/core/log.h" @@ -33,7 +34,7 @@ void Number::publish_state(float state) { this->state = state; ESP_LOGD(TAG, "'%s': Sending state %f", this->get_name().c_str(), state); this->state_callback_.call(state); -#ifdef USE_NUMBER +#if defined(USE_NUMBER) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_number_update(this); #endif } diff --git a/esphome/components/select/select.cpp b/esphome/components/select/select.cpp index fc933c15ef3..9fe7a524227 100644 --- a/esphome/components/select/select.cpp +++ b/esphome/components/select/select.cpp @@ -1,4 +1,5 @@ #include "select.h" +#include "esphome/core/defines.h" #include "esphome/core/controller_registry.h" #include "esphome/core/log.h" #include @@ -34,7 +35,7 @@ void Select::publish_state(size_t index) { ESP_LOGD(TAG, "'%s': Sending state %s (index %zu)", this->get_name().c_str(), option, index); // Callback signature requires std::string, create temporary for compatibility this->state_callback_.call(std::string(option), index); -#ifdef USE_SELECT +#if defined(USE_SELECT) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_select_update(this); #endif } diff --git a/esphome/components/sensor/sensor.cpp b/esphome/components/sensor/sensor.cpp index ac70e457e03..df6bd644e84 100644 --- a/esphome/components/sensor/sensor.cpp +++ b/esphome/components/sensor/sensor.cpp @@ -1,4 +1,5 @@ #include "sensor.h" +#include "esphome/core/defines.h" #include "esphome/core/controller_registry.h" #include "esphome/core/log.h" @@ -132,7 +133,7 @@ void Sensor::internal_send_state_to_frontend(float state) { ESP_LOGD(TAG, "'%s': Sending state %.5f %s with %d decimals of accuracy", this->get_name().c_str(), state, this->get_unit_of_measurement_ref().c_str(), this->get_accuracy_decimals()); this->callback_.call(state); -#ifdef USE_SENSOR +#if defined(USE_SENSOR) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_sensor_update(this); #endif } diff --git a/esphome/components/switch/switch.cpp b/esphome/components/switch/switch.cpp index 49954e6f064..3c3a437ff36 100644 --- a/esphome/components/switch/switch.cpp +++ b/esphome/components/switch/switch.cpp @@ -1,4 +1,5 @@ #include "switch.h" +#include "esphome/core/defines.h" #include "esphome/core/controller_registry.h" #include "esphome/core/log.h" @@ -63,7 +64,7 @@ void Switch::publish_state(bool state) { ESP_LOGD(TAG, "'%s': Sending state %s", this->name_.c_str(), ONOFF(this->state)); this->state_callback_.call(this->state); -#ifdef USE_SWITCH +#if defined(USE_SWITCH) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_switch_update(this); #endif } diff --git a/esphome/components/text/text.cpp b/esphome/components/text/text.cpp index 3028cd85ea2..933d82c85c1 100644 --- a/esphome/components/text/text.cpp +++ b/esphome/components/text/text.cpp @@ -1,4 +1,5 @@ #include "text.h" +#include "esphome/core/defines.h" #include "esphome/core/controller_registry.h" #include "esphome/core/log.h" @@ -17,7 +18,7 @@ void Text::publish_state(const std::string &state) { ESP_LOGD(TAG, "'%s': Sending state %s", this->get_name().c_str(), state.c_str()); } this->state_callback_.call(state); -#ifdef USE_TEXT +#if defined(USE_TEXT) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_text_update(this); #endif } diff --git a/esphome/components/text_sensor/text_sensor.cpp b/esphome/components/text_sensor/text_sensor.cpp index c4a941408ad..a7bcf199672 100644 --- a/esphome/components/text_sensor/text_sensor.cpp +++ b/esphome/components/text_sensor/text_sensor.cpp @@ -1,4 +1,5 @@ #include "text_sensor.h" +#include "esphome/core/defines.h" #include "esphome/core/controller_registry.h" #include "esphome/core/log.h" @@ -85,7 +86,7 @@ void TextSensor::internal_send_state_to_frontend(const std::string &state) { this->set_has_state(true); ESP_LOGD(TAG, "'%s': Sending state '%s'", this->name_.c_str(), state.c_str()); this->callback_.call(state); -#ifdef USE_TEXT_SENSOR +#if defined(USE_TEXT_SENSOR) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_text_sensor_update(this); #endif } diff --git a/esphome/components/update/update_entity.cpp b/esphome/components/update/update_entity.cpp index 9ca2c35f810..567fc9fc8e0 100644 --- a/esphome/components/update/update_entity.cpp +++ b/esphome/components/update/update_entity.cpp @@ -1,4 +1,5 @@ #include "update_entity.h" +#include "esphome/core/defines.h" #include "esphome/core/controller_registry.h" #include "esphome/core/log.h" @@ -32,7 +33,7 @@ void UpdateEntity::publish_state() { this->set_has_state(true); this->state_callback_.call(); -#ifdef USE_UPDATE +#if defined(USE_UPDATE) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_update(this); #endif } diff --git a/esphome/components/valve/valve.cpp b/esphome/components/valve/valve.cpp index 0982892af34..381d9061de3 100644 --- a/esphome/components/valve/valve.cpp +++ b/esphome/components/valve/valve.cpp @@ -1,4 +1,5 @@ #include "valve.h" +#include "esphome/core/defines.h" #include "esphome/core/controller_registry.h" #include "esphome/core/log.h" #include @@ -148,7 +149,7 @@ void Valve::publish_state(bool save) { ESP_LOGD(TAG, " Current Operation: %s", valve_operation_to_str(this->current_operation)); this->state_callback_.call(); -#ifdef USE_VALVE +#if defined(USE_VALVE) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_valve_update(this); #endif