mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 15:12:06 +00:00 
			
		
		
		
	on_not_responding nw state cb
This commit is contained in:
		| @@ -10,11 +10,13 @@ namespace esphome { | |||||||
| namespace modem { | namespace modem { | ||||||
|  |  | ||||||
| class ModemOnNotRespondingTrigger : public Trigger<> { | class ModemOnNotRespondingTrigger : public Trigger<> { | ||||||
|   // not managed by `add_on_state_callback`, because we want to execute the callback |  | ||||||
|   // as a single mode script (we have to know when the callback has ended) |  | ||||||
|  public: |  public: | ||||||
|   explicit ModemOnNotRespondingTrigger(ModemComponent *parent) { |   explicit ModemOnNotRespondingTrigger(ModemComponent *parent) { | ||||||
|     parent->set_not_responding_cb(static_cast<Trigger<> *>(this)); |     parent->add_on_state_callback([this, parent](ModemComponentState old_state, ModemComponentState state) { | ||||||
|  |       if (!parent->is_failed() && state == ModemComponentState::NOT_RESPONDING) { | ||||||
|  |         this->trigger(); | ||||||
|  |       } | ||||||
|  |     }); | ||||||
|   } |   } | ||||||
| }; | }; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -297,16 +297,13 @@ void ModemComponent::loop() { | |||||||
|           this->status_clear_warning(); |           this->status_clear_warning(); | ||||||
|           this->component_state_ = ModemComponentState::DISCONNECTED; |           this->component_state_ = ModemComponentState::DISCONNECTED; | ||||||
|         } else { |         } else { | ||||||
|           if (!this->internal_state_.powered_on) { |           this->modem_lazy_init_(); | ||||||
|             this->poweron_(); |           if (!this->modem_sync_()) { | ||||||
|           } else if (this->not_responding_cb_) { |             ESP_LOGE(TAG, "Unable to recover modem"); | ||||||
|             if (!this->not_responding_cb_->is_action_running()) { |  | ||||||
|               ESP_LOGD(TAG, "Calling 'on_not_responding' callback"); |  | ||||||
|               this->not_responding_cb_->trigger(); |  | ||||||
|             } |  | ||||||
|           } else { |  | ||||||
|             ESP_LOGW(TAG, "Modem not responding, and no 'on_not_responding' action defined"); |  | ||||||
|           } |           } | ||||||
|  |           // if (!this->internal_state_.powered_on) { | ||||||
|  |           //   this->poweron_(); | ||||||
|  |           // } | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|       break; |       break; | ||||||
|   | |||||||
| @@ -64,7 +64,6 @@ class ModemComponent : public Component { | |||||||
|   void set_status_pin(GPIOPin *status_pin) { this->status_pin_ = status_pin; } |   void set_status_pin(GPIOPin *status_pin) { this->status_pin_ = status_pin; } | ||||||
|   void set_pin_code(const std::string &pin_code) { this->pin_code_ = pin_code; } |   void set_pin_code(const std::string &pin_code) { this->pin_code_ = pin_code; } | ||||||
|   void set_apn(const std::string &apn) { this->apn_ = apn; } |   void set_apn(const std::string &apn) { this->apn_ = apn; } | ||||||
|   void set_not_responding_cb(Trigger<> *not_responding_cb) { this->not_responding_cb_ = not_responding_cb; } |  | ||||||
|   void enable_cmux() { this->cmux_ = true; } |   void enable_cmux() { this->cmux_ = true; } | ||||||
|   void enable_debug(); |   void enable_debug(); | ||||||
|   void add_init_at_command(const std::string &cmd) { this->init_at_commands_.push_back(cmd); } |   void add_init_at_command(const std::string &cmd) { this->init_at_commands_.push_back(cmd); } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user