From 8dcc96c083a35079c03eae6b018933f52e6cd174 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Fri, 1 Sep 2023 12:06:37 -0400 Subject: [PATCH] Fix device name in zwave_js repair flow (#99414) --- homeassistant/components/zwave_js/__init__.py | 9 +++------ homeassistant/components/zwave_js/repairs.py | 17 +++++++++++------ tests/components/zwave_js/test_repairs.py | 1 + 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/zwave_js/__init__.py b/homeassistant/components/zwave_js/__init__.py index 2d158f47e44..b56298e36ba 100644 --- a/homeassistant/components/zwave_js/__init__.py +++ b/homeassistant/components/zwave_js/__init__.py @@ -600,19 +600,16 @@ class NodeEvents: # device config has changed, and if so, issue a repair registry entry for a # possible reinterview if not node.is_controller_node and await node.async_has_device_config_changed(): + device_name = device.name_by_user or device.name or "Unnamed device" async_create_issue( self.hass, DOMAIN, f"device_config_file_changed.{device.id}", - data={"device_id": device.id}, + data={"device_id": device.id, "device_name": device_name}, is_fixable=True, is_persistent=False, translation_key="device_config_file_changed", - translation_placeholders={ - "device_name": device.name_by_user - or device.name - or "Unnamed device" - }, + translation_placeholders={"device_name": device_name}, severity=IssueSeverity.WARNING, ) diff --git a/homeassistant/components/zwave_js/repairs.py b/homeassistant/components/zwave_js/repairs.py index 58781941b09..89f51dddb88 100644 --- a/homeassistant/components/zwave_js/repairs.py +++ b/homeassistant/components/zwave_js/repairs.py @@ -1,8 +1,6 @@ """Repairs for Z-Wave JS.""" from __future__ import annotations -from typing import cast - import voluptuous as vol from zwave_js_server.model.node import Node @@ -16,9 +14,10 @@ from .helpers import async_get_node_from_device_id class DeviceConfigFileChangedFlow(RepairsFlow): """Handler for an issue fixing flow.""" - def __init__(self, node: Node) -> None: + def __init__(self, node: Node, device_name: str) -> None: """Initialize.""" self.node = node + self.device_name = device_name async def async_step_init( self, user_input: dict[str, str] | None = None @@ -34,17 +33,23 @@ class DeviceConfigFileChangedFlow(RepairsFlow): self.hass.async_create_task(self.node.async_refresh_info()) return self.async_create_entry(title="", data={}) - return self.async_show_form(step_id="confirm", data_schema=vol.Schema({})) + return self.async_show_form( + step_id="confirm", + data_schema=vol.Schema({}), + description_placeholders={"device_name": self.device_name}, + ) async def async_create_fix_flow( hass: HomeAssistant, issue_id: str, - data: dict[str, str | int | float | None] | None, + data: dict[str, str] | None, ) -> RepairsFlow: """Create flow.""" + if issue_id.split(".")[0] == "device_config_file_changed": + assert data return DeviceConfigFileChangedFlow( - async_get_node_from_device_id(hass, cast(dict, data)["device_id"]) + async_get_node_from_device_id(hass, data["device_id"]), data["device_name"] ) return ConfirmRepairFlow() diff --git a/tests/components/zwave_js/test_repairs.py b/tests/components/zwave_js/test_repairs.py index b1702900d7c..07371a299ef 100644 --- a/tests/components/zwave_js/test_repairs.py +++ b/tests/components/zwave_js/test_repairs.py @@ -77,6 +77,7 @@ async def test_device_config_file_changed( flow_id = data["flow_id"] assert data["step_id"] == "confirm" + assert data["description_placeholders"] == {"device_name": device.name} # Apply fix url = RepairsFlowResourceView.url.format(flow_id=flow_id)