Use zeroconf attributes in elgato (#58958)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-11-15 20:04:21 +01:00 committed by GitHub
parent 0040606c65
commit ce9385d442
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 17 deletions

View File

@ -46,8 +46,8 @@ class ElgatoFlowHandler(ConfigFlow, domain=DOMAIN):
self, discovery_info: zeroconf.ZeroconfServiceInfo
) -> FlowResult:
"""Handle zeroconf discovery."""
self.host = discovery_info[CONF_HOST]
self.port = discovery_info[CONF_PORT] or 9123
self.host = discovery_info[zeroconf.ATTR_HOST]
self.port = discovery_info[zeroconf.ATTR_PORT] or 9123
try:
await self._get_elgato_serial_number()

View File

@ -2,6 +2,7 @@
import aiohttp
from homeassistant import data_entry_flow
from homeassistant.components import zeroconf
from homeassistant.components.elgato.const import CONF_SERIAL_NUMBER, DOMAIN
from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_SOURCE, CONTENT_TYPE_JSON
@ -27,12 +28,12 @@ async def test_full_user_flow_implementation(
await hass.config_entries.flow.async_init(
DOMAIN,
context={CONF_SOURCE: SOURCE_ZEROCONF},
data={
"host": "127.0.0.1",
"hostname": "example.local.",
"port": 9123,
"properties": {},
},
data=zeroconf.ZeroconfServiceInfo(
host="127.0.0.1",
hostname="example.local.",
port=9123,
properties={},
),
)
result = await hass.config_entries.flow.async_init(
@ -70,12 +71,12 @@ async def test_full_zeroconf_flow_implementation(
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={CONF_SOURCE: SOURCE_ZEROCONF},
data={
"host": "127.0.0.1",
"hostname": "example.local.",
"port": 9123,
"properties": {},
},
data=zeroconf.ZeroconfServiceInfo(
host="127.0.0.1",
hostname="example.local.",
port=9123,
properties={},
),
)
assert result["description_placeholders"] == {CONF_SERIAL_NUMBER: "CN11A1A00001"}
@ -127,7 +128,7 @@ async def test_zeroconf_connection_error(
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_ZEROCONF},
data={"host": "127.0.0.1", "port": 9123},
data=zeroconf.ZeroconfServiceInfo(host="127.0.0.1", port=9123),
)
assert result["reason"] == "cannot_connect"
@ -158,7 +159,7 @@ async def test_zeroconf_device_exists_abort(
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={CONF_SOURCE: SOURCE_ZEROCONF},
data={"host": "127.0.0.1", "port": 9123},
data=zeroconf.ZeroconfServiceInfo(host="127.0.0.1", port=9123),
)
assert result["reason"] == "already_configured"
@ -167,7 +168,7 @@ async def test_zeroconf_device_exists_abort(
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={CONF_SOURCE: SOURCE_ZEROCONF},
data={"host": "127.0.0.2", "port": 9123},
data=zeroconf.ZeroconfServiceInfo(host="127.0.0.2", port=9123),
)
assert result["reason"] == "already_configured"