Use ZeroconfServiceInfo in guardian (#59741)

Co-authored-by: epenet <epenet@users.noreply.github.com>
pull/59743/head
epenet 2021-11-15 23:13:17 +01:00 committed by GitHub
parent 032718abb1
commit 0b43cff377
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 19 deletions

View File

@ -112,10 +112,12 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
) -> FlowResult:
"""Handle the configuration via zeroconf."""
self.discovery_info = {
CONF_IP_ADDRESS: discovery_info["host"],
CONF_PORT: discovery_info["port"],
CONF_IP_ADDRESS: discovery_info[zeroconf.ATTR_HOST],
CONF_PORT: discovery_info[zeroconf.ATTR_PORT],
}
pin = async_get_pin_from_discovery_hostname(discovery_info["hostname"])
pin = async_get_pin_from_discovery_hostname(
discovery_info[zeroconf.ATTR_HOSTNAME]
)
await self._async_set_unique_id(pin)
return await self._async_handle_discovery()

View File

@ -4,6 +4,7 @@ from unittest.mock import patch
from aioguardian.errors import GuardianError
from homeassistant import data_entry_flow
from homeassistant.components import zeroconf
from homeassistant.components.dhcp import HOSTNAME, IP_ADDRESS, MAC_ADDRESS
from homeassistant.components.guardian import CONF_UID, DOMAIN
from homeassistant.components.guardian.config_flow import (
@ -83,14 +84,14 @@ async def test_step_user(hass, ping_client):
async def test_step_zeroconf(hass, ping_client):
"""Test the zeroconf step."""
zeroconf_data = {
"host": "192.168.1.100",
"port": 7777,
"hostname": "GVC1-ABCD.local.",
"type": "_api._udp.local.",
"name": "Guardian Valve Controller API._api._udp.local.",
"properties": {"_raw": {}},
}
zeroconf_data = zeroconf.ZeroconfServiceInfo(
host="192.168.1.100",
port=7777,
hostname="GVC1-ABCD.local.",
type="_api._udp.local.",
name="Guardian Valve Controller API._api._udp.local.",
properties={"_raw": {}},
)
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_ZEROCONF}, data=zeroconf_data
@ -112,14 +113,14 @@ async def test_step_zeroconf(hass, ping_client):
async def test_step_zeroconf_already_in_progress(hass):
"""Test the zeroconf step aborting because it's already in progress."""
zeroconf_data = {
"host": "192.168.1.100",
"port": 7777,
"hostname": "GVC1-ABCD.local.",
"type": "_api._udp.local.",
"name": "Guardian Valve Controller API._api._udp.local.",
"properties": {"_raw": {}},
}
zeroconf_data = zeroconf.ZeroconfServiceInfo(
host="192.168.1.100",
port=7777,
hostname="GVC1-ABCD.local.",
type="_api._udp.local.",
name="Guardian Valve Controller API._api._udp.local.",
properties={"_raw": {}},
)
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_ZEROCONF}, data=zeroconf_data