Add NFC enable/disable support; update devices, Sonoff, and Tuya
This commit is contained in:
@@ -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."""
|
||||
|
||||
Reference in New Issue
Block a user