binary sensor

This commit is contained in:
J. Nick Koston 2023-06-07 11:41:02 -05:00
parent 205bbc2066
commit b797256ef4
No known key found for this signature in database
2 changed files with 39 additions and 41 deletions

View File

@ -1,30 +1,30 @@
#include "ratgdo_binary_sensor.h" #include "ratgdo_binary_sensor.h"
#include "esphome/core/log.h"
#include "../ratgdo_state.h" #include "../ratgdo_state.h"
#include "esphome/core/log.h"
namespace esphome { namespace esphome {
namespace ratgdo { namespace ratgdo {
static const char *const TAG = "ratgdo.binary_sensor"; static const char* const TAG = "ratgdo.binary_sensor";
void RATGDOBinarySensor::dump_config() { void RATGDOBinarySensor::dump_config()
LOG_BINARY_SENSOR("", "RATGDO BinarySensor", this); {
ESP_LOGCONFIG(TAG, " Type: %s", this->type_ == SensorType::RATGDO_SENSOR_MOTION ? "Motion" : "Obstruction"); LOG_BINARY_SENSOR("", "RATGDO BinarySensor", this);
} ESP_LOGCONFIG(TAG, " Type: %s", this->type_ == SensorType::RATGDO_SENSOR_MOTION ? "Motion" : "Obstruction");
void RATGDOBinarySensor::on_motion_state(esphome::ratgdo::MotionState state) { }
if (this->type_ == SensorType::RATGDO_SENSOR_MOTION) void RATGDOBinarySensor::on_motion_state(esphome::ratgdo::MotionState state)
this->publish_state(state == esphome::ratgdo::MotionState::MOTION_STATE_DETECTED); {
} if (this->type_ == SensorType::RATGDO_SENSOR_MOTION)
void RATGDOBinarySensor::on_obstruction_state(esphome::ratgdo::ObstructionState state) { this->publish_state(state == esphome::ratgdo::MotionState::MOTION_STATE_DETECTED);
if (this->type_ == SensorType::RATGDO_SENSOR_OBSTRUCTION) }
this->publish_state(state == esphome::ratgdo::ObstructionState::OBSTRUCTION_STATE_OBSTRUCTED); void RATGDOBinarySensor::on_obstruction_state(esphome::ratgdo::ObstructionState state)
} {
void RATGDOBinarySensor::on_door_state(esphome::ratgdo::DoorState state) {} if (this->type_ == SensorType::RATGDO_SENSOR_OBSTRUCTION)
void RATGDOBinarySensor::on_light_state(esphome::ratgdo::LightState state) {} this->publish_state(state == esphome::ratgdo::ObstructionState::OBSTRUCTION_STATE_OBSTRUCTED);
void RATGDOBinarySensor::on_lock_state(esphome::ratgdo::LockState state) {} }
void RATGDOBinarySensor::on_door_state(esphome::ratgdo::DoorState state) { }
void RATGDOBinarySensor::on_light_state(esphome::ratgdo::LightState state) { }
void RATGDOBinarySensor::on_lock_state(esphome::ratgdo::LockState state) { }
} // namespace ratgdo
} // namespace esphome
} // namespace ratgdo
} // namespace esphome

View File

@ -1,32 +1,30 @@
#pragma once #pragma once
#include "esphome/core/component.h" #include "../ratgdo.h"
#include "../ratgdo_child.h" #include "../ratgdo_child.h"
#include "../ratgdo_state.h" #include "../ratgdo_state.h"
#include "../ratgdo.h"
#include "esphome/components/binary_sensor/binary_sensor.h" #include "esphome/components/binary_sensor/binary_sensor.h"
#include "esphome/core/component.h"
namespace esphome { namespace esphome {
namespace ratgdo { namespace ratgdo {
enum SensorType { enum SensorType {
RATGDO_SENSOR_MOTION, RATGDO_SENSOR_MOTION,
RATGDO_SENSOR_OBSTRUCTION, RATGDO_SENSOR_OBSTRUCTION,
}; };
class RATGDOBinarySensor : public binary_sensor::BinarySensor, public RATGDOClient, public Component { class RATGDOBinarySensor : public binary_sensor::BinarySensor, public RATGDOClient, public Component {
public: public:
void dump_config() override; void dump_config() override;
void set_type(SensorType type) { type_ = type_; } void set_type(SensorType type) { type_ = type_; }
void on_motion_state(esphome::ratgdo::MotionState state) override; void on_motion_state(esphome::ratgdo::MotionState state) override;
void on_obstruction_state(esphome::ratgdo::ObstructionState state) override; void on_obstruction_state(esphome::ratgdo::ObstructionState state) override;
protected: protected:
SensorType type_; SensorType type_;
};
};
} // namespace ratgdo
} // namespace esphome
} // namespace ratgdo
} // namespace esphome