diff --git a/base.yml b/base.yml index e7e4e66..d0f1717 100644 --- a/base.yml +++ b/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" diff --git a/components/ratgdo/button/__init__.py b/components/ratgdo/button/__init__.py index a75b332..087fd95 100644 --- a/components/ratgdo/button/__init__.py +++ b/components/ratgdo/button/__init__.py @@ -12,6 +12,7 @@ ButtonType = ratgdo_ns.enum("ButtonType") CONF_TYPE = "type" TYPES = { "sync": ButtonType.RATGDO_SYNC, + "query": ButtonType.RATGDO_QUERY, } diff --git a/components/ratgdo/button/ratgdo_button.cpp b/components/ratgdo/button/ratgdo_button.cpp index f441802..a6c4cf6 100644 --- a/components/ratgdo/button/ratgdo_button.cpp +++ b/components/ratgdo/button/ratgdo_button.cpp @@ -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 diff --git a/components/ratgdo/button/ratgdo_button.h b/components/ratgdo/button/ratgdo_button.h index 41f60cd..34111af 100644 --- a/components/ratgdo/button/ratgdo_button.h +++ b/components/ratgdo/button/ratgdo_button.h @@ -11,6 +11,7 @@ namespace ratgdo { enum ButtonType { RATGDO_SYNC + RATGDO_QUERY }; class RATGDOButton : public button::Button, public RATGDOClient, public Component { diff --git a/components/ratgdo/ratgdo.cpp b/components/ratgdo/ratgdo.cpp index 2f15441..cdfcc1b 100644 --- a/components/ratgdo/ratgdo.cpp +++ b/components/ratgdo/ratgdo.cpp @@ -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() diff --git a/components/ratgdo/ratgdo.h b/components/ratgdo/ratgdo.h index 40a37ab..c86d061 100644 --- a/components/ratgdo/ratgdo.h +++ b/components/ratgdo/ratgdo.h @@ -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();