Skip to content

Commit

Permalink
Remove binary sensor, one must use a GPIO binary sensor to have this …
Browse files Browse the repository at this point in the history
…working
  • Loading branch information
X-Ryl669 committed Mar 26, 2024
1 parent 9dbdcbf commit 1fd4c6b
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 93 deletions.
8 changes: 1 addition & 7 deletions esphome/components/at581x/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import pins, automation, core
from esphome import automation, core
from esphome.components import i2c
from esphome.automation import maybe_simple_id
from esphome.const import (
Expand All @@ -23,7 +23,6 @@

CONF_SENSING_DISTANCE = "sensing_distance"
CONF_SENSITIVITY = "sensitivity"
CONF_DETECTION_PIN = "detection_pin"
CONF_POWERON_SELFCHECK_TIME = "poweron_selfcheck_time"
CONF_PROTECT_TIME = "protect_time"
CONF_TRIGGER_BASE = "trigger_base"
Expand Down Expand Up @@ -68,9 +67,6 @@
CONFIG_SCHEMA = cv.Schema(
{
cv.GenerateID(): cv.declare_id(AT581XComponent),
cv.Optional(
CONF_DETECTION_PIN, default=21
): pins.internal_gpio_input_pin_schema,
}
)

Expand All @@ -83,8 +79,6 @@ async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
await i2c.register_i2c_device(var, config)
pin = await cg.gpio_pin_expression(config[CONF_DETECTION_PIN])
cg.add(var.set_detection_pin(pin))


# Actions
Expand Down
24 changes: 2 additions & 22 deletions esphome/components/at581x/at581x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ namespace at581x {

static const char *const TAG = "at581x";

AT581XComponent::AT581XComponent() {}

bool AT581XComponent::i2c_write_reg(uint8_t addr, uint8_t data) {
return this->write_register(addr, &data, 1) == esphome::i2c::NO_ERROR;
}
Expand All @@ -73,26 +71,8 @@ bool AT581XComponent::i2c_read_reg(uint8_t addr, uint8_t &data) {
return this->read_register(addr, &data, 1) == esphome::i2c::NO_ERROR;
}

void AT581XComponent::setup() {
ESP_LOGCONFIG(TAG, "Setting up AT581X...");
this->detection_pin_->setup();
}
void AT581XComponent::loop() {
// The main operation is to detect the human presence
bool state = this->detection_pin_->digital_read();
#ifdef USE_BINARY_SENSOR
if (this->motion_binary_sensor_ != nullptr) {
this->motion_binary_sensor_->publish_state(state);
}
#endif
}
void AT581XComponent::dump_config() {
#ifdef USE_BINARY_SENSOR
LOG_BINARY_SENSOR("", "AT581X", this->motion_binary_sensor_);
#endif
LOG_PIN(" Pin: ", this->detection_pin_);
LOG_I2C_DEVICE(this);
}
void AT581XComponent::setup() { ESP_LOGCONFIG(TAG, "Setting up AT581X..."); }
void AT581XComponent::dump_config() { LOG_I2C_DEVICE(this); }
#define ARRAY_SIZE(X) (sizeof(X) / sizeof((X)[0]))
bool AT581XComponent::i2c_write_config() {
ESP_LOGCONFIG(TAG, "Writing new config for AT581X...");
Expand Down
12 changes: 0 additions & 12 deletions esphome/components/at581x/at581x.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#include "esphome/core/component.h"
#include "esphome/core/hal.h"
#include "esphome/core/defines.h"
#ifdef USE_BINARY_SENSOR
#include "esphome/components/binary_sensor/binary_sensor.h"
#endif
#ifdef USE_SWITCH
#include "esphome/components/switch/switch.h"
#endif
Expand All @@ -17,10 +14,6 @@ namespace esphome {
namespace at581x {

class AT581XComponent : public Component, public i2c::I2CDevice {
#ifdef USE_BINARY_SENSOR
SUB_BINARY_SENSOR(motion);
#endif

#ifdef USE_SWITCH
protected:
switch_::Switch *rf_power_switch_{nullptr};
Expand All @@ -32,15 +25,12 @@ class AT581XComponent : public Component, public i2c::I2CDevice {
}
#endif

AT581XComponent();
void setup() override;
void loop() override;
void dump_config() override;
// float get_setup_priority() const override;

void set_sensing_distance(int distance) { this->delta_ = 1023 - distance; }

void set_detection_pin(GPIOPin *pin) { this->detection_pin_ = pin; }
void set_rf_mode(bool enabled);
void set_frequency(int frequency) { this->freq_ = frequency; }
void set_poweron_selfcheck_time(int value) { this->self_check_time_ms_ = value; }
Expand All @@ -66,8 +56,6 @@ class AT581XComponent : public Component, public i2c::I2CDevice {
int delta_; /*!< Delta value: 0 ~ 1023, the larger the value, the shorter the distance */
int gain_; /*!< Default: 9dB */
int power_; /*!< In µA */

GPIOPin *detection_pin_;
};

} // namespace at581x
Expand Down
28 changes: 0 additions & 28 deletions esphome/components/at581x/binary_sensor.py

This file was deleted.

6 changes: 2 additions & 4 deletions tests/components/at581x/test.esp32-c3-idf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ esphome:
at581x:
id: "Waveradar"
i2c_id: i2c_bus
detection_pin:
number: GPIO21

i2c:
sda: 8
Expand All @@ -30,8 +28,8 @@ i2c:
id: i2c_bus

binary_sensor:
- platform: at581x
at581x_id: "Waveradar"
- platform: gpio
pin: GPIO21
name: "Radar motion"

switch:
Expand Down
6 changes: 2 additions & 4 deletions tests/components/at581x/test.esp32-c3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ esphome:
at581x:
id: "Waveradar"
i2c_id: i2c_bus
detection_pin:
number: GPIO21

i2c:
sda: 8
Expand All @@ -30,8 +28,8 @@ i2c:
id: i2c_bus

binary_sensor:
- platform: at581x
at581x_id: "Waveradar"
- platform: gpio
pin: GPIO21
name: "Radar motion"

switch:
Expand Down
6 changes: 2 additions & 4 deletions tests/components/at581x/test.esp32-idf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ esphome:
at581x:
id: "Waveradar"
i2c_id: i2c_bus
detection_pin:
number: GPIO21

i2c:
sda: 14
Expand All @@ -30,8 +28,8 @@ i2c:
id: i2c_bus

binary_sensor:
- platform: at581x
at581x_id: "Waveradar"
- platform: gpio
pin: GPIO21
name: "Radar motion"

switch:
Expand Down
6 changes: 2 additions & 4 deletions tests/components/at581x/test.esp32.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ esphome:
at581x:
id: "Waveradar"
i2c_id: i2c_bus
detection_pin:
number: GPIO21

i2c:
sda: 14
Expand All @@ -30,8 +28,8 @@ i2c:
id: i2c_bus

binary_sensor:
- platform: at581x
at581x_id: "Waveradar"
- platform: gpio
pin: GPIO21
name: "Radar motion"

switch:
Expand Down
6 changes: 2 additions & 4 deletions tests/components/at581x/test.esp8266.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ esphome:
at581x:
id: "Waveradar"
i2c_id: i2c_bus
detection_pin:
number: GPIO4

i2c:
sda: 14
Expand All @@ -30,8 +28,8 @@ i2c:
id: i2c_bus

binary_sensor:
- platform: at581x
at581x_id: "Waveradar"
- platform: gpio
pin: GPIO4
name: "Radar motion"

switch:
Expand Down
6 changes: 2 additions & 4 deletions tests/components/at581x/test.rp2040.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ esphome:
at581x:
id: "Waveradar"
i2c_id: i2c_bus
detection_pin:
number: GPIO21

i2c:
sda: 8
Expand All @@ -30,8 +28,8 @@ i2c:
id: i2c_bus

binary_sensor:
- platform: at581x
at581x_id: "Waveradar"
- platform: gpio
pin: GPIO21
name: "Radar motion"

switch:
Expand Down

0 comments on commit 1fd4c6b

Please sign in to comment.