Add NFC enable/disable support; update devices, Sonoff, and Tuya

This commit is contained in:
2026-04-13 21:35:17 +03:00
parent 86bfecca26
commit 5340f88ffe
15 changed files with 843 additions and 175 deletions

View File

@@ -380,3 +380,27 @@ def nfc_enroll(board_id: int):
else:
flash("Card read OK but failed to push config to board.", "danger")
return redirect(url_for("boards.nfc_management", board_id=board_id))
@boards_bp.route("/<int:board_id>/nfc/enable", methods=["POST"])
@login_required
def nfc_enable(board_id: int):
"""Enable or disable the NFC/Mifare access-control module on the board."""
if not current_user.is_admin():
abort(403)
board = db.get_or_404(Board, board_id)
if board.board_type != _NFC_DRIVER_ID:
abort(404)
driver = registry.get(_NFC_DRIVER_ID)
if not driver:
flash("NFC driver not available.", "danger")
return redirect(url_for("boards.nfc_management", board_id=board_id))
enabled = request.form.get("enabled", "0") == "1"
ok = driver.set_nfc_enabled(board, enabled)
if ok:
state_label = "enabled" if enabled else "disabled"
flash(f"NFC access control module {state_label}.", "success")
else:
flash("Failed to change NFC module state — board unreachable.", "danger")
return redirect(url_for("boards.nfc_management", board_id=board_id))