Merge remote-tracking branch 'upstream/dev' into integration

This commit is contained in:
J. Nick Koston
2026-01-26 20:35:17 -10:00
5 changed files with 17 additions and 8 deletions

View File

@@ -1,5 +1,9 @@
<<<<<<< HEAD
<<<<<<< HEAD
a172e2f65981e98354cc6b5ecf69bdb055dd13602226042ab2c7acd037a2bf41
=======
d565b0589e35e692b5f2fc0c14723a99595b4828a3a3ef96c442e86a23176c00
>>>>>>> mqtt_enum_flash
=======
a172e2f65981e98354cc6b5ecf69bdb055dd13602226042ab2c7acd037a2bf41
>>>>>>> upstream/dev

View File

@@ -1,6 +1,7 @@
#pragma once
#include <memory>
#include <vector>
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
@@ -16,20 +17,20 @@ using NfcTagUid = StaticVector<uint8_t, NFC_UID_MAX_LENGTH>;
class NfcTag {
public:
NfcTag() { this->tag_type_ = "Unknown"; };
NfcTag(NfcTagUid &uid) {
NfcTag(const NfcTagUid &uid) {
this->uid_ = uid;
this->tag_type_ = "Unknown";
};
NfcTag(NfcTagUid &uid, const std::string &tag_type) {
NfcTag(const NfcTagUid &uid, const std::string &tag_type) {
this->uid_ = uid;
this->tag_type_ = tag_type;
};
NfcTag(NfcTagUid &uid, const std::string &tag_type, std::unique_ptr<nfc::NdefMessage> ndef_message) {
NfcTag(const NfcTagUid &uid, const std::string &tag_type, std::unique_ptr<nfc::NdefMessage> ndef_message) {
this->uid_ = uid;
this->tag_type_ = tag_type;
this->ndef_message_ = std::move(ndef_message);
};
NfcTag(NfcTagUid &uid, const std::string &tag_type, std::vector<uint8_t> &ndef_data) {
NfcTag(const NfcTagUid &uid, const std::string &tag_type, std::vector<uint8_t> &ndef_data) {
this->uid_ = uid;
this->tag_type_ = tag_type;
this->ndef_message_ = make_unique<NdefMessage>(ndef_data);

View File

@@ -168,11 +168,11 @@ void PN532::loop() {
}
uint8_t nfcid_length = read[5];
nfc::NfcTagUid nfcid(read.begin() + 6, read.begin() + 6 + nfcid_length);
if (read.size() < 6U + nfcid_length) {
if (nfcid_length > nfc::NFC_UID_MAX_LENGTH || read.size() < 6U + nfcid_length) {
// oops, pn532 returned invalid data
return;
}
nfc::NfcTagUid nfcid(read.begin() + 6, read.begin() + 6 + nfcid_length);
bool report = true;
for (auto *bin_sens : this->binary_sensors_) {
@@ -448,7 +448,7 @@ void PN532::dump_config() {
}
}
bool PN532BinarySensor::process(nfc::NfcTagUid &data) {
bool PN532BinarySensor::process(const nfc::NfcTagUid &data) {
if (data.size() != this->uid_.size())
return false;

View File

@@ -120,7 +120,7 @@ class PN532BinarySensor : public binary_sensor::BinarySensor {
public:
void set_uid(const nfc::NfcTagUid &uid) { uid_ = uid; }
bool process(nfc::NfcTagUid &data);
bool process(const nfc::NfcTagUid &data);
void on_scan_end() {
if (!this->found_) {

View File

@@ -291,6 +291,10 @@ template<typename T, size_t N> class StaticVector {
reverse_iterator rend() { return reverse_iterator(begin()); }
const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
// Conversion to std::span for compatibility with span-based APIs
operator std::span<T>() { return std::span<T>(data_.data(), count_); }
operator std::span<const T>() const { return std::span<const T>(data_.data(), count_); }
};
/// Fixed-capacity vector - allocates once at runtime, never reallocates