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:13:59 -06:00
parent c0e4f415f1
commit fc8dc33023
20 changed files with 40 additions and 0 deletions

View File

@@ -34,7 +34,9 @@ void AlarmControlPanel::publish_state(AlarmControlPanelState state) {
LOG_STR_ARG(alarm_control_panel_state_to_string(prev_state))); LOG_STR_ARG(alarm_control_panel_state_to_string(prev_state)));
this->current_state_ = state; this->current_state_ = state;
this->state_callback_.call(); this->state_callback_.call();
#ifdef USE_ALARM_CONTROL_PANEL
ControllerRegistry::notify_alarm_control_panel_update(this); ControllerRegistry::notify_alarm_control_panel_update(this);
#endif
if (state == ACP_STATE_TRIGGERED) { if (state == ACP_STATE_TRIGGERED) {
this->triggered_callback_.call(); this->triggered_callback_.call();
} else if (state == ACP_STATE_ARMING) { } else if (state == ACP_STATE_ARMING) {

View File

@@ -38,7 +38,9 @@ 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 // Note that set_state_ de-dups and will only trigger callbacks if the state has actually changed
if (this->set_state_(new_state)) { if (this->set_state_(new_state)) {
ESP_LOGD(TAG, "'%s': New state is %s", this->get_name().c_str(), ONOFF(new_state)); ESP_LOGD(TAG, "'%s': New state is %s", this->get_name().c_str(), ONOFF(new_state));
#ifdef USE_BINARY_SENSOR
ControllerRegistry::notify_binary_sensor_update(this); ControllerRegistry::notify_binary_sensor_update(this);
#endif
} }
} }

View File

@@ -464,7 +464,9 @@ void Climate::publish_state() {
// Send state to frontend // Send state to frontend
this->state_callback_.call(*this); this->state_callback_.call(*this);
#ifdef USE_CLIMATE
ControllerRegistry::notify_climate_update(this); ControllerRegistry::notify_climate_update(this);
#endif
// Save state // Save state
this->save_state_(); this->save_state_();
} }

View File

@@ -170,7 +170,9 @@ void Cover::publish_state(bool save) {
ESP_LOGD(TAG, " Current Operation: %s", cover_operation_to_str(this->current_operation)); ESP_LOGD(TAG, " Current Operation: %s", cover_operation_to_str(this->current_operation));
this->state_callback_.call(); this->state_callback_.call();
#ifdef USE_COVER
ControllerRegistry::notify_cover_update(this); ControllerRegistry::notify_cover_update(this);
#endif
if (save) { if (save) {
CoverRestoreState restore{}; CoverRestoreState restore{};

View File

@@ -32,7 +32,9 @@ void DateEntity::publish_state() {
this->set_has_state(true); 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_); ESP_LOGD(TAG, "'%s': Sending date %d-%d-%d", this->get_name().c_str(), this->year_, this->month_, this->day_);
this->state_callback_.call(); this->state_callback_.call();
#ifdef USE_DATETIME_DATE
ControllerRegistry::notify_date_update(this); ControllerRegistry::notify_date_update(this);
#endif
} }
DateCall DateEntity::make_call() { return DateCall(this); } DateCall DateEntity::make_call() { return DateCall(this); }

View File

@@ -48,7 +48,9 @@ void DateTimeEntity::publish_state() {
ESP_LOGD(TAG, "'%s': Sending datetime %04u-%02u-%02u %02d:%02d:%02d", this->get_name().c_str(), this->year_, 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->month_, this->day_, this->hour_, this->minute_, this->second_);
this->state_callback_.call(); this->state_callback_.call();
#ifdef USE_DATETIME_DATETIME
ControllerRegistry::notify_datetime_update(this); ControllerRegistry::notify_datetime_update(this);
#endif
} }
DateTimeCall DateTimeEntity::make_call() { return DateTimeCall(this); } DateTimeCall DateTimeEntity::make_call() { return DateTimeCall(this); }

View File

@@ -29,7 +29,9 @@ void TimeEntity::publish_state() {
ESP_LOGD(TAG, "'%s': Sending time %02d:%02d:%02d", this->get_name().c_str(), this->hour_, this->minute_, ESP_LOGD(TAG, "'%s': Sending time %02d:%02d:%02d", this->get_name().c_str(), this->hour_, this->minute_,
this->second_); this->second_);
this->state_callback_.call(); this->state_callback_.call();
#ifdef USE_DATETIME_TIME
ControllerRegistry::notify_time_update(this); ControllerRegistry::notify_time_update(this);
#endif
} }
TimeCall TimeEntity::make_call() { return TimeCall(this); } TimeCall TimeEntity::make_call() { return TimeCall(this); }

View File

@@ -23,7 +23,9 @@ void Event::trigger(const std::string &event_type) {
this->last_event_type_ = found; this->last_event_type_ = found;
ESP_LOGD(TAG, "'%s' Triggered event '%s'", this->get_name().c_str(), this->last_event_type_); ESP_LOGD(TAG, "'%s' Triggered event '%s'", this->get_name().c_str(), this->last_event_type_);
this->event_callback_.call(event_type); this->event_callback_.call(event_type);
#ifdef USE_EVENT
ControllerRegistry::notify_event(this); ControllerRegistry::notify_event(this);
#endif
} }
void Event::set_event_types(const FixedVector<const char *> &event_types) { void Event::set_event_types(const FixedVector<const char *> &event_types) {

View File

@@ -182,7 +182,9 @@ void Fan::publish_state() {
ESP_LOGD(TAG, " Preset Mode: %s", preset); ESP_LOGD(TAG, " Preset Mode: %s", preset);
} }
this->state_callback_.call(); this->state_callback_.call();
#ifdef USE_FAN
ControllerRegistry::notify_fan_update(this); ControllerRegistry::notify_fan_update(this);
#endif
this->save_state_(); this->save_state_();
} }

View File

@@ -140,7 +140,9 @@ float LightState::get_setup_priority() const { return setup_priority::HARDWARE -
void LightState::publish_state() { void LightState::publish_state() {
this->remote_values_callback_.call(); this->remote_values_callback_.call();
#ifdef USE_LIGHT
ControllerRegistry::notify_light_update(this); ControllerRegistry::notify_light_update(this);
#endif
} }
LightOutput *LightState::get_output() const { return this->output_; } LightOutput *LightState::get_output() const { return this->output_; }

View File

@@ -54,7 +54,9 @@ void Lock::publish_state(LockState state) {
this->rtc_.save(&this->state); this->rtc_.save(&this->state);
ESP_LOGD(TAG, "'%s': Sending state %s", this->name_.c_str(), lock_state_to_string(state)); ESP_LOGD(TAG, "'%s': Sending state %s", this->name_.c_str(), lock_state_to_string(state));
this->state_callback_.call(); this->state_callback_.call();
#ifdef USE_LOCK
ControllerRegistry::notify_lock_update(this); ControllerRegistry::notify_lock_update(this);
#endif
} }
void Lock::add_on_state_callback(std::function<void()> &&callback) { this->state_callback_.add(std::move(callback)); } void Lock::add_on_state_callback(std::function<void()> &&callback) { this->state_callback_.add(std::move(callback)); }

View File

@@ -150,7 +150,9 @@ void MediaPlayer::add_on_state_callback(std::function<void()> &&callback) {
void MediaPlayer::publish_state() { void MediaPlayer::publish_state() {
this->state_callback_.call(); this->state_callback_.call();
#ifdef USE_MEDIA_PLAYER
ControllerRegistry::notify_media_player_update(this); ControllerRegistry::notify_media_player_update(this);
#endif
} }
} // namespace media_player } // namespace media_player

View File

