15
|
1 import logging
|
|
2 from dataclasses import dataclass
|
|
3
|
|
4 from color import Color
|
|
5
|
|
6 log = logging.getLogger('conv')
|
|
7
|
|
8
|
|
9 @dataclass(frozen=True)
|
|
10 class DeviceColor:
|
|
11 """neutral representation of the adjusted color that we send to a device"""
|
|
12 r: float = 0
|
|
13 g: float = 0
|
|
14 b: float = 0
|
|
15 w: float = 0
|
|
16 x: float = 0
|
|
17 y: float = 0
|
20
|
18 cw: float = 0
|
|
19 ww: float = 0
|
15
|
20 brightness: float = 0
|
|
21
|
|
22 def summary(self) -> dict:
|
|
23 return dict([(k, round(v, 3)) for k, v in self.__dict__.items() if v > 0])
|
|
24
|
|
25 # fix this to send what z2m likes
|
|
26 def zbConv(c: Color) -> DeviceColor:
|
|
27 return DeviceColor(r=c.r, g=c.g, b=c.b, brightness=max(c.r, c.g, c.b))
|
20
|
28
|
|
29 def oneWhiteConv(c: Color) -> DeviceColor:
|
|
30 return DeviceColor(r=c.r, g=c.g, b=c.b, w=max(c.r, c.g, c.b))
|
|
31
|
|
32 def twoWhitesConv(c: Color) -> DeviceColor:
|
|
33 return DeviceColor(r=c.r, g=c.g, b=c.b, cw=max(c.r, c.g, c.b))
|
|
34
|
|
35 def relayConv(c: Color) -> DeviceColor:
|
|
36 return DeviceColor(brightness=1 if (max(c.r, c.g, c.b) > 0) else 0) |