This commit is contained in:
J. Nick Koston 2023-06-07 11:56:55 -05:00
parent a604b4b6ea
commit 11cbfaba7b
No known key found for this signature in database
3 changed files with 99 additions and 0 deletions

View File

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

View File

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

View File

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