Add target option to zwave_js firmware upload view (#73690)
This commit is contained in:
parent
ab95299150
commit
801ba6ff8e
2 changed files with 8 additions and 2 deletions
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||
from collections.abc import Callable
|
||||
import dataclasses
|
||||
from functools import partial, wraps
|
||||
from typing import Any, Literal
|
||||
from typing import Any, Literal, cast
|
||||
|
||||
from aiohttp import web, web_exceptions, web_request
|
||||
import voluptuous as vol
|
||||
|
@ -1976,6 +1976,10 @@ class FirmwareUploadView(HomeAssistantView):
|
|||
if "file" not in data or not isinstance(data["file"], web_request.FileField):
|
||||
raise web_exceptions.HTTPBadRequest
|
||||
|
||||
target = None
|
||||
if "target" in data:
|
||||
target = int(cast(str, data["target"]))
|
||||
|
||||
uploaded_file: web_request.FileField = data["file"]
|
||||
|
||||
try:
|
||||
|
@ -1985,6 +1989,7 @@ class FirmwareUploadView(HomeAssistantView):
|
|||
uploaded_file.filename,
|
||||
await hass.async_add_executor_job(uploaded_file.file.read),
|
||||
async_get_clientsession(hass),
|
||||
target=target,
|
||||
)
|
||||
except BaseZwaveJSServerError as err:
|
||||
raise web_exceptions.HTTPBadRequest(reason=str(err)) from err
|
||||
|
|
|
@ -2847,9 +2847,10 @@ async def test_firmware_upload_view(
|
|||
) as mock_cmd:
|
||||
resp = await client.post(
|
||||
f"/api/zwave_js/firmware/upload/{device.id}",
|
||||
data={"file": firmware_file},
|
||||
data={"file": firmware_file, "target": "15"},
|
||||
)
|
||||
assert mock_cmd.call_args[0][1:4] == (multisensor_6, "file", bytes(10))
|
||||
assert mock_cmd.call_args[1] == {"target": 15}
|
||||
assert json.loads(await resp.text()) is None
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue