mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Fix error in Squeezebox DHCP discovery flow (#50771)
* Map data from dhcp to squeezebox discovery flow * Add tests for squeezebox dhcp discovery
This commit is contained in:
parent
5ee0df29d4
commit
b3607343fc
@ -6,6 +6,7 @@ from pysqueezebox import Server, async_discover
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
|
from homeassistant.components.dhcp import IP_ADDRESS, MAC_ADDRESS
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
CONF_PASSWORD,
|
CONF_PASSWORD,
|
||||||
@ -172,9 +173,20 @@ class SqueezeboxConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
await self.async_set_unique_id(discovery_info.pop("uuid"))
|
await self.async_set_unique_id(discovery_info.pop("uuid"))
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
else:
|
else:
|
||||||
# attempt to connect to server and determine uuid. will fail if password required
|
# attempt to connect to server and determine uuid. will fail if
|
||||||
|
# password required
|
||||||
|
|
||||||
|
if CONF_HOST not in discovery_info and IP_ADDRESS in discovery_info:
|
||||||
|
discovery_info[CONF_HOST] = discovery_info[IP_ADDRESS]
|
||||||
|
|
||||||
|
if CONF_PORT not in discovery_info:
|
||||||
|
discovery_info[CONF_PORT] = DEFAULT_PORT
|
||||||
|
|
||||||
error = await self._validate_input(discovery_info)
|
error = await self._validate_input(discovery_info)
|
||||||
if error:
|
if error:
|
||||||
|
if MAC_ADDRESS in discovery_info:
|
||||||
|
await self.async_set_unique_id(discovery_info[MAC_ADDRESS])
|
||||||
|
else:
|
||||||
await self._async_handle_discovery_without_unique_id()
|
await self._async_handle_discovery_without_unique_id()
|
||||||
|
|
||||||
# update schema with suggested values from discovery
|
# update schema with suggested values from discovery
|
||||||
|
@ -4,6 +4,7 @@ from unittest.mock import patch
|
|||||||
from pysqueezebox import Server
|
from pysqueezebox import Server
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
|
from homeassistant.components.dhcp import HOSTNAME, IP_ADDRESS, MAC_ADDRESS
|
||||||
from homeassistant.components.squeezebox.const import DOMAIN
|
from homeassistant.components.squeezebox.const import DOMAIN
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
@ -196,6 +197,41 @@ async def test_discovery_no_uuid(hass):
|
|||||||
assert result["step_id"] == "edit"
|
assert result["step_id"] == "edit"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_dhcp_discovery(hass):
|
||||||
|
"""Test we can process discovery from dhcp."""
|
||||||
|
with patch(
|
||||||
|
"pysqueezebox.Server.async_query",
|
||||||
|
return_value={"uuid": UUID},
|
||||||
|
):
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN,
|
||||||
|
context={"source": config_entries.SOURCE_DHCP},
|
||||||
|
data={
|
||||||
|
IP_ADDRESS: "1.1.1.1",
|
||||||
|
MAC_ADDRESS: "AA:BB:CC:DD:EE:FF",
|
||||||
|
HOSTNAME: "any",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert result["type"] == RESULT_TYPE_FORM
|
||||||
|
assert result["step_id"] == "edit"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_dhcp_discovery_no_connection(hass):
|
||||||
|
"""Test we can process discovery from dhcp without connecting to squeezebox server."""
|
||||||
|
with patch("pysqueezebox.Server.async_query", new=patch_async_query_unauthorized):
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN,
|
||||||
|
context={"source": config_entries.SOURCE_DHCP},
|
||||||
|
data={
|
||||||
|
IP_ADDRESS: "1.1.1.1",
|
||||||
|
MAC_ADDRESS: "AA:BB:CC:DD:EE:FF",
|
||||||
|
HOSTNAME: "any",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert result["type"] == RESULT_TYPE_FORM
|
||||||
|
assert result["step_id"] == "edit"
|
||||||
|
|
||||||
|
|
||||||
async def test_import(hass):
|
async def test_import(hass):
|
||||||
"""Test handling of configuration imported."""
|
"""Test handling of configuration imported."""
|
||||||
with patch("pysqueezebox.Server.async_query", return_value={"uuid": UUID},), patch(
|
with patch("pysqueezebox.Server.async_query", return_value={"uuid": UUID},), patch(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user