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

@@ -40,6 +40,9 @@ class Board(db.Model):
firmware_version = db.Column(db.String(64), nullable=True)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
# Extra driver-specific config (JSON) e.g. eWeLink credentials/token
config_json = db.Column(db.Text, default="{}")
# ── relationships ────────────────────────────────────────────────
workflows_trigger = db.relationship(
"Workflow", foreign_keys="Workflow.trigger_board_id",
@@ -49,6 +52,10 @@ class Board(db.Model):
"Workflow", foreign_keys="Workflow.action_board_id",
back_populates="action_board"
)
sonoff_devices = db.relationship(
"SonoffDevice", back_populates="board",
cascade="all, delete-orphan", lazy="dynamic"
)
# ── helpers ──────────────────────────────────────────────────────
@property
@@ -130,6 +137,21 @@ class Board(db.Model):
"idle_label": tdef["idle"][1],
}
@property
def config(self) -> dict:
try:
return json.loads(self.config_json or "{}")
except (ValueError, TypeError):
return {}
@config.setter
def config(self, value: dict):
self.config_json = json.dumps(value)
@property
def is_sonoff_gateway(self) -> bool:
return self.board_type == "sonoff_ewelink"
def get_relay_label(self, relay_num: int) -> str:
return self.get_relay_entity(relay_num)["name"]