Skip to content

Commit 394b991

Browse files
committed
Revert "Unify preset names and change 404 to 400"
This reverts commit 160633f.
1 parent 160633f commit 394b991

File tree

2 files changed

+40
-21
lines changed

2 files changed

+40
-21
lines changed

ledfx/api/presets.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ async def get(self, effect_id) -> web.Response:
2727
return web.json_response(data=response, status=400)
2828

2929
if effect_id in self._ledfx.config["ledfx_presets"].keys():
30-
ledfx_presets = self._ledfx.config["ledfx_presets"][effect_id]
30+
default = self._ledfx.config["ledfx_presets"][effect_id]
3131
else:
32-
ledfx_presets = {}
32+
default = {}
3333

3434
if effect_id in self._ledfx.config["user_presets"].keys():
35-
user_presets = self._ledfx.config["user_presets"][effect_id]
35+
custom = self._ledfx.config["user_presets"][effect_id]
3636
else:
37-
user_presets = {}
37+
custom = {}
3838

3939
response = {
4040
"status": "success",
4141
"effect": effect_id,
42-
"ledfx_presets": ledfx_presets,
43-
"user_presets": user_presets,
42+
"default_presets": default,
43+
"custom_presets": custom,
4444
}
4545
return web.json_response(data=response, status=200)
4646

@@ -65,7 +65,9 @@ async def put(self, effect_id, request) -> web.Response:
6565
if category not in ["ledfx_presets", "user_presets"]:
6666
response = {
6767
"status": "failed",
68-
"reason": f'Category {category} is not "ledfx_presets" or "user_presets"',
68+
"reason": 'Category {} is not "ledfx_presets" or "user_presets"'.format(
69+
category
70+
),
6971
}
7072
return web.json_response(data=response, status=400)
7173

@@ -79,7 +81,9 @@ async def put(self, effect_id, request) -> web.Response:
7981
if effect_id not in self._ledfx.config[category].keys():
8082
response = {
8183
"status": "failed",
82-
"reason": f"Effect {effect_id} does not exist in category {category}",
84+
"reason": "Effect {} does not exist in category {}".format(
85+
effect_id, category
86+
),
8387
}
8488
return web.json_response(data=response, status=400)
8589

@@ -102,7 +106,9 @@ async def put(self, effect_id, request) -> web.Response:
102106
if preset_id not in self._ledfx.config[category][effect_id].keys():
103107
response = {
104108
"status": "failed",
105-
"reason": f"Preset {preset_id} does not exist for effect {effect_id} in category {category}",
109+
"reason": "Preset {} does not exist for effect {} in category {}".format(
110+
preset_id, effect_id, category
111+
),
106112
}
107113
return web.json_response(data=response, status=400)
108114

@@ -142,7 +148,9 @@ async def delete(self, effect_id, request) -> web.Response:
142148
if category not in ["ledfx_presets", "user_presets"]:
143149
response = {
144150
"status": "failed",
145-
"reason": f'Category {category} is not "ledfx_presets" or "user_presets"',
151+
"reason": 'Category {} is not "ledfx_presets" or "user_presets"'.format(
152+
category
153+
),
146154
}
147155
return web.json_response(data=response, status=400)
148156

@@ -165,7 +173,9 @@ async def delete(self, effect_id, request) -> web.Response:
165173
if effect_id not in self._ledfx.config[category].keys():
166174
response = {
167175
"status": "failed",
168-
"reason": f"Effect {effect_id} does not exist in category {category}",
176+
"reason": "Effect {} does not exist in category {}".format(
177+
effect_id, category
178+
),
169179
}
170180
return web.json_response(data=response, status=400)
171181

@@ -179,7 +189,9 @@ async def delete(self, effect_id, request) -> web.Response:
179189
if preset_id not in self._ledfx.config[category][effect_id].keys():
180190
response = {
181191
"status": "failed",
182-
"reason": f"Preset {preset_id} does not exist for effect {effect_id} in category {category}",
192+
"reason": "Preset {} does not exist for effect {} in category {}".format(
193+
preset_id, effect_id, category
194+
),
183195
}
184196
return web.json_response(data=response, status=400)
185197

ledfx/api/virtual_presets.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async def get(self, virtual_id) -> web.Response:
2323
"status": "failed",
2424
"reason": f"Virtual with ID {virtual_id} not found",
2525
}
26-
return web.json_response(data=response, status=400)
26+
return web.json_response(data=response, status=404)
2727

2828
if not virtual.active_effect:
2929
response = {
@@ -48,8 +48,8 @@ async def get(self, virtual_id) -> web.Response:
4848
"status": "success",
4949
"virtual": virtual_id,
5050
"effect": effect_id,
51-
"ledfx_presets": default,
52-
"user_presets": custom,
51+
"default_presets": default,
52+
"custom_presets": custom,
5353
}
5454

5555
return web.json_response(data=response, status=200)
@@ -83,7 +83,7 @@ async def put(self, virtual_id, request) -> web.Response:
8383
"status": "failed",
8484
"reason": f"Virtual with ID {virtual_id} not found",
8585
}
86-
return web.json_response(data=response, status=400)
86+
return web.json_response(data=response, status=404)
8787

8888
try:
8989
data = await request.json()
@@ -100,13 +100,18 @@ async def put(self, virtual_id, request) -> web.Response:
100100
}
101101
return web.json_response(data=response, status=400)
102102

103-
if category not in ["ledfx_presets", "user_presets"]:
103+
if category not in ["default_presets", "custom_presets"]:
104104
response = {
105105
"status": "failed",
106106
"reason": f'Category {category} is not "ledfx_presets" or "user_presets"',
107107
}
108108
return web.json_response(data=response, status=400)
109109

110+
if category == "default_presets":
111+
category = "ledfx_presets"
112+
else:
113+
category = "user_presets"
114+
110115
if effect_id is None:
111116
response = {
112117
"status": "failed",
@@ -131,7 +136,9 @@ async def put(self, virtual_id, request) -> web.Response:
131136
if preset_id not in self._ledfx.config[category][effect_id].keys():
132137
response = {
133138
"status": "failed",
134-
"reason": f"Preset {preset_id} does not exist for effect {effect_id} in category {category}",
139+
"reason": "Preset {} does not exist for effect {} in category {}".format(
140+
preset_id, effect_id, category
141+
),
135142
}
136143
return web.json_response(data=response, status=400)
137144

@@ -174,14 +181,14 @@ async def post(self, virtual_id, request) -> web.Response:
174181
"status": "failed",
175182
"reason": f"Virtual with ID {virtual_id} not found",
176183
}
177-
return web.json_response(data=response, status=400)
184+
return web.json_response(data=response, status=404)
178185

179186
if not virtual.active_effect:
180187
response = {
181188
"status": "failed",
182189
"reason": f"Virtual {virtual_id} has no active effect",
183190
}
184-
return web.json_response(data=response, status=400)
191+
return web.json_response(data=response, status=404)
185192

186193
try:
187194
data = await request.json()
@@ -234,7 +241,7 @@ async def delete(self, virtual_id) -> web.Response:
234241
"status": "failed",
235242
"reason": f"Virtual with ID {virtual_id} not found",
236243
}
237-
return web.json_response(data=response, status=400)
244+
return web.json_response(data=response, status=404)
238245

239246
# Clear the effect
240247
virtual.clear_effect()

0 commit comments

Comments
 (0)