mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Use zeroconf attributes in elgato (#58958)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
0040606c65
commit
ce9385d442
@ -46,8 +46,8 @@ class ElgatoFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
self, discovery_info: zeroconf.ZeroconfServiceInfo
|
self, discovery_info: zeroconf.ZeroconfServiceInfo
|
||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
"""Handle zeroconf discovery."""
|
"""Handle zeroconf discovery."""
|
||||||
self.host = discovery_info[CONF_HOST]
|
self.host = discovery_info[zeroconf.ATTR_HOST]
|
||||||
self.port = discovery_info[CONF_PORT] or 9123
|
self.port = discovery_info[zeroconf.ATTR_PORT] or 9123
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await self._get_elgato_serial_number()
|
await self._get_elgato_serial_number()
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
from homeassistant import data_entry_flow
|
from homeassistant import data_entry_flow
|
||||||
|
from homeassistant.components import zeroconf
|
||||||
from homeassistant.components.elgato.const import CONF_SERIAL_NUMBER, DOMAIN
|
from homeassistant.components.elgato.const import CONF_SERIAL_NUMBER, DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF
|
from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF
|
||||||
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_SOURCE, CONTENT_TYPE_JSON
|
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(
|
await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={CONF_SOURCE: SOURCE_ZEROCONF},
|
context={CONF_SOURCE: SOURCE_ZEROCONF},
|
||||||
data={
|
data=zeroconf.ZeroconfServiceInfo(
|
||||||
"host": "127.0.0.1",
|
host="127.0.0.1",
|
||||||
"hostname": "example.local.",
|
hostname="example.local.",
|
||||||
"port": 9123,
|
port=9123,
|
||||||
"properties": {},
|
properties={},
|
||||||
},
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
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(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={CONF_SOURCE: SOURCE_ZEROCONF},
|
context={CONF_SOURCE: SOURCE_ZEROCONF},
|
||||||
data={
|
data=zeroconf.ZeroconfServiceInfo(
|
||||||
"host": "127.0.0.1",
|
host="127.0.0.1",
|
||||||
"hostname": "example.local.",
|
hostname="example.local.",
|
||||||
"port": 9123,
|
port=9123,
|
||||||
"properties": {},
|
properties={},
|
||||||
},
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["description_placeholders"] == {CONF_SERIAL_NUMBER: "CN11A1A00001"}
|
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(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": SOURCE_ZEROCONF},
|
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"
|
assert result["reason"] == "cannot_connect"
|
||||||
@ -158,7 +159,7 @@ async def test_zeroconf_device_exists_abort(
|
|||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={CONF_SOURCE: SOURCE_ZEROCONF},
|
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"
|
assert result["reason"] == "already_configured"
|
||||||
@ -167,7 +168,7 @@ async def test_zeroconf_device_exists_abort(
|
|||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={CONF_SOURCE: SOURCE_ZEROCONF},
|
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"
|
assert result["reason"] == "already_configured"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user