Browse Source

Remove work on OTA update triggers. These triggers will likely go in ESPHome directory (pull request for that is in progress).

pull/36/head
Maurice Makaay 3 years ago
parent
commit
ae44dea602
2 changed files with 0 additions and 126 deletions
  1. +0
    -70
      components/ota_triggers/__init__.py
  2. +0
    -56
      components/ota_triggers/automation.h

+ 0
- 70
components/ota_triggers/__init__.py View File

@ -1,70 +0,0 @@
from esphome.cpp_generator import RawExpression
from esphome import automation
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components.ota import ota_ns, OTAComponent
from esphome.const import (
CONF_ID,
)
CODEOWNERS = ["@mmakaay"]
DEPENDENCIES = ["ota"]
CONF_ON_BEGIN = "on_begin"
CONF_ON_PROGRESS = "on_progress"
CONF_ON_END = "on_end"
CONF_ON_ERROR = "on_error"
CONF_ON_BEGIN_TRIGGER_ID = "on_begin_trigger_id"
CONF_ON_PROGRESS_TRIGGER_ID = "on_progress_trigger_id"
CONF_ON_END_TRIGGER_ID = "on_end_trigger_id"
CONF_ON_ERROR_TRIGGER_ID = "on_error_trigger_id"
OTAStartTrigger = ota_ns.class_("OTAStartTrigger", automation.Trigger.template())
OTAProgressTrigger = ota_ns.class_("OTAProgressTrigger", automation.Trigger.template())
OTAEndTrigger = ota_ns.class_("OTAEndTrigger", automation.Trigger.template())
OTAErrorTrigger = ota_ns.class_("OTAErrorTrigger", automation.Trigger.template())
CONFIG_SCHEMA = cv.Schema(
{
cv.GenerateID(): cv.use_id(OTAComponent),
cv.Optional(CONF_ON_BEGIN): automation.validate_automation(
{
cv.GenerateID(CONF_ON_BEGIN_TRIGGER_ID): cv.declare_id(OTAStartTrigger),
}
),
cv.Optional(CONF_ON_ERROR): automation.validate_automation(
{
cv.GenerateID(CONF_ON_ERROR_TRIGGER_ID): cv.declare_id(OTAErrorTrigger),
}
),
cv.Optional(CONF_ON_PROGRESS): automation.validate_automation(
{
cv.GenerateID(CONF_ON_PROGRESS_TRIGGER_ID): cv.declare_id(
OTAProgressTrigger
),
}
),
cv.Optional(CONF_ON_END): automation.validate_automation(
{
cv.GenerateID(CONF_ON_END_TRIGGER_ID): cv.declare_id(OTAEndTrigger),
}
),
}
).extend(cv.COMPONENT_SCHEMA)
async def to_code(config):
var = await cg.get_variable(config[CONF_ID])
for conf in config.get(CONF_ON_BEGIN, []):
trigger = cg.new_Pvariable(conf[CONF_ON_BEGIN_TRIGGER_ID], var)
await automation.build_automation(trigger, [], conf)
for conf in config.get(CONF_ON_PROGRESS, []):
trigger = cg.new_Pvariable(conf[CONF_ON_PROGRESS_TRIGGER_ID], var)
await automation.build_automation(trigger, [(float, "x")], conf)
for conf in config.get(CONF_ON_END, []):
trigger = cg.new_Pvariable(conf[CONF_ON_END_TRIGGER_ID], var)
await automation.build_automation(trigger, [], conf)
for conf in config.get(CONF_ON_ERROR, []):
trigger = cg.new_Pvariable(conf[CONF_ON_ERROR_TRIGGER_ID], var)
await automation.build_automation(trigger, [(int, "x")], conf)

+ 0
- 56
components/ota_triggers/automation.h View File

@ -1,56 +0,0 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/core/automation.h"
#include "esphome/components/ota/ota_component.h"
namespace esphome {
namespace ota {
class OTAStartTrigger : public Trigger<> {
public:
explicit OTAStartTrigger(OTAComponent *parent) {
parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) {
if (state == OTAState::Started && !parent->is_failed()) {
trigger();
}
});
}
};
class OTAProgressTrigger : public Trigger<float> {
public:
explicit OTAProgressTrigger(OTAComponent *parent) {
parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) {
if (state == OTAState::InProgress && !parent->is_failed()) {
trigger(progress);
}
});
}
};
class OTAEndTrigger : public Trigger<> {
public:
explicit OTAEndTrigger(OTAComponent *parent) {
parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) {
if (state == OTAState::Completed && !parent->is_failed()) {
trigger();
}
});
}
};
class OTAErrorTrigger : public Trigger<int> {
public:
explicit OTAErrorTrigger(OTAComponent *parent) {
parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) {
if (state == OTAState::Error && !parent->is_failed()) {
trigger(error);
}
});
}
};
} // namespace ota
} // namespace esphome

Loading…
Cancel
Save