cleanups
This commit is contained in:
parent
4f9bfae7b0
commit
96b59f4a4d
6
base.yml
6
base.yml
|
@ -65,3 +65,9 @@ button:
|
|||
entity_category: diagnostic
|
||||
ratgdo_id: ${id_prefix}
|
||||
name: "${friendly_name} Sync"
|
||||
- platform: ratgdo
|
||||
id: ${id_prefix}_query
|
||||
type: query
|
||||
entity_category: diagnostic
|
||||
ratgdo_id: ${id_prefix}
|
||||
name: "${friendly_name} Query"
|
||||
|
|
|
@ -12,6 +12,7 @@ ButtonType = ratgdo_ns.enum("ButtonType")
|
|||
CONF_TYPE = "type"
|
||||
TYPES = {
|
||||
"sync": ButtonType.RATGDO_SYNC,
|
||||
"query": ButtonType.RATGDO_QUERY,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -10,13 +10,17 @@ namespace ratgdo {
|
|||
void RATGDOButton::dump_config()
|
||||
{
|
||||
LOG_BUTTON("", "RATGDO Button", this);
|
||||
ESP_LOGCONFIG(TAG, " Type: Sync");
|
||||
ESP_LOGCONFIG(TAG, " Type: %s", this->button_type_ == ButtonType::RATGDO_SYNC ? "Sync" : "Query");
|
||||
}
|
||||
|
||||
void RATGDOButton::press_action()
|
||||
{
|
||||
ESP_LOGD(TAG, "name: %s this->type_:%d", this->get_name(), this->button_type_);
|
||||
this->parent_->sync();
|
||||
if (this->button_type_ == ButtonType::RATGDO_SYNC) {
|
||||
this->parent_->sync();
|
||||
} else if (this->button_type_ == ButtonType::RATGDO_QUERY) {
|
||||
this->parent_->query();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ratgdo
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace ratgdo {
|
|||
|
||||
enum ButtonType {
|
||||
RATGDO_SYNC
|
||||
RATGDO_QUERY
|
||||
};
|
||||
|
||||
class RATGDOButton : public button::Button, public RATGDOClient, public Component {
|
||||
|
|
|
@ -419,19 +419,13 @@ namespace ratgdo {
|
|||
|
||||
void RATGDOComponent::statusUpdateLoop()
|
||||
{
|
||||
// initialize to unknown
|
||||
static uint8_t previousDoorState = DoorState::DOOR_STATE_UNKNOWN;
|
||||
static uint8_t previousLightState = LightState::LIGHT_STATE_UNKNOWN;
|
||||
static uint8_t previousLockState = LockState::LOCK_STATE_UNKNOWN;
|
||||
static uint8_t previousObstructionState = ObstructionState::OBSTRUCTION_STATE_UNKNOWN;
|
||||
|
||||
if (this->store_.doorState != previousDoorState)
|
||||
if (this->store_.doorState != this->previousDoorState)
|
||||
sendDoorStatus();
|
||||
if (this->store_.lightState != previousLightState)
|
||||
if (this->store_.lightState != this->previousLightState)
|
||||
sendLightStatus();
|
||||
if (this->store_.lockState != previousLockState)
|
||||
if (this->store_.lockState != this->previousLockState)
|
||||
sendLockStatus();
|
||||
if (this->store_.obstructionState != previousObstructionState)
|
||||
if (this->store_.obstructionState != this->previousObstructionState)
|
||||
sendObstructionStatus();
|
||||
|
||||
if (this->store_.motionState == MotionState::MOTION_STATE_DETECTED) {
|
||||
|
@ -439,10 +433,18 @@ namespace ratgdo {
|
|||
this->store_.motionState = MotionState::MOTION_STATE_CLEAR;
|
||||
}
|
||||
|
||||
previousDoorState = this->store_.doorState;
|
||||
previousLightState = this->store_.lightState;
|
||||
previousLockState = this->store_.lockState;
|
||||
previousObstructionState = this->store_.obstructionState;
|
||||
this->previousDoorState = this->store_.doorState;
|
||||
this->previousLightState = this->store_.lightState;
|
||||
this->previousLockState = this->store_.lockState;
|
||||
this->previousObstructionState = this->store_.obstructionState;
|
||||
}
|
||||
|
||||
void RATGDOComponent::query()
|
||||
{
|
||||
this->previousDoorState = DoorState::DOOR_STATE_UNKNOWN;
|
||||
this->previousLightState = LightState::LIGHT_STATE_UNKNOWN;
|
||||
this->previousLockState = LockState::LOCK_STATE_UNKNOWN;
|
||||
sendCommandAndSaveCounter(Commands::REBOOT2);
|
||||
}
|
||||
|
||||
void RATGDOComponent::sendDoorStatus()
|
||||
|
|
|
@ -82,6 +82,11 @@ namespace ratgdo {
|
|||
uint8_t txRollingCode[CODE_LENGTH];
|
||||
uint8_t rxRollingCode[CODE_LENGTH];
|
||||
|
||||
uint8_t previousDoorState { DoorState::DOOR_STATE_UNKNOWN };
|
||||
uint8_t previousLightState { LightState::LIGHT_STATE_UNKNOWN };
|
||||
uint8_t previousLockState { LockState::LOCK_STATE_UNKNOWN };
|
||||
uint8_t previousObstructionState { ObstructionState::OBSTRUCTION_STATE_UNKNOWN };
|
||||
|
||||
void set_output_gdo_pin(InternalGPIOPin* pin) { this->output_gdo_pin_ = pin; };
|
||||
void set_input_gdo_pin(InternalGPIOPin* pin) { this->input_gdo_pin_ = pin; };
|
||||
void set_input_obst_pin(InternalGPIOPin* pin) { this->input_obst_pin_ = pin; };
|
||||
|
@ -118,7 +123,7 @@ namespace ratgdo {
|
|||
void sendLockStatus();
|
||||
|
||||
void sendMotionStatus();
|
||||
|
||||
void query();
|
||||
void doorStateLoop();
|
||||
void dryContactLoop();
|
||||
void printRollingCode();
|
||||
|
|
Loading…
Reference in New Issue