motor
This commit is contained in:
parent
467312da81
commit
ef994dfc4e
6
base.yml
6
base.yml
|
@ -20,6 +20,12 @@ binary_sensor:
|
|||
ratgdo_id: ${id_prefix}
|
||||
name: "${friendly_name} Obstruction"
|
||||
device_class: problem
|
||||
- platform: ratgdo
|
||||
type: motor
|
||||
id: ${id_prefix}_motor
|
||||
ratgdo_id: ${id_prefix}
|
||||
name: "${friendly_name} Motor"
|
||||
device_class: running
|
||||
|
||||
number:
|
||||
- platform: ratgdo
|
||||
|
|
|
@ -16,7 +16,13 @@ namespace ratgdo {
|
|||
void RATGDOBinarySensor::dump_config()
|
||||
{
|
||||
LOG_BINARY_SENSOR("", "RATGDO BinarySensor", this);
|
||||
ESP_LOGCONFIG(TAG, " Type: %s", this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_MOTION ? "Motion" : "Obstruction");
|
||||
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");
|
||||
}
|
||||
}
|
||||
void RATGDOBinarySensor::on_motion_state(MotionState state)
|
||||
{
|
||||
|
@ -30,6 +36,12 @@ namespace ratgdo {
|
|||
if (this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_OBSTRUCTION)
|
||||
this->publish_state(state == ObstructionState::OBSTRUCTION_STATE_OBSTRUCTED);
|
||||
}
|
||||
void RATGDOBinarySensor::on_motor_state(MotorState state)
|
||||
{
|
||||
ESP_LOGD(TAG, "name: %s this->type_:%d on_motor_state: %d", this->get_name(), this->binary_sensor_type_, state);
|
||||
if (this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_MOTOR)
|
||||
this->publish_state(state == MotorState::MOTOR_STATE_ON);
|
||||
}
|
||||
|
||||
} // namespace ratgdo
|
||||
} // namespace esphome
|
||||
|
|
|
@ -12,6 +12,7 @@ namespace ratgdo {
|
|||
enum SensorType {
|
||||
RATGDO_SENSOR_MOTION,
|
||||
RATGDO_SENSOR_OBSTRUCTION,
|
||||
RATGDO_SENSOR_MOTOR
|
||||
};
|
||||
|
||||
class RATGDOBinarySensor : public binary_sensor::BinarySensor, public RATGDOClient, public Component {
|
||||
|
|
|
@ -159,7 +159,7 @@ namespace ratgdo {
|
|||
ESP_LOGCONFIG(TAG, " Rolling Code Counter: %d", this->rollingCodeCounter);
|
||||
}
|
||||
|
||||
void RATGDOComponent::readRollingCode(uint8_t& door, uint8_t& light, uint8_t& lock, uint8_t& motion, uint8_t& obstruction)
|
||||
void RATGDOComponent::readRollingCode(uint8_t& door, uint8_t& light, uint8_t& lock, uint8_t& motion, uint8_t& obstruction, uint8_t& motor)
|
||||
{
|
||||
uint32_t rolling = 0;
|
||||
uint64_t fixed = 0;
|
||||
|
@ -184,6 +184,7 @@ namespace ratgdo {
|
|||
light = (byte2 >> 1) & 1;
|
||||
lock = byte2 & 1;
|
||||
motion = 0; // when the status message is read, reset motion state to 0|clear
|
||||
motor = 0; // when the status message is read, reset motor state to 0|off
|
||||
// obstruction = (byte1 >> 6) & 1; // unreliable due to the time it takes to register an obstruction
|
||||
ESP_LOGD(TAG, "Door: %d Light: %d Lock: %d Motion: %d Obstruction: %d", door, light, lock, motion, obstruction);
|
||||
if (this->forceUpdate_) {
|
||||
|
@ -198,6 +199,8 @@ namespace ratgdo {
|
|||
ESP_LOGD(TAG, "Light: %d (toggle)", light);
|
||||
} else if (cmd == 0x84) {
|
||||
ESP_LOGD(TAG, "Unknown 0x84");
|
||||
} else if (cmd == 0x284) {
|
||||
motor = 1;
|
||||
} else if (cmd == 0x280) {
|
||||
ESP_LOGD(TAG, "Pressed: %s", byte1 == 1 ? "pressed" : "released");
|
||||
} else if (cmd == 0x48c) {
|
||||
|
@ -427,7 +430,7 @@ namespace ratgdo {
|
|||
msgStart = 0;
|
||||
byteCount = 0;
|
||||
|
||||
readRollingCode(this->doorState, this->lightState, this->lockState, this->motionState, this->obstructionState);
|
||||
readRollingCode(this->doorState, this->lightState, this->lockState, this->motionState, this->obstructionState, this->motorState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -497,6 +500,15 @@ namespace ratgdo {
|
|||
}
|
||||
}
|
||||
|
||||
void RATGDOComponent::sendMotorStatus()
|
||||
{
|
||||
MotorState val = static_cast<MotorState>(this->MotorState);
|
||||
ESP_LOGD(TAG, "Motor state %s", motor_state_to_string(val));
|
||||
for (auto* child : this->children_) {
|
||||
child->on_motor_state(val);
|
||||
}
|
||||
}
|
||||
|
||||
void RATGDOComponent::sendObstructionStatus()
|
||||
{
|
||||
ObstructionState val = static_cast<ObstructionState>(this->obstructionState);
|
||||
|
|
|
@ -124,6 +124,7 @@ namespace ratgdo {
|
|||
void sendLockStatus();
|
||||
|
||||
void sendMotionStatus();
|
||||
void sendMotorStatus();
|
||||
void query();
|
||||
void doorStateLoop();
|
||||
void dryContactLoop();
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace ratgdo {
|
|||
void RATGDOClient::on_lock_state(LockState state) {};
|
||||
void RATGDOClient::on_motion_state(MotionState state) {};
|
||||
void RATGDOClient::on_obstruction_state(ObstructionState state) {};
|
||||
void RATGDOClient::on_motor_state(MotorState state) {};
|
||||
void RATGDOClient::on_rolling_code_change(uint32_t rollingCodeCounter) {};
|
||||
|
||||
} // namespace ratgdo
|
||||
|
|
|
@ -18,6 +18,7 @@ namespace ratgdo {
|
|||
virtual void on_lock_state(LockState state);
|
||||
virtual void on_motion_state(MotionState state);
|
||||
virtual void on_obstruction_state(ObstructionState state);
|
||||
virtual void on_motor_state(MotorState state);
|
||||
virtual void on_rolling_code_change(uint32_t rollingCodeCounter);
|
||||
|
||||
protected:
|
||||
|
|
|
@ -54,15 +54,25 @@ namespace ratgdo {
|
|||
const char* motion_state_to_string(MotionState state)
|
||||
{
|
||||
switch (state) {
|
||||
case MOTION_STATE_CLEAR:
|
||||
return "CLEAR";
|
||||
case MOTION_STATE_DETECTED:
|
||||
return "DETECTED";
|
||||
case MOTION_STATE_CLEAR:
|
||||
default:
|
||||
return "CLEAR";
|
||||
}
|
||||
}
|
||||
|
||||
const char* motor_state_to_string(MotorState state)
|
||||
{
|
||||
switch (state) {
|
||||
case MOTOR_STATE_ON:
|
||||
return "ON";
|
||||
case MOTOR_STATE_OFF:
|
||||
default:
|
||||
return "OFF";
|
||||
}
|
||||
}
|
||||
|
||||
const char* obstruction_state_to_string(ObstructionState state)
|
||||
{
|
||||
switch (state) {
|
||||
|
|
|
@ -62,5 +62,11 @@ namespace ratgdo {
|
|||
};
|
||||
const char* obstruction_state_to_string(ObstructionState state);
|
||||
|
||||
/// Enum for all states a the motor can be in.
|
||||
enum MotorState : uint8_t {
|
||||
MOTOR_STATE_OFF = 0,
|
||||
MOTOR_STATE_ON = 1,
|
||||
};
|
||||
|
||||
} // namespace ratgdo
|
||||
} // namespace esphome
|
Loading…
Reference in New Issue