From ae44dea602d3d3921614bab9b3421cd536c47988 Mon Sep 17 00:00:00 2001 From: Maurice Makaay Date: Sun, 20 Jun 2021 00:49:27 +0200 Subject: [PATCH] Remove work on OTA update triggers. These triggers will likely go in ESPHome directory (pull request for that is in progress). --- components/ota_triggers/__init__.py | 70 ---------------------------- components/ota_triggers/automation.h | 56 ---------------------- 2 files changed, 126 deletions(-) delete mode 100644 components/ota_triggers/__init__.py delete mode 100644 components/ota_triggers/automation.h diff --git a/components/ota_triggers/__init__.py b/components/ota_triggers/__init__.py deleted file mode 100644 index e2880ca..0000000 --- a/components/ota_triggers/__init__.py +++ /dev/null @@ -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) diff --git a/components/ota_triggers/automation.h b/components/ota_triggers/automation.h deleted file mode 100644 index 3277658..0000000 --- a/components/ota_triggers/automation.h +++ /dev/null @@ -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 { - 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 { - 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