This commit is contained in:
J. Nick Koston 2023-06-07 13:27:01 -05:00
parent 711e517c82
commit d4e43f2efa
No known key found for this signature in database
4 changed files with 109 additions and 1 deletions

View File

@ -0,0 +1,35 @@
import esphome.codegen as cg
from esphome.const import CONF_ID
import esphome.config_validation as cv
from esphome.const import (
CONF_DURATION,
CONF_CONSTANT_BRIGHTNESS,
CONF_OUTPUT_ID,
CONF_COLD_WHITE_COLOR_TEMPERATURE,
CONF_WARM_WHITE_COLOR_TEMPERATURE,
CONF_REVERSED,
CONF_MIN_BRIGHTNESS, # New in 2023.5
)
from esphome.components import light
from .. import (
ratgdo_ns,
RATGDO,
register_ratgdo_child,
RATGDO_CLIENT_SCHMEA
)
DEPENDENCIES = ["ratgdo"]
RATGDOLightOutput = ratgdo_ns.class_(
"RATGDOLightOutput", light.LightOutput, cg.Component
)
CONFIG_SCHEMA = light.LIGHT_SCHEMA.extend({cv.GenerateID(CONF_OUTPUT_ID): cv.declare_id(RATGDOLightOutput)}).extend(RATGDO_CLIENT_SCHMEA)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_OUTPUT_ID])
await cg.register_component(var, config)
await light.register_light(var, config)
await register_ratgdo_child(var, config)

View File

@ -0,0 +1,42 @@
#include "../ratgdo_state.h"
#include "esphome/core/log.h"
#include "ratgdo_cover.h"
namespace esphome {
namespace ratgdo {
using namespace esphome::cover;
static const char* const TAG = "ratgdo.light";
void RATGDOLightOutput::dump_config()
{
LOG_CONFIG("", "RATGDO Light");
}
void RATGDOLightOutput::on_motion_state(esphome::ratgdo::MotionState state) { }
void RATGDOLightOutput::on_obstruction_state(esphome::ratgdo::ObstructionState state) { }
void RATGDOLightOutput::on_door_state(esphome::ratgdo::DoorState state) { }
void RATGDOLightOutput::on_light_state(esphome::ratgdo::LightState state) { }
void RATGDOLightOutput::on_lock_state(esphome::ratgdo::LockState state) { }
LightTraits RATGDOLightOutput::get_traits()
{
auto traits = LightTraits();
traits.set_supported_color_modes({ light::ColorMode::ON_OFF });
return traits;
}
LightState* RATGDOLightOutput::get_state() { return this->state_; }
void RATGDOLightOutput::write_state(light::LightState* state)
{
bool binary;
state->current_values_as_binary(&binary);
if (binary) {
this->parent_->turnOnLight();
} else {
this->parent_->turnOffLight();
}
}
} // namespace ratgdo
} // namespace esphome

View File

@ -0,0 +1,31 @@
#pragma once
#include "../ratgdo.h"
#include "../ratgdo_child.h"
#include "../ratgdo_state.h"
#include "esphome/components/light/light_output.h"
#include "esphome/core/component.h"
namespace esphome {
namespace ratgdo {
class RATGDOLightOutput : public light::LightOutput, public RATGDOClient, public Component {
public:
void dump_config() override;
light::LightTraits get_traits() override;
light::LightState* get_state() const;
void setup_state(light::LightState* state) override { this->light_state_ = state; }
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:
bool _is_on;
light::LightState* state_;
};
} // namespace ratgdo
} // namespace esphome

View File

@ -12,11 +12,11 @@
************************************/
#pragma once
#include "SoftwareSerial.h" // Using espsoftwareserial https://github.com/plerup/espsoftwareserial
#include "esphome/core/component.h"
#include "esphome/core/gpio.h"
#include "esphome/core/log.h"
#include "esphome/core/preferences.h"
#include "SoftwareSerial.h" // Using espsoftwareserial https://github.com/plerup/espsoftwareserial
extern "C" {
#include "secplus.h"