9 Commits

Author SHA1 Message Date
fbf5802c69 Fix board registration blocked by HMAC auth
- /register endpoint no longer requires verifyAPIRequest() - it is
  the bootstrap handshake and api_secret cannot be set before it runs
- Add api_secret field to the Add Board form (hardware boards only)
  with a cryptographic Generate button, same as the Edit form
- Save api_secret from the add-board POST so the driver can sign
  requests immediately after registration
2026-03-15 16:12:18 +02:00
36de1623c2 Add HMAC-SHA256 API authentication to board drivers and edit UI
- Both olimex_esp32_c6_evb and olimex_esp32_c6_evb_pn532 drivers now
  sign every API request with X-Request-Time / X-Request-Sig headers
  using HMAC-SHA256(api_secret, METHOD:path:unix_timestamp)
- Board model gains api_secret column (nullable, default None)
- boards.py edit route saves api_secret from form
- edit.html adds API Secret input with cryptographic Generate button
- If api_secret is empty/None, headers are omitted (backward compat)
2026-03-15 12:33:45 +02:00
1152f93a00 Add Olimex ESP32-C6-EVB + PN532 NFC driver and web UI
- New driver: app/drivers/olimex_esp32_c6_evb_pn532/
  - Full relay/input control (inherits base behaviour)
  - get_nfc_status(), get_nfc_config(), set_nfc_config() methods
  - manifest.json with NFC hardware metadata (UEXT1 pins, card standard)

- NFC management routes (boards.py):
  - GET  /boards/<id>/nfc            — management page
  - GET  /boards/<id>/nfc/status_json — live JSON (polled every 3 s)
  - POST /boards/<id>/nfc/config     — save auth UID / relay / timeout
  - POST /boards/<id>/nfc/enroll     — enrol last-seen card with one click

- New template: templates/boards/nfc.html
  - Live reader status (PN532 ready, access state, last UID)
  - Quick Enroll: present card → Refresh → Enrol in one click
  - Manual Settings: type/paste UID, pick relay, set absence timeout

- detail.html: NFC Access Control button shown for pn532 board type
2026-03-15 09:41:01 +02:00
4766faa682 Add NFC access control support to Olimex ESP32-C6-EVB driver
- Add get_nfc_status() to retrieve NFC reader state (last UID, access state, auth config)
- Add set_nfc_config() to push NFC access-control config (auth_uid, relay_num, pulse_ms)
- Update API endpoint documentation in module docstring
2026-03-15 08:46:35 +02:00
ske087
b4db41a400 Fix offline board flooding: fail-fast probe in hardware driver poll()
All three hardware drivers (Olimex, generic_esp32, generic_esp8266) now
probe with the first request and bail immediately on failure.

Before: offline board with 4 relays + 3 inputs = 7 requests × 3 s timeout
        = up to 21 s of blocking + 7 log lines per recheck cycle.
After:  exactly 1 request × 3 s timeout regardless of I/O count.
2026-02-27 16:20:10 +02:00
ske087
1e89323035 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
2026-02-27 16:06:48 +02:00
ske087
90cbf4e1f0 Add Layouts module with Konva.js builder; smart offline polling; UI improvements
- Move board cards from dashboard to top of boards list page
- Fix Werkzeug duplicate polling (WERKZEUG_RUN_MAIN guard)
- Smart offline polling: fast loop for online boards, slow recheck for offline
- Add manual ping endpoint POST /api/boards/<id>/ping
- Add spin animation CSS for ping button

Layouts module (new):
- app/models/layout.py: Layout model (canvas_json, thumbnail_b64)
- app/routes/layouts.py: 5 routes (list, create, builder, save, delete)
- app/templates/layouts/: list and builder templates
- app/static/js/layout_builder.js: full Konva.js builder engine
- app/static/vendor/konva/: vendored Konva.js 9
- Structure mode: wall, room, door, window, fence, text shapes
- Devices mode: drag relay/input/Sonoff channels onto canvas
- Live view mode: click relays/Sonoff to toggle, socket.io state updates
- Device selection: click to select, remove individual device, Delete key
- Fix door/Arc size persistence across save/reload (outerRadius, scaleX/Y)
- Fix Sonoff devices missing from palette (add makeSonoffChip function)
2026-02-27 13:34:44 +02:00
ske087
30806560a6 Fix SonoffLAN signing key: hardcode pre-computed HMAC key
The previous _compute_sign_key() function indexed into a base64 string
derived from the full SonoffLAN REGIONS dict (~243 entries). Our partial
dict only produced a 7876-char a string but needed index 7872+, so the
function must use the full dict.

Solution: pre-compute the key once from the full dict and hardcode the
resulting 32-byte ASCII key. This is deterministic — the SonoffLAN
algorithm always produces the same output regardless of when it runs.

The sonoff_ewelink driver now loads cleanly alongside all other drivers.
2026-02-26 20:13:07 +02:00
ske087
7a22575dab Initial commit: Location Management Flask app 2026-02-26 19:24:17 +02:00