Example #1
0
    def run(self):
        url = 'http://%s:5000/' % self.host
        print 'Welcome to ScreenBloom!'
        print 'Server running at: %s' % url
        if not self.stoprequest.isSet():
            # Check For DLL error
            if not utility.dll_check():
                url += 'dll-error'
            # Check if config file has been created yet
            elif os.path.isfile(utility.get_config_path()):
                print 'Config already exists'
                config = ConfigParser.RawConfigParser()
                config.read(utility.get_config_path())
                utility.write_config('App State', 'running', '0')

                # Wait for 200 status code from server then load up interface
                while not utility.check_server(self.host):
                    sleep(0.2)

                sb_controller.start()
            else:
                # Config file doesn't exist, open New User interface
                print 'Config does not exist yet!'
                url += 'new-user'

        webbrowser.open(url)
Example #2
0
def re_initialize():
    config = ConfigParser.RawConfigParser()
    config.read(utility.get_config_path())

    # Attributes
    at = initialize()

    global _screen
    _screen = Screen(*at)

    # Update bulbs with new settings
    results = img_proc.screen_avg(_screen)

    try:
        # Update Hue bulbs to avg color of screen
        if 'zones' in results:
            for zone in results['zones']:
                brightness = utility.get_brightness(_screen,
                                                    int(_screen.max_bri),
                                                    int(_screen.min_bri),
                                                    zone['dark_ratio'])

                for bulb in zone['bulbs']:
                    hue_interface.send_rgb_to_bulb(bulb, zone['rgb'],
                                                   brightness)
        else:
            update_bulbs(results['rgb'], results['dark_ratio'])
    except urllib2.URLError:
        print 'Connection timed out, continuing...'
        pass
Example #3
0
    def startup_checks(self):
        # Check For DLL error
        if params.BUILD == 'win':
            if not utility.dll_check():
                self.url = self.base_url + 'dll-error'
                self.error = True
                return

        # Check if config file has been created yet
        if os.path.isfile(utility.get_config_path()):
            # Check to see if config needs to be updated
            if not utility.config_check():
                self.url = self.base_url + 'update-config'
                self.needs_update = True
                return
            else:
                presets.update_presets_if_necessary()
                config = utility.get_config_dict()
                lights_initial_state = json.dumps(utility.get_hue_initial_state(config['ip'], config['username']))

                # Init Screen object with some first-run defaults
                utility.write_config('App State', 'running', False)
                utility.write_config('Light Settings', 'default', lights_initial_state)
                sb_controller.init()

                self.url = self.base_url
                return
        else:
            # Config file doesn't exist, open New User interface
            self.url = self.base_url + 'new-user'
            self.new_user = True
            return
Example #4
0
    def run(self):
        base_url = 'http://%s:%d/' % (self.host, self.port)
        url = copy(base_url)
        print 'Welcome to ScreenBloom!'
        print 'Server running at: %s' % base_url
        presets.update_presets_if_necessary()

        if not self.stoprequest.isSet():
            # Startup checks
            if params.BUILD == 'win':
                # Check For DLL error
                if not utility.dll_check():
                    url = base_url + 'dll-error'
            # Check if config file has been created yet
            if os.path.isfile(utility.get_config_path()):
                # Check to see if config needs to be updated
                if not utility.config_check():
                    url = base_url + 'update-config'
                else:
                    # Init Screen object
                    sb_controller.init()
            else:
                # Config file doesn't exist, open New User interface
                print 'Redirecting to New User interface...'
                url = base_url + 'new-user'

        # Wait for 200 status code from server then load up interface
        while not utility.check_server(self.host, self.port):
            sleep(0.2)

        webbrowser.open(url)
Example #5
0
def get_lights_data(hue_ip, username):
    bridge = Bridge(device={'ip': hue_ip}, user={'name': username})
    config = ConfigParser.RawConfigParser()
    config.read(utility.get_config_path())
    all_lights = config.get('Light Settings', 'all_lights')
    all_lights = [int(i) for i in all_lights.split(',')]
    active_bulbs = config.get('Light Settings', 'active')
    active_bulbs = [int(i) for i in active_bulbs.split(',')]

    lights = []

    for counter, light in enumerate(all_lights):
        resource = {
            'which': light
        }
        result = bridge.light.get(resource)

        # Skip unavailable lights
        if type(result['resource']) is dict:
            state = result['resource']['state']['on']
            light_name = result['resource']['name']
            light_data = [light, state, light_name, int(active_bulbs[counter])]
            lights.append(light_data)

    return lights
Example #6
0
def remove_config():
    file_path = utility.get_config_path()
    success = True

    try:
        os.remove(file_path)
    except Exception:
        success = False

    return success
Example #7
0
def remove_config():
    file_path = utility.get_config_path()
    success = True

    try:
        os.remove(file_path)
    except Exception as e:
        success = False

    return success
Example #8
0
def create_config(hue_ip, username):
    config = ConfigParser.RawConfigParser()
    lights = hue_interface.get_lights_list(hue_ip, username)
    active = ','.join([str(0) for light in lights])

    default_bulb_settings = {}
    for light in lights:
        settings = {
            'max_bri': 254,
            'min_bri': 1
        }
        default_bulb_settings[light] = settings

    config.add_section('Configuration')
    config.set('Configuration', 'hue_ip', hue_ip)
    config.set('Configuration', 'username', username)
    config.set('Configuration', 'auto_start', 0)
    config.set('Configuration', 'current_preset', '')
    config.set('Configuration', 'color_mode_enabled', 0)

    config.add_section('Light Settings')
    config.set('Light Settings', 'all_lights', ','.join(lights))
    config.set('Light Settings', 'active', active)
    config.set('Light Settings', 'bulb_settings', json.dumps(default_bulb_settings))
    config.set('Light Settings', 'update', '0.7')
    config.set('Light Settings', 'update_buffer', '0')
    config.set('Light Settings', 'default', '255,226,168')
    config.set('Light Settings', 'max_bri', '254')
    config.set('Light Settings', 'min_bri', '1')
    config.set('Light Settings', 'zones', '[]')
    config.set('Light Settings', 'zone_state', 0)
    config.set('Light Settings', 'black_rgb', '1,1,1')
    config.set('Light Settings', 'display_index', 0)
    config.set('Light Settings', 'color_mode', 'average')

    config.add_section('System Monitoring')
    config.set('System Monitoring', 'enabled', 0)
    config.set('System Monitoring', 'mode', 'extreme')
    config.set('System Monitoring', 'interval', 5)
    config.set('System Monitoring', 'cpu_warning_temp', 50)
    config.set('System Monitoring', 'cpu_extreme_temp', 70)
    config.set('System Monitoring', 'cpu_warning_color', '255,165,0')
    config.set('System Monitoring', 'cpu_extreme_color', '255,0,0')
    config.set('System Monitoring', 'gpu_warning_temp', 80)
    config.set('System Monitoring', 'gpu_extreme_temp', 95)
    config.set('System Monitoring', 'gpu_warning_color', '255,165,0')
    config.set('System Monitoring', 'gpu_extreme_color', '255,0,0')

    config.add_section('Party Mode')
    config.set('Party Mode', 'running', '0')

    with open(utility.get_config_path(), 'wb') as config_file:
        config.write(config_file)
Example #9
0
def initialize():
    config = ConfigParser.RawConfigParser()
    config.read(utility.get_config_path())

    ip = config.get('Configuration', 'hue_ip')
    username = config.get('Configuration', 'username')
    bridge = Bridge(device={'ip': ip}, user={'name': username})

    max_bri = config.get('Light Settings', 'max_bri')
    min_bri = config.get('Light Settings', 'min_bri')

    active_lights = config.get('Light Settings', 'active')
    active_lights = [int(i) for i in active_lights.split(',')]

    all_lights = config.get('Light Settings', 'all_lights')
    all_lights = [int(i) for i in all_lights.split(',')]

    # Check selected bulbs vs all known bulbs
    bulb_list = []
    for counter, bulb in enumerate(all_lights):
        try:
            if active_lights[counter]:
                bulb_list.append(bulb)
            else:
                bulb_list.append(0)
        except IndexError:
            bulb_list.append(0)

    bulb_settings = json.loads(config.get('Light Settings', 'bulb_settings'))

    update = config.get('Light Settings', 'update')
    update_buffer = config.get('Light Settings', 'update_buffer')

    default = config.get('Light Settings', 'default').split(',')
    default = (int(default[0]), int(default[1]), int(default[2]))

    zones = config.get('Light Settings', 'zones')
    zones = ast.literal_eval(zones)

    zone_state = config.getboolean('Light Settings', 'zone_state')
    party_mode = config.getboolean('Party Mode', 'running')

    black_rgb = config.get('Light Settings', 'black_rgb').split(',')
    black_rgb = (int(black_rgb[0]), int(black_rgb[1]), int(black_rgb[2]))

    display_index = config.get('Light Settings', 'display_index')

    color_mode = config.get('Light Settings', 'color_mode')

    return bridge, ip, username, bulb_list, bulb_settings, default, default, \
           update, update_buffer, max_bri, min_bri, zones, zone_state, color_mode, \
           black_rgb, display_index, party_mode
