diff color_convert.py @ 15:61d4ccecfed8

rough refactor
author drewp@bigasterisk.com
date Sun, 28 Jan 2024 21:18:01 -0800
parents
children 24a574108365
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/color_convert.py	Sun Jan 28 21:18:01 2024 -0800
@@ -0,0 +1,25 @@
+import logging
+from dataclasses import dataclass
+
+from color import Color
+
+log = logging.getLogger('conv')
+
+
+@dataclass(frozen=True)
+class DeviceColor:
+    """neutral representation of the adjusted color that we send to a device"""
+    r: float = 0
+    g: float = 0
+    b: float = 0
+    w: float = 0
+    x: float = 0
+    y: float = 0
+    brightness: float = 0
+
+    def summary(self) -> dict:
+        return dict([(k, round(v, 3)) for k, v in self.__dict__.items() if v > 0])
+
+# fix this to send what z2m likes
+def zbConv(c: Color) -> DeviceColor:
+    return DeviceColor(r=c.r, g=c.g, b=c.b, brightness=max(c.r, c.g, c.b))