Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 5 additions & 1 deletion homeassistant/components/zwave_js/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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
Expand Down Expand Up @@ -2066,6 +2066,9 @@ async def post(self, request: web.Request, device_id: str) -> web.Response:
raise web_exceptions.HTTPBadRequest

uploaded_file: web_request.FileField = data["file"]
firmware_target: int | None = None
if "target" in data:
firmware_target = int(cast(str, data["target"]))

try:
await update_firmware(
Expand All @@ -2075,6 +2078,7 @@ async def post(self, request: web.Request, device_id: str) -> web.Response:
NodeFirmwareUpdateData(
uploaded_file.filename,
await hass.async_add_executor_job(uploaded_file.file.read),
firmware_target=firmware_target,
)
],
async_get_clientsession(hass),
Expand Down
22 changes: 16 additions & 6 deletions tests/components/zwave_js/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2893,12 +2893,17 @@ async def test_get_config_parameters(
assert msg["error"]["code"] == ERR_NOT_LOADED


@pytest.mark.parametrize(
("include_target"),
[(True), (False)],
Comment thread
raman325 marked this conversation as resolved.
Outdated
)
async def test_firmware_upload_view(
hass: HomeAssistant,
multisensor_6,
integration,
hass_client: ClientSessionGenerator,
firmware_file,
include_target,
Comment thread
raman325 marked this conversation as resolved.
Outdated
) -> None:
"""Test the HTTP firmware upload view."""
client = await hass_client()
Expand All @@ -2909,14 +2914,19 @@ async def test_firmware_upload_view(
"homeassistant.components.zwave_js.api.USER_AGENT",
{"HomeAssistant": "0.0.0"},
):
data = {"file": firmware_file}
if include_target:
data["target"] = "1"
Comment thread
raman325 marked this conversation as resolved.
Outdated

resp = await client.post(
f"/api/zwave_js/firmware/upload/{device.id}",
data={"file": firmware_file},
)
assert mock_cmd.call_args[0][1:3] == (
multisensor_6,
[NodeFirmwareUpdateData("file", bytes(10))],
f"/api/zwave_js/firmware/upload/{device.id}", data=data
)

update_data = NodeFirmwareUpdateData("file", bytes(10))
if include_target:
update_data.firmware_target = 1
Comment thread
raman325 marked this conversation as resolved.
Outdated

assert mock_cmd.call_args[0][1:3] == (multisensor_6, [update_data])
assert mock_cmd.call_args[1] == {
"additional_user_agent_components": {"HomeAssistant": "0.0.0"},
}
Expand Down