Example #10
0
def create_config(hue_ip, username):
    config = ConfigParser.RawConfigParser()
    lights = hue_interface.get_lights_list(hue_ip, username)
    active = ','.join([str(0) for light in lights])

    default_bulb_settings = {}
    for light in lights:
        settings = {'max_bri': 254, 'min_bri': 1}
        default_bulb_settings[light] = settings

    config.add_section('Configuration')
    config.set('Configuration', 'hue_ip', hue_ip)
    config.set('Configuration', 'username', username)
    config.set('Configuration', 'auto_start', 0)
    config.set('Configuration', 'current_preset', '')

    config.add_section('Light Settings')
    config.set('Light Settings', 'all_lights', ','.join(lights))
    config.set('Light Settings', 'active', active)
    config.set('Light Settings', 'bulb_settings',
               json.dumps(default_bulb_settings))
    config.set('Light Settings', 'update', '0.7')
    config.set('Light Settings', 'update_buffer', '0')
    config.set('Light Settings', 'default', '')
    config.set('Light Settings', 'max_bri', '254')
    config.set('Light Settings', 'min_bri', '1')
    config.set('Light Settings', 'zones', '[]')
    config.set('Light Settings', 'zone_state', 0)
    config.set('Light Settings', 'display_index', 0)
    config.set('Light Settings', 'sat', 1.0)

    config.add_section('Party Mode')
    config.set('Party Mode', 'running', 0)

    config.add_section('App State')
    config.set('App State', 'running', False)

    directory = os.getenv('APPDATA') or os.getenv('HOME')
    directory = os.path.join(directory, 'screenBloom')
    if not os.path.exists(directory):
        os.makedirs(directory)

    with open(utility.get_config_path(), 'wb') as config_file:
        config.write(config_file)

    # Now that the config is created, set initial light setting
    utility.write_config(
        'Light Settings', 'default',
        json.dumps(utility.get_hue_initial_state(hue_ip, username)))
Example #11
0
def stop_screenbloom():
    print '\nEnding screenBloom thread...'
    config = ConfigParser.RawConfigParser()
    config.read(utility.get_config_path())
    utility.write_config('App State', 'running', '0')

    # End currently running threads
    try:
        t.join()
    except NameError:
        print 'ScreenBloom thread not running'

    sb_controller.update_bulb_default()
    data = {'message': 'Successfully ended screenBloom thread'}
    return data
Example #12
0
def create_config(hue_ip, username):
    config = ConfigParser.RawConfigParser()
    lights = hue_interface.get_lights_list(hue_ip, username)
    active = ','.join([str(0) for light in lights])

    default_bulb_settings = {}
    for light in lights:
        settings = {
            'max_bri': 254,
            'min_bri': 1
        }
        default_bulb_settings[light] = settings

    config.add_section('Configuration')
    config.set('Configuration', 'hue_ip', hue_ip)
    config.set('Configuration', 'username', username)
    config.set('Configuration', 'auto_start', 0)
    config.set('Configuration', 'current_preset', '')

    config.add_section('Light Settings')
    config.set('Light Settings', 'all_lights', ','.join(lights))
    config.set('Light Settings', 'active', active)
    config.set('Light Settings', 'bulb_settings', json.dumps(default_bulb_settings))
    config.set('Light Settings', 'update', '0.7')
    config.set('Light Settings', 'update_buffer', '0')
    config.set('Light Settings', 'default', '')
    config.set('Light Settings', 'max_bri', '254')
    config.set('Light Settings', 'min_bri', '1')
    config.set('Light Settings', 'zones', '[]')
    config.set('Light Settings', 'zone_state', 0)
    config.set('Light Settings', 'display_index', 0)
    config.set('Light Settings', 'sat', 1.0)

    config.add_section('Party Mode')
    config.set('Party Mode', 'running', 0)

    config.add_section('App State')
    config.set('App State', 'running', False)

    directory = os.getenv('APPDATA') + '\\screenBloom'
    if not os.path.exists(directory):
        os.makedirs(directory)

    with open(utility.get_config_path(), 'wb') as config_file:
        config.write(config_file)

    # Now that the config is created, set initial light setting
    utility.write_config('Light Settings', 'default', json.dumps(utility.get_hue_initial_state(hue_ip, username)))
