Add Tuya Cloud integration; 2-step add-board wizard; DP value formatting

- Tuya Cloud Gateway driver (tuya-device-sharing-sdk):
  - QR-code auth flow: user-provided user_code, terminal_id/endpoint
    returned by Tuya login_result (mirrors HA implementation)
  - Device sync, toggle DP, rename, per-device detail page
  - category → kind mapping; detect_switch_dps helper
  - format_dp_value: temperature (÷10 + °C/°F), humidity (+ %)
    registered as 'tuya_dp' Jinja2 filter

- TuyaDevice model (tuya_devices table)

- Templates:
  - tuya/gateway.html: device grid with live-reading sensor cards
    (config/threshold keys hidden from card, shown on detail page)
  - tuya/device.html: full status table with formatted DP values
  - tuya/auth_settings.html: user_code input + QR scan flow

- Add-board wizard refactored to 2-step flow:
  - Step 1: choose board type (Cloud Gateways vs Hardware)
  - Step 2: type-specific fields; gateways skip IP/relay fields

- Layout builder: Tuya chip support (makeTuyaChip, tuya_update socket)

- requirements.txt: tuya-device-sharing-sdk, cryptography
This commit is contained in:
ske087
2026-02-27 16:06:48 +02:00
parent 90cbf4e1f0
commit 1e89323035
19 changed files with 1873 additions and 84 deletions

View File

@@ -32,9 +32,11 @@ def list_boards():
@login_required
def board_detail(board_id: int):
board = db.get_or_404(Board, board_id)
# Sonoff eWeLink gateway boards have their own page
# Gateway boards have their own dedicated page
if board.board_type == "sonoff_ewelink":
return redirect(url_for("sonoff.gateway", board_id=board_id))
if board.board_type == "tuya_cloud":
return redirect(url_for("tuya.gateway", board_id=board_id))
# Refresh states from device
poll_board(current_app._get_current_object(), board_id)
board = db.session.get(Board, board_id)
@@ -57,14 +59,17 @@ def add_board():
num_relays = int(request.form.get("num_relays", 4))
num_inputs = int(request.form.get("num_inputs", 4))
# Sonoff gateway doesn't need a real host address
is_gateway = board_type == "sonoff_ewelink"
# Gateway boards don't need a real host address
is_gateway = board_type in ("sonoff_ewelink", "tuya_cloud")
if not name or (not host and not is_gateway):
flash("Name and host are required.", "danger")
return render_template("boards/add.html", board_types=_board_types(), drivers=registry.all())
if is_gateway:
host = host or "ewelink.cloud"
if board_type == "tuya_cloud":
host = host or "openapi.tuyaeu.com"
else:
host = host or "ewelink.cloud"
num_relays = 0
num_inputs = 0
@@ -84,6 +89,11 @@ def add_board():
register_webhook(board, server_url)
flash(f"Board '{name}' added successfully.", "success")
# Send gateway boards straight to their auth/settings page
if board_type == "sonoff_ewelink":
return redirect(url_for("sonoff.auth_settings", board_id=board.id))
if board_type == "tuya_cloud":
return redirect(url_for("tuya.auth_settings", board_id=board.id))
return redirect(url_for("boards.board_detail", board_id=board.id))
return render_template("boards/add.html", board_types=_board_types(), drivers=registry.all())