Skip to content

Commit

Permalink
Update protocol_non_nasa.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
tristone-cz authored Nov 5, 2024
1 parent 5094a53 commit c1727e9
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions components/samsung_ac/protocol_non_nasa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ namespace esphome
{
std::list<NonNasaRequestQueueItem> nonnasa_requests;
bool controller_registered = false;
bool controller_register_allow = false;
bool indoor_unit_awake = true;

uint32_t start_millis = millis();
uint32_t registration_interval = 2000;

uint8_t build_checksum(std::vector<uint8_t> &data)
{
uint8_t sum = data[1];
Expand Down Expand Up @@ -648,14 +652,22 @@ namespace esphome
{
// If we're not currently registered, keep sending a registration request until it has
// been confirmed by the outdoor unit.
const uint32_t now = millis();
if (!controller_registered)
{
send_register_controller(target);
// Prevent registration flooding and send the registration request in a reasonable interval
if (now - start_millis >= registration_interval) {
controller_register_allow = true;
}
if (controller_register_allow) {
send_register_controller(target);
controller_register_allow = false;
start_millis = millis();
}
}

// If we have *any* messages in the queue for longer than 15s, assume failure and
// remove from queue (the AC or UART connection is likely offline).
const uint32_t now = millis();
nonnasa_requests.remove_if([&](const NonNasaRequestQueueItem &item)
{ return now - item.time > 15000; });

Expand Down

0 comments on commit c1727e9

Please sign in to comment.