This commit is contained in:
quoije
2022-10-19 03:49:28 -04:00
parent 13f6000768
commit 72c41f15e9
+25 -5
View File
@@ -19,6 +19,9 @@ haHeaders = {
gsAddress = "http://127.0.0.1:50786" gsAddress = "http://127.0.0.1:50786"
gsGame = "HA_LIGHT_SYNC" gsGame = "HA_LIGHT_SYNC"
gsEvent = "SYNC" gsEvent = "SYNC"
redRGB = 0
greenRGB = 0
blueRGB = 0
def checkLight(): def checkLight():
""" Check HA light color """ """ Check HA light color """
@@ -26,6 +29,18 @@ def checkLight():
haData = loads(haResponse.text) haData = loads(haResponse.text)
return haData['attributes']['rgb_color'] return haData['attributes']['rgb_color']
def updateLight():
global redRGB
global greenRGB
global blueRGB
redRGB = checkLight()[0]
greenRGB = checkLight()[1]
blueRGB = checkLight()[2]
print("[+] RED: "+ str(redRGB))
print("[+] GREEN: "+ str(greenRGB))
print("[+] BLUE: "+ str(blueRGB))
def registerGame(): def registerGame():
"""Registers this application to Engine.""" """Registers this application to Engine."""
print("[+] registerGame()") print("[+] registerGame()")
@@ -66,10 +81,10 @@ def bindGameEvent():
"game": gsGame, "game": gsGame,
"event": gsEvent, "event": gsEvent,
"handlers": [{ "handlers": [{
"mode": "color", "mode": "context-color",
"device-type": "keyboard", "device-type": "keyboard",
"zone": "all", "zone": "all",
"color": {"red": 255,"green": 0,"blue": 255} "context-frame-key": "zone-all-color"
}] }]
} }
r = post(endpoint, json=payload) r = post(endpoint, json=payload)
@@ -77,13 +92,16 @@ def bindGameEvent():
def sendGameEvent(kill_switch): def sendGameEvent(kill_switch):
"""Sends a lighting event/frame to Engine.""" """Sends a lighting event/frame to Engine."""
print("[+] sendGameEvent(kill_switch)")
endpoint = f'{gsAddress}/game_event' endpoint = f'{gsAddress}/game_event'
payload = { payload = {
"game": gsGame, "game": gsGame,
"event": gsEvent, "event": gsEvent,
"data" : { "data" : {
"value": 1 "frame": {
"zone-all-color": {
"color": {"red": redRGB,"green": greenRGB,"blue": blueRGB}
}
}
} }
} }
@@ -93,7 +111,9 @@ def sendGameEvent(kill_switch):
""" DEBUG """ """ DEBUG """
print("[+] loopyloop") print("[+] loopyloop")
""" DEBUG """ """ DEBUG """
print("[+] sendGameEvent(kill_switch)")
print("[+] update light RGB state")
updateLight()
r = s.post(endpoint, json=payload) r = s.post(endpoint, json=payload)
print(r.text) print(r.text)