You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.4 KiB

  1. #pragma once
  2. #include "esphome/core/component.h"
  3. #include "esphome/core/automation.h"
  4. #include "esphome/components/ota/ota_component.h"
  5. namespace esphome {
  6. namespace ota {
  7. class OTAStartTrigger : public Trigger<> {
  8. public:
  9. explicit OTAStartTrigger(OTAComponent *parent) {
  10. parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) {
  11. if (state == OTAState::Started && !parent->is_failed()) {
  12. trigger();
  13. }
  14. });
  15. }
  16. };
  17. class OTAProgressTrigger : public Trigger<float> {
  18. public:
  19. explicit OTAProgressTrigger(OTAComponent *parent) {
  20. parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) {
  21. if (state == OTAState::InProgress && !parent->is_failed()) {
  22. trigger(progress);
  23. }
  24. });
  25. }
  26. };
  27. class OTAEndTrigger : public Trigger<> {
  28. public:
  29. explicit OTAEndTrigger(OTAComponent *parent) {
  30. parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) {
  31. if (state == OTAState::Completed && !parent->is_failed()) {
  32. trigger();
  33. }
  34. });
  35. }
  36. };
  37. class OTAErrorTrigger : public Trigger<int> {
  38. public:
  39. explicit OTAErrorTrigger(OTAComponent *parent) {
  40. parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) {
  41. if (state == OTAState::Error && !parent->is_failed()) {
  42. trigger(error);
  43. }
  44. });
  45. }
  46. };
  47. } // namespace ota
  48. } // namespace esphome