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

@@ -209,13 +209,20 @@ class SonoffEweLinkDriver(BoardDriver):
switch_val = "on" if state else "off"
# Build params dict
if dev.num_channels == 1:
params = {"switch": switch_val}
command = "switch"
else:
# Build params dict — detect format from stored params rather than
# relying only on num_channels, because some devices (e.g. UIID 138)
# report num_channels=1 but actually use the "switches" array format.
stored_params = dev.params
uses_switches_fmt = (
dev.num_channels > 1
or "switches" in stored_params
)
if uses_switches_fmt:
params = {"switches": [{"outlet": channel, "switch": switch_val}]}
command = "switches"
else:
params = {"switch": switch_val}
command = "switch"
# ── Try LAN first ───────────────────────────────────────────────────
if dev.ip_address:
@@ -259,9 +266,8 @@ class SonoffEweLinkDriver(BoardDriver):
"""Update the SonoffDevice params in-memory after a successful command."""
p = dev.params
switch_val = "on" if state else "off"
if dev.num_channels == 1:
p["switch"] = switch_val
else:
uses_switches_fmt = dev.num_channels > 1 or "switches" in p
if uses_switches_fmt:
switches = p.get("switches", [])
updated = False
for s in switches:
@@ -272,6 +278,8 @@ class SonoffEweLinkDriver(BoardDriver):
if not updated:
switches.append({"outlet": channel, "switch": switch_val})
p["switches"] = switches
else:
p["switch"] = switch_val
dev.params = p
@staticmethod
@@ -284,11 +292,12 @@ class SonoffEweLinkDriver(BoardDriver):
"""
import requests as req
from .ewelink_api import API, APPID
import time
headers = {"Authorization": f"Bearer {at}", "X-CK-Appid": APPID}
# v2 /device/thing/status requires "type" (1 = device) and "id", not "deviceid"
payload = {
"deviceid": device_id,
"type": 1,
"id": device_id,
"params": params,
}
url = f"{API[region]}/v2/device/thing/status"