Merge pull request 'Improved Lights Module' (#20) from master into Chyron-Module

Reviewed-on: #20
This commit is contained in:
alex_orid 2021-04-09 22:02:14 +00:00
commit 1eb2851986
4 changed files with 57 additions and 33 deletions

View File

@ -21,38 +21,47 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta):
if tempBool == True: if tempBool == True:
LightModule = lights_module.Lights_Module() LightModule = lights_module.Lights_Module()
LightModule.main() LightModule.main()
print("\nRGB Command Detected!") #print("\nRGB Command Detected!")
tempParsedMessage = user_message.message.split(" ") tempParsedMessage = user_message.message.split(" ")
print("\nParsed Command! ", user_message.message) sceneCommand = False
if (len(tempParsedMessage)) > 2: if (len(tempParsedMessage)) > 2:
print("\nRGB Command!") print("RGB Command!")
rgb_r = float(tempParsedMessage[1]) rgb_r = float(tempParsedMessage[1])
rgb_g = float(tempParsedMessage[2]) rgb_g = float(tempParsedMessage[2])
rgb_b = float(tempParsedMessage[3]) rgb_b = float(tempParsedMessage[3])
xy_result = LightModule.rgb_to_xy(rgb_r, rgb_g, rgb_b) xy_result = LightModule.rgb_to_xy(rgb_r, rgb_g, rgb_b)
print("got XY") #print("got XY")
LightModule.bridge_.set_group(16, "xy", xy_result) LightModule.bridge_.set_group(16, "xy", xy_result)
print("sent color") print("sent color to [Lights_Module]")
else: else:
if "stream" in tempParsedMessage: if "stream" in tempParsedMessage:
sceneCommand = True
LightModule.bridge_.run_scene("Downstairs", "Stream") LightModule.bridge_.run_scene("Downstairs", "Stream")
elif "normal" in tempParsedMessage: elif "normal" in tempParsedMessage:
sceneCommand = True
LightModule.bridge_.run_scene("Downstairs", "Bright") LightModule.bridge_.run_scene("Downstairs", "Bright")
elif "haxor" in tempParsedMessage: elif "haxor" in tempParsedMessage:
sceneCommand = True
LightModule.bridge_.run_scene("Downstairs", "hacker vibes") LightModule.bridge_.run_scene("Downstairs", "hacker vibes")
elif "off" in tempParsedMessage: elif "off" in tempParsedMessage:
sceneCommand = True
LightModule.bridge_.set_group("Downstairs", "on", False) LightModule.bridge_.set_group("Downstairs", "on", False)
elif "on" in tempParsedMessage: elif "on" in tempParsedMessage:
sceneCommand = True
LightModule.bridge_.set_group("Downstairs", "on", True) LightModule.bridge_.set_group("Downstairs", "on", True)
elif "ravemode" in tempParsedMessage: elif "ravemode" in tempParsedMessage:
sceneCommand = True
LightModule.raveMode() LightModule.raveMode()
else: else:
print("\nColor Command!") print("Color Command!")
xy_result = LightModule.color_string_parser(tempParsedMessage) xy_result = LightModule.color_string_parser(tempParsedMessage)
print("got XY") #print("got XY")
LightModule.bridge_.set_group(16, "xy", xy_result) LightModule.bridge_.set_group(16, "xy", xy_result)
print("sent color") print("sent color to [Lights_Module]")
if sceneCommand == True:
print("Scene Command!")
returnMessage = "@" + user_message.user + " changed the light's color!" returnMessage = "@" + user_message.user + " changed the light's color!"
bot.return_message(returnMessage) bot.return_message(returnMessage)

View File

