Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NonNasa] Prevent flooding the outdoor unit by registration requests #218

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading