binary sensor
This commit is contained in:
parent
e75db00096
commit
793408186d
|
@ -12,42 +12,69 @@ RATGDO = ratgdo_ns.class_("RATGDOComponent", cg.Component, uart.UARTDevice)
|
|||
|
||||
|
||||
CONF_OUTPUT_GDO = "output_gdo_pin"
|
||||
DEFAULT_OUTPUT_GDO = 2 # D4 ed control terminal / GarageDoorOpener (UART1 TX) pin is D4 on D1 Mini
|
||||
DEFAULT_OUTPUT_GDO = (
|
||||
2 # D4 ed control terminal / GarageDoorOpener (UART1 TX) pin is D4 on D1 Mini
|
||||
)
|
||||
CONF_INPUT_GDO = "input_gdo_pin"
|
||||
DEFAULT_INPUT_GDO = 4 # D2 red control terminal / GarageDoorOpener (UART1 RX) pin is D2 on D1 Mini
|
||||
DEFAULT_INPUT_GDO = (
|
||||
4 # D2 red control terminal / GarageDoorOpener (UART1 RX) pin is D2 on D1 Mini
|
||||
)
|
||||
CONF_INPUT_OBST = "input_obst_pin"
|
||||
DEFAULT_INPUT_OBST = 13 # D7 black obstruction sensor terminal
|
||||
DEFAULT_INPUT_OBST = 13 # D7 black obstruction sensor terminal
|
||||
|
||||
CONF_TRIGGER_OPEN = "trigger_open_pin"
|
||||
DEFAULT_TRIGGER_OPEN = 14 # D5 dry contact for opening door
|
||||
DEFAULT_TRIGGER_OPEN = 14 # D5 dry contact for opening door
|
||||
CONF_TRIGGER_CLOSE = "trigger_close_pin"
|
||||
DEFAULT_TRIGGER_CLOSE = 12 # D6 dry contact for closing door
|
||||
DEFAULT_TRIGGER_CLOSE = 12 # D6 dry contact for closing door
|
||||
CONF_TRIGGER_LIGHT = "trigger_light_pin"
|
||||
DEFAULT_TRIGGER_LIGHT = 0 # D3 dry contact for triggering light (no discrete light commands, so toggle only)
|
||||
DEFAULT_TRIGGER_LIGHT = 0 # D3 dry contact for triggering light (no discrete light commands, so toggle only)
|
||||
|
||||
CONF_STATUS_DOOR = "status_door_pin"
|
||||
DEFAULT_STATUS_DOOR = 16 # D0 output door status, HIGH for open, LOW for closed
|
||||
DEFAULT_STATUS_DOOR = 16 # D0 output door status, HIGH for open, LOW for closed
|
||||
CONF_STATUS_OBST = "status_obst_pin"
|
||||
DEFAULT_STATUS_OBST = 15 # D8 output for obstruction status, HIGH for obstructed, LOW for clear
|
||||
DEFAULT_STATUS_OBST = (
|
||||
15 # D8 output for obstruction status, HIGH for obstructed, LOW for clear
|
||||
)
|
||||
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(RATGDO),
|
||||
cv.Optional(
|
||||
CONF_OUTPUT_GDO, default=DEFAULT_OUTPUT_GDO
|
||||
): pins.internal_gpio_input_pin_schema,
|
||||
cv.Optional(
|
||||
CONF_INPUT_GDO, default=DEFAULT_INPUT_GDO
|
||||
): pins.internal_gpio_input_pin_schema,
|
||||
cv.Optional(
|
||||
CONF_INPUT_OBST, default=DEFAULT_INPUT_OBST
|
||||
): pins.internal_gpio_input_pin_schema,
|
||||
cv.Optional(
|
||||
CONF_TRIGGER_OPEN, default=DEFAULT_TRIGGER_OPEN
|
||||
): pins.internal_gpio_input_pin_schema,
|
||||
cv.Optional(
|
||||
CONF_TRIGGER_CLOSE, default=DEFAULT_TRIGGER_CLOSE
|
||||
): pins.internal_gpio_input_pin_schema,
|
||||
cv.Optional(
|
||||
CONF_TRIGGER_LIGHT, default=DEFAULT_TRIGGER_LIGHT
|
||||
): pins.internal_gpio_input_pin_schema,
|
||||
cv.Optional(
|
||||
CONF_STATUS_DOOR, default=DEFAULT_STATUS_DOOR
|
||||
): pins.internal_gpio_input_pin_schema,
|
||||
cv.Optional(
|
||||
CONF_STATUS_OBST, default=DEFAULT_STATUS_OBST
|
||||
): pins.internal_gpio_input_pin_schema,
|
||||
}
|
||||
)
|
||||
.extend(cv.COMPONENT_SCHEMA)
|
||||
.extend(uart.UART_DEVICE_SCHEMA)
|
||||
)
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(RATGDO),
|
||||
|
||||
cv.Optional(CONF_OUTPUT_GDO, default=DEFAULT_OUTPUT_GDO): pins.internal_gpio_input_pin_schema,
|
||||
cv.Optional(CONF_INPUT_GDO, default=DEFAULT_INPUT_GDO): pins.internal_gpio_input_pin_schema,
|
||||
cv.Optional(CONF_INPUT_OBST, default=DEFAULT_INPUT_OBST): pins.internal_gpio_input_pin_schema,
|
||||
|
||||
cv.Optional(CONF_TRIGGER_OPEN, default=DEFAULT_TRIGGER_OPEN): pins.internal_gpio_input_pin_schema,
|
||||
cv.Optional(CONF_TRIGGER_CLOSE, default=DEFAULT_TRIGGER_CLOSE): pins.internal_gpio_input_pin_schema,
|
||||
cv.Optional(CONF_TRIGGER_LIGHT, default=DEFAULT_TRIGGER_LIGHT): pins.internal_gpio_input_pin_schema,
|
||||
|
||||
cv.Optional(CONF_STATUS_DOOR, default=DEFAULT_STATUS_DOOR): pins.internal_gpio_input_pin_schema,
|
||||
cv.Optional(CONF_STATUS_OBST, default=DEFAULT_STATUS_OBST): pins.internal_gpio_input_pin_schema,
|
||||
}
|
||||
).extend(cv.COMPONENT_SCHEMA).extend(uart.UART_DEVICE_SCHEMA)
|
||||
async def register_ratgdo_child(var, config):
|
||||
parent = cv.use_id(RATGDO)
|
||||
cg.add(parent.register_child(var))
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import binary_sensor
|
||||
from .. import (
|
||||
ratgdo_ns,
|
||||
register_ratgdo_child,
|
||||
)
|
||||
|
||||
DEPENDENCIES = ["ratgdo"]
|
||||
|
||||
RATGDOBinarySensor = ratgdo_ns.class_(
|
||||
"RATGDOBinarySensor", binary_sensor.BinarySensor, cg.Component
|
||||
)
|
||||
|
||||
TYPES = {"motion", "obstruction"}
|
||||
|
||||
|
||||
CONFIG_SCHEMA = binary_sensor.BINARY_SENSOR_SCHEMA.extend(
|
||||
{cv.Optional(type): binary_sensor.binary_sensor_schema() for type in TYPES}
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
for type in TYPES:
|
||||
if type in config:
|
||||
conf = config[type]
|
||||
var = await binary_sensor.new_binary_sensor(conf)
|
||||
await register_ratgdo_child(var, config)
|
|
@ -0,0 +1,28 @@
|
|||
#include "ratgdo_binary_sensor.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "../ratgdo_state.h"
|
||||
|
||||
#ifdef USE_ESP32
|
||||
|
||||
namespace esphome {
|
||||
namespace ratgdo {
|
||||
|
||||
using namespace esphome::binary_sensor;
|
||||
|
||||
void RATGDOBinarySensor::dump_config() {
|
||||
LOG_BINARY_SENSOR("", "RATGDO BinarySensor", this);
|
||||
}
|
||||
|
||||
void RATGDOBinarySensor::setup() {}
|
||||
void RATGDOBinarySensor::on_door_state(esphome::ratgdo::DoorState state) {}
|
||||
void RATGDOBinarySensor::on_light_state(esphome::ratgdo::LightState state) {}
|
||||
void RATGDOBinarySensor::on_lock_state(esphome::ratgdo::LockState state) {}
|
||||
void RATGDOBinarySensor::on_motion_state(esphome::ratgdo::MotionState state) {}
|
||||
void RATGDOBinarySensor::on_obstruction_state(esphome::ratgdo::ObstructionState state) {}
|
||||
|
||||
void RATGDOBinarySensor::loop() {}
|
||||
|
||||
} // namespace ratgdo
|
||||
} // namespace esphome
|
||||
|
||||
#endif
|
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/defines.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include "../ratgdo_client.h"
|
||||
#include "../ratgdo_state.h"
|
||||
#include "../ratgdo.h"
|
||||
#include "esphome/components/binary_sensor/binary_sensor.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace ratgdo {
|
||||
|
||||
class RATGDOBinarySensor : public binary_sensor::BinarySensor, public RATGDOClient, public Component {
|
||||
public:
|
||||
void setup() override;
|
||||
void loop() override;
|
||||
void update() override;
|
||||
void dump_config() 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;
|
||||
void on_motion_state(esphome::ratgdo::MotionState state) override;
|
||||
void on_obstruction_state(esphome::ratgdo::ObstructionState state) override;
|
||||
|
||||
};
|
||||
|
||||
} // namespace ratgdo
|
||||
} // namespace esphome
|
||||
|
|
@ -21,7 +21,6 @@ namespace ratgdo {
|
|||
|
||||
protected:
|
||||
friend RATGDOComponent;
|
||||
virtual std::string describe() = 0;
|
||||
};
|
||||
|
||||
} // namespace ratgdo
|
||||
|
|
Loading…
Reference in New Issue