@ -17,41 +17,51 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta):
super().__init__(CommandRoll.command, n_args=3, command_type=AbstractCommand.CommandType.TWITCH) super().__init__(CommandRoll.command, n_args=3, command_type=AbstractCommand.CommandType.TWITCH)
def do_command(self, bot, twitch_message): def do_command(self, bot, twitch_message):
if bot.allow_rgbLightControl == True: if bot.allow_rgbLightControl == True:
LightModule = lights_module.Lights_Module() LightModule = lights_module.Lights_Module()
LightModule.main() LightModule.main()
print("\nRGB Command Detected!") #print("\nRGB Command Detected!")
tempParsedMessage = twitch_message.text.split(" ") tempParsedMessage = twitch_message.text.split(" ")
print("\nParsed Command! ", twitch_message.text) sceneCommand = False
if (len(tempParsedMessage)) > 2: if (len(tempParsedMessage)) > 2:
print("\nRGB Command!") print("RGB Command!")
rgb_r = float(tempParsedMessage[1]) rgb_r = float(tempParsedMessage[1])
rgb_g = float(tempParsedMessage[2]) rgb_g = float(tempParsedMessage[2])
rgb_b = float(tempParsedMessage[3]) rgb_b = float(tempParsedMessage[3])
xy_result = LightModule.rgb_to_xy(rgb_r, rgb_g, rgb_b) xy_result = LightModule.rgb_to_xy(rgb_r, rgb_g, rgb_b)
print("got XY") #print("got XY")
LightModule.bridge_.set_group(16, "xy", xy_result) LightModule.bridge_.set_group(16, "xy", xy_result)
print("sent color") print("sent color to [Lights_Module]")
else: else:
if "stream" in tempParsedMessage: if "stream" in tempParsedMessage:
sceneCommand = True
LightModule.bridge_.run_scene("Downstairs", "Stream") LightModule.bridge_.run_scene("Downstairs", "Stream")
elif "normal" in tempParsedMessage: elif "normal" in tempParsedMessage:
sceneCommand = True
LightModule.bridge_.run_scene("Downstairs", "Bright") LightModule.bridge_.run_scene("Downstairs", "Bright")
elif "haxor" in tempParsedMessage: elif "haxor" in tempParsedMessage:
sceneCommand = True
LightModule.bridge_.run_scene("Downstairs", "hacker vibes") LightModule.bridge_.run_scene("Downstairs", "hacker vibes")
elif "off" in tempParsedMessage: elif "off" in tempParsedMessage:
sceneCommand = True
LightModule.bridge_.set_group("Downstairs", "on", False) LightModule.bridge_.set_group("Downstairs", "on", False)
elif "on" in tempParsedMessage: elif "on" in tempParsedMessage:
sceneCommand = True
LightModule.bridge_.set_group("Downstairs", "on", True) LightModule.bridge_.set_group("Downstairs", "on", True)
elif "ravemode" in tempParsedMessage: elif "ravemode" in tempParsedMessage:
sceneCommand = True
LightModule.raveMode() LightModule.raveMode()
else: else:
print("\nColor Command!") print("Color Command!")
xy_result = LightModule.color_string_parser(tempParsedMessage) xy_result = LightModule.color_string_parser(tempParsedMessage)
print("got XY") #print("got XY")
LightModule.bridge_.set_group(16, "xy", xy_result) LightModule.bridge_.set_group(16, "xy", xy_result)
print("sent color") print("sent color to [Lights_Module]")
if sceneCommand == True:
print("Scene Command!")
returnMessage = "@" + twitch_message.sender + " changed the light's color!" returnMessage = "@" + twitch_message.sender + " changed the light's color!"
bot.send_message(returnMessage) bot.send_message(returnMessage)

View File

@ -44,6 +44,11 @@ autoEnabled_Discord_rgbLightControl = False
#Chyron Module Configs #Chyron Module Configs
chyronListSpaceCount = 25 chyronListSpaceCount = 25
#Lights Module Configs
colorParse_maxDigits = 4
#General Configs #General Configs
skip_splashScreen = False skip_splashScreen = False
skip_splashScreenClear = False skip_splashScreenClear = False

View File

