This commit is contained in:
J. Nick Koston 2023-06-09 15:54:20 -05:00
parent c1c1a126a2
commit 93d404993b
No known key found for this signature in database
5 changed files with 110 additions and 5 deletions

View File

@ -24,13 +24,20 @@ ratgdo:
switch: switch:
- platform: ratgdo
id: ${id_prefix}_lock_remotes
type: lock
entity_category: config
ratgdo_id: ${id_prefix}
name: "${friendly_name} Lock remotes"
- platform: gpio - platform: gpio
id: "${id_prefix}_status_door" id: "${id_prefix}_status_door"
pin: pin:
number: D0 # D0 output door status, HIGH for open, LOW for closed number: D0 # D0 output door status, HIGH for open, LOW for closed
mode: mode:
output: true output: true
name: "${friendly_name} Status Door" name: "${friendly_name} Status door"
entity_category: diagnostic entity_category: diagnostic
- platform: gpio - platform: gpio
id: "${id_prefix}_status_obstruction" id: "${id_prefix}_status_obstruction"
@ -38,7 +45,7 @@ switch:
number: D8 # D8 output for obstruction status, HIGH for obstructed, LOW for clear number: D8 # D8 output for obstruction status, HIGH for obstructed, LOW for clear
mode: mode:
output: true output: true
name: "${friendly_name} Status Obstruction" name: "${friendly_name} Status obstruction"
entity_category: diagnostic entity_category: diagnostic
binary_sensor: binary_sensor:
@ -116,7 +123,7 @@ number:
type: rolling_code_counter type: rolling_code_counter
entity_category: config entity_category: config
ratgdo_id: ${id_prefix} ratgdo_id: ${id_prefix}
name: "${friendly_name} Rolling Code Counter" name: "${friendly_name} Rolling code counter"
mode: box mode: box
unit_of_measurement: "codes" unit_of_measurement: "codes"
@ -152,7 +159,7 @@ button:
- platform: restart - platform: restart
name: "${friendly_name} Restart" name: "${friendly_name} Restart"
- platform: safe_mode - platform: safe_mode
name: "${friendly_name} Safe Mode Boot" name: "${friendly_name} Safe mode boot"
entity_category: diagnostic entity_category: diagnostic
- platform: ratgdo - platform: ratgdo
id: ${id_prefix}_sync id: ${id_prefix}_sync

View File

@ -436,7 +436,7 @@ namespace ratgdo {
if (this->lightState == LightState::LIGHT_STATE_ON) { if (this->lightState == LightState::LIGHT_STATE_ON) {
ESP_LOGD(TAG, "The light is already on"); ESP_LOGD(TAG, "The light is already on");
return; return;
} }
toggleLight(); toggleLight();
// We don't always get the state back so be optimistic // We don't always get the state back so be optimistic
this->previousLightState = this->lightState; this->previousLightState = this->lightState;

View File

@ -0,0 +1,34 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.const import CONF_ID
from esphome.components import switch
from .. import ratgdo_ns, register_ratgdo_child, RATGDO_CLIENT_SCHMEA
DEPENDENCIES = ["ratgdo"]
RATGDOSwitch = ratgdo_ns.class_("RATGDOSwitch", switch.Switch, cg.Component)
SwitchType = ratgdo_ns.enum("SwitchType")
CONF_TYPE = "type"
TYPES = {
"lock": SwitchType.RATGDO_LOCK,
}
CONFIG_SCHEMA = (
switch.switch_schema(RATGDOSwitch)
.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 switch.register_switch(var, config)
await cg.register_component(var, config)
cg.add(var.set_switch_type(config[CONF_TYPE]))
await register_ratgdo_child(var, config)

View File

@ -0,0 +1,34 @@
#include "ratgdo_switch.h"
#include "../ratgdo_state.h"
#include "esphome/core/log.h"
namespace esphome {
namespace ratgdo {
static const char* const TAG = "ratgdo.switch";
void RATGDOSwitch::dump_config()
{
LOG_NUMBER("", "RATGDO Switch", this);
ESP_LOGCONFIG(TAG, " Type: Lock");
}
void RATGDOSwitch::on_lock_state(LockState state)
{
this->state(state == LockState::LOCK_STATE_LOCKED) this->publish_state();
}
void RATGDOSwitch::turn_on()
{
ESP_LOGD(TAG, "name: %s this->type_:%d ON", this->get_name(), this->switch_type_);
this->parent_->lock(value);
this->publish_state(value);
}
void RATGDOSwitch::turn_off()
{
ESP_LOGD(TAG, "name: %s this->type_:%d OFF", this->get_name(), this->switch_type_);
this->parent_->unlock(value);
this->publish_state(value);
}
} // namespace ratgdo
} // namespace esphome

View File

@ -0,0 +1,30 @@
#pragma once
#include "../ratgdo.h"
#include "../ratgdo_child.h"
#include "../ratgdo_state.h"
#include "esphome/components/switch/switch.h"
#include "esphome/core/component.h"
namespace esphome {
namespace ratgdo {
enum SwitchType {
RATGDO_LOCK
};
class RATGDOSwitch : public switch ::Switch, public RATGDOClient, public Component {
public:
void dump_config() override;
void set_switch_type(SwitchType switch_type_) { this->switch_type_ = switch_type_; }
void on_lock_state(LockState state) override;
void turn_off() override;
void turn_on() override;
protected:
SwitchType switch_type_;
};
} // namespace ratgdo
} // namespace esphome