Update ZeroconfServiceInfo in tests (n-t) (#60219)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-11-23 17:35:44 +01:00 committed by GitHub
parent 7a0ff4e2e1
commit 77dfeb062f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 119 additions and 22 deletions

View file

@ -12,7 +12,14 @@ from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_USER, SOURCE_ZERO
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
DISCOVERY_INFO = zeroconf.ZeroconfServiceInfo(host="10.10.2.3") DISCOVERY_INFO = zeroconf.ZeroconfServiceInfo(
host="10.10.2.3",
hostname="mock_hostname",
name="mock_name",
port=None,
properties={},
type="mock_type",
)
VALID_CONFIG = {"host": "10.10.2.3"} VALID_CONFIG = {"host": "10.10.2.3"}
VALID_AUTH = {"username": "fake_username", "password": "fake_password"} VALID_AUTH = {"username": "fake_username", "password": "fake_password"}

View file

@ -238,9 +238,11 @@ async def test_discovery_link_unavailable(
context={"source": source}, context={"source": source},
data=zeroconf.ZeroconfServiceInfo( data=zeroconf.ZeroconfServiceInfo(
host=TEST_HOST, host=TEST_HOST,
hostname="mock_hostname",
name=f"{TEST_NAME}.{type_in_discovery_info}", name=f"{TEST_NAME}.{type_in_discovery_info}",
type=type_in_discovery_info, port=None,
properties={zeroconf.ATTR_PROPERTIES_ID: TEST_DEVICE_ID}, properties={zeroconf.ATTR_PROPERTIES_ID: TEST_DEVICE_ID},
type=type_in_discovery_info,
), ),
) )
assert result["type"] == "form" assert result["type"] == "form"
@ -420,9 +422,11 @@ async def test_import_discovery_integration(
context={"source": source}, context={"source": source},
data=zeroconf.ZeroconfServiceInfo( data=zeroconf.ZeroconfServiceInfo(
host=TEST_HOST, host=TEST_HOST,
hostname="mock_hostname",
name=f"{TEST_NAME}.{type_in_discovery}", name=f"{TEST_NAME}.{type_in_discovery}",
type=type_in_discovery, port=None,
properties={zeroconf.ATTR_PROPERTIES_ID: TEST_DEVICE_ID}, properties={zeroconf.ATTR_PROPERTIES_ID: TEST_DEVICE_ID},
type=type_in_discovery,
), ),
) )
assert result["type"] == "create_entry" assert result["type"] == "create_entry"

View file

@ -42,7 +42,11 @@ async def test_abort_if_existing_entry(hass):
context={"source": config_entries.SOURCE_HOMEKIT}, context={"source": config_entries.SOURCE_HOMEKIT},
data=zeroconf.ZeroconfServiceInfo( data=zeroconf.ZeroconfServiceInfo(
host="0.0.0.0", host="0.0.0.0",
hostname="mock_hostname",
name="mock_name",
port=None,
properties={zeroconf.ATTR_PROPERTIES_ID: "aa:bb:cc:dd:ee:ff"}, properties={zeroconf.ATTR_PROPERTIES_ID: "aa:bb:cc:dd:ee:ff"},
type="mock_type",
), ),
) )
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT

View file

@ -35,7 +35,14 @@ async def test_form_zeroconf(hass):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF}, context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.ZeroconfServiceInfo(host="192.168.1.5", port=1234), data=zeroconf.ZeroconfServiceInfo(
host="192.168.1.5",
hostname="mock_hostname",
name="mock_name",
port=1234,
properties={},
type="mock_type",
),
) )
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "user" assert result["step_id"] == "user"

View file

