13 LOG_BINARY_SENSOR(
"",
"NFC Tag Binary Sensor",
this);
15 ESP_LOGCONFIG(TAG,
" Tag %s: %s", this->
match_tag_name_ ? LOG_STR_LITERAL(
"name") : LOG_STR_LITERAL(
"contains"),
20 char uid_buf[FORMAT_BYTES_BUFFER_SIZE];
38 for (
const auto &record : msg->get_records()) {
39 if (record->get_payload().find(this->match_string_.c_str(), 0, this->match_string_.size()) != std::string::npos) {
47 for (
const auto &record : msg->get_records()) {
48 if (record->get_payload().find(HA_TAG_ID_PREFIX) != std::string::npos) {
49 auto rec_substr = record->get_payload().substr(
sizeof(HA_TAG_ID_PREFIX) - 1);
50 if (rec_substr.find(this->match_string_.c_str(), 0, this->match_string_.size()) != std::string::npos) {
59 if (data.size() != this->uid_.size()) {
63 for (
size_t i = 0; i < data.size(); i++) {
64 if (data[i] != this->
uid_[i]) {
StringRef is a reference to a string owned by something else.
constexpr const char * c_str() const
constexpr bool empty() const
void publish_state(bool new_state)
Publish a new state to the front-end.
void publish_initial_state(bool new_state)
Publish the initial state, this will not make the callback manager send callbacks and is meant only f...
void dump_config() override
bool tag_match_tag_name(const std::shared_ptr< NdefMessage > &msg)
void tag_on(NfcTag &tag) override
void set_tag_name(const char *str)
void set_ndef_match_string(const char *str)
bool tag_match_uid(const NfcTagUid &data)
void set_uid(const NfcTagUid &uid)
void tag_off(NfcTag &tag) override
bool tag_match_ndef_string(const std::shared_ptr< NdefMessage > &msg)
bool has_ndef_message() const
const std::shared_ptr< NdefMessage > & get_ndef_message() const
char * format_bytes_to(char *buffer, std::span< const uint8_t > bytes)
Format bytes to buffer with ' ' separator (e.g., "04 11 22 33"). Returns buffer for inline use.
ESPHOME_LOG_TAG(TAG, "nfc.binary_sensor")