Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
effects=effects,
palettes=palettes,
state_on=on,
state_brightness=brightness,
)
for segment_id, segment in enumerate(data.get("seg", []))
]
return State(
brightness=brightness,
nightlight=Nightlight.from_dict(data),
on=on,
playlist=data.get("pl", -1),
preset=data.get("ps", -1),
segments=segments,
sync=Sync.from_dict(data),
transition=data.get("transition", 0),
)
def from_dict(data: Dict[str, Any]) -> Sync:
"""Return Sync object from WLED API response."""
sync = data.get("udpn", {})
return Sync(send=sync.get("send", False), receive=sync.get("recv", False))
version=data.get("ver", "Unknown"),
wifi=Wifi.from_dict(data),
)
@dataclass
class State:
"""Object holding the state of WLED."""
brightness: int
nightlight: Nightlight
on: bool
playlist: int
preset: int
segments: List[Segment]
sync: Sync
transition: int
@property
def playlist_active(self) -> bool:
"""Return if a playlist is currently active."""
return self.playlist == -1
@property
def preset_active(self) -> bool:
"""Return if a preset is currently active."""
return self.preset == -1
@staticmethod
def from_dict(
data: Dict[str, Any], effects: List[Effect], palettes: List[Palette]
) -> State: