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 get
|
||||||
from requests import post
|
from requests import post
|
||||||
from json import loads
|
from json import loads
|
||||||
@@ -13,16 +13,19 @@ haAddress = "192.168.0.42"
|
|||||||
haLight = "light.sb50_l4"
|
haLight = "light.sb50_l4"
|
||||||
haUrl = "http://" + haAddress + ":8123/api/states/" + haLight
|
haUrl = "http://" + haAddress + ":8123/api/states/" + haLight
|
||||||
haHeaders = {
|
haHeaders = {
|
||||||
"Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI0ZmQ4MzQxNTZjNjg0YThlYTFjY2NiYmNkNWEzYTI4OSIsImlhdCI6MTY2NjExMDcwMiwiZXhwIjoxOTgxNDcwNzAyfQ.5KVla7Y72yKFrWhF01EupQpSHX0Rbr0CQ-LMLW6v6VU",
|
"Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI0ZmQ4MzQxNTZjNjg0YThlYTFjY2NiYmNkNWEzYTI4OSIsImlhdCI6MTY2NjExMDcwMiwiZXhwIjoxOTgxNDcwNzAyfQ.5KVla7Y72yKFrWhF01EupQpSHX0Rbr0CQ-LMLW6v6VU",
|
||||||
"content-type": "application/json",
|
"content-type": "application/json"
|
||||||
}
|
}
|
||||||
haResponse = get(haUrl, headers=haHeaders)
|
|
||||||
haData = loads(haResponse.text)
|
|
||||||
haLightColor = haData['attributes']['rgb_color']
|
|
||||||
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"
|
||||||
|
|
||||||
|
def checkLight():
|
||||||
|
""" Check HA light color """
|
||||||
|
haResponse = get(haUrl, headers=haHeaders)
|
||||||
|
haData = loads(haResponse.text)
|
||||||
|
return haData['attributes']['rgb_color']
|
||||||
|
|
||||||
def registerGame():
|
def registerGame():
|
||||||
"""Registers this application to Engine."""
|
"""Registers this application to Engine."""
|
||||||
print("[+] registerGame()")
|
print("[+] registerGame()")
|
||||||
@@ -33,7 +36,16 @@ def registerGame():
|
|||||||
"developer" : "quoije"
|
"developer" : "quoije"
|
||||||
}
|
}
|
||||||
r = post(endpoint, json=payload)
|
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():
|
def removeGameEvent():
|
||||||
"""Removes a lighting event from Engine."""
|
"""Removes a lighting event from Engine."""
|
||||||
@@ -43,47 +55,63 @@ def removeGameEvent():
|
|||||||
"game" : gsGame,
|
"game" : gsGame,
|
||||||
"event" : gsEvent
|
"event" : gsEvent
|
||||||
}
|
}
|
||||||
post(endpoint, json=payload)
|
r = post(endpoint, json=payload)
|
||||||
|
print(r.text)
|
||||||
|
|
||||||
def bindGameEvent():
|
def bindGameEvent():
|
||||||
"""Binds a lighting event to Engine."""
|
"""Binds a lighting event to Engine."""
|
||||||
print("[+] bindGameEvent()")
|
print("[+] bindGameEvent()")
|
||||||
endpoint = f'{gsAddress}/register_game_event'
|
endpoint = f'{gsAddress}/bind_game_event'
|
||||||
payload = {
|
payload = {
|
||||||
"game" : gsGame,
|
"game": gsGame,
|
||||||
"event": gsEvent,
|
"event": gsEvent,
|
||||||
"handlers" :
|
"handlers": [{
|
||||||
{
|
"mode": "color",
|
||||||
"device-type": "rgb-zoned-device",
|
"device-type": "keyboard",
|
||||||
"zone": "two",
|
"zone": "all",
|
||||||
"color": {"red": 0, "green": 255, "blue": 0},
|
"color": {"red": 255,"green": 0,"blue": 255}
|
||||||
"mode": "color"
|
}]
|
||||||
}
|
}
|
||||||
}
|
r = post(endpoint, json=payload)
|
||||||
post(endpoint, json=payload)
|
print(r.text)
|
||||||
|
|
||||||
def sendGameEvent(event, kill_switch):
|
def sendGameEvent(kill_switch):
|
||||||
"""Sends a lighting event/frame to Engine."""
|
"""Sends a lighting event/frame to Engine."""
|
||||||
print("[+] sendGameEvent(kill_switch)")
|
print("[+] sendGameEvent(kill_switch)")
|
||||||
|
endpoint = f'{gsAddress}/game_event'
|
||||||
if event == "init":
|
payload = {
|
||||||
print("ayyy")
|
"game": gsGame,
|
||||||
elif event == gsEvent:
|
"event": gsEvent,
|
||||||
endpoint = f'{gsAddress}/game_event'
|
"data" : {
|
||||||
payload = {
|
"value": 1
|
||||||
"game": gsGame,
|
|
||||||
"event": gsEvent,
|
|
||||||
"data": {
|
|
||||||
"value" : 50
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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()
|
bindGameEvent()
|
||||||
sendGameEvent(gsEvent, 0)
|
print("[+] send game for debug")
|
||||||
|
sendGameEvent(0)
|
||||||
Reference in New Issue
Block a user