diff --git a/streamdeckapi/server.py b/streamdeckapi/server.py index 2195be9..b32907c 100644 --- a/streamdeckapi/server.py +++ b/streamdeckapi/server.py @@ -41,34 +41,19 @@ application: SDApplication = SDApplication( devices: list[SDDevice] = [] buttons: dict[str, SDButton] = {} -# Examples -# devices.append( -# SDDevice( -# { -# "id": "08B602C026FC8D1989FDF80EB8658612", -# "name": "Stream Deck", -# "size": {"columns": 5, "rows": 3}, -# "type": 0, -# } -# ) -# ) -# buttons["576e8e7fc6ac2a37fa436ed3dc76652b"] = SDButton( -# { -# "uuid": "kind-sloth-97", -# "device": "08B602C026FC8D1989FDF80EB8658612", -# "position": {"x": 0, "y": 0}, -# "svg": 'offPhilips Hue Huelight', -# } -# ) - async def api_info_handler( request: web.Request, -): # FIXME: can result in unparseable json (different keys, f.ex. x - x_pos) +): # FIXME: unparseable json (x -> x_pos, y -> y_pos, platformVersion -> platform_version) json_data = encode( {"devices": devices, "application": application, "buttons": buttons}, unpicklable=False, ) + if not isinstance(json_data, str): + return web.Response(status=500, text="jsonpickle error") + json_data = json_data.replace('"x_pos"', '"x"').replace('"y_pos"', '"y"').replace( + '"platform_version"', '"platformVersion"' + ) return web.Response(text=json_data, content_type="application/json") @@ -185,6 +170,7 @@ def init_all(): } ) + deck.reset() # TODO: write svg to buttons deck.set_key_callback(on_key_change)