2023-06-07 23:10:02 +00:00
|
|
|
#include "ratgdo_number.h"
|
|
|
|
#include "../ratgdo_state.h"
|
|
|
|
#include "esphome/core/log.h"
|
|
|
|
|
|
|
|
namespace esphome {
|
|
|
|
namespace ratgdo {
|
|
|
|
|
|
|
|
static const char* const TAG = "ratgdo.number";
|
|
|
|
|
|
|
|
void RATGDONumber::dump_config()
|
|
|
|
{
|
2023-06-07 23:13:38 +00:00
|
|
|
LOG_NUMBER("", "RATGDO Number", this);
|
2023-06-25 23:03:39 +00:00
|
|
|
if (this->number_type_ == RATGDO_ROLLING_CODE_COUNTER) {
|
|
|
|
ESP_LOGCONFIG(TAG, " Type: Rolling Code Counter");
|
|
|
|
} else if (this->number_type_ == RATGDO_OPENING_DURATION) {
|
|
|
|
ESP_LOGCONFIG(TAG, " Type: Opening Duration");
|
|
|
|
} else if (this->number_type_ == RATGDO_CLOSING_DURATION) {
|
|
|
|
ESP_LOGCONFIG(TAG, " Type: Closing Duration");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-25 23:43:00 +00:00
|
|
|
void RATGDONumber::set_number_type(NumberType number_type_)
|
|
|
|
{
|
|
|
|
this->number_type_ = number_type_;
|
2023-06-25 23:03:39 +00:00
|
|
|
if (this->number_type_ == RATGDO_OPENING_DURATION || this->number_type_ == RATGDO_CLOSING_DURATION) {
|
|
|
|
this->traits.set_step(0.1);
|
|
|
|
}
|
2023-06-07 23:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RATGDONumber::on_rolling_code_change(uint32_t rollingCodeCounter)
|
|
|
|
{
|
2023-06-25 23:03:39 +00:00
|
|
|
if (this->number_type_ != RATGDO_ROLLING_CODE_COUNTER) {
|
|
|
|
return;
|
|
|
|
}
|
2023-06-07 23:10:02 +00:00
|
|
|
this->publish_state(rollingCodeCounter);
|
|
|
|
}
|
2023-06-25 23:03:39 +00:00
|
|
|
|
|
|
|
void RATGDONumber::on_opening_duration_change(float duration)
|
|
|
|
{
|
|
|
|
if (this->number_type_ != RATGDO_OPENING_DURATION) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this->publish_state(duration);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RATGDONumber::on_closing_duration_change(float duration)
|
|
|
|
{
|
|
|
|
if (this->number_type_ != RATGDO_CLOSING_DURATION) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this->publish_state(duration);
|
|
|
|
}
|
|
|
|
|
2023-06-07 23:10:02 +00:00
|
|
|
void RATGDONumber::control(float value)
|
|
|
|
{
|
2023-06-25 23:03:39 +00:00
|
|
|
if (this->number_type_ == RATGDO_ROLLING_CODE_COUNTER) {
|
|
|
|
this->parent_->setRollingCodeCounter(value);
|
|
|
|
} else if (this->number_type_ == RATGDO_OPENING_DURATION) {
|
|
|
|
this->parent_->setOpeningDuration(value);
|
|
|
|
} else if (this->number_type_ == RATGDO_CLOSING_DURATION) {
|
|
|
|
this->parent_->setClosingDuration(value);
|
|
|
|
}
|
2023-06-07 23:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace ratgdo
|
|
|
|
} // namespace esphome
|