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()
|
|
|
|
{
|
|
|
|
if (this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_MOTION)
|
2023-06-07 22:28:29 +00:00
|
|
|
this->publish_state(false);
|
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-07 16:41:02 +00:00
|
|
|
}
|
2023-06-07 19:08:35 +00:00
|
|
|
void RATGDOBinarySensor::on_motion_state(MotionState state)
|
2023-06-07 16:41:02 +00:00
|
|
|
{
|
2023-06-09 21:48:48 +00:00
|
|
|
if (this->binary_sensor_type_ != SensorType::RATGDO_SENSOR_MOTION)
|
|
|
|
return;
|
2023-06-07 19:48:20 +00:00
|
|
|
ESP_LOGD(TAG, "name: %s this->type_:%d on_motion_state: %d", this->get_name(), this->binary_sensor_type_, state);
|
2023-06-09 21:48:48 +00:00
|
|
|
this->publish_state(state == MotionState::MOTION_STATE_DETECTED);
|
2023-06-07 16:41:02 +00:00
|
|
|
}
|
2023-06-07 19:08:35 +00:00
|
|
|
void RATGDOBinarySensor::on_obstruction_state(ObstructionState state)
|
2023-06-07 16:41:02 +00:00
|
|
|
{
|
2023-06-09 21:48:48 +00:00
|
|
|
if (this->binary_sensor_type_ != SensorType::RATGDO_SENSOR_OBSTRUCTION)
|
|
|
|
return;
|
2023-06-07 19:48:20 +00:00
|
|
|
ESP_LOGD(TAG, "name: %s this->type_:%d on_obstruction_state: %d", this->get_name(), this->binary_sensor_type_, state);
|
2023-06-09 21:48:48 +00:00
|
|
|
this->publish_state(state == ObstructionState::OBSTRUCTION_STATE_OBSTRUCTED);
|
2023-06-07 16:41:02 +00:00
|
|
|
}
|
2023-06-08 02:40:07 +00:00
|
|
|
void RATGDOBinarySensor::on_motor_state(MotorState state)
|
|
|
|
{
|
2023-06-09 21:48:48 +00:00
|
|
|
if (this->binary_sensor_type_ != SensorType::RATGDO_SENSOR_MOTOR)
|
|
|
|
return;
|
2023-06-08 02:40:07 +00:00
|
|
|
ESP_LOGD(TAG, "name: %s this->type_:%d on_motor_state: %d", this->get_name(), this->binary_sensor_type_, state);
|
2023-06-09 21:48:48 +00:00
|
|
|
this->publish_state(state == MotorState::MOTOR_STATE_ON);
|
2023-06-08 02:40:07 +00:00
|
|
|
}
|
2023-06-07 22:49:37 +00:00
|
|
|
|
2023-06-07 16:41:02 +00:00
|
|
|
} // namespace ratgdo
|
|
|
|
} // namespace esphome
|