Clean up unused vehicle distance derivatives
This commit is contained in:
@@ -2,7 +2,6 @@ from dataclasses import dataclass
|
||||
|
||||
from esphome import automation, pins
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import binary_sensor
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import CONF_ID, CONF_TRIGGER_ID
|
||||
from esphome.core import CORE
|
||||
@@ -25,9 +24,6 @@ class RATGDOData:
|
||||
door_state: int = 0
|
||||
door_action_delayed: int = 0
|
||||
distance: int = 0
|
||||
vehicle_detected: int = 0
|
||||
vehicle_arriving: int = 0
|
||||
vehicle_leaving: int = 0
|
||||
|
||||
|
||||
def _get_data() -> RATGDOData:
|
||||
@@ -48,18 +44,6 @@ def subscribe_distance() -> None:
|
||||
_get_data().distance += 1
|
||||
|
||||
|
||||
def subscribe_vehicle_detected() -> None:
|
||||
_get_data().vehicle_detected += 1
|
||||
|
||||
|
||||
def subscribe_vehicle_arriving() -> None:
|
||||
_get_data().vehicle_arriving += 1
|
||||
|
||||
|
||||
def subscribe_vehicle_leaving() -> None:
|
||||
_get_data().vehicle_leaving += 1
|
||||
|
||||
|
||||
@coroutine_with_priority(CoroPriority.FINAL)
|
||||
async def _emit_subscriber_defines():
|
||||
"""Emit observable subscriber count defines after all children have registered."""
|
||||
@@ -69,9 +53,6 @@ async def _emit_subscriber_defines():
|
||||
"RATGDO_MAX_DOOR_ACTION_DELAYED_SUBSCRIBERS", data.door_action_delayed
|
||||
)
|
||||
cg.add_define("RATGDO_MAX_DISTANCE_SUBSCRIBERS", data.distance)
|
||||
cg.add_define("RATGDO_MAX_VEHICLE_DETECTED_SUBSCRIBERS", data.vehicle_detected)
|
||||
cg.add_define("RATGDO_MAX_VEHICLE_ARRIVING_SUBSCRIBERS", data.vehicle_arriving)
|
||||
cg.add_define("RATGDO_MAX_VEHICLE_LEAVING_SUBSCRIBERS", data.vehicle_leaving)
|
||||
|
||||
|
||||
SyncFailed = ratgdo_ns.class_("SyncFailed", automation.Trigger.template())
|
||||
|
||||
@@ -16,7 +16,6 @@ void RATGDOBinarySensor::setup()
|
||||
case SensorType::RATGDO_SENSOR_VEHICLE_DETECTED:
|
||||
this->parent_->subscribe_vehicle_detected_state([this](VehicleDetectedState state) {
|
||||
this->publish_state(state == VehicleDetectedState::YES);
|
||||
this->parent_->presence_change(state == VehicleDetectedState::YES);
|
||||
});
|
||||
break;
|
||||
case SensorType::RATGDO_SENSOR_VEHICLE_ARRIVING:
|
||||
|
||||
@@ -8,7 +8,6 @@ from .. import (
|
||||
ratgdo_ns,
|
||||
register_ratgdo_child,
|
||||
subscribe_door_action_delayed,
|
||||
subscribe_vehicle_arriving,
|
||||
)
|
||||
|
||||
CONF_RTTTL = "rtttl"
|
||||
@@ -39,5 +38,4 @@ async def to_code(config):
|
||||
cg.add(var.set_rtttl(rtttl))
|
||||
cg.add(var.set_song(config[CONF_SONG]))
|
||||
await register_ratgdo_child(var, config)
|
||||
subscribe_vehicle_arriving()
|
||||
subscribe_door_action_delayed()
|
||||
|
||||
@@ -13,14 +13,6 @@ void RATGDOOutput::setup()
|
||||
if (this->output_type_ == OutputType::RATGDO_BEEPER) {
|
||||
this->beeper_->add_on_finished_playback_callback([this] { this->finished_playback(); });
|
||||
|
||||
#ifdef RATGDO_USE_VEHICLE_SENSORS
|
||||
this->parent_->subscribe_vehicle_arriving_state([this](VehicleArrivingState state) {
|
||||
if (state == VehicleArrivingState::YES) {
|
||||
this->play();
|
||||
}
|
||||
});
|
||||
#endif
|
||||
|
||||
this->parent_->subscribe_door_action_delayed([this](DoorActionDelayed state) {
|
||||
if (state == DoorActionDelayed::YES) {
|
||||
this->play();
|
||||
|
||||
@@ -16,42 +16,6 @@ class RATGDOComponent;
|
||||
|
||||
namespace protocol {
|
||||
|
||||
const uint32_t HAS_DOOR_OPEN = 1 << 0; // has idempotent open door command
|
||||
const uint32_t HAS_DOOR_CLOSE = 1 << 1; // has idempotent close door command
|
||||
const uint32_t HAS_DOOR_STOP = 1 << 2; // has idempotent stop door command
|
||||
const uint32_t HAS_DOOR_STATUS = 1 << 3;
|
||||
|
||||
const uint32_t HAS_LIGHT_TOGGLE = 1 << 10; // some protocols might not support this
|
||||
|
||||
const uint32_t HAS_LOCK_TOGGLE = 1 << 20;
|
||||
|
||||
class Traits {
|
||||
uint32_t value;
|
||||
|
||||
public:
|
||||
Traits()
|
||||
: value(0)
|
||||
{
|
||||
}
|
||||
|
||||
bool has_door_open() const { return this->value & HAS_DOOR_OPEN; }
|
||||
bool has_door_close() const { return this->value & HAS_DOOR_CLOSE; }
|
||||
bool has_door_stop() const { return this->value & HAS_DOOR_STOP; }
|
||||
bool has_door_status() const { return this->value & HAS_DOOR_STATUS; }
|
||||
|
||||
bool has_light_toggle() const { return this->value & HAS_LIGHT_TOGGLE; }
|
||||
|
||||
bool has_lock_toggle() const { return this->value & HAS_LOCK_TOGGLE; }
|
||||
|
||||
void set_features(uint32_t feature) { this->value |= feature; }
|
||||
void clear_features(uint32_t feature) { this->value &= ~feature; }
|
||||
|
||||
static uint32_t all()
|
||||
{
|
||||
return HAS_DOOR_CLOSE | HAS_DOOR_OPEN | HAS_DOOR_STOP | HAS_DOOR_STATUS | HAS_LIGHT_TOGGLE | HAS_LOCK_TOGGLE;
|
||||
}
|
||||
};
|
||||
|
||||
struct SetRollingCodeCounter {
|
||||
uint32_t counter;
|
||||
};
|
||||
@@ -90,8 +54,6 @@ namespace protocol {
|
||||
|
||||
virtual void sync();
|
||||
|
||||
virtual const Traits& traits() const;
|
||||
|
||||
virtual void light_action(LightAction action);
|
||||
virtual void lock_action(LockAction action);
|
||||
virtual void door_action(DoorAction action);
|
||||
|
||||
@@ -41,19 +41,6 @@ void log_subscriber_overflow(const LogString* observable_name, uint32_t max)
|
||||
LOG_STR_ARG(observable_name), (int)max);
|
||||
}
|
||||
|
||||
#ifdef RATGDO_USE_VEHICLE_SENSORS
|
||||
static constexpr int CLEAR_PRESENCE = 60000; // how long to keep arriving/leaving active
|
||||
static constexpr int PRESENCE_DETECT_WINDOW = 300000; // how long to calculate presence after door state change
|
||||
static constexpr int PRESENCE_DETECT_WINDOW_AFTER_CLOSE = 15000; // how long to keep presence window active after door reaches closed
|
||||
|
||||
// increasing these values increases reliability but also increases detection
|
||||
// time
|
||||
static constexpr int PRESENCE_DETECTION_ON_THRESHOLD = 5; // Minimum percentage of valid bitset::in_range samples required to
|
||||
// detect vehicle
|
||||
static constexpr int PRESENCE_DETECTION_OFF_DEBOUNCE = 2; // The number of consecutive bitset::in_range iterations that must be 0
|
||||
// before clearing vehicle detected state
|
||||
#endif
|
||||
|
||||
void RATGDOComponent::setup()
|
||||
{
|
||||
this->output_gdo_pin_->setup();
|
||||
@@ -288,70 +275,6 @@ void RATGDOComponent::set_target_distance_measurement(int16_t distance)
|
||||
void RATGDOComponent::set_distance_measurement(int16_t distance)
|
||||
{
|
||||
this->last_distance_measurement = distance;
|
||||
|
||||
#ifdef RATGDO_USE_VEHICLE_SENSORS
|
||||
this->in_range <<= 1;
|
||||
this->in_range.set(0, distance <= *this->target_distance_measurement);
|
||||
this->calculate_presence();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef RATGDO_USE_VEHICLE_SENSORS
|
||||
void RATGDOComponent::calculate_presence()
|
||||
{
|
||||
int percent = this->in_range.count() * 100 / this->in_range.size();
|
||||
|
||||
if (percent >= PRESENCE_DETECTION_ON_THRESHOLD)
|
||||
this->vehicle_detected_state = VehicleDetectedState::YES;
|
||||
|
||||
if (percent == 0 && *this->vehicle_detected_state == VehicleDetectedState::YES) {
|
||||
this->presence_off_counter_++;
|
||||
ESP_LOGD(TAG, "Off counter: %d", this->presence_off_counter_);
|
||||
|
||||
if (this->presence_off_counter_ / this->in_range.size() >= PRESENCE_DETECTION_OFF_DEBOUNCE) {
|
||||
this->presence_off_counter_ = 0;
|
||||
this->vehicle_detected_state = VehicleDetectedState::NO;
|
||||
}
|
||||
}
|
||||
|
||||
if (percent != this->last_presence_percent_) {
|
||||
ESP_LOGD(TAG, "pct_in_range: %d", percent);
|
||||
this->last_presence_percent_ = percent;
|
||||
this->presence_off_counter_ = 0;
|
||||
}
|
||||
// ESP_LOGD(TAG, "in_range: %s", this->in_range.to_string().c_str());
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef RATGDO_USE_VEHICLE_SENSORS
|
||||
void RATGDOComponent::presence_change(bool sensor_value)
|
||||
{
|
||||
if (this->flags_.presence_detect_window_active) {
|
||||
// Arriving and leaving are mutually exclusive — each branch clears the
|
||||
// other state. Sharing TIMEOUT_CLEAR_PRESENCE ensures that switching from
|
||||
// arriving to leaving (or vice versa) cancels the previous clear timeout,
|
||||
// which is correct since the previous state was already cleared above.
|
||||
if (sensor_value) {
|
||||
this->vehicle_arriving_state = VehicleArrivingState::YES;
|
||||
this->vehicle_leaving_state = VehicleLeavingState::NO;
|
||||
this->set_timeout(TIMEOUT_CLEAR_PRESENCE, CLEAR_PRESENCE, [this] {
|
||||
this->vehicle_arriving_state = VehicleArrivingState::NO;
|
||||
});
|
||||
} else {
|
||||
this->vehicle_arriving_state = VehicleArrivingState::NO;
|
||||
this->vehicle_leaving_state = VehicleLeavingState::YES;
|
||||
this->set_timeout(TIMEOUT_CLEAR_PRESENCE, CLEAR_PRESENCE, [this] {
|
||||
this->vehicle_leaving_state = VehicleLeavingState::NO;
|
||||
});
|
||||
}
|
||||
// if the door is closed, clear the presence detect window since a vehicle
|
||||
// can't be arriving or leaving with the door shut
|
||||
if (*this->door_state == DoorState::CLOSED) {
|
||||
this->flags_.presence_detect_window_active = false;
|
||||
this->cancel_timeout(TIMEOUT_PRESENCE_DETECT_WINDOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -530,12 +453,6 @@ void RATGDOComponent::light_off()
|
||||
this->protocol_->light_action(LightAction::OFF);
|
||||
}
|
||||
|
||||
void RATGDOComponent::light_toggle()
|
||||
{
|
||||
this->light_state = light_state_toggle(*this->light_state);
|
||||
this->protocol_->light_action(LightAction::TOGGLE);
|
||||
}
|
||||
|
||||
LightState RATGDOComponent::get_light_state() const
|
||||
{
|
||||
return *this->light_state;
|
||||
@@ -554,12 +471,6 @@ void RATGDOComponent::unlock()
|
||||
this->protocol_->lock_action(LockAction::UNLOCK);
|
||||
}
|
||||
|
||||
void RATGDOComponent::lock_toggle()
|
||||
{
|
||||
this->lock_state = lock_state_toggle(*this->lock_state);
|
||||
this->protocol_->lock_action(LockAction::TOGGLE);
|
||||
}
|
||||
|
||||
// Subscribe implementations are now templates in ratgdo.h
|
||||
|
||||
} // namespace esphome::ratgdo
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/binary_sensor/binary_sensor.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/defines.h"
|
||||
#include "esphome/core/hal.h"
|
||||
@@ -40,15 +39,6 @@
|
||||
#ifndef RATGDO_MAX_DISTANCE_SUBSCRIBERS
|
||||
#error "RATGDO_MAX_DISTANCE_SUBSCRIBERS must be defined by codegen"
|
||||
#endif
|
||||
#ifndef RATGDO_MAX_VEHICLE_DETECTED_SUBSCRIBERS
|
||||
#error "RATGDO_MAX_VEHICLE_DETECTED_SUBSCRIBERS must be defined by codegen"
|
||||
#endif
|
||||
#ifndef RATGDO_MAX_VEHICLE_ARRIVING_SUBSCRIBERS
|
||||
#error "RATGDO_MAX_VEHICLE_ARRIVING_SUBSCRIBERS must be defined by codegen"
|
||||
#endif
|
||||
#ifndef RATGDO_MAX_VEHICLE_LEAVING_SUBSCRIBERS
|
||||
#error "RATGDO_MAX_VEHICLE_LEAVING_SUBSCRIBERS must be defined by codegen"
|
||||
#endif
|
||||
|
||||
namespace esphome {
|
||||
class InternalGPIOPin;
|
||||
@@ -105,11 +95,6 @@ public:
|
||||
|
||||
single_observable<LightState> light_state { LightState::UNKNOWN };
|
||||
single_observable<LockState> lock_state { LockState::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 };
|
||||
observable<VehicleLeavingState, RATGDO_MAX_VEHICLE_LEAVING_SUBSCRIBERS> vehicle_leaving_state { VehicleLeavingState::NO };
|
||||
#endif
|
||||
|
||||
OnceCallbacks<void(DoorState)> on_door_state_;
|
||||
|
||||
@@ -147,19 +132,13 @@ public:
|
||||
void set_target_distance_measurement(int16_t distance);
|
||||
void set_distance_measurement(int16_t distance);
|
||||
#endif
|
||||
#ifdef RATGDO_USE_VEHICLE_SENSORS
|
||||
void calculate_presence();
|
||||
void presence_change(bool sensor_value);
|
||||
#endif
|
||||
|
||||
// light
|
||||
void light_toggle();
|
||||
void light_on();
|
||||
void light_off();
|
||||
LightState get_light_state() const;
|
||||
|
||||
// lock
|
||||
void lock_toggle();
|
||||
void lock();
|
||||
void unlock();
|
||||
|
||||
@@ -239,14 +218,6 @@ public:
|
||||
template <typename F>
|
||||
void subscribe_distance_measurement(F&& f);
|
||||
#endif
|
||||
#ifdef RATGDO_USE_VEHICLE_SENSORS
|
||||
template <typename F>
|
||||
void subscribe_vehicle_detected_state(F&& f);
|
||||
template <typename F>
|
||||
void subscribe_vehicle_arriving_state(F&& f);
|
||||
template <typename F>
|
||||
void subscribe_vehicle_leaving_state(F&& f);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
// Pointers first (4-byte aligned)
|
||||
@@ -256,12 +227,7 @@ protected:
|
||||
|
||||
// Bool members packed into bitfield
|
||||
struct {
|
||||
#ifdef RATGDO_USE_VEHICLE_SENSORS
|
||||
uint8_t presence_detect_window_active : 1;
|
||||
uint8_t reserved : 7; // Reserved for future use
|
||||
#else
|
||||
uint8_t reserved : 8; // Reserved for future use
|
||||
#endif
|
||||
} flags_ { 0 };
|
||||
|
||||
// Subscriber counters for defer name allocation
|
||||
@@ -270,14 +236,6 @@ protected:
|
||||
#ifdef RATGDO_USE_DISTANCE_SENSOR
|
||||
uint8_t distance_sub_num_ { 0 };
|
||||
#endif
|
||||
#ifdef RATGDO_USE_VEHICLE_SENSORS
|
||||
uint8_t vehicle_detected_sub_num_ { 0 };
|
||||
uint8_t vehicle_arriving_sub_num_ { 0 };
|
||||
uint8_t vehicle_leaving_sub_num_ { 0 };
|
||||
int last_presence_percent_ { -1 };
|
||||
int presence_off_counter_ { 0 };
|
||||
DoorState last_door_state_for_presence_ { DoorState::UNKNOWN };
|
||||
#endif
|
||||
}; // RATGDOComponent
|
||||
|
||||
void log_subscriber_overflow(const LogString* observable_name, uint32_t max);
|
||||
@@ -315,21 +273,9 @@ namespace scheduler_ids {
|
||||
inline constexpr uint32_t DEFER_DISTANCE_END = DEFER_DOOR_ACTION_DELAYED_BASE + DEFER_DOOR_ACTION_DELAYED_COUNT;
|
||||
#endif
|
||||
|
||||
#ifdef RATGDO_USE_VEHICLE_SENSORS
|
||||
inline constexpr uint32_t DEFER_VEHICLE_DETECTED_COUNT = RATGDO_MAX_VEHICLE_DETECTED_SUBSCRIBERS;
|
||||
inline constexpr uint32_t DEFER_VEHICLE_DETECTED_BASE = DEFER_DISTANCE_END;
|
||||
inline constexpr uint32_t DEFER_VEHICLE_ARRIVING_COUNT = RATGDO_MAX_VEHICLE_ARRIVING_SUBSCRIBERS;
|
||||
inline constexpr uint32_t DEFER_VEHICLE_ARRIVING_BASE = DEFER_VEHICLE_DETECTED_BASE + DEFER_VEHICLE_DETECTED_COUNT;
|
||||
inline constexpr uint32_t DEFER_VEHICLE_LEAVING_COUNT = RATGDO_MAX_VEHICLE_LEAVING_SUBSCRIBERS;
|
||||
inline constexpr uint32_t DEFER_VEHICLE_LEAVING_BASE = DEFER_VEHICLE_ARRIVING_BASE + DEFER_VEHICLE_ARRIVING_COUNT;
|
||||
inline constexpr uint32_t DEFER_VEHICLE_END = DEFER_VEHICLE_LEAVING_BASE + DEFER_VEHICLE_LEAVING_COUNT;
|
||||
#else
|
||||
inline constexpr uint32_t DEFER_VEHICLE_END = DEFER_DISTANCE_END;
|
||||
#endif
|
||||
|
||||
// Single-subscriber IDs
|
||||
enum : uint32_t {
|
||||
DEFER_ROLLING_CODE = DEFER_VEHICLE_END,
|
||||
DEFER_ROLLING_CODE = DEFER_DISTANCE_END,
|
||||
DEFER_OPENING_DURATION,
|
||||
DEFER_CLOSING_DURATION,
|
||||
DEFER_CLOSING_DELAY,
|
||||
@@ -342,8 +288,6 @@ namespace scheduler_ids {
|
||||
TIMEOUT_DOOR_ACTION,
|
||||
TIMEOUT_MOVE_TO_POSITION,
|
||||
TIMEOUT_DOOR_STATE_EXPIRY,
|
||||
TIMEOUT_PRESENCE_DETECT_WINDOW,
|
||||
TIMEOUT_CLEAR_PRESENCE,
|
||||
TIMEOUT_SYNC,
|
||||
};
|
||||
} // namespace scheduler_ids
|
||||
@@ -457,36 +401,4 @@ void RATGDOComponent::subscribe_distance_measurement(F&& f)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef RATGDO_USE_VEHICLE_SENSORS
|
||||
template <typename F>
|
||||
void RATGDOComponent::subscribe_vehicle_detected_state(F&& f)
|
||||
{
|
||||
uint32_t id = get_scheduler_id(scheduler_ids::DEFER_VEHICLE_DETECTED_BASE, scheduler_ids::DEFER_VEHICLE_DETECTED_COUNT,
|
||||
this->vehicle_detected_sub_num_, LOG_STR("vehicle_detected"));
|
||||
this->vehicle_detected_state.subscribe([this, f, id](VehicleDetectedState state) {
|
||||
defer(id, [f, state] { f(state); });
|
||||
});
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
void RATGDOComponent::subscribe_vehicle_arriving_state(F&& f)
|
||||
{
|
||||
uint32_t id = get_scheduler_id(scheduler_ids::DEFER_VEHICLE_ARRIVING_BASE, scheduler_ids::DEFER_VEHICLE_ARRIVING_COUNT,
|
||||
this->vehicle_arriving_sub_num_, LOG_STR("vehicle_arriving"));
|
||||
this->vehicle_arriving_state.subscribe([this, f, id](VehicleArrivingState state) {
|
||||
defer(id, [f, state] { f(state); });
|
||||
});
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
void RATGDOComponent::subscribe_vehicle_leaving_state(F&& f)
|
||||
{
|
||||
uint32_t id = get_scheduler_id(scheduler_ids::DEFER_VEHICLE_LEAVING_BASE, scheduler_ids::DEFER_VEHICLE_LEAVING_COUNT,
|
||||
this->vehicle_leaving_sub_num_, LOG_STR("vehicle_leaving"));
|
||||
this->vehicle_leaving_state.subscribe([this, f, id](VehicleLeavingState state) {
|
||||
defer(id, [f, state] { f(state); });
|
||||
});
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace esphome::ratgdo
|
||||
|
||||
@@ -16,18 +16,4 @@ LightState light_state_toggle(LightState state)
|
||||
}
|
||||
}
|
||||
|
||||
LockState lock_state_toggle(LockState state)
|
||||
{
|
||||
switch (state) {
|
||||
case LockState::UNLOCKED:
|
||||
return LockState::LOCKED;
|
||||
case LockState::LOCKED:
|
||||
return LockState::UNLOCKED;
|
||||
// 2 and 3 appears sometimes
|
||||
case LockState::UNKNOWN:
|
||||
default:
|
||||
return LockState::UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace esphome::ratgdo
|
||||
|
||||
@@ -42,7 +42,6 @@ ENUM(LockState, uint8_t,
|
||||
(UNLOCKED, 0),
|
||||
(LOCKED, 1),
|
||||
(UNKNOWN, 2))
|
||||
LockState lock_state_toggle(LockState state);
|
||||
|
||||
// actions
|
||||
ENUM(LightAction, uint8_t,
|
||||
@@ -54,7 +53,6 @@ ENUM(LightAction, uint8_t,
|
||||
ENUM(LockAction, uint8_t,
|
||||
(UNLOCK, 0),
|
||||
(LOCK, 1),
|
||||
(TOGGLE, 2),
|
||||
(UNKNOWN, 3))
|
||||
|
||||
ENUM(DoorAction, uint8_t,
|
||||
@@ -64,20 +62,6 @@ ENUM(DoorAction, uint8_t,
|
||||
(STOP, 3),
|
||||
(UNKNOWN, 4))
|
||||
|
||||
#ifdef RATGDO_USE_VEHICLE_SENSORS
|
||||
ENUM(VehicleDetectedState, uint8_t,
|
||||
(NO, 0),
|
||||
(YES, 1))
|
||||
|
||||
ENUM(VehicleArrivingState, uint8_t,
|
||||
(NO, 0),
|
||||
(YES, 1))
|
||||
|
||||
ENUM(VehicleLeavingState, uint8_t,
|
||||
(NO, 0),
|
||||
(YES, 1))
|
||||
#endif
|
||||
|
||||
struct Openings {
|
||||
uint16_t count;
|
||||
uint8_t flag;
|
||||
|
||||
@@ -38,8 +38,6 @@ namespace secplus2 {
|
||||
this->uart_.begin(9600, RATGDO_UART_8N1, rx_pin->get_pin(), tx_pin->get_pin(), true);
|
||||
this->uart_.enableIntTx(false);
|
||||
this->uart_.enableAutoBaud(true);
|
||||
|
||||
this->traits_.set_features(Traits::all());
|
||||
}
|
||||
|
||||
void Secplus2::loop()
|
||||
|
||||
@@ -81,8 +81,6 @@ namespace secplus2 {
|
||||
|
||||
Result call(Args args);
|
||||
|
||||
const Traits& traits() const { return this->traits_; }
|
||||
|
||||
protected:
|
||||
void increment_rolling_code_counter(int delta = 1);
|
||||
void set_rolling_code_counter(uint32_t counter);
|
||||
@@ -139,7 +137,6 @@ namespace secplus2 {
|
||||
// Larger structures
|
||||
single_observable<uint32_t> rolling_code_counter_ { 0 };
|
||||
OnceCallbacks<void()> on_command_sent_;
|
||||
Traits traits_;
|
||||
RatgdoUART uart_;
|
||||
|
||||
// 19-byte arrays
|
||||
@@ -151,7 +148,6 @@ namespace secplus2 {
|
||||
struct {
|
||||
uint8_t transmit_pending : 1;
|
||||
uint8_t rx_reading_msg : 1;
|
||||
uint8_t reserved : 6; // Reserved for future use
|
||||
} flags_ { 0 };
|
||||
};
|
||||
} // namespace secplus2
|
||||
|
||||
@@ -8,7 +8,6 @@ from .. import (
|
||||
RATGDO_CLIENT_SCHMEA,
|
||||
ratgdo_ns,
|
||||
register_ratgdo_child,
|
||||
subscribe_vehicle_arriving,
|
||||
)
|
||||
|
||||
DEPENDENCIES = ["ratgdo"]
|
||||
@@ -41,8 +40,3 @@ async def to_code(config):
|
||||
if CONF_PIN in config:
|
||||
pin = await cg.gpio_pin_expression(config[CONF_PIN])
|
||||
cg.add(var.set_pin(pin))
|
||||
# LED switch conditionally subscribes to vehicle_arriving in C++ (#ifdef RATGDO_USE_VEHICLE_SENSORS).
|
||||
# Always register the subscription — the C++ guard ensures it's only active when vehicle sensors
|
||||
# are enabled, and the codegen emits the define to size the observable accordingly.
|
||||
if config[CONF_TYPE] == "led":
|
||||
subscribe_vehicle_arriving()
|
||||
|
||||
@@ -23,11 +23,6 @@ void RATGDOSwitch::setup()
|
||||
switch (this->switch_type_) {
|
||||
case SwitchType::RATGDO_LED:
|
||||
this->pin_->setup();
|
||||
#ifdef RATGDO_USE_VEHICLE_SENSORS
|
||||
this->parent_->subscribe_vehicle_arriving_state([this](VehicleArrivingState state) {
|
||||
this->write_state(state == VehicleArrivingState::YES);
|
||||
});
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user