From 11cbfaba7bf75b3f4ff3585c462a4c603c367268 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 7 Jun 2023 11:56:55 -0500 Subject: [PATCH] adj --- components/ratgdo/cover/__init__.py | 24 ++++++++++++ components/ratgdo/cover/ratgdo_cover.cpp | 47 ++++++++++++++++++++++++ components/ratgdo/cover/ratgdo_cover.h | 28 ++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 components/ratgdo/cover/__init__.py create mode 100644 components/ratgdo/cover/ratgdo_cover.cpp create mode 100644 components/ratgdo/cover/ratgdo_cover.h diff --git a/components/ratgdo/cover/__init__.py b/components/ratgdo/cover/__init__.py new file mode 100644 index 0000000..d4d3cc7 --- /dev/null +++ b/components/ratgdo/cover/__init__.py @@ -0,0 +1,24 @@ +import esphome.codegen as cg +from esphome.const import CONF_ID +from esphome.components import cover +from .. import ( + ratgdo_ns, + register_ratgdo_child, + RATGDO_CLIENT_SCHMEA +) + +DEPENDENCIES = ["ratgdo"] + +RATGDOCover = ratgdo_ns.class_( + "RATGDOCover", cover.Cover, cg.Component +) + + +CONFIG_SCHEMA = cover.COVER_SCHEMA.extend(RATGDO_CLIENT_SCHMEA) + + +async def to_code(config): + var = cg.new_Pvariable(config[CONF_ID]) + await cover.register_cover(var, config) + await cg.register_component(var, config) + await register_ratgdo_child(var, config) diff --git a/components/ratgdo/cover/ratgdo_cover.cpp b/components/ratgdo/cover/ratgdo_cover.cpp new file mode 100644 index 0000000..7b36e30 --- /dev/null +++ b/components/ratgdo/cover/ratgdo_cover.cpp @@ -0,0 +1,47 @@ +#include "../ratgdo_state.h" +#include "esphome/core/log.h" +#include "ratgdo_binary_sensor.h" + +namespace esphome { +namespace ratgdo { + + using namespace esphome::cover; + + static const char* const TAG = "ratgdo.cover"; + + void RATGDOCover::dump_config() + { + LOG_COVER("", "RATGDO Cover", this); + } + void RATGDOCover::on_motion_state(esphome::ratgdo::MotionState state) { } + void RATGDOCover::on_obstruction_state(esphome::ratgdo::ObstructionState state) { } + void RATGDOCover::on_door_state(esphome::ratgdo::DoorState state) + { + + if (state == esphome::ratgdo::DoorState::DOOR_STATE_OPEN) + this->position = COVER_OPEN; + this->current_operation = COVER_OPERATION_IDLE; + else if (state == esphome::ratgdo::DoorState::DOOR_STATE_CLOSED) this->position = COVER_CLOSED; + this->current_operation = COVER_OPERATION_IDLE; + else if (state == esphome::ratgdo::DoorState::DOOR_STATE_OPENING) this->current_operation = COVER_OPERATION_OPENING; + else if (state == esphome::ratgdo::DoorState::DOOR_STATE_CLOSING) this->current_operation = COVER_OPERATION_CLOSING; + else if (state == esphome::ratgdo::DoorState::DOOR_STATE_STOPPED) this->current_operation = COVER_OPERATION_IDLE; + else this->current_operation = COVER_OPERATION_IDLE; + + this->publish_state(); + } + void RATGDOCover::on_light_state(esphome::ratgdo::LightState state) { } + void RATGDOCover::on_lock_state(esphome::ratgdo::LockState state) { } + + CoverTraits RATGDOCover::get_traits() + { + auto traits = CoverTraits(); + traits.set_supports_stop(true); + traits.set_supports_position(false); + traits.set_supports_tilt(false); + traits.set_is_assumed_state(false); + return traits; + } + +} // namespace ratgdo +} // namespace esphome diff --git a/components/ratgdo/cover/ratgdo_cover.h b/components/ratgdo/cover/ratgdo_cover.h new file mode 100644 index 0000000..0f8d60c --- /dev/null +++ b/components/ratgdo/cover/ratgdo_cover.h @@ -0,0 +1,28 @@ +#pragma once + +#include "../ratgdo.h" +#include "../ratgdo_child.h" +#include "../ratgdo_state.h" +#include "esphome/components/cover/cover.h" +#include "esphome/core/component.h" + +namespace esphome { +namespace ratgdo { + + class RATGDOCover : public cover::Cover, public RATGDOClient, public Component { + public: + void dump_config() override; + cover::CoverTraits get_traits() override; + + void on_motion_state(esphome::ratgdo::MotionState state) override; + void on_obstruction_state(esphome::ratgdo::ObstructionState state) override; + void on_door_state(esphome::ratgdo::DoorState state) override; + void on_light_state(esphome::ratgdo::LightState state) override; + void on_lock_state(esphome::ratgdo::LockState state) override; + + // protected: + // void control(const cover::CoverCall &call) override; + }; + +} // namespace ratgdo +} // namespace esphome