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

@@ -109,17 +109,18 @@ class SonoffDevice(db.Model):
def get_channel_state(self, channel: int = 0) -> bool:
"""Return True if channel is ON.
For single-channel devices uses 'switch' param.
For multi-channel uses 'switches' array with outlet index.
Detects format from stored params: if 'switches' key is present (or
num_channels > 1) uses the switches-array format; otherwise uses 'switch'.
"""
p = self.params
if self.num_channels == 1:
return p.get("switch") == "on"
switches = p.get("switches", [])
for s in switches:
if s.get("outlet") == channel:
return s.get("switch") == "on"
return False
uses_switches_fmt = self.num_channels > 1 or "switches" in p
if uses_switches_fmt:
switches = p.get("switches", [])
for s in switches:
if s.get("outlet") == channel:
return s.get("switch") == "on"
return False
return p.get("switch") == "on"
def all_channel_states(self) -> list[dict]:
"""Return [{channel, label, state}, ...] for every channel."""