from dataclasses import dataclass, field import struct import colorsys @dataclass class ColorRGBW: r: float g: float b: float w: float def __repr__(self): return f"#({self.r}, {self.g}, {self.b}, {self.w})" def as_bytes(self) -> bytes: assert self.is_valid(), "Trying to send invalid " + repr(self) return struct.pack(" bytes: return struct.pack(" bytes: return self.color.as_bytes() + struct.pack(" bytes: return self.color.as_bytes() + struct.pack(" bytes: return struct.pack( " bytes: c1 = ColorHSV.fromRGB(self.color1) if isinstance(self.color1, ColorRGBW) else self.color1 c2 = ColorHSV.fromRGB(self.color2) if isinstance(self.color2, ColorRGBW) else self.color2 return struct.pack(" bytes: return struct.pack(" bytes: return self.swipe.as_bytes() + self.change.as_bytes() def __repr__(self) -> str: return f"Swipe and Change: \n {str(self.swipe)}\n {str(self.change)}" @dataclass class EffectReverseSwipe: swipeSpeed: float = 2 * 360 bellCurveWidthInLeds: float = 3 startPosition: float = 180 def as_bytes(self) -> bytes: return struct.pack(" str: return f"Reverse swipe, speed {self.swipeSpeed}, width in leds {self.bellCurveWidthInLeds}, start position {self.startPosition}"