From 8d69a4968f95a688142e734633281d40fbe8864e Mon Sep 17 00:00:00 2001 From: uvjustin <46082645+uvjustin@users.noreply.github.com> Date: Wed, 24 Jun 2020 20:19:08 +0800 Subject: [PATCH] Handle unexpected versions in forked_daapd zeroconf (#37053) --- .../components/forked_daapd/config_flow.py | 16 ++++++++++------ .../components/forked_daapd/test_config_flow.py | 11 +++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/forked_daapd/config_flow.py b/homeassistant/components/forked_daapd/config_flow.py index 07eaaf4c3fe..d27c40af316 100644 --- a/homeassistant/components/forked_daapd/config_flow.py +++ b/homeassistant/components/forked_daapd/config_flow.py @@ -156,14 +156,18 @@ class ForkedDaapdFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): async def async_step_zeroconf(self, discovery_info): """Prepare configuration for a discovered forked-daapd device.""" - if not ( - discovery_info.get("properties") - and int(discovery_info["properties"].get("mtd-version", "0").split(".")[0]) - >= 27 - and discovery_info["properties"].get("Machine Name") + version_num = 0 + if discovery_info.get("properties") and discovery_info["properties"].get( + "Machine Name" ): + try: + version_num = int( + discovery_info["properties"].get("mtd-version", "0").split(".")[0] + ) + except ValueError: + pass + if version_num < 27: return self.async_abort(reason="not_forked_daapd") - await self.async_set_unique_id(discovery_info["properties"]["Machine Name"]) self._abort_if_unique_id_configured() diff --git a/tests/components/forked_daapd/test_config_flow.py b/tests/components/forked_daapd/test_config_flow.py index 3dc62bae8bd..17b30121aaf 100644 --- a/tests/components/forked_daapd/test_config_flow.py +++ b/tests/components/forked_daapd/test_config_flow.py @@ -158,6 +158,17 @@ async def test_config_flow_zeroconf_invalid(hass): ) # doesn't create the entry, tries to show form but gets abort assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "not_forked_daapd" + # test with svn mtd-version from Firefly + discovery_info = { + "host": "127.0.0.1", + "port": 23, + "properties": {"mtd-version": "svn-1676", "Machine Name": "firefly"}, + } + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": SOURCE_ZEROCONF}, data=discovery_info + ) # doesn't create the entry, tries to show form but gets abort + assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT + assert result["reason"] == "not_forked_daapd" async def test_config_flow_zeroconf_valid(hass):