1 #include "binary_sensor.h" 2 #include "../nfc_helpers.h" 8 static const char *
const TAG =
"nfc.binary_sensor";
11 this->
parent_->register_listener(
this);
16 std::string match_str =
"name";
18 LOG_BINARY_SENSOR(
"",
"NFC Tag Binary Sensor",
this);
21 match_str =
"contains";
23 ESP_LOGCONFIG(TAG,
" Tag %s: %s", match_str.c_str(), this->
match_string_.c_str());
26 if (!this->
uid_.empty()) {
44 for (
const auto &record : msg->get_records()) {
45 if (record->get_payload().find(this->
match_string_) != std::string::npos) {
53 for (
const auto &record : msg->get_records()) {
54 if (record->get_payload().find(HA_TAG_ID_PREFIX) != std::string::npos) {
55 auto rec_substr = record->get_payload().substr(
sizeof(HA_TAG_ID_PREFIX) - 1);
56 if (rec_substr.find(this->match_string_) != std::string::npos) {
65 if (data.size() != this->
uid_.size()) {
69 for (
size_t i = 0; i < data.size(); i++) {
70 if (data[i] != this->
uid_[i]) {
void publish_initial_state(bool state)
Publish the initial state, this will not make the callback manager send callbacks and is meant only f...
const std::shared_ptr< NdefMessage > & get_ndef_message()
std::vector< uint8_t > uid_
void set_ndef_match_string(const std::string &str)
void dump_config() override
void set_uid(const std::vector< uint8_t > &uid)
bool tag_match_ndef_string(const std::shared_ptr< NdefMessage > &msg)
void publish_state(bool state)
Publish a new state to the front-end.
std::vector< uint8_t > & get_uid()
bool tag_match_tag_name(const std::shared_ptr< NdefMessage > &msg)
std::string match_string_
void set_tag_name(const std::string &str)
void tag_on(NfcTag &tag) override
void tag_off(NfcTag &tag) override
bool tag_match_uid(const std::vector< uint8_t > &data)
Implementation of SPI Controller mode.
std::string format_bytes(std::vector< uint8_t > &bytes)