esphome-ratgdo/components/ratgdo/binary_sensor/ratgdo_binary_sensor.cpp

50 lines
2.2 KiB
C++
Raw Normal View History

2023-06-07 15:37:51 +00:00
#include "ratgdo_binary_sensor.h"
#include "../ratgdo_state.h"
2023-06-07 16:41:02 +00:00
#include "esphome/core/log.h"
2023-06-07 15:37:51 +00:00
namespace esphome {
namespace ratgdo {
2023-06-07 16:41:02 +00:00
static const char* const TAG = "ratgdo.binary_sensor";
2023-06-07 16:40:49 +00:00
2023-06-07 22:24:46 +00:00
void RATGDOBinarySensor::setup()
{
2023-06-10 00:06:17 +00:00
if (this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_MOTION || this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_OBSTRUCTION || this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_BUTTON)
2023-06-07 22:28:29 +00:00
this->publish_state(false);
if (this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_MOTION) {
this->parent_->subscribe_motion_state([=](MotionState state) {
this->publish_state(state == MotionState::MOTION_STATE_DETECTED);
});
} else if (this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_OBSTRUCTION) {
this->parent_->subscribe_obstruction_state([=](ObstructionState state) {
this->publish_state(state == ObstructionState::OBSTRUCTION_STATE_OBSTRUCTED);
});
} else if (this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_MOTOR) {
this->parent_->subscribe_motor_state([=](MotorState state) {
this->publish_state(state == MotorState::MOTOR_STATE_ON);
});
} else if (this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_BUTTON) {
this->parent_->subscribe_button_state([=](ButtonState state) {
this->publish_state(state == ButtonState::BUTTON_STATE_PRESSED);
});
}
2023-06-07 22:24:46 +00:00
}
2023-06-07 16:41:02 +00:00
void RATGDOBinarySensor::dump_config()
{
LOG_BINARY_SENSOR("", "RATGDO BinarySensor", this);
2023-06-08 02:40:07 +00:00
if (this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_MOTION) {
ESP_LOGCONFIG(TAG, " Type: Motion");
} else if (this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_OBSTRUCTION) {
ESP_LOGCONFIG(TAG, " Type: Obstruction");
} else if (this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_MOTOR) {
ESP_LOGCONFIG(TAG, " Type: Motor");
2023-06-09 23:04:29 +00:00
} else if (this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_BUTTON) {
2023-06-09 23:04:32 +00:00
ESP_LOGCONFIG(TAG, " Type: Button");
2023-06-08 02:40:07 +00:00
}
2023-06-07 16:41:02 +00:00
}
2023-06-07 22:49:37 +00:00
2023-06-07 16:41:02 +00:00
} // namespace ratgdo
} // namespace esphome