mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 23:21:54 +00:00 
			
		
		
		
	make sure components that disable in setup are disabled at start
This commit is contained in:
		| @@ -243,24 +243,22 @@ void Application::teardown_components(uint32_t timeout_ms) { | |||||||
| } | } | ||||||
|  |  | ||||||
| void Application::calculate_looping_components_() { | void Application::calculate_looping_components_() { | ||||||
|  |   // First add all active components | ||||||
|   for (auto *obj : this->components_) { |   for (auto *obj : this->components_) { | ||||||
|     if (obj->has_overridden_loop()) { |     if (obj->has_overridden_loop() && | ||||||
|  |         (obj->get_component_state() & COMPONENT_STATE_MASK) != COMPONENT_STATE_LOOP_DONE) { | ||||||
|       this->looping_components_.push_back(obj); |       this->looping_components_.push_back(obj); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Partition components based on their current state |   this->looping_components_active_end_ = this->looping_components_.size(); | ||||||
|   // Components that have already called disable_loop() during setup (state == LOOP_DONE) |  | ||||||
|   // should start in the inactive section of the partition |   // Then add all inactive (LOOP_DONE) components | ||||||
|   this->looping_components_active_end_ = 0; |   // This handles components that called disable_loop() during setup, before this method runs | ||||||
|   for (uint16_t i = 0; i < this->looping_components_.size(); i++) { |   for (auto *obj : this->components_) { | ||||||
|     Component *comp = this->looping_components_[i]; |     if (obj->has_overridden_loop() && | ||||||
|     if ((comp->get_component_state() & COMPONENT_STATE_MASK) != COMPONENT_STATE_LOOP_DONE) { |         (obj->get_component_state() & COMPONENT_STATE_MASK) == COMPONENT_STATE_LOOP_DONE) { | ||||||
|       // Component is active - swap it to the active section if needed |       this->looping_components_.push_back(obj); | ||||||
|       if (i != this->looping_components_active_end_) { |  | ||||||
|         std::swap(this->looping_components_[i], this->looping_components_[this->looping_components_active_end_]); |  | ||||||
|       } |  | ||||||
|       this->looping_components_active_end_++; |  | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user