add sync button

This commit is contained in:
J. Nick Koston 2023-06-07 18:44:58 -05:00
parent 8ca0dcf41b
commit 3e9ba56970
No known key found for this signature in database
3 changed files with 87 additions and 0 deletions

View File

@ -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)

View File

@ -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

View File

@ -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