Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
primary_color = tuple(colors.pop(0)) # type: ignore
secondary_color = tuple(colors.pop(0)) # type: ignore
tertiary_color = tuple(colors.pop(0)) # type: ignore
except IndexError:
pass
effect = next(
(item for item in effects if item.effect_id == data.get("fx", 0)),
Effect(effect_id=0, name="Unknown"),
)
palette = next(
(item for item in palettes if item.palette_id == data.get("pal", 0)),
Palette(palette_id=0, name="Unknown"),
)
return Segment(
brightness=data.get("bri", state_brightness),
clones=data.get("cln", -1),
color_primary=primary_color, # type: ignore
color_secondary=secondary_color, # type: ignore
color_tertiary=tertiary_color, # type: ignore
effect=effect,
intensity=data.get("ix", 0),
length=length,
on=data.get("on", state_on),
palette=palette,
reverse=data.get("reverse", False),
segment_id=segment_id,
selected=data.get("sel", False),
speed=data.get("sx", 0),
start=start,
stop=stop,
def from_dict(
data: Dict[str, Any], effects: List[Effect], palettes: List[Palette]
) -> State:
"""Return State object from WLED API response."""
brightness = data.get("bri", 1)
on = data.get("on", False)
segments = [
Segment.from_dict(
segment_id=segment_id,
data=segment,
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),
version_id=data.get("vid", "Unknown"),
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]