mirror of
https://github.com/esphome/esphome.git
synced 2025-09-14 09:12:19 +01:00
rename, cleanup
This commit is contained in:
@@ -19,8 +19,8 @@ void Anova::setup() {
|
||||
|
||||
void Anova::loop() {
|
||||
// This component uses polling via update() and BLE callbacks
|
||||
// Empty loop not needed, mark as done to save CPU cycles
|
||||
this->mark_loop_done();
|
||||
// Empty loop not needed, disable to save CPU cycles
|
||||
this->disable_loop();
|
||||
}
|
||||
|
||||
void Anova::control(const ClimateCall &call) {
|
||||
|
@@ -482,8 +482,8 @@ void BedJetHub::set_clock(uint8_t hour, uint8_t minute) {
|
||||
|
||||
void BedJetHub::loop() {
|
||||
// This component uses polling via update() and BLE callbacks
|
||||
// Empty loop not needed, mark as done to save CPU cycles
|
||||
this->mark_loop_done();
|
||||
// Empty loop not needed, disable to save CPU cycles
|
||||
this->disable_loop();
|
||||
}
|
||||
void BedJetHub::update() { this->dispatch_status_(); }
|
||||
|
||||
|
@@ -85,8 +85,8 @@ void BedJetClimate::reset_state_() {
|
||||
|
||||
void BedJetClimate::loop() {
|
||||
// This component is controlled via the parent BedJetHub
|
||||
// Empty loop not needed, mark as done to save CPU cycles
|
||||
this->mark_loop_done();
|
||||
// Empty loop not needed, disable to save CPU cycles
|
||||
this->disable_loop();
|
||||
}
|
||||
|
||||
void BedJetClimate::control(const ClimateCall &call) {
|
||||
|
@@ -13,8 +13,8 @@ static const char *const TAG = "ble_rssi_sensor";
|
||||
|
||||
void BLEClientRSSISensor::loop() {
|
||||
// This component uses polling via update() and BLE GAP callbacks
|
||||
// Empty loop not needed, mark as done to save CPU cycles
|
||||
this->mark_loop_done();
|
||||
// Empty loop not needed, disable to save CPU cycles
|
||||
this->disable_loop();
|
||||
}
|
||||
|
||||
void BLEClientRSSISensor::dump_config() {
|
||||
|
@@ -13,8 +13,8 @@ static const char *const TAG = "ble_sensor";
|
||||
|
||||
void BLESensor::loop() {
|
||||
// This component uses polling via update() and BLE callbacks
|
||||
// Empty loop not needed, mark as done to save CPU cycles
|
||||
this->mark_loop_done();
|
||||
// Empty loop not needed, disable to save CPU cycles
|
||||
this->disable_loop();
|
||||
}
|
||||
|
||||
void BLESensor::dump_config() {
|
||||
|
@@ -16,8 +16,8 @@ static const std::string EMPTY = "";
|
||||
|
||||
void BLETextSensor::loop() {
|
||||
// This component uses polling via update() and BLE callbacks
|
||||
// Empty loop not needed, mark as done to save CPU cycles
|
||||
this->mark_loop_done();
|
||||
// Empty loop not needed, disable to save CPU cycles
|
||||
this->disable_loop();
|
||||
}
|
||||
|
||||
void BLETextSensor::dump_config() {
|
||||
|
@@ -37,7 +37,12 @@ void CaptivePortal::handle_wifisave(AsyncWebServerRequest *request) {
|
||||
request->redirect("/?save");
|
||||
}
|
||||
|
||||
void CaptivePortal::setup() {}
|
||||
void CaptivePortal::setup() {
|
||||
#ifndef USE_ARDUINO
|
||||
// No DNS server needed for non-Arduino frameworks
|
||||
this->disable_loop();
|
||||
#endif
|
||||
}
|
||||
void CaptivePortal::start() {
|
||||
this->base_->init();
|
||||
if (!this->initialized_) {
|
||||
@@ -50,6 +55,8 @@ void CaptivePortal::start() {
|
||||
this->dns_server_->setErrorReplyCode(DNSReplyCode::NoError);
|
||||
network::IPAddress ip = wifi::global_wifi_component->wifi_soft_ap_ip();
|
||||
this->dns_server_->start(53, "*", ip);
|
||||
// Re-enable loop() when DNS server is started
|
||||
this->enable_loop();
|
||||
#endif
|
||||
|
||||
this->base_->get_server()->onNotFound([this](AsyncWebServerRequest *req) {
|
||||
|
@@ -23,6 +23,8 @@ class CaptivePortal : public AsyncWebHandler, public Component {
|
||||
void loop() override {
|
||||
if (this->dns_server_ != nullptr)
|
||||
this->dns_server_->processNextRequest();
|
||||
else
|
||||
this->disable_loop();
|
||||
}
|
||||
#endif
|
||||
float get_setup_priority() const override;
|
||||
|
@@ -23,6 +23,12 @@ void BLEClientBase::setup() {
|
||||
}
|
||||
|
||||
void BLEClientBase::loop() {
|
||||
// If address is 0, this connection is not in use
|
||||
if (this->address_ == 0) {
|
||||
this->disable_loop();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!esp32_ble::global_ble->is_active()) {
|
||||
this->set_state(espbt::ClientState::INIT);
|
||||
return;
|
||||
|
@@ -62,6 +62,8 @@ class BLEClientBase : public espbt::ESPBTClient, public Component {
|
||||
(uint8_t) (this->address_ >> 32) & 0xff, (uint8_t) (this->address_ >> 24) & 0xff,
|
||||
(uint8_t) (this->address_ >> 16) & 0xff, (uint8_t) (this->address_ >> 8) & 0xff,
|
||||
(uint8_t) (this->address_ >> 0) & 0xff);
|
||||
// Re-enable loop() when a new address is assigned
|
||||
this->enable_loop();
|
||||
}
|
||||
}
|
||||
std::string address_str() const { return this->address_str_; }
|
||||
|
@@ -169,7 +169,7 @@ void ESP32ImprovComponent::loop() {
|
||||
this->incoming_data_.clear();
|
||||
this->set_status_indicator_state_(false);
|
||||
// Provisioning complete, no further loop execution needed
|
||||
this->mark_loop_done();
|
||||
this->disable_loop();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -178,18 +178,21 @@ void OnlineImage::update() {
|
||||
if (this->format_ == ImageFormat::BMP) {
|
||||
ESP_LOGD(TAG, "Allocating BMP decoder");
|
||||
this->decoder_ = make_unique<BmpDecoder>(this);
|
||||
this->enable_loop();
|
||||
}
|
||||
#endif // USE_ONLINE_IMAGE_BMP_SUPPORT
|
||||
#ifdef USE_ONLINE_IMAGE_JPEG_SUPPORT
|
||||
if (this->format_ == ImageFormat::JPEG) {
|
||||
ESP_LOGD(TAG, "Allocating JPEG decoder");
|
||||
this->decoder_ = esphome::make_unique<JpegDecoder>(this);
|
||||
this->enable_loop();
|
||||
}
|
||||
#endif // USE_ONLINE_IMAGE_JPEG_SUPPORT
|
||||
#ifdef USE_ONLINE_IMAGE_PNG_SUPPORT
|
||||
if (this->format_ == ImageFormat::PNG) {
|
||||
ESP_LOGD(TAG, "Allocating PNG decoder");
|
||||
this->decoder_ = make_unique<PngDecoder>(this);
|
||||
this->enable_loop();
|
||||
}
|
||||
#endif // USE_ONLINE_IMAGE_PNG_SUPPORT
|
||||
|
||||
@@ -212,6 +215,7 @@ void OnlineImage::update() {
|
||||
void OnlineImage::loop() {
|
||||
if (!this->decoder_) {
|
||||
// Not decoding at the moment => nothing to do.
|
||||
this->disable_loop();
|
||||
return;
|
||||
}
|
||||
if (!this->downloader_ || this->decoder_->is_finished()) {
|
||||
|
@@ -13,7 +13,7 @@ class IntervalSyncer : public Component {
|
||||
if (this->write_interval_ != 0) {
|
||||
set_interval(this->write_interval_, []() { global_preferences->sync(); });
|
||||
// When using interval-based syncing, we don't need the loop
|
||||
this->mark_loop_done();
|
||||
this->disable_loop();
|
||||
}
|
||||
}
|
||||
void loop() override {
|
||||
|
@@ -142,8 +142,10 @@ void Rtttl::stop() {
|
||||
}
|
||||
|
||||
void Rtttl::loop() {
|
||||
if (this->note_duration_ == 0 || this->state_ == State::STATE_STOPPED)
|
||||
if (this->note_duration_ == 0 || this->state_ == State::STATE_STOPPED) {
|
||||
this->disable_loop();
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef USE_SPEAKER
|
||||
if (this->speaker_ != nullptr) {
|
||||
@@ -391,6 +393,11 @@ void Rtttl::set_state_(State state) {
|
||||
this->state_ = state;
|
||||
ESP_LOGV(TAG, "State changed from %s to %s", LOG_STR_ARG(state_to_string(old_state)),
|
||||
LOG_STR_ARG(state_to_string(state)));
|
||||
|
||||
// Clear loop_done when transitioning from STOPPED to any other state
|
||||
if (old_state == State::STATE_STOPPED && state != State::STATE_STOPPED) {
|
||||
this->enable_loop();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace rtttl
|
||||
|
@@ -42,8 +42,8 @@ void SafeModeComponent::loop() {
|
||||
ESP_LOGI(TAG, "Boot seems successful; resetting boot loop counter");
|
||||
this->clean_rtc();
|
||||
this->boot_successful_ = true;
|
||||
// Mark loop as done since we no longer need to check
|
||||
this->mark_loop_done();
|
||||
// Disable loop since we no longer need to check
|
||||
this->disable_loop();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -71,7 +71,7 @@ void SNTPComponent::loop() {
|
||||
#ifdef USE_ESP_IDF
|
||||
// On ESP-IDF, time sync is permanent and update() doesn't force resync
|
||||
// Time is now synchronized, no need to check anymore
|
||||
this->mark_loop_done();
|
||||
this->disable_loop();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@@ -24,8 +24,10 @@ void TLC5971::dump_config() {
|
||||
}
|
||||
|
||||
void TLC5971::loop() {
|
||||
if (!this->update_)
|
||||
if (!this->update_) {
|
||||
this->disable_loop();
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t command;
|
||||
|
||||
@@ -93,6 +95,7 @@ void TLC5971::set_channel_value(uint16_t channel, uint16_t value) {
|
||||
return;
|
||||
if (this->pwm_amounts_[channel] != value) {
|
||||
this->update_ = true;
|
||||
this->enable_loop();
|
||||
}
|
||||
this->pwm_amounts_[channel] = value;
|
||||
}
|
||||
|
@@ -137,11 +137,18 @@ void Component::mark_failed() {
|
||||
this->component_state_ |= COMPONENT_STATE_FAILED;
|
||||
this->status_set_error();
|
||||
}
|
||||
void Component::mark_loop_done() {
|
||||
ESP_LOGD(TAG, "Component %s loop marked as done.", this->get_component_source());
|
||||
void Component::disable_loop() {
|
||||
ESP_LOGD(TAG, "Component %s loop disabled.", this->get_component_source());
|
||||
this->component_state_ &= ~COMPONENT_STATE_MASK;
|
||||
this->component_state_ |= COMPONENT_STATE_LOOP_DONE;
|
||||
}
|
||||
void Component::enable_loop() {
|
||||
if ((this->component_state_ & COMPONENT_STATE_MASK) == COMPONENT_STATE_LOOP_DONE) {
|
||||
ESP_LOGD(TAG, "Component %s loop enabled.", this->get_component_source());
|
||||
this->component_state_ &= ~COMPONENT_STATE_MASK;
|
||||
this->component_state_ |= COMPONENT_STATE_LOOP;
|
||||
}
|
||||
}
|
||||
void Component::reset_to_construction_state() {
|
||||
if ((this->component_state_ & COMPONENT_STATE_MASK) == COMPONENT_STATE_FAILED) {
|
||||
ESP_LOGI(TAG, "Component %s is being reset to construction state.", this->get_component_source());
|
||||
|
@@ -151,12 +151,19 @@ class Component {
|
||||
this->mark_failed();
|
||||
}
|
||||
|
||||
/** Mark this component's loop as done. The loop will no longer be called.
|
||||
/** Disable this component's loop. The loop() method will no longer be called.
|
||||
*
|
||||
* This is useful for components that only need to run for a certain period of time
|
||||
* and then no longer need their loop() method called, saving CPU cycles.
|
||||
* or when inactive, saving CPU cycles.
|
||||
*/
|
||||
void mark_loop_done();
|
||||
void disable_loop();
|
||||
|
||||
/** Enable this component's loop. The loop() method will be called normally.
|
||||
*
|
||||
* This is useful for components that transition between active and inactive states
|
||||
* and need to re-enable their loop() method when becoming active again.
|
||||
*/
|
||||
void enable_loop();
|
||||
|
||||
bool is_failed() const;
|
||||
|
||||
|
Reference in New Issue
Block a user