1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-17 15:26:01 +00:00
This commit is contained in:
J. Nick Koston
2025-11-07 16:33:01 -06:00
parent 1b6471f4b0
commit 8229e3a471
20 changed files with 40 additions and 20 deletions

View File

@@ -1,4 +1,5 @@
#include <utility>
#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) {

View File

@@ -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
}

View File

@@ -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

View File

@@ -1,4 +1,5 @@
#include "cover.h"
#include "esphome/core/defines.h"
#include <strings.h>
#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

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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_();

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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<void()> &&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
}

View File

@@ -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
}

View File

@@ -1,4 +1,5 @@
#include "select.h"
#include "esphome/core/defines.h"
#include "esphome/core/controller_registry.h"
#include "esphome/core/log.h"
#include <cstring>
@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -1,4 +1,5 @@
#include "valve.h"
#include "esphome/core/defines.h"
#include "esphome/core/controller_registry.h"
#include "esphome/core/log.h"
#include <strings.h>
@@ -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