diff --git a/base.yaml b/base.yaml index 881eb97..73d5959 100644 --- a/base.yaml +++ b/base.yaml @@ -1,10 +1,11 @@ --- - external_components: - source: - type: git - url: https://github.com/ratgdo/esphome-ratgdo - refresh: 1s + type: local + path: components + # type: git + # url: https://github.com/ratgdo/esphome-ratgdo + # refresh: 1s safe_mode: diff --git a/components/ratgdo/output/__init__.py b/components/ratgdo/output/__init__.py new file mode 100644 index 0000000..11ea083 --- /dev/null +++ b/components/ratgdo/output/__init__.py @@ -0,0 +1,33 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome import pins +from esphome.components import output +from esphome.const import CONF_ID, CONF_PIN + +from .. import RATGDO_CLIENT_SCHMEA, ratgdo_ns, register_ratgdo_child + +DEPENDENCIES = ["esp32","ratgdo"] + +RATGDOFloatOutput = ratgdo_ns.class_("RATGDOFloatOutput", output.FloatOutput, cg.Component) +OutputType = ratgdo_ns.enum("OutputType") + +CONF_TYPE = "type" +TYPES = { + "test": OutputType.RATGDO_TEST +} + +CONFIG_SCHEMA = ( + output.FLOAT_OUTPUT_SCHEMA.extend( + { + cv.Required(CONF_ID): cv.declare_id(RATGDOFloatOutput), + cv.Required(CONF_TYPE): cv.enum(TYPES, lower=True), + cv.Required(CONF_PIN): pins.internal_gpio_output_pin_schema, + } + ) + .extend(RATGDO_CLIENT_SCHMEA) +) + +async def to_code(config): + var = cg.new_Pvariable(config[CONF_ID]) + await output.register_output(var, config) + await cg.register_component(var, config) \ No newline at end of file diff --git a/components/ratgdo/output/ratgdo_output.cpp b/components/ratgdo/output/ratgdo_output.cpp new file mode 100644 index 0000000..fc57d58 --- /dev/null +++ b/components/ratgdo/output/ratgdo_output.cpp @@ -0,0 +1,27 @@ +#include "esphome/core/log.h" +#include "ratgdo_output.h" + +namespace esphome { +namespace ratgdo { + +static const char *TAG = "ratgdo.output"; + +void RATGDOFloatOutput::setup(){ + ESP_LOGD("yyy","Output was setup"); + //this->parent_->door_stop(); +} + +void RATGDOFloatOutput::write_state(float state){ + +} + +void RATGDOFloatOutput::dump_config() { + ESP_LOGCONFIG(TAG, "Empty custom float output"); +} + +void RATGDOFloatOutput::set_output_type(OutputType output_type_) { + this->output_type_ = output_type_; +} + +} //namespace ratgdo +} //namespace esphome \ No newline at end of file diff --git a/components/ratgdo/output/ratgdo_output.h b/components/ratgdo/output/ratgdo_output.h new file mode 100644 index 0000000..4328d68 --- /dev/null +++ b/components/ratgdo/output/ratgdo_output.h @@ -0,0 +1,26 @@ +#pragma once + +#include "../ratgdo.h" +#include "esphome/core/component.h" +#include "esphome/components/output/float_output.h" + +namespace esphome { +namespace ratgdo { + + enum OutputType { + RATGDO_TEST + }; + + class RATGDOFloatOutput : public output::FloatOutput, public RATGDOClient, public Component { + public: + void setup() override; + void write_state(float state) override; + void dump_config() override; + void set_output_type(OutputType output_type); + + protected: + OutputType output_type_; + }; + +} //namespace ratgdo +} //namespace esphome \ No newline at end of file diff --git a/components/ratgdo/rtttl/__init__.py b/components/ratgdo/rtttl/__init__.py new file mode 100644 index 0000000..11ea083 --- /dev/null +++ b/components/ratgdo/rtttl/__init__.py @@ -0,0 +1,33 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome import pins +from esphome.components import output +from esphome.const import CONF_ID, CONF_PIN + +from .. import RATGDO_CLIENT_SCHMEA, ratgdo_ns, register_ratgdo_child + +DEPENDENCIES = ["esp32","ratgdo"] + +RATGDOFloatOutput = ratgdo_ns.class_("RATGDOFloatOutput", output.FloatOutput, cg.Component) +OutputType = ratgdo_ns.enum("OutputType") + +CONF_TYPE = "type" +TYPES = { + "test": OutputType.RATGDO_TEST +} + +CONFIG_SCHEMA = ( + output.FLOAT_OUTPUT_SCHEMA.extend( + { + cv.Required(CONF_ID): cv.declare_id(RATGDOFloatOutput), + cv.Required(CONF_TYPE): cv.enum(TYPES, lower=True), + cv.Required(CONF_PIN): pins.internal_gpio_output_pin_schema, + } + ) + .extend(RATGDO_CLIENT_SCHMEA) +) + +async def to_code(config): + var = cg.new_Pvariable(config[CONF_ID]) + await output.register_output(var, config) + await cg.register_component(var, config) \ No newline at end of file diff --git a/components/ratgdo/rtttl/my_rtttl.cpp b/components/ratgdo/rtttl/my_rtttl.cpp new file mode 100644 index 0000000..795344b --- /dev/null +++ b/components/ratgdo/rtttl/my_rtttl.cpp @@ -0,0 +1,27 @@ +#include "esphome/core/log.h" +#include "my_rtttl.h" + +namespace esphome { +namespace ratgdo { + +static const char *TAG = "my_rtttl"; + +void RATGDOFloatOutput::setup(){ + ESP_LOGD("yyy","Output was setup"); + this->parent_->door_stop(); +} + +void RATGDOFloatOutput::write_state(float state){ + +} + +void RATGDOFloatOutput::dump_config() { + ESP_LOGCONFIG(TAG, "Empty custom float output"); +} + +void RATGDOFloatOutput::set_output_type(OutputType output_type_) { + this->output_type_ = output_type_; +} + +} //namespace ratgdo +} //namespace esphome \ No newline at end of file diff --git a/components/ratgdo/rtttl/my_rtttl.h b/components/ratgdo/rtttl/my_rtttl.h new file mode 100644 index 0000000..4328d68 --- /dev/null +++ b/components/ratgdo/rtttl/my_rtttl.h @@ -0,0 +1,26 @@ +#pragma once + +#include "../ratgdo.h" +#include "esphome/core/component.h" +#include "esphome/components/output/float_output.h" + +namespace esphome { +namespace ratgdo { + + enum OutputType { + RATGDO_TEST + }; + + class RATGDOFloatOutput : public output::FloatOutput, public RATGDOClient, public Component { + public: + void setup() override; + void write_state(float state) override; + void dump_config() override; + void set_output_type(OutputType output_type); + + protected: + OutputType output_type_; + }; + +} //namespace ratgdo +} //namespace esphome \ No newline at end of file diff --git a/custom_component_test1.yaml b/custom_component_test1.yaml new file mode 100644 index 0000000..2697b78 --- /dev/null +++ b/custom_component_test1.yaml @@ -0,0 +1,41 @@ +substitutions: + id_prefix: ratgdo32 + friendly_name: "ratgdo" + uart_tx_pin: GPIO22 + uart_rx_pin: GPIO22 + input_obst_pin: GPIO22 + status_door_pin: GPIO22 + status_obstruction_pin: GPIO22 + dry_contact_open_pin: GPIO22 + dry_contact_close_pin: GPIO22 + dry_contact_light_pin: GPIO22 + +esphome: + name: esp32-wroom-test + +esp32: + board: esp32dev + +packages: + remote_package: !include + file: base.yaml + +web_server: + +wifi: + ssid: !secret wifi_ssid + password: !secret wifi_pw + +output: + - platform: ratgdo + ratgdo_id: ${id_prefix} + type: test + pin: GPIO33 + id: ${id_prefix}_output + +rtttl: + - platform: ratgdo + +logger: + +ota: \ No newline at end of file