Skip to content

Commit 97c7686

Browse files
agnersclaude
andauthored
Simplify API validation by removing confusing origin parameter (#6203)
Co-authored-by: Claude <[email protected]>
1 parent 42f93d0 commit 97c7686

File tree

4 files changed

+5
-13
lines changed

4 files changed

+5
-13
lines changed

supervisor/addons/options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def _single_validate(self, typ: str, value: Any, key: str) -> Any:
187187

188188
# Device valid
189189
self.devices.add(device)
190-
return str(device.path)
190+
return str(value)
191191

192192
raise vol.Invalid(
193193
f"Fatal error for option '{key}' with type '{typ}' in {self._name} ({self._slug})"

supervisor/api/addons.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ async def options(self, request: web.Request) -> None:
306306
)
307307

308308
# Validate/Process Body
309-
body = await api_validate(addon_schema, request, origin=[ATTR_OPTIONS])
309+
body = await api_validate(addon_schema, request)
310310
if ATTR_OPTIONS in body:
311311
addon.options = body[ATTR_OPTIONS]
312312
if ATTR_BOOT in body:

supervisor/api/utils.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ def api_return_ok(data: dict[str, Any] | list[Any] | None = None) -> web.Respons
190190
async def api_validate(
191191
schema: vol.Schema | vol.All,
192192
request: web.Request,
193-
origin: list[str] | None = None,
194193
) -> dict[str, Any]:
195194
"""Validate request data with schema."""
196195
data: dict[str, Any] = await request.json(loads=json_loads)
@@ -199,14 +198,6 @@ async def api_validate(
199198
except vol.Invalid as ex:
200199
raise APIError(humanize_error(data, ex)) from None
201200

202-
if not origin:
203-
return data_validated
204-
205-
for origin_value in origin:
206-
if origin_value not in data_validated:
207-
continue
208-
data_validated[origin_value] = data[origin_value]
209-
210201
return data_validated
211202

212203

tests/addons/test_options.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,20 +233,21 @@ def test_simple_device_schema(coresys):
233233
):
234234
coresys.hardware.update_device(device)
235235

236-
assert AddonOptions(
236+
data_device_path = AddonOptions(
237237
coresys,
238238
{"name": "str", "password": "password", "input": "device"},
239239
MOCK_ADDON_NAME,
240240
MOCK_ADDON_SLUG,
241241
)({"name": "Pascal", "password": "1234", "input": "/dev/ttyUSB0"})
242+
assert data_device_path["input"] == "/dev/ttyUSB0"
242243

243244
data = AddonOptions(
244245
coresys,
245246
{"name": "str", "password": "password", "input": "device"},
246247
MOCK_ADDON_NAME,
247248
MOCK_ADDON_SLUG,
248249
)({"name": "Pascal", "password": "1234", "input": "/dev/serial/by-id/xyx"})
249-
assert data["input"] == "/dev/ttyUSB0"
250+
assert data["input"] == "/dev/serial/by-id/xyx"
250251

251252
assert AddonOptions(
252253
coresys,

0 commit comments

Comments
 (0)