utils.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:timer-workflow 作者: 5fth 项目源码 文件源码
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()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号