From eaa72ef06bb734606d92233544e208275dec0c99 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 6 Oct 2020 20:12:54 +0200 Subject: [PATCH] Made the daemon wrok --- modules/hue/hue_remote.py | 14 +++++++------- speech_daemon.py | 18 ++++++++++++++---- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/modules/hue/hue_remote.py b/modules/hue/hue_remote.py index 5ce5763..b97cb97 100755 --- a/modules/hue/hue_remote.py +++ b/modules/hue/hue_remote.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: - help() # display the help page if parameters are missing (it will give out an IndexError) - print( "\n\nError: " + str(err) ) + if(displayHelp): + help() # display the help page if parameters are missing (it will give out an IndexError) + 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() diff --git a/speech_daemon.py b/speech_daemon.py index 55b240c..896744b 100755 --- a/speech_daemon.py +++ b/speech_daemon.py @@ -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 )