Remove unused sensors
- obstruction - remotes - learning mode
This commit is contained in:
@@ -24,9 +24,6 @@ SensorType = ratgdo_ns.enum("SensorType")
|
||||
|
||||
CONF_TYPE = "type"
|
||||
TYPES = {
|
||||
"motion": SensorType.RATGDO_SENSOR_MOTION,
|
||||
"obstruction": SensorType.RATGDO_SENSOR_OBSTRUCTION,
|
||||
"motor": SensorType.RATGDO_SENSOR_MOTOR,
|
||||
"button": SensorType.RATGDO_SENSOR_BUTTON,
|
||||
"vehicle_detected": SensorType.RATGDO_SENSOR_VEHICLE_DETECTED,
|
||||
"vehicle_arriving": SensorType.RATGDO_SENSOR_VEHICLE_ARRIVING,
|
||||
|
||||
@@ -8,27 +8,10 @@ static const char* const TAG = "ratgdo.binary_sensor";
|
||||
|
||||
void RATGDOBinarySensor::setup()
|
||||
{
|
||||
// Initialize all sensors to false except motor (which doesn't set initial state)
|
||||
if (this->binary_sensor_type_ != SensorType::RATGDO_SENSOR_MOTOR) {
|
||||
this->publish_initial_state(false);
|
||||
}
|
||||
// Initialize all sensors to false
|
||||
this->publish_initial_state(false);
|
||||
|
||||
switch (this->binary_sensor_type_) {
|
||||
case SensorType::RATGDO_SENSOR_MOTION:
|
||||
this->parent_->subscribe_motion_state([this](MotionState state) {
|
||||
this->publish_state(state == MotionState::DETECTED);
|
||||
});
|
||||
break;
|
||||
case SensorType::RATGDO_SENSOR_OBSTRUCTION:
|
||||
this->parent_->subscribe_obstruction_state([this](ObstructionState state) {
|
||||
this->publish_state(state == ObstructionState::OBSTRUCTED);
|
||||
});
|
||||
break;
|
||||
case SensorType::RATGDO_SENSOR_MOTOR:
|
||||
this->parent_->subscribe_motor_state([this](MotorState state) {
|
||||
this->publish_state(state == MotorState::ON);
|
||||
});
|
||||
break;
|
||||
case SensorType::RATGDO_SENSOR_BUTTON:
|
||||
this->parent_->subscribe_button_state([this](ButtonState state) {
|
||||
this->publish_state(state == ButtonState::PRESSED);
|
||||
@@ -61,15 +44,6 @@ void RATGDOBinarySensor::dump_config()
|
||||
{
|
||||
LOG_BINARY_SENSOR("", "RATGDO BinarySensor", this);
|
||||
switch (this->binary_sensor_type_) {
|
||||
case SensorType::RATGDO_SENSOR_MOTION:
|
||||
ESP_LOGCONFIG(TAG, " Type: Motion");
|
||||
break;
|
||||
case SensorType::RATGDO_SENSOR_OBSTRUCTION:
|
||||
ESP_LOGCONFIG(TAG, " Type: Obstruction");
|
||||
break;
|
||||
case SensorType::RATGDO_SENSOR_MOTOR:
|
||||
ESP_LOGCONFIG(TAG, " Type: Motor");
|
||||
break;
|
||||
case SensorType::RATGDO_SENSOR_BUTTON:
|
||||
ESP_LOGCONFIG(TAG, " Type: Button");
|
||||
break;
|
||||
|
||||
@@ -9,10 +9,7 @@
|
||||
namespace esphome::ratgdo {
|
||||
|
||||
enum SensorType : uint8_t {
|
||||
RATGDO_SENSOR_MOTION,
|
||||
RATGDO_SENSOR_OBSTRUCTION,
|
||||
RATGDO_SENSOR_MOTOR,
|
||||
RATGDO_SENSOR_BUTTON,
|
||||
RATGDO_SENSOR_BUTTON = 3,
|
||||
#ifdef RATGDO_USE_VEHICLE_SENSORS
|
||||
RATGDO_SENSOR_VEHICLE_DETECTED,
|
||||
RATGDO_SENSOR_VEHICLE_ARRIVING,
|
||||
|
||||
@@ -64,18 +64,6 @@ namespace protocol {
|
||||
};
|
||||
struct QueryOpenings {
|
||||
};
|
||||
struct ActivateLearn {
|
||||
};
|
||||
struct InactivateLearn {
|
||||
};
|
||||
struct QueryPairedDevices {
|
||||
PairedDevice kind;
|
||||
};
|
||||
struct QueryPairedDevicesAll {
|
||||
};
|
||||
struct ClearPairedDevices {
|
||||
PairedDevice kind;
|
||||
};
|
||||
|
||||
// a poor man's sum-type, because C++
|
||||
SUM_TYPE(Args,
|
||||
@@ -83,12 +71,7 @@ namespace protocol {
|
||||
(GetRollingCodeCounter, get_rolling_code_counter),
|
||||
(SetClientID, set_client_id),
|
||||
(QueryStatus, query_status),
|
||||
(QueryOpenings, query_openings),
|
||||
(ActivateLearn, activate_learn),
|
||||
(InactivateLearn, inactivate_learn),
|
||||
(QueryPairedDevices, query_paired_devices),
|
||||
(QueryPairedDevicesAll, query_paired_devices_all),
|
||||
(ClearPairedDevices, clear_paired_devices), )
|
||||
(QueryOpenings, query_openings), )
|
||||
|
||||
struct RollingCodeCounter {
|
||||
single_observable<uint32_t>* value;
|
||||
|
||||
@@ -70,16 +70,6 @@ void RATGDOComponent::setup()
|
||||
this->input_gdo_pin_->setup();
|
||||
this->input_gdo_pin_->pin_mode(gpio::FLAG_INPUT | gpio::FLAG_PULLUP);
|
||||
|
||||
this->input_obst_pin_->setup();
|
||||
#ifdef USE_ESP32
|
||||
this->input_obst_pin_->pin_mode(gpio::FLAG_INPUT | gpio::FLAG_PULLUP);
|
||||
#else
|
||||
this->input_obst_pin_->pin_mode(gpio::FLAG_INPUT);
|
||||
#endif
|
||||
this->input_obst_pin_->attach_interrupt(RATGDOStore::isr_obstruction,
|
||||
&this->isr_store_,
|
||||
gpio::INTERRUPT_FALLING_EDGE);
|
||||
|
||||
this->protocol_->setup(this, &App.scheduler, this->input_gdo_pin_,
|
||||
this->output_gdo_pin_);
|
||||
|
||||
@@ -128,11 +118,6 @@ void RATGDOComponent::init_protocol()
|
||||
|
||||
void RATGDOComponent::loop()
|
||||
{
|
||||
// obstruction_loop() must run before protocol_->loop() because it uses
|
||||
// App.get_loop_component_start_time() and protocol_->loop() may block
|
||||
// for up to 1.3ms (secplus2 transmit collision wait), which would make
|
||||
// the cached timestamp stale.
|
||||
this->obstruction_loop();
|
||||
this->protocol_->loop();
|
||||
}
|
||||
|
||||
@@ -141,7 +126,6 @@ void RATGDOComponent::dump_config()
|
||||
ESP_LOGCONFIG(TAG, "Setting up RATGDO...");
|
||||
LOG_PIN(" Output GDO Pin: ", this->output_gdo_pin_);
|
||||
LOG_PIN(" Input GDO Pin: ", this->input_gdo_pin_);
|
||||
LOG_PIN(" Input Obstruction Pin: ", this->input_obst_pin_);
|
||||
this->protocol_->dump_config();
|
||||
}
|
||||
|
||||
@@ -234,10 +218,6 @@ void RATGDOComponent::received(const DoorState door_state)
|
||||
this->cancel_position_sync_callbacks();
|
||||
}
|
||||
|
||||
if (door_state == DoorState::OPEN || door_state == DoorState::CLOSED || door_state == DoorState::STOPPED) {
|
||||
this->motor_state = MotorState::OFF;
|
||||
}
|
||||
|
||||
if (door_state == DoorState::CLOSED && door_state != prev_door_state) {
|
||||
this->query_openings();
|
||||
}
|
||||
@@ -246,22 +226,6 @@ void RATGDOComponent::received(const DoorState door_state)
|
||||
this->on_door_state_.trigger(door_state);
|
||||
}
|
||||
|
||||
void RATGDOComponent::received(const LearnState learn_state)
|
||||
{
|
||||
ESP_LOGD(TAG, "Learn state=%s",
|
||||
LOG_STR_ARG(LearnState_to_string(learn_state)));
|
||||
|
||||
if (*this->learn_state == learn_state) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (learn_state == LearnState::INACTIVE) {
|
||||
this->query_paired_devices();
|
||||
}
|
||||
|
||||
this->learn_state = learn_state;
|
||||
}
|
||||
|
||||
void RATGDOComponent::received(const LightState light_state)
|
||||
{
|
||||
ESP_LOGD(TAG, "Light state=%s",
|
||||
@@ -275,26 +239,6 @@ void RATGDOComponent::received(const LockState lock_state)
|
||||
this->lock_state = lock_state;
|
||||
}
|
||||
|
||||
void RATGDOComponent::received(const ObstructionState obstruction_state)
|
||||
{
|
||||
if (!this->flags_.obstruction_sensor_detected) {
|
||||
ESP_LOGD(TAG, "Obstruction: state=%s",
|
||||
LOG_STR_ARG(ObstructionState_to_string(*this->obstruction_state)));
|
||||
|
||||
this->obstruction_state = obstruction_state;
|
||||
// This isn't very fast to update, but its still better
|
||||
// than nothing in the case the obstruction sensor is not
|
||||
// wired up.
|
||||
}
|
||||
}
|
||||
|
||||
void RATGDOComponent::received(const MotorState motor_state)
|
||||
{
|
||||
ESP_LOGD(TAG, "Motor: state=%s",
|
||||
LOG_STR_ARG(MotorState_to_string(*this->motor_state)));
|
||||
this->motor_state = motor_state;
|
||||
}
|
||||
|
||||
void RATGDOComponent::received(const ButtonState button_state)
|
||||
{
|
||||
ESP_LOGD(TAG, "Button state=%s",
|
||||
@@ -302,20 +246,6 @@ void RATGDOComponent::received(const ButtonState button_state)
|
||||
this->button_state = button_state;
|
||||
}
|
||||
|
||||
void RATGDOComponent::received(const MotionState motion_state)
|
||||
{
|
||||
ESP_LOGD(TAG, "Motion: %s",
|
||||
LOG_STR_ARG(MotionState_to_string(*this->motion_state)));
|
||||
this->motion_state = motion_state;
|
||||
if (motion_state == MotionState::DETECTED) {
|
||||
this->set_timeout(TIMEOUT_CLEAR_MOTION, 3000,
|
||||
[this] { this->motion_state = MotionState::CLEAR; });
|
||||
if (*this->light_state == LightState::OFF) {
|
||||
this->query_status();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RATGDOComponent::received(const LightAction light_action)
|
||||
{
|
||||
ESP_LOGD(TAG, "Light cmd=%s state=%s",
|
||||
@@ -340,24 +270,6 @@ void RATGDOComponent::received(const Openings openings)
|
||||
}
|
||||
}
|
||||
|
||||
void RATGDOComponent::received(const PairedDeviceCount pdc)
|
||||
{
|
||||
ESP_LOGD(TAG, "Paired device count, kind=%s count=%d",
|
||||
LOG_STR_ARG(PairedDevice_to_string(pdc.kind)), pdc.count);
|
||||
|
||||
if (pdc.kind == PairedDevice::ALL) {
|
||||
this->paired_total = pdc.count;
|
||||
} else if (pdc.kind == PairedDevice::REMOTE) {
|
||||
this->paired_remotes = pdc.count;
|
||||
} else if (pdc.kind == PairedDevice::KEYPAD) {
|
||||
this->paired_keypads = pdc.count;
|
||||
} else if (pdc.kind == PairedDevice::WALL_CONTROL) {
|
||||
this->paired_wall_controls = pdc.count;
|
||||
} else if (pdc.kind == PairedDevice::ACCESSORY) {
|
||||
this->paired_accessories = pdc.count;
|
||||
}
|
||||
}
|
||||
|
||||
void RATGDOComponent::received(const TimeToClose ttc)
|
||||
{
|
||||
ESP_LOGD(TAG, "Time to close (TTC): %ds", ttc.seconds);
|
||||
@@ -501,57 +413,6 @@ Result RATGDOComponent::call_protocol(Args args)
|
||||
return this->protocol_->call(args);
|
||||
}
|
||||
|
||||
/*************************** OBSTRUCTION DETECTION ***************************/
|
||||
|
||||
void RATGDOComponent::obstruction_loop()
|
||||
{
|
||||
// Safe to use cached loop timestamp here because obstruction_loop()
|
||||
// runs before protocol_->loop() which contains the 1.3ms blocking
|
||||
// transmit in secplus2. The 50ms CHECK_PERIOD has ample margin.
|
||||
const uint32_t current_millis = App.get_loop_component_start_time();
|
||||
static uint32_t last_millis = 0;
|
||||
static uint32_t last_asleep = 0;
|
||||
|
||||
// the obstruction sensor has 3 states: clear (HIGH with LOW pulse every 7ms),
|
||||
// obstructed (HIGH), asleep (LOW) the transitions between awake and asleep
|
||||
// are tricky because the voltage drops slowly when falling asleep and is high
|
||||
// without pulses when waking up
|
||||
|
||||
// If at least 3 low pulses are counted within 50ms, the door is awake, not
|
||||
// obstructed and we don't have to check anything else
|
||||
|
||||
constexpr uint32_t CHECK_PERIOD = 50;
|
||||
constexpr uint32_t PULSES_LOWER_LIMIT = 3;
|
||||
|
||||
if (current_millis - last_millis > CHECK_PERIOD) {
|
||||
// ESP_LOGD(TAG, "%ld: Obstruction count: %d, expected: %d, since asleep:
|
||||
// %ld",
|
||||
// current_millis, this->isr_store_.obstruction_low_count,
|
||||
// PULSES_LOWER_LIMIT, current_millis - last_asleep
|
||||
// );
|
||||
|
||||
// check to see if we got more then PULSES_LOWER_LIMIT pulses
|
||||
if (this->isr_store_.obstruction_low_count > PULSES_LOWER_LIMIT) {
|
||||
this->obstruction_state = ObstructionState::CLEAR;
|
||||
this->flags_.obstruction_sensor_detected = true;
|
||||
} else if (this->isr_store_.obstruction_low_count == 0) {
|
||||
// if there have been no pulses the line is steady high or low
|
||||
if (this->input_obst_pin_->digital_read() != this->flags_.obst_sleep_low) {
|
||||
// asleep
|
||||
last_asleep = current_millis;
|
||||
} else {
|
||||
// if the line is high and was last asleep more than 700ms ago, then
|
||||
// there is an obstruction present
|
||||
if (current_millis - last_asleep > 700) {
|
||||
this->obstruction_state = ObstructionState::OBSTRUCTED;
|
||||
}
|
||||
}
|
||||
}
|
||||
last_millis = current_millis;
|
||||
this->isr_store_.obstruction_low_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void RATGDOComponent::query_status() { this->protocol_->call(QueryStatus { }); }
|
||||
|
||||
void RATGDOComponent::query_openings()
|
||||
@@ -559,21 +420,6 @@ void RATGDOComponent::query_openings()
|
||||
this->protocol_->call(QueryOpenings { });
|
||||
}
|
||||
|
||||
void RATGDOComponent::query_paired_devices()
|
||||
{
|
||||
this->protocol_->call(QueryPairedDevicesAll { });
|
||||
}
|
||||
|
||||
void RATGDOComponent::query_paired_devices(PairedDevice kind)
|
||||
{
|
||||
this->protocol_->call(QueryPairedDevices { kind });
|
||||
}
|
||||
|
||||
void RATGDOComponent::clear_paired_devices(PairedDevice kind)
|
||||
{
|
||||
this->protocol_->call(ClearPairedDevices { kind });
|
||||
}
|
||||
|
||||
void RATGDOComponent::sync()
|
||||
{
|
||||
this->protocol_->sync();
|
||||
@@ -780,17 +626,6 @@ void RATGDOComponent::lock_toggle()
|
||||
this->protocol_->lock_action(LockAction::TOGGLE);
|
||||
}
|
||||
|
||||
// Learn functions
|
||||
void RATGDOComponent::activate_learn()
|
||||
{
|
||||
this->protocol_->call(ActivateLearn { });
|
||||
}
|
||||
|
||||
void RATGDOComponent::inactivate_learn()
|
||||
{
|
||||
this->protocol_->call(InactivateLearn { });
|
||||
}
|
||||
|
||||
// Subscribe implementations are now templates in ratgdo.h
|
||||
|
||||
// dry contact methods
|
||||
|
||||
@@ -61,7 +61,6 @@ typedef Parented<RATGDOComponent> RATGDOClient;
|
||||
|
||||
const float DOOR_POSITION_UNKNOWN = -1.0;
|
||||
const float DOOR_DELTA_UNKNOWN = -2.0;
|
||||
const uint8_t PAIRED_DEVICES_UNKNOWN = 0xFF;
|
||||
|
||||
struct RATGDOStore {
|
||||
volatile uint32_t obstruction_low_count = 0; // count obstruction low pulses
|
||||
@@ -88,8 +87,6 @@ public:
|
||||
|
||||
void init_protocol();
|
||||
|
||||
void obstruction_loop();
|
||||
|
||||
float start_opening { -1 };
|
||||
single_observable<float> opening_duration { 0 };
|
||||
float start_closing { -1 };
|
||||
@@ -105,11 +102,6 @@ public:
|
||||
#endif
|
||||
|
||||
single_observable<uint16_t> openings { 0 }; // number of times the door has been opened
|
||||
single_observable<uint8_t> paired_total { PAIRED_DEVICES_UNKNOWN };
|
||||
single_observable<uint8_t> paired_remotes { PAIRED_DEVICES_UNKNOWN };
|
||||
single_observable<uint8_t> paired_keypads { PAIRED_DEVICES_UNKNOWN };
|
||||
single_observable<uint8_t> paired_wall_controls { PAIRED_DEVICES_UNKNOWN };
|
||||
single_observable<uint8_t> paired_accessories { PAIRED_DEVICES_UNKNOWN };
|
||||
|
||||
observable<DoorState, RATGDO_MAX_DOOR_STATE_SUBSCRIBERS> door_state { DoorState::UNKNOWN };
|
||||
observable<float, RATGDO_MAX_DOOR_STATE_SUBSCRIBERS> door_position { DOOR_POSITION_UNKNOWN };
|
||||
@@ -122,11 +114,7 @@ public:
|
||||
|
||||
single_observable<LightState> light_state { LightState::UNKNOWN };
|
||||
single_observable<LockState> lock_state { LockState::UNKNOWN };
|
||||
single_observable<ObstructionState> obstruction_state { ObstructionState::UNKNOWN };
|
||||
single_observable<MotorState> motor_state { MotorState::UNKNOWN };
|
||||
single_observable<ButtonState> button_state { ButtonState::UNKNOWN };
|
||||
single_observable<MotionState> motion_state { MotionState::UNKNOWN };
|
||||
single_observable<LearnState> learn_state { LearnState::UNKNOWN };
|
||||
#ifdef RATGDO_USE_VEHICLE_SENSORS
|
||||
observable<VehicleDetectedState, RATGDO_MAX_VEHICLE_DETECTED_SUBSCRIBERS> vehicle_detected_state { VehicleDetectedState::NO };
|
||||
observable<VehicleArrivingState, RATGDO_MAX_VEHICLE_ARRIVING_SUBSCRIBERS> vehicle_arriving_state { VehicleArrivingState::NO };
|
||||
@@ -153,15 +141,10 @@ public:
|
||||
void received(const DoorState door_state);
|
||||
void received(const LightState light_state);
|
||||
void received(const LockState lock_state);
|
||||
void received(const ObstructionState obstruction_state);
|
||||
void received(const LightAction light_action);
|
||||
void received(const MotorState motor_state);
|
||||
void received(const ButtonState button_state);
|
||||
void received(const MotionState motion_state);
|
||||
void received(const LearnState light_state);
|
||||
void received(const Openings openings);
|
||||
void received(const TimeToClose ttc);
|
||||
void received(const PairedDeviceCount pdc);
|
||||
void received(const BatteryState pdc);
|
||||
|
||||
// door
|
||||
@@ -202,37 +185,6 @@ public:
|
||||
void lock();
|
||||
void unlock();
|
||||
|
||||
// Learn & Paired
|
||||
void activate_learn();
|
||||
void inactivate_learn();
|
||||
void query_paired_devices();
|
||||
void query_paired_devices(PairedDevice kind);
|
||||
void clear_paired_devices(PairedDevice kind);
|
||||
|
||||
// Uses length + first character instead of string comparisons to avoid
|
||||
// string literals in RODATA which consume RAM on ESP8266.
|
||||
// Valid values: "all" (3,a), "remote" (6,r), "keypad" (6,k), "wall" (4,w), "accessory" (9,a)
|
||||
// Template so it works with std::string, StringRef, or any type with length() and operator[].
|
||||
template <typename StringT>
|
||||
void clear_paired_devices(const StringT& kind)
|
||||
{
|
||||
PairedDevice device;
|
||||
if (kind.length() == 3 && kind[0] == 'a') {
|
||||
device = PairedDevice::ALL;
|
||||
} else if (kind.length() == 6 && kind[0] == 'r') {
|
||||
device = PairedDevice::REMOTE;
|
||||
} else if (kind.length() == 6 && kind[0] == 'k') {
|
||||
device = PairedDevice::KEYPAD;
|
||||
} else if (kind.length() == 4 && kind[0] == 'w') {
|
||||
device = PairedDevice::WALL_CONTROL;
|
||||
} else if (kind.length() == 9 && kind[0] == 'a') {
|
||||
device = PairedDevice::ACCESSORY;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
this->clear_paired_devices(device);
|
||||
}
|
||||
|
||||
// button functionality
|
||||
void query_status();
|
||||
void query_openings();
|
||||
@@ -296,34 +248,16 @@ public:
|
||||
template <typename F>
|
||||
void subscribe_openings(F&& f);
|
||||
template <typename F>
|
||||
void subscribe_paired_devices_total(F&& f);
|
||||
template <typename F>
|
||||
void subscribe_paired_remotes(F&& f);
|
||||
template <typename F>
|
||||
void subscribe_paired_keypads(F&& f);
|
||||
template <typename F>
|
||||
void subscribe_paired_wall_controls(F&& f);
|
||||
template <typename F>
|
||||
void subscribe_paired_accessories(F&& f);
|
||||
template <typename F>
|
||||
void subscribe_door_state(F&& f);
|
||||
template <typename F>
|
||||
void subscribe_light_state(F&& f);
|
||||
template <typename F>
|
||||
void subscribe_lock_state(F&& f);
|
||||
template <typename F>
|
||||
void subscribe_obstruction_state(F&& f);
|
||||
template <typename F>
|
||||
void subscribe_motor_state(F&& f);
|
||||
template <typename F>
|
||||
void subscribe_button_state(F&& f);
|
||||
template <typename F>
|
||||
void subscribe_motion_state(F&& f);
|
||||
template <typename F>
|
||||
void subscribe_sync_failed(F&& f);
|
||||
template <typename F>
|
||||
void subscribe_learn_state(F&& f);
|
||||
template <typename F>
|
||||
void subscribe_door_action_delayed(F&& f);
|
||||
#ifdef RATGDO_USE_DISTANCE_SENSOR
|
||||
template <typename F>
|
||||
@@ -432,24 +366,14 @@ namespace scheduler_ids {
|
||||
DEFER_CLOSING_DURATION,
|
||||
DEFER_CLOSING_DELAY,
|
||||
DEFER_OPENINGS,
|
||||
DEFER_PAIRED_TOTAL,
|
||||
DEFER_PAIRED_REMOTES,
|
||||
DEFER_PAIRED_KEYPADS,
|
||||
DEFER_PAIRED_WALL_CONTROLS,
|
||||
DEFER_PAIRED_ACCESSORIES,
|
||||
DEFER_LIGHT_STATE,
|
||||
DEFER_LOCK_STATE,
|
||||
DEFER_OBSTRUCTION_STATE,
|
||||
DEFER_MOTOR_STATE,
|
||||
DEFER_BUTTON_STATE,
|
||||
DEFER_MOTION_STATE,
|
||||
DEFER_LEARN_STATE,
|
||||
|
||||
// Named timeout IDs (replacing string-based names)
|
||||
TIMEOUT_DOOR_QUERY_STATE,
|
||||
TIMEOUT_DOOR_ACTION,
|
||||
TIMEOUT_MOVE_TO_POSITION,
|
||||
TIMEOUT_CLEAR_MOTION,
|
||||
// Shared by RATGDOComponent and Secplus1 — safe because only one
|
||||
// protocol is compiled at a time (#ifdef PROTOCOL_SECPLUSV1) and
|
||||
// both use ratgdo_ as the scheduler owner.
|
||||
@@ -513,46 +437,6 @@ void RATGDOComponent::subscribe_openings(F&& f)
|
||||
});
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
void RATGDOComponent::subscribe_paired_devices_total(F&& f)
|
||||
{
|
||||
this->paired_total.subscribe([this, f](uint8_t state) {
|
||||
defer(scheduler_ids::DEFER_PAIRED_TOTAL, [f, state] { f(state); });
|
||||
});
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
void RATGDOComponent::subscribe_paired_remotes(F&& f)
|
||||
{
|
||||
this->paired_remotes.subscribe([this, f](uint8_t state) {
|
||||
defer(scheduler_ids::DEFER_PAIRED_REMOTES, [f, state] { f(state); });
|
||||
});
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
void RATGDOComponent::subscribe_paired_keypads(F&& f)
|
||||
{
|
||||
this->paired_keypads.subscribe([this, f](uint8_t state) {
|
||||
defer(scheduler_ids::DEFER_PAIRED_KEYPADS, [f, state] { f(state); });
|
||||
});
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
void RATGDOComponent::subscribe_paired_wall_controls(F&& f)
|
||||
{
|
||||
this->paired_wall_controls.subscribe([this, f](uint8_t state) {
|
||||
defer(scheduler_ids::DEFER_PAIRED_WALL_CONTROLS, [f, state] { f(state); });
|
||||
});
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
void RATGDOComponent::subscribe_paired_accessories(F&& f)
|
||||
{
|
||||
this->paired_accessories.subscribe([this, f](uint8_t state) {
|
||||
defer(scheduler_ids::DEFER_PAIRED_ACCESSORIES, [f, state] { f(state); });
|
||||
});
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
void RATGDOComponent::subscribe_door_state(F&& f)
|
||||
{
|
||||
@@ -582,22 +466,6 @@ void RATGDOComponent::subscribe_lock_state(F&& f)
|
||||
});
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
void RATGDOComponent::subscribe_obstruction_state(F&& f)
|
||||
{
|
||||
this->obstruction_state.subscribe([this, f](ObstructionState state) {
|
||||
defer(scheduler_ids::DEFER_OBSTRUCTION_STATE, [f, state] { f(state); });
|
||||
});
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
void RATGDOComponent::subscribe_motor_state(F&& f)
|
||||
{
|
||||
this->motor_state.subscribe([this, f](MotorState state) {
|
||||
defer(scheduler_ids::DEFER_MOTOR_STATE, [f, state] { f(state); });
|
||||
});
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
void RATGDOComponent::subscribe_button_state(F&& f)
|
||||
{
|
||||
@@ -606,28 +474,12 @@ void RATGDOComponent::subscribe_button_state(F&& f)
|
||||
});
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
void RATGDOComponent::subscribe_motion_state(F&& f)
|
||||
{
|
||||
this->motion_state.subscribe([this, f](MotionState state) {
|
||||
defer(scheduler_ids::DEFER_MOTION_STATE, [f, state] { f(state); });
|
||||
});
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
void RATGDOComponent::subscribe_sync_failed(F&& f)
|
||||
{
|
||||
this->sync_failed.subscribe(std::forward<F>(f));
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
void RATGDOComponent::subscribe_learn_state(F&& f)
|
||||
{
|
||||
this->learn_state.subscribe([this, f](LearnState state) {
|
||||
defer(scheduler_ids::DEFER_LEARN_STATE, [f, state] { f(state); });
|
||||
});
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
void RATGDOComponent::subscribe_door_action_delayed(F&& f)
|
||||
{
|
||||
|
||||
@@ -30,18 +30,4 @@ LockState lock_state_toggle(LockState state)
|
||||
}
|
||||
}
|
||||
|
||||
LearnState learn_state_toggle(LearnState state)
|
||||
{
|
||||
switch (state) {
|
||||
case LearnState::ACTIVE:
|
||||
return LearnState::INACTIVE;
|
||||
case LearnState::INACTIVE:
|
||||
return LearnState::ACTIVE;
|
||||
// 2 and 3 appears sometimes
|
||||
case LearnState::UNKNOWN:
|
||||
default:
|
||||
return LearnState::UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace esphome::ratgdo
|
||||
|
||||
@@ -44,24 +44,6 @@ ENUM(LockState, uint8_t,
|
||||
(UNKNOWN, 2))
|
||||
LockState lock_state_toggle(LockState state);
|
||||
|
||||
/// MotionState for all states a the motion can be in.
|
||||
ENUM(MotionState, uint8_t,
|
||||
(CLEAR, 0),
|
||||
(DETECTED, 1),
|
||||
(UNKNOWN, 2))
|
||||
|
||||
/// Enum for all states a the obstruction can be in.
|
||||
ENUM(ObstructionState, uint8_t,
|
||||
(OBSTRUCTED, 0),
|
||||
(CLEAR, 1),
|
||||
(UNKNOWN, 2))
|
||||
|
||||
/// Enum for all states a the motor can be in.
|
||||
ENUM(MotorState, uint8_t,
|
||||
(OFF, 0),
|
||||
(ON, 1),
|
||||
(UNKNOWN, 2))
|
||||
|
||||
/// Enum for all states the button can be in.
|
||||
ENUM(ButtonState, uint8_t,
|
||||
(PRESSED, 0),
|
||||
@@ -73,21 +55,6 @@ ENUM_SPARSE(BatteryState, uint8_t,
|
||||
(CHARGING, 0x6),
|
||||
(FULL, 0x8))
|
||||
|
||||
/// Enum for learn states.
|
||||
ENUM(LearnState, uint8_t,
|
||||
(INACTIVE, 0),
|
||||
(ACTIVE, 1),
|
||||
(UNKNOWN, 2))
|
||||
LearnState learn_state_toggle(LearnState state);
|
||||
|
||||
ENUM(PairedDevice, uint8_t,
|
||||
(ALL, 0),
|
||||
(REMOTE, 1),
|
||||
(KEYPAD, 2),
|
||||
(WALL_CONTROL, 3),
|
||||
(ACCESSORY, 4),
|
||||
(UNKNOWN, 0xff))
|
||||
|
||||
// actions
|
||||
ENUM(LightAction, uint8_t,
|
||||
(OFF, 0),
|
||||
@@ -127,11 +94,6 @@ struct Openings {
|
||||
uint8_t flag;
|
||||
};
|
||||
|
||||
struct PairedDeviceCount {
|
||||
PairedDevice kind;
|
||||
uint8_t count;
|
||||
};
|
||||
|
||||
struct TimeToClose {
|
||||
uint16_t seconds;
|
||||
};
|
||||
|
||||
@@ -81,26 +81,6 @@ namespace secplus2 {
|
||||
this->query_openings();
|
||||
synced = false;
|
||||
}
|
||||
if (*this->ratgdo_->paired_total == PAIRED_DEVICES_UNKNOWN) {
|
||||
this->query_paired_devices(PairedDevice::ALL);
|
||||
synced = false;
|
||||
}
|
||||
if (*this->ratgdo_->paired_remotes == PAIRED_DEVICES_UNKNOWN) {
|
||||
this->query_paired_devices(PairedDevice::REMOTE);
|
||||
synced = false;
|
||||
}
|
||||
if (*this->ratgdo_->paired_keypads == PAIRED_DEVICES_UNKNOWN) {
|
||||
this->query_paired_devices(PairedDevice::KEYPAD);
|
||||
synced = false;
|
||||
}
|
||||
if (*this->ratgdo_->paired_wall_controls == PAIRED_DEVICES_UNKNOWN) {
|
||||
this->query_paired_devices(PairedDevice::WALL_CONTROL);
|
||||
synced = false;
|
||||
}
|
||||
if (*this->ratgdo_->paired_accessories == PAIRED_DEVICES_UNKNOWN) {
|
||||
this->query_paired_devices(PairedDevice::ACCESSORY);
|
||||
synced = false;
|
||||
}
|
||||
|
||||
if (synced) {
|
||||
return;
|
||||
@@ -168,16 +148,6 @@ namespace secplus2 {
|
||||
this->set_rolling_code_counter(args.value.set_rolling_code_counter.counter);
|
||||
} else if (args.tag == Tag::set_client_id) {
|
||||
this->set_client_id(args.value.set_client_id.client_id);
|
||||
} else if (args.tag == Tag::query_paired_devices) {
|
||||
this->query_paired_devices(args.value.query_paired_devices.kind);
|
||||
} else if (args.tag == Tag::query_paired_devices_all) {
|
||||
this->query_paired_devices();
|
||||
} else if (args.tag == Tag::clear_paired_devices) {
|
||||
this->clear_paired_devices(args.value.clear_paired_devices.kind);
|
||||
} else if (args.tag == Tag::activate_learn) {
|
||||
this->activate_learn();
|
||||
} else if (args.tag == Tag::inactivate_learn) {
|
||||
this->inactivate_learn();
|
||||
}
|
||||
return { };
|
||||
}
|
||||
@@ -201,67 +171,6 @@ namespace secplus2 {
|
||||
this->send_command(CommandType::GET_OPENINGS);
|
||||
}
|
||||
|
||||
void Secplus2::query_paired_devices()
|
||||
{
|
||||
const auto kinds = {
|
||||
PairedDevice::ALL,
|
||||
PairedDevice::REMOTE,
|
||||
PairedDevice::KEYPAD,
|
||||
PairedDevice::WALL_CONTROL,
|
||||
PairedDevice::ACCESSORY
|
||||
};
|
||||
uint32_t timeout = 0;
|
||||
for (auto kind : kinds) {
|
||||
timeout += 200;
|
||||
this->ratgdo_->set_timeout(timeout, [this, kind] { this->query_paired_devices(kind); });
|
||||
}
|
||||
}
|
||||
|
||||
void Secplus2::query_paired_devices(PairedDevice kind)
|
||||
{
|
||||
ESP_LOGD(TAG, "Query paired devices of type: %s", LOG_STR_ARG(PairedDevice_to_string(kind)));
|
||||
this->send_command(Command { CommandType::GET_PAIRED_DEVICES, static_cast<uint8_t>(kind) });
|
||||
}
|
||||
|
||||
// wipe devices from memory based on get paired devices nibble values
|
||||
void Secplus2::clear_paired_devices(PairedDevice kind)
|
||||
{
|
||||
if (kind == PairedDevice::UNKNOWN) {
|
||||
return;
|
||||
}
|
||||
ESP_LOGW(TAG, "Clear paired devices of type: %s", LOG_STR_ARG(PairedDevice_to_string(kind)));
|
||||
if (kind == PairedDevice::ALL) {
|
||||
this->ratgdo_->set_timeout(200, [this] { this->send_command(Command { CommandType::CLEAR_PAIRED_DEVICES, static_cast<uint8_t>(PairedDevice::REMOTE) - 1 }); }); // wireless
|
||||
this->ratgdo_->set_timeout(400, [this] { this->send_command(Command { CommandType::CLEAR_PAIRED_DEVICES, static_cast<uint8_t>(PairedDevice::KEYPAD) - 1 }); }); // keypads
|
||||
this->ratgdo_->set_timeout(600, [this] { this->send_command(Command { CommandType::CLEAR_PAIRED_DEVICES, static_cast<uint8_t>(PairedDevice::WALL_CONTROL) - 1 }); }); // wall controls
|
||||
this->ratgdo_->set_timeout(800, [this] { this->send_command(Command { CommandType::CLEAR_PAIRED_DEVICES, static_cast<uint8_t>(PairedDevice::ACCESSORY) - 1 }); }); // accessories
|
||||
this->ratgdo_->set_timeout(1000, [this] { this->query_status(); });
|
||||
this->ratgdo_->set_timeout(1200, [this] { this->query_paired_devices(); });
|
||||
} else {
|
||||
uint8_t dev_kind = static_cast<uint8_t>(kind) - 1;
|
||||
this->send_command(Command { CommandType::CLEAR_PAIRED_DEVICES, dev_kind }); // just requested device
|
||||
this->ratgdo_->set_timeout(200, [this] { this->query_status(); });
|
||||
this->ratgdo_->set_timeout(400, [this, kind] { this->query_paired_devices(kind); });
|
||||
}
|
||||
}
|
||||
|
||||
// Learn functions
|
||||
void Secplus2::activate_learn()
|
||||
{
|
||||
// Send LEARN with nibble = 0 then nibble = 1 to mimic wall control learn button
|
||||
this->send_command(Command { CommandType::LEARN, 0 });
|
||||
this->ratgdo_->set_timeout(150, [this] { this->send_command(Command { CommandType::LEARN, 1 }); });
|
||||
this->ratgdo_->set_timeout(500, [this] { this->query_status(); });
|
||||
}
|
||||
|
||||
void Secplus2::inactivate_learn()
|
||||
{
|
||||
// Send LEARN twice with nibble = 0 to inactivate learn and get status to update switch state
|
||||
this->send_command(Command { CommandType::LEARN, 0 });
|
||||
this->ratgdo_->set_timeout(150, [this] { this->send_command(Command { CommandType::LEARN, 0 }); });
|
||||
this->ratgdo_->set_timeout(500, [this] { this->query_status(); });
|
||||
}
|
||||
|
||||
optional<Command> Secplus2::read_command()
|
||||
{
|
||||
if (!this->flags_.rx_reading_msg) {
|
||||
@@ -370,37 +279,15 @@ namespace secplus2 {
|
||||
this->ratgdo_->received(to_DoorState(cmd.nibble, DoorState::UNKNOWN));
|
||||
this->ratgdo_->received(to_LightState((cmd.byte2 >> 1) & 1, LightState::UNKNOWN));
|
||||
this->ratgdo_->received(to_LockState((cmd.byte2 & 1), LockState::UNKNOWN));
|
||||
// ESP_LOGD(TAG, "Obstruction: reading from byte2, bit2, status=%d", ((byte2 >> 2) & 1) == 1);
|
||||
this->ratgdo_->received(to_ObstructionState((cmd.byte1 >> 6) & 1, ObstructionState::UNKNOWN));
|
||||
this->ratgdo_->received(to_LearnState((cmd.byte2 >> 5) & 1, LearnState::UNKNOWN));
|
||||
} else if (cmd.type == CommandType::LIGHT) {
|
||||
this->ratgdo_->received(to_LightAction(cmd.nibble, LightAction::UNKNOWN));
|
||||
} else if (cmd.type == CommandType::MOTOR_ON) {
|
||||
this->ratgdo_->received(MotorState::ON);
|
||||
} else if (cmd.type == CommandType::DOOR_ACTION) {
|
||||
auto button_state = (cmd.byte1 & 1) == 1 ? ButtonState::PRESSED : ButtonState::RELEASED;
|
||||
this->ratgdo_->received(button_state);
|
||||
} else if (cmd.type == CommandType::MOTION) {
|
||||
this->ratgdo_->received(MotionState::DETECTED);
|
||||
} else if (cmd.type == CommandType::OPENINGS) {
|
||||
this->ratgdo_->received(Openings { static_cast<uint16_t>((cmd.byte1 << 8) | cmd.byte2), cmd.nibble });
|
||||
} else if (cmd.type == CommandType::SET_TTC) {
|
||||
this->ratgdo_->received(TimeToClose { static_cast<uint16_t>((cmd.byte1 << 8) | cmd.byte2) });
|
||||
} else if (cmd.type == CommandType::PAIRED_DEVICES) {
|
||||
PairedDeviceCount pdc;
|
||||
pdc.kind = to_PairedDevice(cmd.nibble, PairedDevice::UNKNOWN);
|
||||
if (pdc.kind == PairedDevice::ALL) {
|
||||
pdc.count = cmd.byte2;
|
||||
} else if (pdc.kind == PairedDevice::REMOTE) {
|
||||
pdc.count = cmd.byte2;
|
||||
} else if (pdc.kind == PairedDevice::KEYPAD) {
|
||||
pdc.count = cmd.byte2;
|
||||
} else if (pdc.kind == PairedDevice::WALL_CONTROL) {
|
||||
pdc.count = cmd.byte2;
|
||||
} else if (pdc.kind == PairedDevice::ACCESSORY) {
|
||||
pdc.count = cmd.byte2;
|
||||
}
|
||||
this->ratgdo_->received(pdc);
|
||||
} else if (cmd.type == CommandType::BATTERY_STATUS) {
|
||||
this->ratgdo_->received(to_BatteryState(cmd.byte1, BatteryState::UNKNOWN));
|
||||
}
|
||||
|
||||
@@ -145,11 +145,6 @@ namespace secplus2 {
|
||||
|
||||
void query_status();
|
||||
void query_openings();
|
||||
void query_paired_devices();
|
||||
void query_paired_devices(PairedDevice kind);
|
||||
void clear_paired_devices(PairedDevice kind);
|
||||
void activate_learn();
|
||||
void inactivate_learn();
|
||||
|
||||
void print_packet(const esphome::LogString* prefix, const WirePacket& packet) const;
|
||||
optional<Command> decode_packet(const WirePacket& packet) const;
|
||||
@@ -182,7 +177,6 @@ namespace secplus2 {
|
||||
|
||||
// Small members at the end
|
||||
uint16_t rx_byte_count_ { 0 };
|
||||
LearnState learn_state_ { LearnState::UNKNOWN };
|
||||
struct {
|
||||
uint8_t transmit_pending : 1;
|
||||
uint8_t rx_reading_msg : 1;
|
||||
|
||||
@@ -23,11 +23,6 @@ RATGDOSensorType = ratgdo_ns.enum("RATGDOSensorType")
|
||||
CONF_TYPE = "type"
|
||||
TYPES = {
|
||||
"openings": RATGDOSensorType.RATGDO_OPENINGS,
|
||||
"paired_devices_total": RATGDOSensorType.RATGDO_PAIRED_DEVICES_TOTAL,
|
||||
"paired_devices_remotes": RATGDOSensorType.RATGDO_PAIRED_REMOTES,
|
||||
"paired_devices_keypads": RATGDOSensorType.RATGDO_PAIRED_KEYPADS,
|
||||
"paired_devices_wall_controls": RATGDOSensorType.RATGDO_PAIRED_WALL_CONTROLS,
|
||||
"paired_devices_accessories": RATGDOSensorType.RATGDO_PAIRED_ACCESSORIES,
|
||||
"distance": RATGDOSensorType.RATGDO_DISTANCE,
|
||||
}
|
||||
|
||||
|
||||
@@ -16,31 +16,6 @@ void RATGDOSensor::setup()
|
||||
this->publish_state(value);
|
||||
});
|
||||
break;
|
||||
case RATGDOSensorType::RATGDO_PAIRED_DEVICES_TOTAL:
|
||||
this->parent_->subscribe_paired_devices_total([this](uint8_t value) {
|
||||
this->publish_state(value);
|
||||
});
|
||||
break;
|
||||
case RATGDOSensorType::RATGDO_PAIRED_REMOTES:
|
||||
this->parent_->subscribe_paired_remotes([this](uint8_t value) {
|
||||
this->publish_state(value);
|
||||
});
|
||||
break;
|
||||
case RATGDOSensorType::RATGDO_PAIRED_KEYPADS:
|
||||
this->parent_->subscribe_paired_keypads([this](uint8_t value) {
|
||||
this->publish_state(value);
|
||||
});
|
||||
break;
|
||||
case RATGDOSensorType::RATGDO_PAIRED_WALL_CONTROLS:
|
||||
this->parent_->subscribe_paired_wall_controls([this](uint8_t value) {
|
||||
this->publish_state(value);
|
||||
});
|
||||
break;
|
||||
case RATGDOSensorType::RATGDO_PAIRED_ACCESSORIES:
|
||||
this->parent_->subscribe_paired_accessories([this](uint8_t value) {
|
||||
this->publish_state(value);
|
||||
});
|
||||
break;
|
||||
case RATGDOSensorType::RATGDO_DISTANCE:
|
||||
#ifdef RATGDO_USE_DISTANCE_SENSOR
|
||||
this->distance_sensor_.setI2cDevice(&I2C);
|
||||
@@ -71,21 +46,6 @@ void RATGDOSensor::dump_config()
|
||||
case RATGDOSensorType::RATGDO_OPENINGS:
|
||||
ESP_LOGCONFIG(TAG, " Type: Openings");
|
||||
break;
|
||||
case RATGDOSensorType::RATGDO_PAIRED_DEVICES_TOTAL:
|
||||
ESP_LOGCONFIG(TAG, " Type: Paired Devices");
|
||||
break;
|
||||
case RATGDOSensorType::RATGDO_PAIRED_REMOTES:
|
||||
ESP_LOGCONFIG(TAG, " Type: Paired Remotes");
|
||||
break;
|
||||
case RATGDOSensorType::RATGDO_PAIRED_KEYPADS:
|
||||
ESP_LOGCONFIG(TAG, " Type: Paired Keypads");
|
||||
break;
|
||||
case RATGDOSensorType::RATGDO_PAIRED_WALL_CONTROLS:
|
||||
ESP_LOGCONFIG(TAG, " Type: Paired Wall Controls");
|
||||
break;
|
||||
case RATGDOSensorType::RATGDO_PAIRED_ACCESSORIES:
|
||||
ESP_LOGCONFIG(TAG, " Type: Paired Accessories");
|
||||
break;
|
||||
case RATGDOSensorType::RATGDO_DISTANCE:
|
||||
ESP_LOGCONFIG(TAG, " Type: Distance");
|
||||
break;
|
||||
|
||||
@@ -16,12 +16,7 @@ namespace esphome::ratgdo {
|
||||
|
||||
enum RATGDOSensorType : uint8_t {
|
||||
RATGDO_OPENINGS,
|
||||
RATGDO_PAIRED_DEVICES_TOTAL,
|
||||
RATGDO_PAIRED_REMOTES,
|
||||
RATGDO_PAIRED_KEYPADS,
|
||||
RATGDO_PAIRED_WALL_CONTROLS,
|
||||
RATGDO_PAIRED_ACCESSORIES,
|
||||
RATGDO_DISTANCE
|
||||
RATGDO_DISTANCE = 6
|
||||
};
|
||||
|
||||
class RATGDOSensor : public sensor::Sensor, public RATGDOClient, public Component {
|
||||
|
||||
@@ -17,7 +17,7 @@ RATGDOSwitch = ratgdo_ns.class_("RATGDOSwitch", switch.Switch, cg.Component)
|
||||
SwitchType = ratgdo_ns.enum("SwitchType")
|
||||
|
||||
CONF_TYPE = "type"
|
||||
TYPES = {"learn": SwitchType.RATGDO_LEARN, "led": SwitchType.RATGDO_LED}
|
||||
TYPES = {"led": SwitchType.RATGDO_LED}
|
||||
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
|
||||
@@ -10,9 +10,6 @@ void RATGDOSwitch::dump_config()
|
||||
{
|
||||
LOG_SWITCH("", "RATGDO Switch", this);
|
||||
switch (this->switch_type_) {
|
||||
case SwitchType::RATGDO_LEARN:
|
||||
ESP_LOGCONFIG(TAG, " Type: Learn");
|
||||
break;
|
||||
case SwitchType::RATGDO_LED:
|
||||
ESP_LOGCONFIG(TAG, " Type: LED");
|
||||
break;
|
||||
@@ -24,11 +21,6 @@ void RATGDOSwitch::dump_config()
|
||||
void RATGDOSwitch::setup()
|
||||
{
|
||||
switch (this->switch_type_) {
|
||||
case SwitchType::RATGDO_LEARN:
|
||||
this->parent_->subscribe_learn_state([this](LearnState state) {
|
||||
this->publish_state(state == LearnState::ACTIVE);
|
||||
});
|
||||
break;
|
||||
case SwitchType::RATGDO_LED:
|
||||
this->pin_->setup();
|
||||
#ifdef RATGDO_USE_VEHICLE_SENSORS
|
||||
@@ -45,13 +37,6 @@ void RATGDOSwitch::setup()
|
||||
void RATGDOSwitch::write_state(bool state)
|
||||
{
|
||||
switch (this->switch_type_) {
|
||||
case SwitchType::RATGDO_LEARN:
|
||||
if (state) {
|
||||
this->parent_->activate_learn();
|
||||
} else {
|
||||
this->parent_->inactivate_learn();
|
||||
}
|
||||
break;
|
||||
case SwitchType::RATGDO_LED:
|
||||
this->pin_->digital_write(state);
|
||||
this->publish_state(state);
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
namespace esphome::ratgdo {
|
||||
|
||||
enum SwitchType {
|
||||
RATGDO_LEARN,
|
||||
RATGDO_LED
|
||||
RATGDO_LED = 1
|
||||
};
|
||||
|
||||
class RATGDOSwitch : public switch_::Switch, public RATGDOClient, public Component {
|
||||
|
||||
Reference in New Issue
Block a user