Use ZeroconfServiceInfo in nanoleaf (#60045)

This commit is contained in:
epenet 2021-11-21 14:51:50 +01:00 committed by GitHub
parent 56e93ff0ec
commit 25e5263954
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 15 deletions

View File

@ -107,9 +107,11 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
) -> FlowResult:
"""Handle Nanoleaf Homekit and Zeroconf discovery."""
return await self._async_discovery_handler(
discovery_info["host"],
discovery_info["name"].replace(f".{discovery_info['type']}", ""),
discovery_info["properties"]["id"],
discovery_info[zeroconf.ATTR_HOST],
discovery_info[zeroconf.ATTR_NAME].replace(
f".{discovery_info[zeroconf.ATTR_TYPE]}", ""
),
discovery_info[zeroconf.ATTR_PROPERTIES][zeroconf.ATTR_PROPERTIES_ID],
)
async def async_step_ssdp(self, discovery_info: DiscoveryInfoType) -> FlowResult:

View File

@ -7,6 +7,7 @@ from aionanoleaf import InvalidToken, NanoleafException, Unauthorized, Unavailab
import pytest
from homeassistant import config_entries
from homeassistant.components import zeroconf
from homeassistant.components.nanoleaf.const import DOMAIN
from homeassistant.const import CONF_HOST, CONF_TOKEN
from homeassistant.core import HomeAssistant
@ -235,12 +236,12 @@ async def test_discovery_link_unavailable(
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": source},
data={
"host": TEST_HOST,
"name": f"{TEST_NAME}.{type_in_discovery_info}",
"type": type_in_discovery_info,
"properties": {"id": TEST_DEVICE_ID},
},
data=zeroconf.ZeroconfServiceInfo(
host=TEST_HOST,
name=f"{TEST_NAME}.{type_in_discovery_info}",
type=type_in_discovery_info,
properties={zeroconf.ATTR_PROPERTIES_ID: TEST_DEVICE_ID},
),
)
assert result["type"] == "form"
assert result["step_id"] == "link"
@ -417,12 +418,12 @@ async def test_import_discovery_integration(
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": source},
data={
"host": TEST_HOST,
"name": f"{TEST_NAME}.{type_in_discovery}",
"type": type_in_discovery,
"properties": {"id": TEST_DEVICE_ID},
},
data=zeroconf.ZeroconfServiceInfo(
host=TEST_HOST,
name=f"{TEST_NAME}.{type_in_discovery}",
type=type_in_discovery,
properties={zeroconf.ATTR_PROPERTIES_ID: TEST_DEVICE_ID},
),
)
assert result["type"] == "create_entry"
assert result["title"] == TEST_NAME