Beispiel #1
0
def send_rgb_to_bulb(bulb, rgb, brightness):
    _screen = sb_controller.get_screen_object()
    if bulb:  # Only contact active lights
        bulb_settings = _screen.bulb_settings[str(bulb)]
        bulb_gamut = bulb_settings['gamut']
        name = bulb_settings['name']
        gamut = get_rgb_xy_gamut(bulb_gamut)
        converter = rgb_xy.Converter(gamut)
        print 'Updating %s -> Color: rgb%s | Gamut: %s | Bri: %s' % (
            str(name), str(rgb), str(bulb_gamut), str(brightness))

        if int(brightness
               ) < 5:  # Maybe set user controlled darkness threshold here?
            rgb = _screen.black_rgb

        try:
            hue_color = converter.rgb_to_xy(rgb[0], rgb[1], rgb[2])
        except ZeroDivisionError as e:
            print e
            return

        resource = {
            'which': bulb,
            'data': {
                'state': {
                    'xy': hue_color,
                    'bri': int(brightness),
                    'transitiontime':
                    utility.get_transition_time(_screen.update)
                }
            }
        }
        _screen.bridge.light.update(resource)
Beispiel #2
0
def send_rgb_or_xy_to_bulb(bulb, rgb_or_xy, brightness):
    _screen = sb_controller.get_screen_object()
    bulb_settings = _screen.bulb_settings[str(bulb)]
    bulb_gamut = bulb_settings['gamut']
    gamut = get_rgb_xy_gamut(bulb_gamut)
    converter = rgb_xy.Converter(gamut)

    resource = {
        'which': bulb,
        'data': {
            'state': {
                'bri': int(brightness),
                'transitiontime': utility.get_transition_time(_screen.update)
            }
        }
    }

    if rgb_or_xy:
        if len(rgb_or_xy) > 2:  # [R, G, B] vs [X, Y]
            try:
                hue_color = converter.rgb_to_xy(rgb_or_xy[0], rgb_or_xy[1], rgb_or_xy[2])
            except ZeroDivisionError:
                return
        else:
            hue_color = (rgb_or_xy[0], rgb_or_xy[1])

        resource['data']['state']['xy'] = hue_color

    _screen.bridge.light.update(resource)
def lights_on_off(state):
    _screen = sb_controller.get_screen_object()

    active_lights = _screen.bulbs
    on = True if state == 'on' else False

    for light in active_lights:
        state = {
            'on': on,
            'bri': int(_screen.max_bri),
            'transitiontime': _screen.update
        }
        update_light(_screen.ip, _screen.devicename, light, json.dumps(state))
Beispiel #4
0
def start_screenbloom():
    config = utility.get_config_dict()
    state = config['app_state']
    sb_controller.get_screen_object().bulb_state = 'on'
    hue_interface.lights_on_off('On')

    if state:
        message = 'ScreenBloom already running'
    else:
        sb_controller.re_initialize()
        sb_controller.start()

        message = 'ScreenBloom Started!'

    data = {'message': message}
    return data
Beispiel #5
0
def start_screenbloom():
    config = utility.get_config_dict()
    state = config['color_mode_enabled']
    sb_controller.get_screen_object().bulb_state = 'on'
    hue_interface.lights_on_off('On')

    if state:
        message = 'ScreenBloom already running'
    else:
        utility.write_config('Configuration', 'color_mode_enabled', True)
        sb_controller.re_initialize()
        sb_controller.start()

        message = 'Color Mode Started!'

    data = {'message': message}
    return data
Beispiel #6
0
def lights_on_off(state):
    _screen = sb_controller.get_screen_object()

    active_lights = _screen.bulbs
    state = True if state == 'On' else False

    for light in active_lights:
        resource = {
            'which': light,
            'data': {
                'state': {
                    'on': state,
                    'bri': int(_screen.max_bri),
                    'transitiontime': _screen.update
                }
            }
        }
        _screen.bridge.light.update(resource)
Beispiel #7
0
def start_screenbloom():
    config = utility.get_config_dict()
    state = config['app_state']
    sb_controller.get_screen_object().bulb_state = 'on'
    hue_interface.lights_on_off('On')

    if state:
        message = 'ScreenBloom already running'
    else:
        sb_controller.re_initialize()
        sb_controller.start()

        message = 'ScreenBloom Started!'

    data = {
        'message': message
    }
    return data
Beispiel #8
0
def send_rgb_to_bulb(bulb, rgb, brightness):
    _screen = sb_controller.get_screen_object()
    if bulb:  # Only contact active lights
        print 'Updating Bulb: %s -> Color: %s | Bri: %s' % (str(bulb), str(rgb), str(brightness))

        if int(brightness) < 5:  # Maybe set user controlled darkness threshold here?
            rgb = _screen.black_rgb

        hue_color = rgb_cie.Converter().rgbToCIE1931(rgb[0], rgb[1], rgb[2])
        resource = {
            'which': bulb,
            'data': {
                'state': {
                    'xy': hue_color,
                    'bri': int(brightness),
                    'transitiontime': utility.get_transition_time(_screen.update)
                }
            }
        }
        _screen.bridge.light.update(resource)
Beispiel #9
0
def start_screenbloom():
    config = ConfigParser.RawConfigParser()
    config.read(utility.get_config_path())
    state = int(config.get('App State', 'running'))
    update = config.get('Light Settings', 'update')
    sb_controller.get_screen_object().bulb_state = 'on'

    if update:
        state = False

    if state:
        message = 'ScreenBloom already running'
    else:
        utility.write_config('App State', 'running', '1')

        global t
        t = sb_controller.ScreenBloom(update)
        t.start()

        print '\nHello!'
        message = 'ScreenBloom thread initialized'

    data = {'message': message}
    return data