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

33 lines
1.3 KiB
C++
Raw Normal View History

2023-06-07 10:37:51 -05:00
#include "ratgdo_binary_sensor.h"
#include "../ratgdo_state.h"
2023-06-07 11:41:02 -05:00
#include "esphome/core/log.h"
2023-06-07 10:37:51 -05:00
namespace esphome {
namespace ratgdo {
2023-06-07 11:41:02 -05:00
static const char* const TAG = "ratgdo.binary_sensor";
2023-06-07 11:40:49 -05:00
2023-06-07 11:41:02 -05:00
void RATGDOBinarySensor::dump_config()
{
LOG_BINARY_SENSOR("", "RATGDO BinarySensor", this);
ESP_LOGCONFIG(TAG, " Type: %s", this->type_ == SensorType::RATGDO_SENSOR_MOTION ? "Motion" : "Obstruction");
}
2023-06-07 14:08:35 -05:00
void RATGDOBinarySensor::on_motion_state(MotionState state)
2023-06-07 11:41:02 -05:00
{
2023-06-07 14:34:29 -05:00
ESP_LOGD(TAG, "this->type_:%s on_motion_state: %d", this->type_, state);
2023-06-07 11:41:02 -05:00
if (this->type_ == SensorType::RATGDO_SENSOR_MOTION)
2023-06-07 14:08:35 -05:00
this->publish_state(state == MotionState::MOTION_STATE_DETECTED);
2023-06-07 11:41:02 -05:00
}
2023-06-07 14:08:35 -05:00
void RATGDOBinarySensor::on_obstruction_state(ObstructionState state)
2023-06-07 11:41:02 -05:00
{
2023-06-07 14:34:29 -05:00
ESP_LOGD(TAG, "this->type_:%s on_obstruction_state: %d", this->type_, state);
2023-06-07 11:41:02 -05:00
if (this->type_ == SensorType::RATGDO_SENSOR_OBSTRUCTION)
2023-06-07 14:08:35 -05:00
this->publish_state(state == ObstructionState::OBSTRUCTION_STATE_OBSTRUCTED);
2023-06-07 11:41:02 -05:00
}
2023-06-07 14:08:35 -05:00
void RATGDOBinarySensor::on_door_state(DoorState state) { }
void RATGDOBinarySensor::on_light_state(LightState state) { }
2023-06-07 14:08:52 -05:00
void RATGDOBinarySensor::on_lock_state(LockState state) { }
2023-06-07 10:37:51 -05:00
2023-06-07 11:41:02 -05:00
} // namespace ratgdo
} // namespace esphome