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
|
21 temp: float = 0
|
15
|
22
|
|
23 def summary(self) -> dict:
|
|
24 return dict([(k, round(v, 3)) for k, v in self.__dict__.items() if v > 0])
|
|
25
|
21
|
26
|
15
|
27 # fix this to send what z2m likes
|
|
28 def zbConv(c: Color) -> DeviceColor:
|
|
29 return DeviceColor(r=c.r, g=c.g, b=c.b, brightness=max(c.r, c.g, c.b))
|
20
|
30
|
21
|
31
|
|
32 def ikeaWhiteConv(c: Color) -> DeviceColor:
|
|
33 return DeviceColor(brightness=max(c.r, c.g, c.b), temp=454)
|
|
34
|
|
35
|
20
|
36 def oneWhiteConv(c: Color) -> DeviceColor:
|
|
37 return DeviceColor(r=c.r, g=c.g, b=c.b, w=max(c.r, c.g, c.b))
|
|
38
|
21
|
39 def brightnessConv(c: Color) -> DeviceColor:
|
|
40 return DeviceColor(brightness=max(c.r, c.g, c.b))
|
|
41
|
|
42
|
20
|
43 def twoWhitesConv(c: Color) -> DeviceColor:
|
21
|
44 return DeviceColor(r=c.r, g=c.g, b=c.b, cw=max(c.r, c.g, c.b), ww=0)
|
|
45
|
20
|
46
|
|
47 def relayConv(c: Color) -> DeviceColor:
|
21
|
48 return DeviceColor(brightness=1 if (max(c.r, c.g, c.b) > 0) else 0)
|