mirror of
https://github.com/esphome/esphome.git
synced 2024-12-24 14:34:54 +01:00
on_not_responding nw state cb
This commit is contained in:
parent
3a289c8284
commit
00f54725e3
3 changed files with 11 additions and 13 deletions
|
@ -10,11 +10,13 @@ namespace esphome {
|
|||
namespace modem {
|
||||
|
||||
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:
|
||||
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->component_state_ = ModemComponentState::DISCONNECTED;
|
||||
} else {
|
||||
if (!this->internal_state_.powered_on) {
|
||||
this->poweron_();
|
||||
} else if (this->not_responding_cb_) {
|
||||
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");
|
||||
this->modem_lazy_init_();
|
||||
if (!this->modem_sync_()) {
|
||||
ESP_LOGE(TAG, "Unable to recover modem");
|
||||
}
|
||||
// if (!this->internal_state_.powered_on) {
|
||||
// this->poweron_();
|
||||
// }
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -64,7 +64,6 @@ class ModemComponent : public Component {
|
|||
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_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_debug();
|
||||
void add_init_at_command(const std::string &cmd) { this->init_at_commands_.push_back(cmd); }
|
||||
|
|
Loading…
Reference in a new issue