def create_light_icon(lid, light_data):
"""Creates a 1x1 PNG icon of light's RGB color and saves it to the local dir.
"""
# Create a color converter & helper
converter = colors.Converter()
# Set color based on the type of light
# See: http://www.developers.meethue.com/documentation/supported-lights
if light_data['state'].get('xy'):
rgb_value = converter.xy_to_rgb(light_data['state']['xy'][0], light_data['state']['xy'][1])
elif light_data['state'].get('bri'):
rgb_value = colorsys.hsv_to_rgb(0, 0, float(light_data['state']['bri']) / 255)
rgb_value = tuple([255 * x for x in rgb_value])
else:
rgb_value = (255, 255, 255) if light_data['state']['on'] else (0, 0, 0)
f = open(alp.local('icons/%s.png' % lid), 'wb')
w = png.Writer(1, 1)
w.write(f, [rgb_value])
f.close()
评论列表
文章目录