Revert "Made code pep8 compliant once again"

This reverts commit c0ad5ce2d7.
pull/3/head
Alve 5 years ago
parent c0ad5ce2d7
commit ea87ee293c
  1. 2
      hue_cmd.py
  2. 1
      modules/configloader/__init__.py
  3. 1
      modules/configloader/loader.py
  4. 11
      modules/hue/hue_controller.py
  5. 9
      modules/hue/hue_remote.py
  6. 5
      modules/hue/lib/func.py
  7. 6
      modules/speech/speech.py
  8. 2
      speech_daemon.py

@ -3,12 +3,10 @@
from modules.hue.hue_controller import controller from modules.hue.hue_controller import controller
from modules.hue.hue_remote import parseCommandline from modules.hue.hue_remote import parseCommandline
def init(): def init():
controller.init() # very important to initialize the controller controller.init() # very important to initialize the controller
parseCommandline() parseCommandline()
controller.end() # also to end it controller.end() # also to end it
if __name__ == "__main__": if __name__ == "__main__":
init() init()

@ -1,6 +1,5 @@
import json import json
def readconfig(path): def readconfig(path):
try: try:
with open(path) as cfg: with open(path) as cfg:

@ -17,11 +17,9 @@ 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 PRE_URL + params return PRE_URL + params
class APIrequest: class APIrequest:
# Get Req # Get Req
async def get( dest: str="", payload: str="" ): async def get( dest: str="", payload: str="" ):
@ -71,8 +69,7 @@ class controller:
async def setLightRGB( index: int, r:int, g:int, b:int ): async def setLightRGB( index: int, r:int, g:int, b:int ):
h, s, v = rgbToHsv(r, g, b) h, s, v = rgbToHsv(r, g, b)
payload = '{"sat":' + str(s) + ', "bri":' + \ payload = '{"sat":' + str(s) + ', "bri":' + str(v) + ', "hue":' + str(h) + '}'
str(v) + ', "hue":' + str(h) + '}'
await APIrequest.put( "/lights/" + str(index) + "/state", payload ) await APIrequest.put( "/lights/" + str(index) + "/state", payload )
@ -82,8 +79,7 @@ class controller:
if(key): if(key):
if( key.get("state") ): if( key.get("state") ):
curPower = LIGHTS[str(index)]["state"]["on"] curPower = LIGHTS[str(index)]["state"]["on"]
loop.run_until_complete( loop.run_until_complete( controller.toggleLight(index, not curPower))
controller.toggleLight(index, not curPower))
else: else:
print("Error: Light index '" + str(index) + "' out of range") print("Error: Light index '" + str(index) + "' out of range")
@ -101,8 +97,7 @@ class controller:
def setLightBrightness( index:int, b:int ): def setLightBrightness( index:int, b:int ):
if( LIGHTS.get(str(index)) ): if( LIGHTS.get(str(index)) ):
payload = '{"bri":' + str(b) + '}' payload = '{"bri":' + str(b) + '}'
loop.run_until_complete(APIrequest.put( loop.run_until_complete( APIrequest.put( "/lights/" + str(index) + "/state", payload ) )
"/lights/" + str(index) + "/state", payload))
else: else:
print("Error: Light index '" + str(index) + "' out of range") print("Error: Light index '" + str(index) + "' out of range")

