@@ -112,6 +112,37 @@ def color_temperature(self):
112
112
"""The color temperature in degrees Kelvin."""
113
113
return self ._temperature_and_lux_dn40 ()[1 ]
114
114
115
+ @property
116
+ def color_rgb_bytes (self ):
117
+ """Read the RGB color detected by the sensor. Returns a 3-tuple of
118
+ red, green, blue component values as bytes (0-255).
119
+ """
120
+ r , g , b , clear = self .color_raw
121
+ # Avoid divide by zero errors ... if clear = 0 return black
122
+ if clear == 0 :
123
+ return (0 , 0 , 0 )
124
+ # pylint: disable=bad-whitespace
125
+ red = int (pow ((int ((r / clear ) * 256 ) / 255 ), 2.5 ) * 255 )
126
+ green = int (pow ((int ((g / clear ) * 256 ) / 255 ), 2.5 ) * 255 )
127
+ blue = int (pow ((int ((b / clear ) * 256 ) / 255 ), 2.5 ) * 255 )
128
+ # Handle possible 8-bit overflow
129
+ if red > 255 :
130
+ red = 255
131
+ if green > 255 :
132
+ green = 255
133
+ if blue > 255 :
134
+ blue = 255
135
+ return (red , green , blue )
136
+
137
+ @property
138
+ def color (self ):
139
+ """Read the RGB color detected by the sensor. Returns an int with 8 bits per channel.
140
+ Examples: Red = 16711680 (0xff0000), Green = 65280 (0x00ff00),
141
+ Blue = 255 (0x0000ff), SlateGray = 7372944 (0x708090)
142
+ """
143
+ r , g , b = self .color_rgb_bytes
144
+ return (r << 16 ) | (g << 8 ) | b
145
+
115
146
@property
116
147
def active (self ):
117
148
"""The active state of the sensor. Boolean value that will
0 commit comments