updated to multiple cared on nfc

This commit is contained in:
2026-06-13 10:30:53 +03:00
parent 916e35b22b
commit 61ae9b2431
3 changed files with 136 additions and 48 deletions
@@ -189,27 +189,34 @@ class OlimexESP32C6EVBPn532Driver(BoardDriver):
def set_nfc_config(
self,
board: "Board",
auth_uid: str = "",
auth_uids: list[str] | None = None,
auth_uid: str = "", # legacy single-UID shim — ignored if auth_uids given
relay_num: int = 1,
pulse_ms: int = 3000,
pulse_ms: int = 0,
) -> bool:
"""Push NFC access-control config to the board.
auth_uid: authorized card UID (e.g. "04:AB:CD:EF"); empty = no card authorized.
auth_uids: list of authorized card UIDs (up to 10); empty list = clear all.
relay_num: which relay to open on a matching card (1-4).
pulse_ms: absence timeout — relay closes this many ms after card is removed (100-60000).
pulse_ms: absence timeout ms; 0 = use board default (5 s).
"""
if auth_uids is None:
# backwards-compat: single uid string → list
auth_uids = [auth_uid.upper().strip()] if auth_uid.strip() else []
uids_clean = [u.upper().strip() for u in auth_uids if u.strip()][:10]
uids_param = urllib.parse.quote(",".join(uids_clean))
url = (
f"{board.base_url}/nfc/config"
f"?auth_uid={urllib.parse.quote(auth_uid.upper())}"
f"?auth_uids={uids_param}"
f"&relay={relay_num}"
f"&pulse_ms={pulse_ms}"
)
result = _post(url, _auth(board, "POST", url))
if result:
logger.info(
"NFC config pushed to board '%s': uid='%s' relay=%d pulse=%dms",
board.name, auth_uid, relay_num, pulse_ms,
"NFC config pushed to board '%s': uids=%s relay=%d pulse=%dms",
board.name, uids_clean, relay_num, pulse_ms,
)
else:
logger.warning("NFC config push failed for board '%s'", board.name)