Added new config system

fetchIP
E. Almqvist 4 years ago
parent 6f248ca809
commit 62b7cbbeab
  1. 9
      default-config.json
  2. 41
      default-presets.json
  3. 1
      modules/configloader/__init__.py
  4. 0
      modules/configloader/__main__.py
  5. 12
      modules/configloader/loader.py
  6. 26
      modules/hue/hue_controller.py
  7. 7
      setup.sh

@ -0,0 +1,9 @@
{
"hue": {
"address": "",
"username": ""
},
"speech": {
"device_index": 30
}
}

@ -0,0 +1,41 @@
{
"default": {
"color": {178, 199, 255},
"brightness": 255
},
"dim": {
"color": {178, 199, 255},
"brightness": 111
},
"dim": {
"color": {178, 199, 255},
"brightness": 80
},
"red": {
"color": {255, 0, 0},
"brightness": 255
},
"green": {
"color": {0, 255, 0},
"brightness": 255
},
"blue": {
"color": {0, 0, 255},
"brightness": 255
},
"ice" : {
"color": {80, 100, 255},
"brightness": 120
},
"sleep": {
"color": {185, 155, 25},
"brightness": 60
}
}

@ -0,0 +1,12 @@
import json
def readconfig(path):
#try:
with open(path) as cfg:
data = json.load(cfg)
return data
#except:
#print("[Error] Something went wrong reading the configuration file.")
#print("--", path)

@ -5,15 +5,20 @@ import time
from .lib.func import * # useful functions
from .config import * # Configuration for the controller (/config.py <- change this file)
from .presets import * # presets for the lights
from modules.configloader.loader import readconfig # used to read the config files
from os.path import expanduser # to get the home dir
homedir = expanduser("~") # get the home directory of the current user
LIGHTS = {} # dictionary of all the lights
CONFIG = {} # the configuration
PRESETS = {} # the presets
PRE_URL = "" # prefix
loop = asyncio.get_event_loop() # ASync loop
def genUrl(params: str):
return "http://" + hue_config.address + "/api/" + hue_config.username + params
return PRE_URL + params
class APIrequest:
# Get Req
@ -142,9 +147,20 @@ class controller:
def delay(n:int):
time.sleep(n)
def init():
jsonLights = loop.run_until_complete(APIrequest.get("/lights"))
def init( cfgPath="{0}/.config/roomcomputer/config.json".format(homedir), presetPath="{0}/.config/roomcomputer/presets.json".format(homedir) ):
config = readconfig(cfgPath)
presets = readconfig(presetPath)
global CONFIG
CONFIG = config["hue"]
global PRESETS
PRESETS = presets
global PRE_URL
PRE_URL = "http://" + CONFIG["address"] + "/api/" + CONFIG["username"]
jsonLights = loop.run_until_complete(APIrequest.get("/lights"))
global LIGHTS
LIGHTS = json.loads(jsonLights.text)

@ -0,0 +1,7 @@
#!/usr/bin/bash
cfgPath="$HOME/.config/roomcomputer"
mkdir $cfgPath
cp default-config.json $cfgPath/config.json
cp default-presets.json $cfgPath/presets.json
Loading…
Cancel
Save