Button updates (#14)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Marius Muja 2023-06-24 16:51:19 -07:00 committed by GitHub
parent a24a112c73
commit 49487afde1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 102 deletions

View File

@ -157,15 +157,30 @@ button:
- platform: safe_mode
name: "Safe mode boot"
entity_category: diagnostic
- platform: ratgdo
id: ${id_prefix}_sync
type: sync
- platform: template
id: ${id_prefix}_query_status
entity_category: diagnostic
ratgdo_id: ${id_prefix}
name: "Query status"
on_press:
then:
lambda: !lambda |-
id($id_prefix).query_status();
- platform: template
id: ${id_prefix}_query_openings
name: "Query openings"
entity_category: diagnostic
on_press:
then:
lambda: !lambda |-
id($id_prefix).query_openings();
- platform: template
id: ${id_prefix}_test
name: "Sync"
- platform: ratgdo
id: ${id_prefix}_query
type: query
entity_category: diagnostic
ratgdo_id: ${id_prefix}
name: "Query"
on_press:
then:
lambda: !lambda |-
id($id_prefix).sync();

View File

@ -1,36 +0,0 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import button
from esphome.const import CONF_ID
from .. import RATGDO_CLIENT_SCHMEA, ratgdo_ns, register_ratgdo_child
DEPENDENCIES = ["ratgdo"]
RATGDOButton = ratgdo_ns.class_("RATGDOButton", button.Button, cg.Component)
ButtonType = ratgdo_ns.enum("ButtonType")
CONF_TYPE = "type"
TYPES = {
"sync": ButtonType.RATGDO_SYNC,
"query": ButtonType.RATGDO_QUERY,
}
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

@ -1,26 +0,0 @@
#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_BUTTON("", "RATGDO Button", this);
ESP_LOGCONFIG(TAG, " Type: %s", this->button_type_ == ButtonType::RATGDO_SYNC ? "Sync" : "Query");
}
void RATGDOButton::press_action()
{
if (this->button_type_ == ButtonType::RATGDO_SYNC) {
this->parent_->sync();
} else if (this->button_type_ == ButtonType::RATGDO_QUERY) {
this->parent_->query();
}
}
} // namespace ratgdo
} // namespace esphome

View File

@ -1,29 +0,0 @@
#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,
RATGDO_QUERY
};
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 press_action() override;
protected:
ButtonType button_type_;
};
} // namespace ratgdo
} // namespace esphome

View File

@ -416,12 +416,17 @@ namespace ratgdo {
}
}
void RATGDOComponent::query()
void RATGDOComponent::query_status()
{
this->forceUpdate_ = true;
transmit(command::GET_STATUS);
}
void RATGDOComponent::query_openings()
{
transmit(command::GET_OPENINGS);
}
/************************* DOOR COMMUNICATION *************************/
/*
* Transmit a message to the door opener over uart1

View File

@ -176,7 +176,9 @@ namespace ratgdo {
void toggleLock();
void lock();
void unlock();
void query();
void query_status();
void query_openings();
void printRollingCode();
void getRollingCode(command::cmd command, uint32_t data, bool increment);