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.
This commit is contained in:
ske087
2026-02-26 20:13:07 +02:00
parent 7a22575dab
commit 30806560a6
17 changed files with 1864 additions and 19 deletions

View File

@@ -35,6 +35,7 @@ def create_app(config_name: str = "default") -> Flask:
from app.routes.workflows import workflows_bp
from app.routes.api import api_bp
from app.routes.admin import admin_bp
from app.routes.sonoff import sonoff_bp
app.register_blueprint(auth_bp)
app.register_blueprint(dashboard_bp)
@@ -42,6 +43,7 @@ def create_app(config_name: str = "default") -> Flask:
app.register_blueprint(workflows_bp, url_prefix="/workflows")
app.register_blueprint(api_bp, url_prefix="/api")
app.register_blueprint(admin_bp, url_prefix="/admin")
app.register_blueprint(sonoff_bp)
# ── user loader ───────────────────────────────────────────────────────────
from app.models.user import User
@@ -57,9 +59,13 @@ def create_app(config_name: str = "default") -> Flask:
# ── create tables & seed admin on first run ───────────────────────────────
with app.app_context():
# Import all models so their tables are registered before create_all
from app.models import board, user, workflow # noqa: F401
from app.models import sonoff_device # noqa: F401
db.create_all()
_seed_admin(app)
_add_entities_column(app)
_add_config_json_column(app)
_migrate_board_types(app)
return app
@@ -77,6 +83,18 @@ def _add_entities_column(app: Flask) -> None:
db.session.rollback() # Column already exists — safe to ignore
def _add_config_json_column(app: Flask) -> None:
"""Add config_json column to boards table if it doesn't exist yet."""
from sqlalchemy import text
with app.app_context():
try:
db.session.execute(text("ALTER TABLE boards ADD COLUMN config_json TEXT DEFAULT '{}'"))
db.session.commit()
app.logger.info("Added config_json column to boards table")
except Exception:
db.session.rollback() # Column already exists — safe to ignore
def _migrate_board_types(app: Flask) -> None:
"""Rename legacy board_type values to current driver IDs."""
from app.models.board import Board