@ -172,9 +172,11 @@ async def test_show_zerconf_form(hass: HomeAssistant) -> None:
context={"source": config_entries.SOURCE_ZEROCONF}, context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.ZeroconfServiceInfo( data=zeroconf.ZeroconfServiceInfo(
host="192.168.1.123", host="192.168.1.123",
port=80,
hostname="example.local.", hostname="example.local.",
name="mock_name",
port=80,
properties={"uuid": "83747482", "path": "/foo/"}, properties={"uuid": "83747482", "path": "/foo/"},
type="mock_type",
), ),
) )
assert result["type"] == "form" assert result["type"] == "form"
@ -487,9 +489,11 @@ async def test_duplicate_zerconf_ignored(hass: HomeAssistant) -> None:
context={"source": config_entries.SOURCE_ZEROCONF}, context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.ZeroconfServiceInfo( data=zeroconf.ZeroconfServiceInfo(
host="192.168.1.123", host="192.168.1.123",
port=80,
hostname="example.local.", hostname="example.local.",
name="mock_name",
port=80,
properties={"uuid": "83747482", "path": "/foo/"}, properties={"uuid": "83747482", "path": "/foo/"},
type="mock_type",
), ),
) )
assert result["type"] == "abort" assert result["type"] == "abort"

View file

@ -42,25 +42,27 @@ TEST_USERNAME2 = "stretch"
TEST_DISCOVERY = zeroconf.ZeroconfServiceInfo( TEST_DISCOVERY = zeroconf.ZeroconfServiceInfo(
host=TEST_HOST, host=TEST_HOST,
port=DEFAULT_PORT,
hostname=f"{TEST_HOSTNAME}.local.", hostname=f"{TEST_HOSTNAME}.local.",
server=f"{TEST_HOSTNAME}.local.", name="mock_name",
port=DEFAULT_PORT,
properties={ properties={
"product": "smile", "product": "smile",
"version": "1.2.3", "version": "1.2.3",
"hostname": f"{TEST_HOSTNAME}.local.", "hostname": f"{TEST_HOSTNAME}.local.",
}, },
type="mock_type",
) )
TEST_DISCOVERY2 = zeroconf.ZeroconfServiceInfo( TEST_DISCOVERY2 = zeroconf.ZeroconfServiceInfo(
host=TEST_HOST, host=TEST_HOST,
port=DEFAULT_PORT,
hostname=f"{TEST_HOSTNAME2}.local.", hostname=f"{TEST_HOSTNAME2}.local.",
server=f"{TEST_HOSTNAME2}.local.", name="mock_name",
port=DEFAULT_PORT,
properties={ properties={
"product": "stretch", "product": "stretch",
"version": "1.2.3", "version": "1.2.3",
"hostname": f"{TEST_HOSTNAME2}.local.", "hostname": f"{TEST_HOSTNAME2}.local.",
}, },
type="mock_type",
) )

View file

@ -113,7 +113,12 @@ async def test_form_homekit(hass):
DOMAIN, DOMAIN,
context={"source": config_entries.SOURCE_HOMEKIT}, context={"source": config_entries.SOURCE_HOMEKIT},
data=zeroconf.ZeroconfServiceInfo( data=zeroconf.ZeroconfServiceInfo(
properties={zeroconf.ATTR_PROPERTIES_ID: "AA:BB:CC:DD:EE:FF"} host="mock_host",
hostname="mock_hostname",
name="mock_name",
port=None,
properties={zeroconf.ATTR_PROPERTIES_ID: "AA:BB:CC:DD:EE:FF"},
type="mock_type",
), ),
) )
assert result["type"] == "form" assert result["type"] == "form"
@ -132,7 +137,12 @@ async def test_form_homekit(hass):
DOMAIN, DOMAIN,
context={"source": config_entries.SOURCE_HOMEKIT}, context={"source": config_entries.SOURCE_HOMEKIT},
data=zeroconf.ZeroconfServiceInfo( data=zeroconf.ZeroconfServiceInfo(
properties={zeroconf.ATTR_PROPERTIES_ID: "AA:BB:CC:DD:EE:FF"} host="mock_host",
hostname="mock_hostname",
name="mock_name",
port=None,
properties={zeroconf.ATTR_PROPERTIES_ID: "AA:BB:CC:DD:EE:FF"},
type="mock_type",
), ),
) )
assert result["type"] == "abort" assert result["type"] == "abort"

