def cfg_keyvalue(key, value): # Depending on PUT/GET we will either change or read # values. If key is unknown, then this call fails with 404 if key is not None: if settings.getUser(key) is None: abort(404) return if request.method == 'PUT': if key == "keywords": # Keywords has its own API abort(404) return settings.setUser(key, value) settings.save() if key in ['width', 'height', 'depth', 'tvservice']: display.setConfiguration(settings.getUser('width'), settings.getUser('height'), settings.getUser('depth'), settings.getUser('tvservice')) display.enable(True, True) if key in ['display-on', 'display-off']: timekeeper.setConfiguration(settings.getUser('display-on'), settings.getUser('display-off')) return jsonify({'status': True}) elif request.method == 'GET': if key is None: return jsonify(settings.getUser()) else: return jsonify({key: settings.getUser(key)}) abort(404)
def cfg_keyvalue(key, value): global powermanagement # Depending on PUT/GET we will either change or read # values. If key is unknown, then this call fails with 404 if key is not None: if settings.getUser(key) is None: abort(404) return if request.method == 'PUT': status = True if key == "keywords": # Keywords has its own API abort(404) return settings.setUser(key, value) if key in ['display-driver']: drv = settings.getUser('display-driver') if drv == 'none': drv = None special = drivers.activate(drv) if special is None: settings.setUser('display-driver', 'none') settings.setUser('display-special', None) status = False else: settings.setUser('display-special', special) if key in ['timezone']: # Make sure we convert + to / settings.setUser('timezone', value.replace('+', '/')) helper.timezoneSet(settings.getUser('timezone')) if key in ['resolution', 'tvservice']: width, height, tvservice = display.setConfiguration( value, settings.getUser('display-special')) settings.setUser('tvservice', tvservice) settings.setUser('width', width) settings.setUser('height', height) display.enable(True, True) if key in ['display-on', 'display-off']: timekeeper.setConfiguration(settings.getUser('display-on'), settings.getUser('display-off')) if key in ['autooff-lux', 'autooff-time']: timekeeper.setAmbientSensitivity(settings.getUser('autooff-lux'), settings.getUser('autooff-time')) if key in ['powersave']: timekeeper.setPowermode(settings.getUser('powersave')) if key in ['shutdown-pin']: powermanagement.stopmonitor() powermanagement = shutdown(settings.getUser('shutdown-pin')) settings.save() return jsonify({'status': status}) elif request.method == 'GET': if key is None: return jsonify(settings.getUser()) else: return jsonify({key: settings.getUser(key)}) abort(404)
else: break # Let the display know the URL to use display.setConfigPage('http://%s:%d/' % (settings.get('local-ip'), 7777)) # Prep random random.seed(long(time.clock())) colormatch = colormatch(settings.get('colortemp-script'), 2700) # 2700K = Soft white, lowest we'll go slideshow = slideshow(display, settings, colormatch) timekeeper = timekeeper(display.enable, slideshow.start) slideshow.setQueryPower(timekeeper.getDisplayOn) slideshow.setServiceManager(services) timekeeper.setConfiguration(settings.getUser('display-on'), settings.getUser('display-off')) timekeeper.setAmbientSensitivity(settings.getUser('autooff-lux'), settings.getUser('autooff-time')) timekeeper.setPowermode(settings.getUser('powersave')) colormatch.setUpdateListener(timekeeper.sensorListener) powermanagement = shutdown(settings.getUser('shutdown-pin')) if __name__ == "__main__": # This allows us to use a plain HTTP callback os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1' app.secret_key = os.urandom(24) slideshow.start() app.run(debug=False, port=cmdline.port, host=cmdline.listen) sys.exit(0)