Made the daemon wrok

fetchIP
E. Almqvist 4 years ago
parent 86d7681f7d
commit eaa72ef06b
  1. 12
      modules/hue/hue_remote.py
  2. 18
      speech_daemon.py

@ -31,7 +31,7 @@ boolConvert = {
# this is the most spaghetti-ish code I have ever written but it works
def parseCommand( cmd:list, pos:int, i=-1 ):
def parseCommand( cmd:list, pos:int, i=-1, displayHelp=True ):
index = int(i)
try:
if( cmd[pos] == "on" or cmd[pos] == "off" ):
@ -82,18 +82,18 @@ def parseCommand( cmd:list, pos:int, i=-1 ):
help() # display help if function did nothing
except (RuntimeError, TypeError, NameError, IndexError) as err:
if(displayHelp):
help() # display the help page if parameters are missing (it will give out an IndexError)
print( "\n\nError: " + str(err) )
print( "\n\nError: " + str(err) )
def parseCommandline():
cmd = sys.argv
def parseCommandline( cmd=sys.argv, needHelp=True ):
if( len(cmd) > 1 ):
if( cmd[1] == "light" ):
parseCommand( cmd, 3, cmd[2] )
parseCommand( cmd, 3, cmd[2], displayHelp=needHelp )
elif( cmd[1] == "lights" ):
parseCommand( cmd, 2 )
parseCommand( cmd, 2, displayHelp=needHelp )
else:
help()

@ -1,16 +1,26 @@
#!/usr/bin/env python
from modules.hue.hue_remote import parseCommand
from modules.hue.hue_remote import parseCommandline
from modules.speech.speech import voiceInput
prefixes = ["computer", "computers"]
class speech_daemon(object):
voiceInpObj = None
def __init__(self, deviceIndex=30):
voiceInpObj = voiceInput()
voiceInpObj.setMuted(False)
self.voiceInpObj = voiceInput()
self.voiceInpObj.setMuted(False)
voiceInpObj.start(deviceIndex)
def start(self):
return self.voiceInpObj.start()
if __name__ == "__main__":
daemon = speech_daemon()
cmdBuf = None
for inp in daemon.start():
cmdBuf = inp.lower().split(" ")
if( cmdBuf[0] in prefixes ):
print("CMD:", cmdBuf)
parseCommandline( cmdBuf[1:], False )

Loading…
Cancel
Save