Example #13
0
def delete_preset(preset_number):
    config = ConfigParser.RawConfigParser()
    config.read(utility.get_config_path())
    current_preset = config.get('Configuration', 'current_preset')

    with open(utility.get_json_filepath()) as data_file:
        presets = json.load(data_file)
        key = 'preset_' + str(preset_number)

        if presets[key]['preset_name'] == current_preset:
            utility.write_config('Configuration', 'current_preset', '')

        del presets[key]

    with open(utility.get_json_filepath(), 'w') as f:
        json.dump(presets, f)
Example #14
0
def delete_preset(preset_number):
    config = ConfigParser.RawConfigParser()
    config.read(utility.get_config_path())
    current_preset = config.get('Configuration', 'current_preset')

    with open(utility.get_json_filepath()) as data_file:
        presets = json.load(data_file)
        key = 'preset_' + str(preset_number)

        if presets[key]['preset_name'] == current_preset:
            utility.write_config('Configuration', 'current_preset', '')

        del presets[key]

    with open(utility.get_json_filepath(), 'w') as f:
        json.dump(presets, f)
Example #15
0
def restart_check():
    global t
    config = ConfigParser.RawConfigParser()
    config.read(utility.get_config_path())
    update = config.get('Light Settings', 'update')

    try:
        if t.isAlive():
            print 'Restarting thread...'
            t.join()
            sb_controller.re_initialize()
            utility.write_config('App State', 'running', '1')

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

            print '\nHello!'
        else:
            sb_controller.re_initialize()
    except NameError:
        print 'Thread does not exist yet'
        sb_controller.re_initialize()
Example #16
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
Example #17
0
def get_index_data():
    config = ConfigParser.RawConfigParser()
    config.read(utility.get_config_path())

    state = config.get('App State', 'running')
    hue_ip = config.get('Configuration', 'hue_ip')
    username = config.get('Configuration', 'username')
    auto_start = config.getboolean('Configuration', 'auto_start')
    current_preset = config.get('Configuration', 'current_preset')
    update = config.get('Light Settings', 'update')
    update_buffer = config.get('Light Settings', 'update_buffer')
    max_bri = config.get('Light Settings', 'max_bri')
    min_bri = config.get('Light Settings', 'min_bri')
    bulb_settings = json.loads(config.get('Light Settings', 'bulb_settings'))
    default = config.get('Light Settings', 'default')
    black = config.get('Light Settings', 'black_rgb')
    zones = config.get('Light Settings', 'zones')
    zone_state = config.getboolean('Light Settings', 'zone_state')
    color_mode = config.get('Light Settings', 'color_mode')
    party_mode = config.getboolean('Party Mode', 'running')

    default_color = default.split(',')
    black_rgb = black.split(',')
    zones = ast.literal_eval(zones)

    lights = hue_interface.get_lights_data(hue_ip, username)
    for light in lights:
        light.append(int(bulb_settings[unicode(light[0])]['max_bri']))
        light.append(int(bulb_settings[unicode(light[0])]['min_bri']))

    display_index = config.get('Light Settings', 'display_index')

    filepath = utility.get_json_filepath()
    presets = []
    if os.path.isfile(filepath):
        with open(filepath) as data_file:
            presets = json.load(data_file)

    icon_size = 10
    if len(lights) > 3:
        icon_size = 4

    data = {
        'state': state,
        'auto_start_state': auto_start,
        'update': update,
        'update_buffer': update_buffer,
        'max_bri': max_bri,
        'min_bri': min_bri,
        'default': default,
        'default_color': default_color,
        'black_rgb': black_rgb,
        'lights': lights,
        'lights_number': len(lights),
        'icon_size': icon_size,
        'username': username,
        'party_mode': party_mode,
        'zones': zones,
        'zone_state': zone_state,
        'display_index': display_index,
        'presets': presets,
        'current_preset': current_preset,
        'color_mode': color_mode
    }
    return data