From 2e167835ead5cc85d3507d0f262695ed112d5729 Mon Sep 17 00:00:00 2001 From: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> Date: Wed, 25 Feb 2026 15:15:49 -0500 Subject: [PATCH] [pn532] Replace millis zero sentinel with optional (#14295) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- esphome/components/pn532/pn532.cpp | 8 ++++---- esphome/components/pn532/pn532.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/esphome/components/pn532/pn532.cpp b/esphome/components/pn532/pn532.cpp index 1ab0da3df7..199a44dacc 100644 --- a/esphome/components/pn532/pn532.cpp +++ b/esphome/components/pn532/pn532.cpp @@ -308,13 +308,13 @@ void PN532::send_nack_() { enum PN532ReadReady PN532::read_ready_(bool block) { if (this->rd_ready_ == READY) { if (block) { - this->rd_start_time_ = 0; + this->rd_start_time_.reset(); this->rd_ready_ = WOULDBLOCK; } return READY; } - if (!this->rd_start_time_) { + if (!this->rd_start_time_.has_value()) { this->rd_start_time_ = millis(); } @@ -324,7 +324,7 @@ enum PN532ReadReady PN532::read_ready_(bool block) { break; } - if (millis() - this->rd_start_time_ > 100) { + if (millis() - *this->rd_start_time_ > 100) { ESP_LOGV(TAG, "Timed out waiting for readiness from PN532!"); this->rd_ready_ = TIMEOUT; break; @@ -340,7 +340,7 @@ enum PN532ReadReady PN532::read_ready_(bool block) { auto rdy = this->rd_ready_; if (block || rdy == TIMEOUT) { - this->rd_start_time_ = 0; + this->rd_start_time_.reset(); this->rd_ready_ = WOULDBLOCK; } return rdy; diff --git a/esphome/components/pn532/pn532.h b/esphome/components/pn532/pn532.h index f98c0f9322..e57ecd8104 100644 --- a/esphome/components/pn532/pn532.h +++ b/esphome/components/pn532/pn532.h @@ -99,7 +99,7 @@ class PN532 : public PollingComponent { std::vector triggers_ontagremoved_; nfc::NfcTagUid current_uid_; nfc::NdefMessage *next_task_message_to_write_; - uint32_t rd_start_time_{0}; + optional rd_start_time_{}; enum PN532ReadReady rd_ready_ { WOULDBLOCK }; enum NfcTask { READ = 0,