This commit is contained in:
J. Nick Koston
2025-11-28 13:50:20 -06:00
parent 515cdf9b9f
commit a224d0acbd
2 changed files with 7 additions and 26 deletions

View File

@@ -1,7 +1,6 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/core/defines.h"
#include "esphome/core/helpers.h"
#include "esphome/components/http_request/http_request.h"

View File

@@ -14,17 +14,21 @@ class OTAStateChangeTrigger final : public Trigger<OTAState>, public OTAStateLis
void on_ota_state(OTAState state, float progress, uint8_t error) override { this->trigger(state); }
};
class OTAStartTrigger final : public Trigger<>, public OTAStateListener {
template<OTAState State> class OTAStateTrigger final : public Trigger<>, public OTAStateListener {
public:
explicit OTAStartTrigger(OTAComponent *parent) { parent->add_state_listener(this); }
explicit OTAStateTrigger(OTAComponent *parent) { parent->add_state_listener(this); }
void on_ota_state(OTAState state, float progress, uint8_t error) override {
if (state == OTA_STARTED) {
if (state == State) {
this->trigger();
}
}
};
using OTAStartTrigger = OTAStateTrigger<OTA_STARTED>;
using OTAEndTrigger = OTAStateTrigger<OTA_COMPLETED>;
using OTAAbortTrigger = OTAStateTrigger<OTA_ABORT>;
class OTAProgressTrigger final : public Trigger<float>, public OTAStateListener {
public:
explicit OTAProgressTrigger(OTAComponent *parent) { parent->add_state_listener(this); }
@@ -36,28 +40,6 @@ class OTAProgressTrigger final : public Trigger<float>, public OTAStateListener
}
};
class OTAEndTrigger final : public Trigger<>, public OTAStateListener {
public:
explicit OTAEndTrigger(OTAComponent *parent) { parent->add_state_listener(this); }
void on_ota_state(OTAState state, float progress, uint8_t error) override {
if (state == OTA_COMPLETED) {
this->trigger();
}
}
};
class OTAAbortTrigger final : public Trigger<>, public OTAStateListener {
public:
explicit OTAAbortTrigger(OTAComponent *parent) { parent->add_state_listener(this); }
void on_ota_state(OTAState state, float progress, uint8_t error) override {
if (state == OTA_ABORT) {
this->trigger();
}
}
};
class OTAErrorTrigger final : public Trigger<uint8_t>, public OTAStateListener {
public:
explicit OTAErrorTrigger(OTAComponent *parent) { parent->add_state_listener(this); }