mirror of
https://github.com/esphome/esphome.git
synced 2026-02-20 16:35:37 -07:00
dry
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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); }
|
||||
|
||||
Reference in New Issue
Block a user