View file

@ -235,7 +235,14 @@ async def test_step_homekit_zeroconf_ip_already_exists(hass, source):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={"source": source}, context={"source": source},
data=zeroconf.ZeroconfServiceInfo(host="192.168.1.100"), data=zeroconf.ZeroconfServiceInfo(
host="192.168.1.100",
hostname="mock_hostname",
name="mock_name",
port=None,
properties={},
type="mock_type",
),
) )
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
@ -264,7 +271,14 @@ async def test_step_homekit_zeroconf_ip_change(hass, source):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={"source": source}, context={"source": source},
data=zeroconf.ZeroconfServiceInfo(host="192.168.1.2"), data=zeroconf.ZeroconfServiceInfo(
host="192.168.1.2",
hostname="mock_hostname",
name="mock_name",
port=None,
properties={},
type="mock_type",
),
) )
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
@ -295,7 +309,14 @@ async def test_step_homekit_zeroconf_new_controller_when_some_exist(hass, source
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={"source": source}, context={"source": source},
data=zeroconf.ZeroconfServiceInfo(host="192.168.1.100"), data=zeroconf.ZeroconfServiceInfo(
host="192.168.1.100",
hostname="mock_hostname",
name="mock_name",
port=None,
properties={},
type="mock_type",
),
) )
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
@ -339,7 +360,14 @@ async def test_discovery_by_homekit_and_zeroconf_same_time(hass):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF}, context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.ZeroconfServiceInfo(host="192.168.1.100"), data=zeroconf.ZeroconfServiceInfo(
host="192.168.1.100",
hostname="mock_hostname",
name="mock_name",
port=None,
properties={},
type="mock_type",
),
) )
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
@ -352,7 +380,14 @@ async def test_discovery_by_homekit_and_zeroconf_same_time(hass):
result2 = await hass.config_entries.flow.async_init( result2 = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={"source": config_entries.SOURCE_HOMEKIT}, context={"source": config_entries.SOURCE_HOMEKIT},
data=zeroconf.ZeroconfServiceInfo(host="192.168.1.100"), data=zeroconf.ZeroconfServiceInfo(
host="192.168.1.100",
hostname="mock_hostname",
name="mock_name",
port=None,
properties={},
type="mock_type",
),
) )
assert result2["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result2["type"] == data_entry_flow.RESULT_TYPE_ABORT

View file

@ -33,11 +33,14 @@ MOCK_SSDP_DISCOVERY_INFO = {
HOMEKIT_HOST = "192.168.1.161" HOMEKIT_HOST = "192.168.1.161"
MOCK_HOMEKIT_DISCOVERY_INFO = zeroconf.ZeroconfServiceInfo( MOCK_HOMEKIT_DISCOVERY_INFO = zeroconf.ZeroconfServiceInfo(
name="onn._hap._tcp.local.",
host=HOMEKIT_HOST, host=HOMEKIT_HOST,
hostname="mock_hostname",
name="onn._hap._tcp.local.",
port=None,
properties={ properties={
zeroconf.ATTR_PROPERTIES_ID: "2d:97:da:ee:dc:99", zeroconf.ATTR_PROPERTIES_ID: "2d:97:da:ee:dc:99",
}, },
type="mock_type",
) )

View file

@ -90,6 +90,8 @@ MOCK_DHCP_DATA = dhcp.DhcpServiceInfo(
EXISTING_IP = "192.168.40.221" EXISTING_IP = "192.168.40.221"
MOCK_ZEROCONF_DATA = zeroconf.ZeroconfServiceInfo( MOCK_ZEROCONF_DATA = zeroconf.ZeroconfServiceInfo(
host="fake_host", host="fake_host",
hostname="mock_hostname",
name="mock_name",
port=1234, port=1234,
properties={ properties={
"deviceid": "aa:bb:cc:dd:ee:ff", "deviceid": "aa:bb:cc:dd:ee:ff",
@ -97,6 +99,7 @@ MOCK_ZEROCONF_DATA = zeroconf.ZeroconfServiceInfo(
"model": "fake_model", "model": "fake_model",
"serialNumber": "fake_serial", "serialNumber": "fake_serial",
}, },
type="mock_type",
) )
MOCK_OLD_ENTRY = { MOCK_OLD_ENTRY = {
CONF_HOST: "fake_host", CONF_HOST: "fake_host",

View file

@ -19,8 +19,11 @@ MOCK_SETTINGS = {
} }
DISCOVERY_INFO = zeroconf.ZeroconfServiceInfo( DISCOVERY_INFO = zeroconf.ZeroconfServiceInfo(
host="1.1.1.1", host="1.1.1.1",
hostname="mock_hostname",
name="shelly1pm-12345", name="shelly1pm-12345",
properties={"id": "shelly1pm-12345"}, port=None,
properties={zeroconf.ATTR_PROPERTIES_ID: "shelly1pm-12345"},
type="mock_type",
) )
MOCK_CONFIG = { MOCK_CONFIG = {
"wifi": {"ap": {"ssid": "Test name"}}, "wifi": {"ap": {"ssid": "Test name"}},

View file

@ -46,9 +46,11 @@ async def test_zeroconf_form(hass: core.HomeAssistant):
context={"source": config_entries.SOURCE_ZEROCONF}, context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.ZeroconfServiceInfo( data=zeroconf.ZeroconfServiceInfo(
host="192.168.4.2", host="192.168.4.2",
name="Sonos-aaa@Living Room._sonos._tcp.local.",
hostname="Sonos-aaa", hostname="Sonos-aaa",
name="Sonos-aaa@Living Room._sonos._tcp.local.",
port=None,
properties={"bootseq": "1234"}, properties={"bootseq": "1234"},
type="mock_type",
), ),
) )
assert result["type"] == "form" assert result["type"] == "form"
@ -136,7 +138,10 @@ async def test_zeroconf_form_not_sonos(hass: core.HomeAssistant):
data=zeroconf.ZeroconfServiceInfo( data=zeroconf.ZeroconfServiceInfo(
host="192.168.4.2", host="192.168.4.2",
hostname="not-aaa", hostname="not-aaa",
name="mock_name",
port=None,
properties={"bootseq": "1234"}, properties={"bootseq": "1234"},
type="mock_type",
), ),
) )
assert result["type"] == "abort" assert result["type"] == "abort"

View file

@ -128,7 +128,12 @@ async def test_form_homekit(hass):
DOMAIN, DOMAIN,
context={"source": config_entries.SOURCE_HOMEKIT}, context={"source": config_entries.SOURCE_HOMEKIT},
data=zeroconf.ZeroconfServiceInfo( data=zeroconf.ZeroconfServiceInfo(
properties={zeroconf.ATTR_PROPERTIES_ID: "AA:BB:CC:DD:EE:FF"} host="mock_host",
hostname="mock_hostname",
name="mock_name",
port=None,
properties={zeroconf.ATTR_PROPERTIES_ID: "AA:BB:CC:DD:EE:FF"},
type="mock_type",
), ),
) )
assert result["type"] == "form" assert result["type"] == "form"
@ -149,7 +154,12 @@ async def test_form_homekit(hass):
DOMAIN, DOMAIN,
context={"source": config_entries.SOURCE_HOMEKIT}, context={"source": config_entries.SOURCE_HOMEKIT},
data=zeroconf.ZeroconfServiceInfo( data=zeroconf.ZeroconfServiceInfo(
properties={zeroconf.ATTR_PROPERTIES_ID: "AA:BB:CC:DD:EE:FF"} host="mock_host",
hostname="mock_hostname",
name="mock_name",
port=None,
properties={zeroconf.ATTR_PROPERTIES_ID: "AA:BB:CC:DD:EE:FF"},
type="mock_type",
), ),
) )
assert result["type"] == "abort" assert result["type"] == "abort"