Merge pull request #6 from E-Almqvist/configFix

New config reading
fetchIP
E. Almqvist 4 years ago committed by GitHub
commit 01073429a1
  1. 10
      default-config.json
  2. 21
      default-presets.json
  3. 1
      modules/configloader/__init__.py
  4. 0
      modules/configloader/__main__.py
  5. 12
      modules/configloader/loader.py
  6. 4
      modules/hue/config.py
  7. 8
      modules/hue/default-config.py
  8. 26
      modules/hue/hue_controller.py
  9. 7
      setup.sh
  10. 30
      speech_daemon.py

@ -0,0 +1,10 @@
{
"hue": {
"address": "",
"username": ""
},
"speech": {
"device_index": 30,
"prefixes": ["computer", "computers"]
}
}

@ -1,44 +1,41 @@
# Presets goes in here {
PRESETS = {
"default": { "default": {
"color": (178, 199, 255), "color": [178, 199, 255],
"brightness": 255 "brightness": 255
}, },
"dim": { "dim": {
"color": (178, 199, 255), "color": [178, 199, 255],
"brightness": 111 "brightness": 111
}, },
"dim": { "dim": {
"color": (178, 199, 255), "color": [178, 199, 255],
"brightness": 80 "brightness": 80
}, },
"red": { "red": {
"color": (255, 0, 0), "color": [255, 0, 0],
"brightness": 255 "brightness": 255
}, },
"green": { "green": {
"color": (0, 255, 0), "color": [0, 255, 0],
"brightness": 255 "brightness": 255
}, },
"blue": { "blue": {
"color": (0, 0, 255), "color": [0, 0, 255],
"brightness": 255 "brightness": 255
}, },
"ice" : { "ice" : {
"color": ( 80, 100, 255 ), "color": [80, 100, 255],
"brightness": 120 "brightness": 120
}, },
"sleep": { "sleep": {
"color": (185, 155, 25), "color": [185, 155, 25],
"brightness": 60 "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)

@ -1,4 +0,0 @@
# Hue Remote Settings
class hue_config:
address = "192.168.0.3"
username = "E0ru0AeVFKEH1E30X40JAJfovg4Uu1aTkdrKQ2Oi"

@ -1,8 +0,0 @@
##################################
# RENAME THIS FILE TO "config.py"#
##################################
# Hue Remote Settings
class hue_config:
address = "" # Local IPv4 address to the HUE bridge
username = "" # Username for the bridge

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

@ -1,24 +1,47 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys
from modules.hue.hue_remote import parseCommandline from modules.hue.hue_remote import parseCommandline
from modules.hue.hue_controller import controller from modules.hue.hue_controller import controller
from modules.speech.speech import voiceInput from modules.speech.speech import voiceInput
prefixes = ["computer", "computers"] from modules.configloader.loader import readconfig
from os.path import expanduser
homedir = expanduser("~")
CONFIG = {}
class speech_daemon(object): class speech_daemon(object):
voiceInpObj = None voiceInpObj = None
deviceIndex = 30
def __init__(self, deviceIndex=30): def __init__(self, deviceIndex=30):
self.voiceInpObj = voiceInput() self.voiceInpObj = voiceInput()
self.voiceInpObj.setMuted(False) self.voiceInpObj.setMuted(False)
self.deviceIndex = deviceIndex
def loadconfig(self):
path = homedir + "/.config/roomcomputer/config.json"
# if no config path is
# specified then choose the users default
if( len(sys.argv) > 1 ):
path = sys.argv[1]
cfg = readconfig(path) # read the config
global CONFIG
CONFIG = cfg
def start(self): def start(self):
controller.init() controller.init()
for inp in self.voiceInpObj.start(): for inp in self.voiceInpObj.start( self.deviceIndex ):
cmdBuf = inp.lower().split(" ") cmdBuf = inp.lower().split(" ")
if( cmdBuf[0] in prefixes ): if( cmdBuf[0] in CONFIG["speech"]["prefixes"] ):
print("CMD:", cmdBuf) print("CMD:", cmdBuf)
parseCommandline( cmdBuf, False ) parseCommandline( cmdBuf, False )
@ -26,4 +49,5 @@ class speech_daemon(object):
if __name__ == "__main__": if __name__ == "__main__":
daemon = speech_daemon() daemon = speech_daemon()
daemon.loadconfig()
daemon.start() daemon.start()

Loading…
Cancel
Save