From 522e90f43048f9f2fb30b3d8f35c101a05c02bac Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 7 Jun 2023 12:01:36 -0500 Subject: [PATCH] binary sensor --- components/ratgdo/cover/ratgdo_cover.cpp | 27 +++++++++++++++--------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/components/ratgdo/cover/ratgdo_cover.cpp b/components/ratgdo/cover/ratgdo_cover.cpp index 119a306..64b6e08 100644 --- a/components/ratgdo/cover/ratgdo_cover.cpp +++ b/components/ratgdo/cover/ratgdo_cover.cpp @@ -1,6 +1,6 @@ +#include "ratgdo_cover.h" #include "../ratgdo_state.h" #include "esphome/core/log.h" -#include "ratgdo_cover.h" namespace esphome { namespace ratgdo { @@ -17,16 +17,23 @@ namespace ratgdo { void RATGDOCover::on_obstruction_state(esphome::ratgdo::ObstructionState state) { } void RATGDOCover::on_door_state(esphome::ratgdo::DoorState state) { - - if (state == esphome::ratgdo::DoorState::DOOR_STATE_OPEN) + switch (state) { + case esphome::ratgdo::DoorState::DOOR_STATE_OPEN: this->position = COVER_OPEN; - this->current_operation = COVER_OPERATION_IDLE; - else if (state == esphome::ratgdo::DoorState::DOOR_STATE_CLOSED) this->position = COVER_CLOSED; - this->current_operation = COVER_OPERATION_IDLE; - else if (state == esphome::ratgdo::DoorState::DOOR_STATE_OPENING) this->current_operation = COVER_OPERATION_OPENING; - else if (state == esphome::ratgdo::DoorState::DOOR_STATE_CLOSING) this->current_operation = COVER_OPERATION_CLOSING; - else if (state == esphome::ratgdo::DoorState::DOOR_STATE_STOPPED) this->current_operation = COVER_OPERATION_IDLE; - else this->current_operation = COVER_OPERATION_IDLE; + this->current_operation = COVER_OPERATION_IDLE; + case esphome::ratgdo::DoorState::DOOR_STATE_CLOSED: + this->position = COVER_CLOSED; + this->current_operation = COVER_OPERATION_IDLE; + case esphome::ratgdo::DoorState::DOOR_STATE_OPENING: + this->current_operation = COVER_OPERATION_OPENING; + case esphome::ratgdo::DoorState::DOOR_STATE_CLOSING: + this->current_operation = COVER_OPERATION_CLOSING; + case esphome::ratgdo::DoorState::DOOR_STATE_STOPPED: + default: + this->current_operation = COVER_OPERATION_IDLE; + + break; + } this->publish_state(); }