From 030205df8fae4beae3db90a15f8fff1f7deea279 Mon Sep 17 00:00:00 2001 From: Martin Hjelmare Date: Tue, 11 Oct 2022 17:37:21 +0200 Subject: [PATCH] Filter out non official zwave_js add-on discovery (#80110) * Filter out non official zwave_js add-on discovery * Add test --- .../components/zwave_js/config_flow.py | 4 ++++ .../components/zwave_js/strings.json | 3 ++- tests/components/zwave_js/test_config_flow.py | 22 +++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/zwave_js/config_flow.py b/homeassistant/components/zwave_js/config_flow.py index c114662888f..378580160d1 100644 --- a/homeassistant/components/zwave_js/config_flow.py +++ b/homeassistant/components/zwave_js/config_flow.py @@ -29,6 +29,7 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession from . import disconnect_client from .addon import AddonError, AddonInfo, AddonManager, AddonState, get_addon_manager from .const import ( + ADDON_SLUG, CONF_ADDON_DEVICE, CONF_ADDON_EMULATE_HARDWARE, CONF_ADDON_LOG_LEVEL, @@ -492,6 +493,9 @@ class ConfigFlow(BaseZwaveJSFlow, config_entries.ConfigFlow, domain=DOMAIN): if self._async_in_progress(): return self.async_abort(reason="already_in_progress") + if discovery_info.slug != ADDON_SLUG: + return self.async_abort(reason="not_zwave_js_addon") + self.ws_address = ( f"ws://{discovery_info.config['host']}:{discovery_info.config['port']}" ) diff --git a/homeassistant/components/zwave_js/strings.json b/homeassistant/components/zwave_js/strings.json index 19587cf0c0f..7446edb0c5d 100644 --- a/homeassistant/components/zwave_js/strings.json +++ b/homeassistant/components/zwave_js/strings.json @@ -58,7 +58,8 @@ "addon_get_discovery_info_failed": "Failed to get Z-Wave JS add-on discovery info.", "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]", "discovery_requires_supervisor": "Discovery requires the supervisor.", - "not_zwave_device": "Discovered device is not a Z-Wave device." + "not_zwave_device": "Discovered device is not a Z-Wave device.", + "not_zwave_js_addon": "Discovered add-on is not the official Z-Wave JS add-on." }, "progress": { "install_addon": "Please wait while the Z-Wave JS add-on installation finishes. This can take several minutes.", diff --git a/tests/components/zwave_js/test_config_flow.py b/tests/components/zwave_js/test_config_flow.py index d297b183dd1..5e58ef25339 100644 --- a/tests/components/zwave_js/test_config_flow.py +++ b/tests/components/zwave_js/test_config_flow.py @@ -505,6 +505,28 @@ async def test_abort_hassio_discovery_with_existing_flow( assert result2["reason"] == "already_in_progress" +async def test_abort_hassio_discovery_for_other_addon( + hass, supervisor, addon_installed, addon_options +): + """Test hassio discovery flow is aborted for a non official add-on discovery.""" + result2 = await hass.config_entries.flow.async_init( + DOMAIN, + context={"source": config_entries.SOURCE_HASSIO}, + data=HassioServiceInfo( + config={ + "addon": "Other Z-Wave JS", + "host": "host1", + "port": 3001, + }, + name="Other Z-Wave JS", + slug="other_addon", + ), + ) + + assert result2["type"] == "abort" + assert result2["reason"] == "not_zwave_js_addon" + + @pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) async def test_usb_discovery( hass,