Normalize client_id when manually entered (#97)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
5bd2464588
commit
cdc7780c72
|
@ -5,6 +5,15 @@
|
|||
namespace esphome {
|
||||
namespace ratgdo {
|
||||
|
||||
float normalize_client_id(float client_id)
|
||||
{
|
||||
uint32_t int_value = static_cast<uint32_t>(client_id);
|
||||
if ((int_value & 0xFFF) != 0x539) {
|
||||
client_id = ceil((client_id - 0x539) / 0x1000) * 0x1000 + 0x539;
|
||||
}
|
||||
return client_id;
|
||||
}
|
||||
|
||||
static const char* const TAG = "ratgdo.number";
|
||||
|
||||
void RATGDONumber::dump_config()
|
||||
|
@ -31,8 +40,7 @@ namespace ratgdo {
|
|||
} else {
|
||||
value = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (this->number_type_ == RATGDO_CLIENT_ID) {
|
||||
uint32_t int_value = static_cast<uint32_t>(value);
|
||||
if ((int_value & 0xFFF) != 0x539) {
|
||||
|
@ -41,7 +49,6 @@ namespace ratgdo {
|
|||
}
|
||||
}
|
||||
}
|
||||
this->publish_state(value);
|
||||
this->control(value);
|
||||
|
||||
if (this->number_type_ == RATGDO_ROLLING_CODE_COUNTER) {
|
||||
|
@ -90,6 +97,7 @@ namespace ratgdo {
|
|||
} else if (this->number_type_ == RATGDO_CLOSING_DURATION) {
|
||||
this->parent_->set_closing_duration(value);
|
||||
} else if (this->number_type_ == RATGDO_CLIENT_ID) {
|
||||
value = normalize_client_id(value);
|
||||
this->parent_->set_client_id(value);
|
||||
}
|
||||
this->update_state(value);
|
||||
|
|
Loading…
Reference in New Issue