@ -7,13 +7,11 @@ from modules.hue import hue_controller as hue # Actual controller
cmd = "hue" cmd = "hue"
def help(): def help():
print("--Help page--") print("--Help page--")
print( "'" + cmd + "' : Display this help page" ) print( "'" + cmd + "' : Display this help page" )
print("'" + cmd + " light (index)' ... : Specify light target, from 1-" + print( "'" + cmd + " light (index)' ... : Specify light target, from 1-" + str(hue.controller.countLights()) )
str(hue.controller.countLights()))
print( "'" + cmd + " lights' ... : Specify all lights\n" ) print( "'" + cmd + " lights' ... : Specify all lights\n" )
print("--Commands--") print("--Commands--")
@ -26,7 +24,6 @@ def help():
print("\nExamples:\n'hue light 2 on' : Turn on light 2\n'hue lights set color 255 255 255' : Set all lights colors to white") print("\nExamples:\n'hue light 2 on' : Turn on light 2\n'hue lights set color 255 255 255' : Set all lights colors to white")
boolConvert = { boolConvert = {
"on": True, "on": True,
"off": False "off": False
@ -34,7 +31,6 @@ boolConvert = {
# this is the most spaghetti-ish code I have ever written but it works # this is the most spaghetti-ish code I have ever written but it works
def parseCommand( cmd:list, pos:int, index=-1, displayHelp=True ): def parseCommand( cmd:list, pos:int, index=-1, displayHelp=True ):
try: try:
if( cmd[pos] == "on" or cmd[pos] == "off" ): if( cmd[pos] == "on" or cmd[pos] == "off" ):
@ -63,8 +59,7 @@ def parseCommand(cmd: list, pos: int, index=-1, displayHelp=True):
r, g, b = int(cmd[pos+2]), int(cmd[pos+3]), int(cmd[pos+4]) r, g, b = int(cmd[pos+2]), int(cmd[pos+3]), int(cmd[pos+4])
if( index == -1 ): if( index == -1 ):
hue.controller.setAllLightsColor( hue.controller.setAllLightsColor( r, g, b ) # this code is bad
r, g, b) # this code is bad
else: else:
hue.controller.setLightColor( index, r, g, b ) hue.controller.setLightColor( index, r, g, b )

@ -5,23 +5,18 @@ boolStr = {
False: "false" False: "false"
} }
def boolToString(v: bool): # To fix the dumb python syntax def boolToString(v: bool): # To fix the dumb python syntax
return boolStr[v] return boolStr[v]
def rgbToDecimal( r:int, g:int, b:int ): def rgbToDecimal( r:int, g:int, b:int ):
return round(r/255, 1), round(g/255, 1), round(b/255, 1) return round(r/255, 1), round(g/255, 1), round(b/255, 1)
def svNumFix(n: float): def svNumFix(n: float):
return int(round(n*254, 0)) return int(round(n*254, 0))
def hueNumFix(n: float): def hueNumFix(n: float):
return int(round(n*65535, 0)) return int(round(n*65535, 0))
def rgbToHsv( r:int, g:int, b:int ): def rgbToHsv( r:int, g:int, b:int ):
R, G, B = rgbToDecimal(r, g, b) R, G, B = rgbToDecimal(r, g, b)
H, S, V = colorsys.rgb_to_hsv(R, G, B) H, S, V = colorsys.rgb_to_hsv(R, G, B)

@ -1,6 +1,5 @@
import speech_recognition as sr import speech_recognition as sr
class voiceInput(object): class voiceInput(object):
recognizer = sr.Recognizer() recognizer = sr.Recognizer()
@ -17,8 +16,7 @@ class voiceInput(object):
with sr.Microphone( deviceIndex ) as src: with sr.Microphone( deviceIndex ) as src:
self.recognizer.adjust_for_ambient_noise( src, 0.2 ) self.recognizer.adjust_for_ambient_noise( src, 0.2 )
print("Listening...") print("Listening...")
audio = self.recognizer.listen( audio = self.recognizer.listen( src, phrase_time_limit=5 )
src, phrase_time_limit=5)
print("Thinking...") print("Thinking...")
text = self.recognizer.recognize_google(audio) text = self.recognizer.recognize_google(audio)
yield text yield text
@ -30,8 +28,10 @@ class voiceInput(object):
except sr.UnknownValueError: except sr.UnknownValueError:
yield self.what yield self.what
def setMuted( self, setm: bool=True ): def setMuted( self, setm: bool=True ):
self.muted = setm self.muted = setm
def switchMute( self ): def switchMute( self ):
self.setMuted( not self.muted ) self.setMuted( not self.muted )

@ -13,7 +13,6 @@ homedir = expanduser("~")
CONFIG = {} CONFIG = {}
class speech_daemon(object): class speech_daemon(object):
voiceInpObj = None voiceInpObj = None
deviceIndex = 30 deviceIndex = 30
@ -48,7 +47,6 @@ class speech_daemon(object):
controller.end() controller.end()
if __name__ == "__main__": if __name__ == "__main__":
daemon = speech_daemon() daemon = speech_daemon()
daemon.loadconfig() daemon.loadconfig()

Loading…
Cancel
Save