mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Use ZeroconfServiceInfo in wled (#60130)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
c8451001a0
commit
7e1b00c491
@ -44,14 +44,14 @@ class WLEDFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
"""Handle zeroconf discovery."""
|
||||
|
||||
# Hostname is format: wled-livingroom.local.
|
||||
host = discovery_info["hostname"].rstrip(".")
|
||||
host = discovery_info[zeroconf.ATTR_HOSTNAME].rstrip(".")
|
||||
name, _ = host.rsplit(".")
|
||||
|
||||
self.context.update(
|
||||
{
|
||||
CONF_HOST: discovery_info["host"],
|
||||
CONF_HOST: discovery_info[zeroconf.ATTR_HOST],
|
||||
CONF_NAME: name,
|
||||
CONF_MAC: discovery_info["properties"].get(CONF_MAC),
|
||||
CONF_MAC: discovery_info[zeroconf.ATTR_PROPERTIES].get(CONF_MAC),
|
||||
"title_placeholders": {"name": name},
|
||||
}
|
||||
)
|
||||
|
@ -3,6 +3,7 @@ from unittest.mock import MagicMock
|
||||
|
||||
from wled import WLEDConnectionError
|
||||
|
||||
from homeassistant.components import zeroconf
|
||||
from homeassistant.components.wled.const import CONF_KEEP_MASTER_LIGHT, DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF
|
||||
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_NAME
|
||||
@ -47,7 +48,9 @@ async def test_full_zeroconf_flow_implementation(
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_ZEROCONF},
|
||||
data={"host": "192.168.1.123", "hostname": "example.local.", "properties": {}},
|
||||
data=zeroconf.ZeroconfServiceInfo(
|
||||
host="192.168.1.123", hostname="example.local.", properties={}
|
||||
),
|
||||
)
|
||||
|
||||
flows = hass.config_entries.flow.async_progress()
|
||||
@ -100,7 +103,9 @@ async def test_zeroconf_connection_error(
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_ZEROCONF},
|
||||
data={"host": "192.168.1.123", "hostname": "example.local.", "properties": {}},
|
||||
data=zeroconf.ZeroconfServiceInfo(
|
||||
host="192.168.1.123", hostname="example.local.", properties={}
|
||||
),
|
||||
)
|
||||
|
||||
assert result.get("type") == RESULT_TYPE_ABORT
|
||||
@ -120,7 +125,9 @@ async def test_zeroconf_confirm_connection_error(
|
||||
CONF_HOST: "example.com",
|
||||
CONF_NAME: "test",
|
||||
},
|
||||
data={"host": "192.168.1.123", "hostname": "example.com.", "properties": {}},
|
||||
data=zeroconf.ZeroconfServiceInfo(
|
||||
host="192.168.1.123", hostname="example.com.", properties={}
|
||||
),
|
||||
)
|
||||
|
||||
assert result.get("type") == RESULT_TYPE_ABORT
|
||||
@ -152,7 +159,9 @@ async def test_zeroconf_device_exists_abort(
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_ZEROCONF},
|
||||
data={"host": "192.168.1.123", "hostname": "example.local.", "properties": {}},
|
||||
data=zeroconf.ZeroconfServiceInfo(
|
||||
host="192.168.1.123", hostname="example.local.", properties={}
|
||||
),
|
||||
)
|
||||
|
||||
assert result.get("type") == RESULT_TYPE_ABORT
|
||||
@ -168,11 +177,11 @@ async def test_zeroconf_with_mac_device_exists_abort(
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_ZEROCONF},
|
||||
data={
|
||||
"host": "192.168.1.123",
|
||||
"hostname": "example.local.",
|
||||
"properties": {CONF_MAC: "aabbccddeeff"},
|
||||
},
|
||||
data=zeroconf.ZeroconfServiceInfo(
|
||||
host="192.168.1.123",
|
||||
hostname="example.local.",
|
||||
properties={CONF_MAC: "aabbccddeeff"},
|
||||
),
|
||||
)
|
||||
|
||||
assert result.get("type") == RESULT_TYPE_ABORT
|
||||
|
Loading…
x
Reference in New Issue
Block a user