9static const char *
const TAG =
"nfc.binary_sensor";
12 this->
parent_->register_listener(
this);
17 std::string match_str =
"name";
19 LOG_BINARY_SENSOR(
"",
"NFC Tag Binary Sensor",
this);
22 match_str =
"contains";
24 ESP_LOGCONFIG(TAG,
" Tag %s: %s", match_str.c_str(), this->match_string_.c_str());
28 char uid_buf[FORMAT_BYTES_BUFFER_SIZE];
46 for (
const auto &record : msg->get_records()) {
47 if (record->get_payload().find(this->match_string_) != std::string::npos) {
55 for (
const auto &record : msg->get_records()) {
56 if (record->get_payload().find(HA_TAG_ID_PREFIX) != std::string::npos) {
57 auto rec_substr = record->get_payload().substr(
sizeof(HA_TAG_ID_PREFIX) - 1);
58 if (rec_substr.find(this->match_string_) != std::string::npos) {
67 if (data.
size() != this->uid_.size()) {
71 for (
size_t i = 0; i < data.
size(); i++) {
72 if (data[i] != this->
uid_[i]) {
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...
std::string match_string_
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 std::string &str)
bool tag_match_uid(const NfcTagUid &data)
void set_ndef_match_string(const std::string &str)
void set_uid(const NfcTagUid &uid)
void tag_off(NfcTag &tag) override
bool tag_match_ndef_string(const std::shared_ptr< NdefMessage > &msg)
const std::shared_ptr< NdefMessage > & get_ndef_message()
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.
Providing packet encoding functions for exchanging data with a remote host.