Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,5 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/
urequests.py
urequests.py
src/test/
17 changes: 12 additions & 5 deletions src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,24 @@ class ApiInterface:
__PREVIOUS_DEVICE_URL = __DEVICE_URL + "/previous"
__PLAY_URL = __BASE_URL + "/play"

def request(self, method: str, url: str, data=None) -> urequests.Response:
def request(self, method: str, url: str, data=None, params=None) -> urequests.Response:
if data is None:
data = {}
if params is None:
params = {}

query_string = '&'.join([f"{key}={value}" for key, value in params.items()])
if query_string:
url = f"{url}?{query_string}"

if method == "GET":
if data:
raise ValueError("GET requests cannot have data, use params instead")

resp = urequests.request(method, url, headers=self.__HEADERS)
else:
resp = urequests.request(method, url, headers=self.__HEADERS, data=json.dumps(data))

print(resp.status_code)
print(resp.text)
return resp

def check_health(self) -> bool:
Expand All @@ -34,8 +41,8 @@ def check_health(self) -> bool:
except:
return False

def get_current_device(self) -> dict:
return self.request("GET", self.__DEVICE_URL).json()
def get_current_device(self, reset: bool = False) -> dict:
return self.request("GET", self.__DEVICE_URL, params={"reset": reset}).json()

def next_device(self) -> dict:
return self.request("POST", self.__NEXT_DEVICE_URL).json()
Expand Down
8 changes: 7 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,16 @@ def __display_current_device(self) -> None:
self.__display.clear()
self.__display.print("Devices:", line=1)

current_device_data = self.__api.get_current_device()
current_device_data = self.__api.get_current_device(reset=True)
self.__change_device(current_device_data)

def __change_device(self, device_data: dict) -> None:
if device_data == {}:
self.__display.print("No devices", line=2)
return

print(device_data)

text = f"{device_data['index'] + 1}/{device_data['total']} {device_data['device']['name']}"
self.__display.print(text, line=2)

Expand Down