Change version check in forked-daapd zeroconf step (#35796)

This commit is contained in:
uvjustin 2020-05-19 21:17:02 +08:00 committed by GitHub
parent a51372f7b3
commit 8c8feb95a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 3 deletions

View File

@ -158,7 +158,8 @@ class ForkedDaapdFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
"""Prepare configuration for a discovered forked-daapd device."""
if not (
discovery_info.get("properties")
and float(discovery_info["properties"].get("mtd-version", 0)) >= 27.0
and int(discovery_info["properties"].get("mtd-version", "0").split(".")[0])
>= 27
and discovery_info["properties"].get("Machine Name")
):
return self.async_abort(reason="not_forked_daapd")

View File

@ -103,7 +103,7 @@ async def test_zeroconf_updates_title(hass, config_entry):
discovery_info = {
"host": "192.168.1.1",
"port": 23,
"properties": {"mtd-version": 27.0, "Machine Name": "zeroconf_test"},
"properties": {"mtd-version": "27.0", "Machine Name": "zeroconf_test"},
}
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_ZEROCONF}, data=discovery_info
@ -129,12 +129,35 @@ async def test_config_flow_no_websocket(hass, config_entry):
async def test_config_flow_zeroconf_invalid(hass):
"""Test that an invalid zeroconf entry doesn't work."""
# test with no discovery properties
discovery_info = {"host": "127.0.0.1", "port": 23}
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"
# test with forked-daapd version < 27
discovery_info = {
"host": "127.0.0.1",
"port": 23,
"properties": {"mtd-version": "26.3", "Machine Name": "forked-daapd"},
}
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"
# test with verbose mtd-version from Firefly
discovery_info = {
"host": "127.0.0.1",
"port": 23,
"properties": {"mtd-version": "0.2.4.1", "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):
@ -143,7 +166,7 @@ async def test_config_flow_zeroconf_valid(hass):
"host": "192.168.1.1",
"port": 23,
"properties": {
"mtd-version": 27.0,
"mtd-version": "27.0",
"Machine Name": "zeroconf_test",
"Machine ID": "5E55EEFF",
},