@@ -33,7 +33,9 @@ void Number::publish_state(float state) {
this->state = state; this->state = state;
ESP_LOGD(TAG, "'%s': Sending state %f", this->get_name().c_str(), state); ESP_LOGD(TAG, "'%s': Sending state %f", this->get_name().c_str(), state);
this->state_callback_.call(state); this->state_callback_.call(state);
#ifdef USE_NUMBER
ControllerRegistry::notify_number_update(this); ControllerRegistry::notify_number_update(this);
#endif
} }
void Number::add_on_state_callback(std::function<void(float)> &&callback) { void Number::add_on_state_callback(std::function<void(float)> &&callback) {

View File

@@ -34,7 +34,9 @@ void Select::publish_state(size_t index) {
ESP_LOGD(TAG, "'%s': Sending state %s (index %zu)", this->get_name().c_str(), option, 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 // Callback signature requires std::string, create temporary for compatibility
this->state_callback_.call(std::string(option), index); this->state_callback_.call(std::string(option), index);
#ifdef USE_SELECT
ControllerRegistry::notify_select_update(this); ControllerRegistry::notify_select_update(this);
#endif
} }
const char *Select::current_option() const { return this->has_state() ? this->option_at(this->active_index_) : ""; } const char *Select::current_option() const { return this->has_state() ? this->option_at(this->active_index_) : ""; }

View File

@@ -132,7 +132,9 @@ 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, 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->get_unit_of_measurement_ref().c_str(), this->get_accuracy_decimals());
this->callback_.call(state); this->callback_.call(state);
#ifdef USE_SENSOR
ControllerRegistry::notify_sensor_update(this); ControllerRegistry::notify_sensor_update(this);
#endif
} }
} // namespace sensor } // namespace sensor

View File

@@ -63,7 +63,9 @@ void Switch::publish_state(bool state) {
ESP_LOGD(TAG, "'%s': Sending state %s", this->name_.c_str(), ONOFF(this->state)); ESP_LOGD(TAG, "'%s': Sending state %s", this->name_.c_str(), ONOFF(this->state));
this->state_callback_.call(this->state); this->state_callback_.call(this->state);
#ifdef USE_SWITCH
ControllerRegistry::notify_switch_update(this); ControllerRegistry::notify_switch_update(this);
#endif
} }
bool Switch::assumed_state() { return false; } bool Switch::assumed_state() { return false; }

View File

@@ -17,7 +17,9 @@ void Text::publish_state(const std::string &state) {
ESP_LOGD(TAG, "'%s': Sending state %s", this->get_name().c_str(), state.c_str()); ESP_LOGD(TAG, "'%s': Sending state %s", this->get_name().c_str(), state.c_str());
} }
this->state_callback_.call(state); this->state_callback_.call(state);
#ifdef USE_TEXT
ControllerRegistry::notify_text_update(this); ControllerRegistry::notify_text_update(this);
#endif
} }
void Text::add_on_state_callback(std::function<void(std::string)> &&callback) { void Text::add_on_state_callback(std::function<void(std::string)> &&callback) {

View File

@@ -85,7 +85,9 @@ void TextSensor::internal_send_state_to_frontend(const std::string &state) {
this->set_has_state(true); this->set_has_state(true);
ESP_LOGD(TAG, "'%s': Sending state '%s'", this->name_.c_str(), state.c_str()); ESP_LOGD(TAG, "'%s': Sending state '%s'", this->name_.c_str(), state.c_str());
this->callback_.call(state); this->callback_.call(state);
#ifdef USE_TEXT_SENSOR
ControllerRegistry::notify_text_sensor_update(this); ControllerRegistry::notify_text_sensor_update(this);
#endif
} }
} // namespace text_sensor } // namespace text_sensor

View File

@@ -32,7 +32,9 @@ void UpdateEntity::publish_state() {
this->set_has_state(true); this->set_has_state(true);
this->state_callback_.call(); this->state_callback_.call();
#ifdef USE_UPDATE
ControllerRegistry::notify_update(this); ControllerRegistry::notify_update(this);
#endif
} }
} // namespace update } // namespace update

View File

@@ -148,7 +148,9 @@ void Valve::publish_state(bool save) {
ESP_LOGD(TAG, " Current Operation: %s", valve_operation_to_str(this->current_operation)); ESP_LOGD(TAG, " Current Operation: %s", valve_operation_to_str(this->current_operation));
this->state_callback_.call(); this->state_callback_.call();
#ifdef USE_VALVE
ControllerRegistry::notify_valve_update(this); ControllerRegistry::notify_valve_update(this);
#endif
if (save) { if (save) {
ValveRestoreState restore{}; ValveRestoreState restore{};