diff --git a/base.yaml b/base.yaml index a864835..05a998b 100644 --- a/base.yaml +++ b/base.yaml @@ -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" \ No newline at end of file + on_press: + then: + lambda: !lambda |- + id($id_prefix).sync(); \ No newline at end of file diff --git a/components/ratgdo/button/__init__.py b/components/ratgdo/button/__init__.py deleted file mode 100644 index e74f93b..0000000 --- a/components/ratgdo/button/__init__.py +++ /dev/null @@ -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) diff --git a/components/ratgdo/button/ratgdo_button.cpp b/components/ratgdo/button/ratgdo_button.cpp deleted file mode 100644 index bec2478..0000000 --- a/components/ratgdo/button/ratgdo_button.cpp +++ /dev/null @@ -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 diff --git a/components/ratgdo/button/ratgdo_button.h b/components/ratgdo/button/ratgdo_button.h deleted file mode 100644 index 4efcb2d..0000000 --- a/components/ratgdo/button/ratgdo_button.h +++ /dev/null @@ -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 diff --git a/components/ratgdo/ratgdo.cpp b/components/ratgdo/ratgdo.cpp index fff3880..173ba8c 100644 --- a/components/ratgdo/ratgdo.cpp +++ b/components/ratgdo/ratgdo.cpp @@ -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 diff --git a/components/ratgdo/ratgdo.h b/components/ratgdo/ratgdo.h index ec05070..e47fd86 100644 --- a/components/ratgdo/ratgdo.h +++ b/components/ratgdo/ratgdo.h @@ -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);