diff --git a/components/ratgdo/button/__init__.py b/components/ratgdo/button/__init__.py new file mode 100644 index 0000000..2989d39 --- /dev/null +++ b/components/ratgdo/button/__init__.py @@ -0,0 +1,36 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome.const import CONF_ID +from esphome.components import button +from .. import ( + ratgdo_ns, + register_ratgdo_child, + RATGDO_CLIENT_SCHMEA +) + +DEPENDENCIES = ["ratgdo"] + +RATGDOButton = ratgdo_ns.class_( + "RATGDOButton", button.Button, cg.Component +) +ButtonType = ratgdo_ns.enum("ButtonType") + +CONF_TYPE = "type" +TYPES = { + "sync": ButtonType.RATGDO_SYNC, +} + + +CONFIG_SCHEMA = button.button_schema(RATGDOButton).extend( + { + cv.Required(CONF_TYPE): cv.enum(TYPES, lower=True), + } +).extend(RATGDO_CLIENT_SCHMEA) + + +async def to_code(config): + var = cg.new_Pvariable(config[CONF_ID]) + await button.register_button(var, config) + await cg.register_component(var, config) + cg.add(var.set_button_type(config[CONF_TYPE])) + await register_ratgdo_child(var, config) diff --git a/components/ratgdo/button/ratgdo_button.cpp b/components/ratgdo/button/ratgdo_button.cpp new file mode 100644 index 0000000..d780e9b --- /dev/null +++ b/components/ratgdo/button/ratgdo_button.cpp @@ -0,0 +1,23 @@ +#include "ratgdo_button.h" +#include "../ratgdo_state.h" +#include "esphome/core/log.h" + +namespace esphome { +namespace ratgdo { + + static const char* const TAG = "ratgdo.button"; + + void RATGDOButton::dump_config() + { + LOG_NUMBER("", "RATGDO Button", this); + ESP_LOGCONFIG(TAG, " Type: Sync"); + } + + void RATGDOButton::control(float value) + { + ESP_LOGD(TAG, "name: %s this->type_:%d", this->get_name(), this->button_type_); + this->parent_->sync(); + } + +} // namespace ratgdo +} // namespace esphome diff --git a/components/ratgdo/button/ratgdo_button.h b/components/ratgdo/button/ratgdo_button.h new file mode 100644 index 0000000..d808076 --- /dev/null +++ b/components/ratgdo/button/ratgdo_button.h @@ -0,0 +1,28 @@ +#pragma once + +#include "../ratgdo.h" +#include "../ratgdo_child.h" +#include "../ratgdo_state.h" +#include "esphome/components/button/button.h" +#include "esphome/core/component.h" + +namespace esphome { +namespace ratgdo { + + enum ButtonType { + RATGDO_SYNC + }; + + class RATGDOButton : public button::Button, public RATGDOClient, public Component { + public: + void dump_config() override; + void set_button_type(ButtonType button_type_) { this->button_type_ = button_type_; } + + void control(float value) override; + + protected: + ButtonType button_type_; + }; + +} // namespace ratgdo +} // namespace esphome