Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 38 additions & 30 deletions ChromaPython/ChromaApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,50 @@

class ChromaApp:
def __init__(self, Info: ChromaAppInfo):
url = 'http://localhost:54235/razer/chromasdk'
data = {
"title": Info.Title,
"description": Info.Description,
"author": {
"name": Info.DeveloperName,
"contact": Info.DeveloperContact
},
"device_supported": Info.SupportedDevices,
"category": Info.Category
}
try:
url = 'http://localhost:54235/razer/chromasdk'

data = {
"title": Info.Title,
"description": Info.Description,
"author": {
"name": Info.DeveloperName,
"contact": Info.DeveloperContact
},
"device_supported": Info.SupportedDevices,
"category": Info.Category
}
response = requests.post(url=url, json=data)
self.SessionID, self.URI = response.json()['sessionid'], response.json()['uri']
self.heartbeat = Heartbeat(self.URI)
self.Keyboard = Keyboard(self.URI)
self.Mouse = Mouse(self.URI)
self.Mousepad = Mousepad(self.URI)
self.Headset = Headset(self.URI)
self.ChromaLink = ChromaLink(self.URI)
self.BcaHandler = ChromaBcaHandler()
except:
# TODO Add proper exception handling
print('Unexpected Error!')
raise
except Exception as err:
print('Can\'nt connect to ' + str(url) + '.\nError:' + str(err))
exit(1)
response_json = response.json()
try:
self.SessionID, self.URI = response_json['sessionid'], response_json['uri']
except KeyError as err:
print('Missing sessionid or uri from response.\nError:' + str(err))
exit(1)
self.heartbeat = Heartbeat(self.URI)
self.Keyboard = Keyboard(self.URI)
self.Mouse = Mouse(self.URI)
self.Mousepad = Mousepad(self.URI)
self.Headset = Headset(self.URI)
self.ChromaLink = ChromaLink(self.URI)
self.BcaHandler = ChromaBcaHandler()

def Version(self):
url = 'http://localhost:54235/razer/chromasdk'
try:
response = requests.get(url=url)
except Exception as err:
print('Can\'nt connect to ' + str(url) + '.\nError:' + str(err))
exit(1)
try:
return requests.get(url='http://localhost:54235/razer/chromasdk').json()['version']
except:
# TODO Add proper exception handling
print('Unexpected Error!')
raise
return response.json()['version']
except KeyError as err:
print('Missing version from response.\nError:' + str(err))
exit(1)

def __del__(self):
print('Im dying')
print('I\'m dying')
self.heartbeat.stop()
requests.delete(self.URI)