@ -14,7 +14,7 @@ class Lights_Module():
self.bridge_:Bridge = Bridge('192.168.191.146') self.bridge_:Bridge = Bridge('192.168.191.146')
def main(self): def main(self):
print("Starting up Lights_Modules....") print("Starting up [Lights_Module]...")
self.bridge_.connect() self.bridge_.connect()
self.bridge_.get_api() self.bridge_.get_api()
@ -24,11 +24,11 @@ class Lights_Module():
groups = self.bridge_.get_group() groups = self.bridge_.get_group()
groupCount = 0 groupCount = 0
print("\n -Listing Lights...") #print("\n -Listing Lights...")
for l in light_list: for l in light_list:
pass pass
#print(l.name) #print(l.name)
print("\n -Counting Groups...") #print("\n -Counting Groups...")
for g in groups: for g in groups:
#print(g) #print(g)
groupCount = int(g) groupCount = int(g)
@ -65,7 +65,7 @@ class Lights_Module():
# This will set the group Downstairs to the Stream scene # This will set the group Downstairs to the Stream scene
#self.bridge_.run_scene("Downstairs", "Stream") #self.bridge_.run_scene("Downstairs", "Stream")
print("\n Setup Complete") print("-[Lights_Module] Setup Complete")
def setLight(): def setLight():
pass pass
@ -117,23 +117,23 @@ class Lights_Module():
return [x, y] return [x, y]
def color_string_parser(self, message): def color_string_parser(self, message):
maxDigits = 4 maxDigits = config.colorParse_maxDigits
print("trying to find color") print("Searching for color...")
xy_color = [0, 0] xy_color = [0, 0]
for text in message: for text in message:
#print("testing word") #print("testing word")
if "red" in text.lower(): if "red" in text.lower():
xy_color = self.rgb_to_xy(1,0,0) xy_color = self.rgb_to_xy(1,0,0)
print("found: red") print("-found: red")
if "blue" in text.lower(): if "blue" in text.lower():
print("found: blue") print("-found: blue")
xy_color = self.rgb_to_xy(0,0,1) xy_color = self.rgb_to_xy(0,0,1)
if "green" in text.lower(): if "green" in text.lower():
print("found: green") print("-found: green")
xy_color = self.rgb_to_xy(0,1,0) xy_color = self.rgb_to_xy(0,1,0)
if "yellow" in text.lower(): if "yellow" in text.lower():
print("found: yellow") print("-found: yellow")
xy_color = self.rgb_to_xy( xy_color = self.rgb_to_xy(
0.7, 0.7,
0.64, 0.64,
@ -141,23 +141,23 @@ class Lights_Module():
if "cyan" in text.lower(): if "cyan" in text.lower():
print("found: cyan") print("-found: cyan")
xy_color = self.rgb_to_xy(0,1,1) xy_color = self.rgb_to_xy(0,1,1)
if "aquamarine" in text.lower(): if "aquamarine" in text.lower():
print("found: aquamarine") print("-found: aquamarine")
xy_color = self.rgb_to_xy( xy_color = self.rgb_to_xy(
round(utilities.rescale_value(111,0,254),maxDigits), round(utilities.rescale_value(111,0,254),maxDigits),
round(utilities.rescale_value(218,0,254),maxDigits), round(utilities.rescale_value(218,0,254),maxDigits),
round(utilities.rescale_value(146,0,254),maxDigits)) round(utilities.rescale_value(146,0,254),maxDigits))
if "turquoise" in text.lower(): if "turquoise" in text.lower():
print("found: turquoise") print("-found: turquoise")
xy_color = self.rgb_to_xy( xy_color = self.rgb_to_xy(
round(utilities.rescale_value(172,0,254),maxDigits), round(utilities.rescale_value(172,0,254),maxDigits),
round(utilities.rescale_value(233,0,254),maxDigits), round(utilities.rescale_value(233,0,254),maxDigits),
round(utilities.rescale_value(232,0,254),maxDigits)) round(utilities.rescale_value(232,0,254),maxDigits))
if "orange" in text.lower(): if "orange" in text.lower():
print("found: orange") print("-found: orange")
xy_color = self.rgb_to_xy( xy_color = self.rgb_to_xy(
1, 1,
round(utilities.rescale_value(126,0,254),maxDigits), round(utilities.rescale_value(126,0,254),maxDigits),
@ -165,21 +165,21 @@ class Lights_Module():
if "magenta" in text.lower(): if "magenta" in text.lower():
print("found: magenta") print("-found: magenta")
xy_color = self.rgb_to_xy( xy_color = self.rgb_to_xy(
1, 1,
0, 0,
1) 1)
if "purple" in text.lower(): if "purple" in text.lower():
print("found: purple") print("-found: purple")
xy_color = self.rgb_to_xy( xy_color = self.rgb_to_xy(
round(utilities.rescale_value(159,0,254),maxDigits), round(utilities.rescale_value(159,0,254),maxDigits),
round(utilities.rescale_value(32,0,254),maxDigits), round(utilities.rescale_value(32,0,254),maxDigits),
round(utilities.rescale_value(239,0,254),maxDigits)) round(utilities.rescale_value(239,0,254),maxDigits))
if "violet" in text.lower(): if "violet" in text.lower():
print("found: violet") print("-found: violet")
xy_color = self.rgb_to_xy( xy_color = self.rgb_to_xy(
round(utilities.rescale_value(237,0,254),maxDigits), round(utilities.rescale_value(237,0,254),maxDigits),
round(utilities.rescale_value(129,0,254),maxDigits), round(utilities.rescale_value(129,0,254),maxDigits),