binary sensor
This commit is contained in:
parent
6a9b065f5e
commit
9f75f8cf58
|
@ -13,14 +13,18 @@ DEPENDENCIES = ["ratgdo"]
|
|||
RATGDOBinarySensor = ratgdo_ns.class_(
|
||||
"RATGDOBinarySensor", binary_sensor.BinarySensor, cg.Component
|
||||
)
|
||||
SensorType = ratgdo_ns.enum("SensorType")
|
||||
|
||||
CONF_TYPE = "type"
|
||||
TYPES = {"motion", "obstruction"}
|
||||
TYPES = {
|
||||
"motion": SensorType.RATGDO_SENSOR_MOTION,
|
||||
"obstruction": SensorType.RATGDO_SENSOR_OBSTRUCTION,
|
||||
}
|
||||
|
||||
|
||||
CONFIG_SCHEMA = binary_sensor.binary_sensor_schema(RATGDOBinarySensor).extend(
|
||||
{
|
||||
cv.Required(CONF_TYPE): str
|
||||
cv.Required(CONF_TYPE): cv.enum(TYPES, lower=True),
|
||||
}
|
||||
).extend(RATGDO_CLIENT_SCHMEA)
|
||||
|
||||
|
@ -29,5 +33,5 @@ async def to_code(config):
|
|||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await binary_sensor.register_binary_sensor(var, config)
|
||||
await cg.register_component(var, config)
|
||||
await register_ratgdo_child(var, config)
|
||||
cg.add(var.set_type(var, config[CONF_TYPE]))
|
||||
await register_ratgdo_child(var, config)
|
||||
|
|
|
@ -12,12 +12,14 @@ void RATGDOBinarySensor::dump_config() {
|
|||
ESP_LOGCONFIG(" Type: %s", this->type_);
|
||||
|
||||
}
|
||||
|
||||
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) {}
|
||||
void RATGDOBinarySensor::on_motion_state(esphome::ratgdo::MotionState state) {}
|
||||
void RATGDOBinarySensor::on_obstruction_state(esphome::ratgdo::ObstructionState state) {}
|
||||
void RATGDOBinarySensor::on_motion_state(esphome::ratgdo::MotionState state) {
|
||||
if (this->type_ == SensorType::RATGDO_SENSOR_MOTION)
|
||||
this->publish_state(state == esphome::ratgdo::MotionState::MOTION_STATE_DETECTED);
|
||||
}
|
||||
void RATGDOBinarySensor::on_obstruction_state(esphome::ratgdo::ObstructionState state) {
|
||||
if (this->type_ == SensorType::RATGDO_SENSOR_OBSTRUCTION)
|
||||
this->publish_state(state == esphome::ratgdo::ObstructionState::OBSTRUCTION_STATE_OBSTRUCTED);
|
||||
}
|
||||
} // namespace ratgdo
|
||||
} // namespace esphome
|
||||
|
||||
|
|
|
@ -9,19 +9,21 @@
|
|||
namespace esphome {
|
||||
namespace ratgdo {
|
||||
|
||||
enum SensorType {
|
||||
RATGDO_SENSOR_MOTION,
|
||||
RATGDO_SENSOR_OBSTRUCTION,
|
||||
};
|
||||
|
||||
class RATGDOBinarySensor : public binary_sensor::BinarySensor, public RATGDOClient, public Component {
|
||||
public:
|
||||
void dump_config() override;
|
||||
void set_type(const char *) { this->type_ = type_; }
|
||||
void set_type(SensorType type) { type_ = type_; }
|
||||
|
||||
void on_door_state(esphome::ratgdo::DoorState state) override;
|
||||
void on_light_state(esphome::ratgdo::LightState state) override;
|
||||
void on_lock_state(esphome::ratgdo::LockState state) override;
|
||||
void on_motion_state(esphome::ratgdo::MotionState state) override;
|
||||
void on_obstruction_state(esphome::ratgdo::ObstructionState state) override;
|
||||
|
||||
protected:
|
||||
const char *type_;
|
||||
SensorType type_;
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue