annotate color_convert.py @ 22:178e020289c1

'full' button; other clean up
author drewp@bigasterisk.com
date Mon, 29 Jan 2024 13:01:23 -0800
parents b8201490c731
children ecbbf76318bb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
61d4ccecfed8 rough refactor
drewp@bigasterisk.com
parents:
diff changeset
1 import logging
61d4ccecfed8 rough refactor
drewp@bigasterisk.com
parents:
diff changeset
2 from dataclasses import dataclass
61d4ccecfed8 rough refactor
drewp@bigasterisk.com
parents:
diff changeset
3
61d4ccecfed8 rough refactor
drewp@bigasterisk.com
parents:
diff changeset
4 from color import Color
61d4ccecfed8 rough refactor
drewp@bigasterisk.com
parents:
diff changeset
5
61d4ccecfed8 rough refactor
drewp@bigasterisk.com
parents:
diff changeset
6 log = logging.getLogger('conv')
61d4ccecfed8 rough refactor
drewp@bigasterisk.com
parents:
diff changeset
7
61d4ccecfed8 rough refactor
drewp@bigasterisk.com
parents:
diff changeset
8
61d4ccecfed8 rough refactor
drewp@bigasterisk.com
parents:
diff changeset
9 @dataclass(frozen=True)
61d4ccecfed8 rough refactor
drewp@bigasterisk.com
parents:
diff changeset
10 class DeviceColor:
61d4ccecfed8 rough refactor
drewp@bigasterisk.com
parents:
diff changeset
11 """neutral representation of the adjusted color that we send to a device"""
61d4ccecfed8 rough refactor
drewp@bigasterisk.com
parents:
diff changeset
12 r: float = 0
61d4ccecfed8 rough refactor
drewp@bigasterisk.com
parents:
diff changeset
13 g: float = 0
61d4ccecfed8 rough refactor
drewp@bigasterisk.com
parents:
diff changeset
14 b: float = 0
61d4ccecfed8 rough refactor
drewp@bigasterisk.com
parents:
diff changeset
15 w: float = 0
61d4ccecfed8 rough refactor
drewp@bigasterisk.com
parents:
diff changeset
16 x: float = 0
61d4ccecfed8 rough refactor
drewp@bigasterisk.com
parents:
diff changeset
17 y: float = 0
20
24a574108365 more protocols; bugs in setColor
drewp@bigasterisk.com
parents: 15
diff changeset
18 cw: float = 0
24a574108365 more protocols; bugs in setColor
drewp@bigasterisk.com
parents: 15
diff changeset
19 ww: float = 0
15
61d4ccecfed8 rough refactor
drewp@bigasterisk.com
parents:
diff changeset
20 brightness: float = 0
21
b8201490c731 more light types
drewp@bigasterisk.com
parents: 20
diff changeset
21 temp: float = 0
15
61d4ccecfed8 rough refactor
drewp@bigasterisk.com
parents:
diff changeset
22
61d4ccecfed8 rough refactor
drewp@bigasterisk.com
parents:
diff changeset
23 def summary(self) -> dict:
61d4ccecfed8 rough refactor
drewp@bigasterisk.com
parents:
diff changeset
24 return dict([(k, round(v, 3)) for k, v in self.__dict__.items() if v > 0])
61d4ccecfed8 rough refactor
drewp@bigasterisk.com
parents:
diff changeset
25
21
b8201490c731 more light types
drewp@bigasterisk.com
parents: 20
diff changeset
26
15
61d4ccecfed8 rough refactor
drewp@bigasterisk.com
parents:
diff changeset
27 # fix this to send what z2m likes
61d4ccecfed8 rough refactor
drewp@bigasterisk.com
parents:
diff changeset
28 def zbConv(c: Color) -> DeviceColor:
61d4ccecfed8 rough refactor
drewp@bigasterisk.com
parents:
diff changeset
29 return DeviceColor(r=c.r, g=c.g, b=c.b, brightness=max(c.r, c.g, c.b))
20
24a574108365 more protocols; bugs in setColor
drewp@bigasterisk.com
parents: 15
diff changeset
30
21
b8201490c731 more light types
drewp@bigasterisk.com
parents: 20
diff changeset
31
b8201490c731 more light types
drewp@bigasterisk.com
parents: 20
diff changeset
32 def ikeaWhiteConv(c: Color) -> DeviceColor:
b8201490c731 more light types
drewp@bigasterisk.com
parents: 20
diff changeset
33 return DeviceColor(brightness=max(c.r, c.g, c.b), temp=454)
b8201490c731 more light types
drewp@bigasterisk.com
parents: 20
diff changeset
34
b8201490c731 more light types
drewp@bigasterisk.com
parents: 20
diff changeset
35
20
24a574108365 more protocols; bugs in setColor
drewp@bigasterisk.com
parents: 15
diff changeset
36 def oneWhiteConv(c: Color) -> DeviceColor:
24a574108365 more protocols; bugs in setColor
drewp@bigasterisk.com
parents: 15
diff changeset
37 return DeviceColor(r=c.r, g=c.g, b=c.b, w=max(c.r, c.g, c.b))
24a574108365 more protocols; bugs in setColor
drewp@bigasterisk.com
parents: 15
diff changeset
38
21
b8201490c731 more light types
drewp@bigasterisk.com
parents: 20
diff changeset
39 def brightnessConv(c: Color) -> DeviceColor:
b8201490c731 more light types
drewp@bigasterisk.com
parents: 20
diff changeset
40 return DeviceColor(brightness=max(c.r, c.g, c.b))
b8201490c731 more light types
drewp@bigasterisk.com
parents: 20
diff changeset
41
b8201490c731 more light types
drewp@bigasterisk.com
parents: 20
diff changeset
42
20
24a574108365 more protocols; bugs in setColor
drewp@bigasterisk.com
parents: 15
diff changeset
43 def twoWhitesConv(c: Color) -> DeviceColor:
21
b8201490c731 more light types
drewp@bigasterisk.com
parents: 20
diff changeset
44 return DeviceColor(r=c.r, g=c.g, b=c.b, cw=max(c.r, c.g, c.b), ww=0)
b8201490c731 more light types
drewp@bigasterisk.com
parents: 20
diff changeset
45
20
24a574108365 more protocols; bugs in setColor
drewp@bigasterisk.com
parents: 15
diff changeset
46
24a574108365 more protocols; bugs in setColor
drewp@bigasterisk.com
parents: 15
diff changeset
47 def relayConv(c: Color) -> DeviceColor:
21
b8201490c731 more light types
drewp@bigasterisk.com
parents: 20
diff changeset
48 return DeviceColor(brightness=1 if (max(c.r, c.g, c.b) > 0) else 0)