help
This commit is contained in:
+67
-39
@@ -1,4 +1,4 @@
|
||||
from xml.sax import handler
|
||||
from logging import handlers
|
||||
from requests import get
|
||||
from requests import post
|
||||
from json import loads
|
||||
@@ -13,16 +13,19 @@ haAddress = "192.168.0.42"
|
||||
haLight = "light.sb50_l4"
|
||||
haUrl = "http://" + haAddress + ":8123/api/states/" + haLight
|
||||
haHeaders = {
|
||||
"Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI0ZmQ4MzQxNTZjNjg0YThlYTFjY2NiYmNkNWEzYTI4OSIsImlhdCI6MTY2NjExMDcwMiwiZXhwIjoxOTgxNDcwNzAyfQ.5KVla7Y72yKFrWhF01EupQpSHX0Rbr0CQ-LMLW6v6VU",
|
||||
"content-type": "application/json",
|
||||
}
|
||||
haResponse = get(haUrl, headers=haHeaders)
|
||||
haData = loads(haResponse.text)
|
||||
haLightColor = haData['attributes']['rgb_color']
|
||||
"Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI0ZmQ4MzQxNTZjNjg0YThlYTFjY2NiYmNkNWEzYTI4OSIsImlhdCI6MTY2NjExMDcwMiwiZXhwIjoxOTgxNDcwNzAyfQ.5KVla7Y72yKFrWhF01EupQpSHX0Rbr0CQ-LMLW6v6VU",
|
||||
"content-type": "application/json"
|
||||
}
|
||||
gsAddress = "http://127.0.0.1:50786"
|
||||
gsGame = "HA_LIGHT_SYNC"
|
||||
gsEvent = "SYNC"
|
||||
|
||||
def checkLight():
|
||||
""" Check HA light color """
|
||||
haResponse = get(haUrl, headers=haHeaders)
|
||||
haData = loads(haResponse.text)
|
||||
return haData['attributes']['rgb_color']
|
||||
|
||||
def registerGame():
|
||||
"""Registers this application to Engine."""
|
||||
print("[+] registerGame()")
|
||||
@@ -33,7 +36,16 @@ def registerGame():
|
||||
"developer" : "quoije"
|
||||
}
|
||||
r = post(endpoint, json=payload)
|
||||
print(r.text)
|
||||
print(r.text)
|
||||
|
||||
def removeGame():
|
||||
"""Removes this application from Engine."""
|
||||
endpoint = f'{gsAddress}/remove_game'
|
||||
payload = {
|
||||
"game": gsGame
|
||||
}
|
||||
r = post(endpoint, json=payload)
|
||||
print(r.text)
|
||||
|
||||
def removeGameEvent():
|
||||
"""Removes a lighting event from Engine."""
|
||||
@@ -43,47 +55,63 @@ def removeGameEvent():
|
||||
"game" : gsGame,
|
||||
"event" : gsEvent
|
||||
}
|
||||
post(endpoint, json=payload)
|
||||
r = post(endpoint, json=payload)
|
||||
print(r.text)
|
||||
|
||||
def bindGameEvent():
|
||||
"""Binds a lighting event to Engine."""
|
||||
print("[+] bindGameEvent()")
|
||||
endpoint = f'{gsAddress}/register_game_event'
|
||||
endpoint = f'{gsAddress}/bind_game_event'
|
||||
payload = {
|
||||
"game" : gsGame,
|
||||
"game": gsGame,
|
||||
"event": gsEvent,
|
||||
"handlers" :
|
||||
{
|
||||
"device-type": "rgb-zoned-device",
|
||||
"zone": "two",
|
||||
"color": {"red": 0, "green": 255, "blue": 0},
|
||||
"mode": "color"
|
||||
}
|
||||
}
|
||||
post(endpoint, json=payload)
|
||||
"handlers": [{
|
||||
"mode": "color",
|
||||
"device-type": "keyboard",
|
||||
"zone": "all",
|
||||
"color": {"red": 255,"green": 0,"blue": 255}
|
||||
}]
|
||||
}
|
||||
r = post(endpoint, json=payload)
|
||||
print(r.text)
|
||||
|
||||
def sendGameEvent(event, kill_switch):
|
||||
def sendGameEvent(kill_switch):
|
||||
"""Sends a lighting event/frame to Engine."""
|
||||
print("[+] sendGameEvent(kill_switch)")
|
||||
|
||||
if event == "init":
|
||||
print("ayyy")
|
||||
elif event == gsEvent:
|
||||
endpoint = f'{gsAddress}/game_event'
|
||||
payload = {
|
||||
"game": gsGame,
|
||||
"event": gsEvent,
|
||||
"data": {
|
||||
"value" : 50
|
||||
}
|
||||
endpoint = f'{gsAddress}/game_event'
|
||||
payload = {
|
||||
"game": gsGame,
|
||||
"event": gsEvent,
|
||||
"data" : {
|
||||
"value": 1
|
||||
}
|
||||
with Session() as s:
|
||||
while kill_switch == 0:
|
||||
print("[+] loopyloop")
|
||||
s.post(endpoint, json=payload)
|
||||
if kill_switch == 1: break
|
||||
sleep(0.01)
|
||||
}
|
||||
|
||||
with Session() as s:
|
||||
while kill_switch == 0:
|
||||
|
||||
""" DEBUG """
|
||||
print("[+] loopyloop")
|
||||
""" DEBUG """
|
||||
|
||||
r = s.post(endpoint, json=payload)
|
||||
print(r.text)
|
||||
|
||||
if kill_switch == 1: break
|
||||
|
||||
""" DEBUG """
|
||||
print("[+] HA RGB: " + str(checkLight()[0]) + " " + str(checkLight()[1]) + " " + str(checkLight()[2]))
|
||||
""" DEBUG """
|
||||
|
||||
sleep(1.01)
|
||||
|
||||
print("[+] removing game event for debug")
|
||||
removeGameEvent()
|
||||
print("[+] removing game for debug")
|
||||
removeGame()
|
||||
print("[+] register game for debug")
|
||||
registerGame()
|
||||
print("[+] bind game for debug")
|
||||
bindGameEvent()
|
||||
sendGameEvent(gsEvent, 0)
|
||||
print("[+] send game for debug")
|
||||
sendGameEvent(0)
|
||||
Reference in New Issue
Block a user