Rename zeroconf service info (#59467)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-11-10 15:26:47 +01:00 committed by GitHub
parent 6cba03aa4a
commit ab1e14204f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 47 additions and 43 deletions

View file

@ -61,7 +61,7 @@ MAX_PROPERTY_VALUE_LEN = 230
# Dns label max length
MAX_NAME_LEN = 63
# Attributes for HaServiceInfo
# Attributes for ZeroconfServiceInfo
ATTR_HOST: Final = "host"
ATTR_HOSTNAME: Final = "hostname"
ATTR_NAME: Final = "name"
@ -87,7 +87,7 @@ CONFIG_SCHEMA = vol.Schema(
)
class HaServiceInfo(TypedDict):
class ZeroconfServiceInfo(TypedDict):
"""Prepared info from mDNS entries."""
host: str
@ -466,7 +466,7 @@ def async_get_homekit_discovery_domain(
return None
def info_from_service(service: AsyncServiceInfo) -> HaServiceInfo | None:
def info_from_service(service: AsyncServiceInfo) -> ZeroconfServiceInfo | None:
"""Return prepared info from mDNS entries."""
properties: dict[str, Any] = {"_raw": {}}
@ -493,7 +493,7 @@ def info_from_service(service: AsyncServiceInfo) -> HaServiceInfo | None:
if (host := _first_non_link_local_or_v6_address(addresses)) is None:
return None
return HaServiceInfo(
return ZeroconfServiceInfo(
host=str(host),
port=service.port,
hostname=service.server,

View file

@ -12,7 +12,7 @@ from homeassistant.components.apple_tv.const import CONF_START_OFF, DOMAIN
from tests.common import MockConfigEntry
DMAP_SERVICE = zeroconf.HaServiceInfo(
DMAP_SERVICE = zeroconf.ZeroconfServiceInfo(
type="_touch-able._tcp.local.",
name="dmapid.something",
properties={"CtlN": "Apple TV"},
@ -400,7 +400,7 @@ async def test_zeroconf_unsupported_service_aborts(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
type="_dummy._tcp.local.",
properties={},
),
@ -414,7 +414,7 @@ async def test_zeroconf_add_mrp_device(hass, mrp_device, pairing):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
type="_mediaremotetv._tcp.local.",
properties={"UniqueIdentifier": "mrpid", "Name": "Kitchen"},
),

View file

@ -293,7 +293,7 @@ async def test_reauth_flow_update_configuration(hass):
),
(
SOURCE_ZEROCONF,
zeroconf.HaServiceInfo(
zeroconf.ZeroconfServiceInfo(
host=DEFAULT_HOST,
port=80,
hostname=f"axis-{MAC.lower()}.local.",
@ -363,7 +363,7 @@ async def test_discovery_flow(hass, source: str, discovery_info: dict):
),
(
SOURCE_ZEROCONF,
zeroconf.HaServiceInfo(
zeroconf.ZeroconfServiceInfo(
host=DEFAULT_HOST,
port=80,
name=f"AXIS M1065-LW - {MAC}._axis-video._tcp.local.",
@ -411,7 +411,7 @@ async def test_discovered_device_already_configured(
),
(
SOURCE_ZEROCONF,
zeroconf.HaServiceInfo(
zeroconf.ZeroconfServiceInfo(
host="2.3.4.5",
port=8080,
name=f"AXIS M1065-LW - {MAC}._axis-video._tcp.local.",
@ -479,7 +479,7 @@ async def test_discovery_flow_updated_configuration(
),
(
SOURCE_ZEROCONF,
zeroconf.HaServiceInfo(
zeroconf.ZeroconfServiceInfo(
host="",
port=0,
name="",
@ -517,7 +517,7 @@ async def test_discovery_flow_ignore_non_axis_device(
),
(
SOURCE_ZEROCONF,
zeroconf.HaServiceInfo(
zeroconf.ZeroconfServiceInfo(
host="169.254.3.4",
port=80,
name=f"AXIS M1065-LW - {MAC}._axis-video._tcp.local.",

View file

@ -197,7 +197,7 @@ async def test_zeroconf_form(hass: core.HomeAssistant):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
name="test-bond-id.some-other-tail-info", host="test-host"
),
)
@ -229,7 +229,7 @@ async def test_zeroconf_form_token_unavailable(hass: core.HomeAssistant):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
name="test-bond-id.some-other-tail-info", host="test-host"
),
)
@ -264,7 +264,7 @@ async def test_zeroconf_form_with_token_available(hass: core.HomeAssistant):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
name="test-bond-id.some-other-tail-info", host="test-host"
),
)
@ -302,7 +302,7 @@ async def test_zeroconf_already_configured(hass: core.HomeAssistant):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
name="already-registered-bond-id.some-other-tail-info",
host="updated-host",
),
@ -343,7 +343,7 @@ async def test_zeroconf_already_configured_refresh_token(hass: core.HomeAssistan
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
name="already-registered-bond-id.some-other-tail-info",
host="updated-host",
),
@ -376,7 +376,7 @@ async def test_zeroconf_already_configured_no_reload_same_host(
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
name="already-registered-bond-id.some-other-tail-info",
host="stored-host",
),
@ -393,7 +393,7 @@ async def test_zeroconf_form_unexpected_error(hass: core.HomeAssistant):
await _help_test_form_unexpected_error(
hass,
source=config_entries.SOURCE_ZEROCONF,
initial_input=zeroconf.HaServiceInfo(
initial_input=zeroconf.ZeroconfServiceInfo(
name="test-bond-id.some-other-tail-info",
host="test-host",
),

View file

@ -20,7 +20,7 @@ MOCK_SETTINGS = {
"name": "Test name",
"device": {"mac": "test-mac", "hostname": "test-host"},
}
DISCOVERY_INFO = zeroconf.HaServiceInfo(
DISCOVERY_INFO = zeroconf.ZeroconfServiceInfo(
host=["169.1.1.1", "1.1.1.1"],
port=0,
hostname="shc012345.local.",
@ -528,7 +528,7 @@ async def test_zeroconf_cannot_connect(hass, mock_zeroconf):
async def test_zeroconf_link_local(hass, mock_zeroconf):
"""Test we get the form."""
DISCOVERY_INFO_LINK_LOCAL = zeroconf.HaServiceInfo(
DISCOVERY_INFO_LINK_LOCAL = zeroconf.ZeroconfServiceInfo(
host=["169.1.1.1"],
port=0,
hostname="shc012345.local.",
@ -552,7 +552,7 @@ async def test_zeroconf_not_bosch_shc(hass, mock_zeroconf):
"""Test we filter out non-bosch_shc devices."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
data=zeroconf.HaServiceInfo(host="1.1.1.1", name="notboschshc"),
data=zeroconf.ZeroconfServiceInfo(host="1.1.1.1", name="notboschshc"),
context={"source": config_entries.SOURCE_ZEROCONF},
)
assert result["type"] == "abort"

View file

@ -144,7 +144,7 @@ async def test_zeroconf_snmp_error(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
hostname="example.local.", name="Brother Printer"
),
)
@ -159,7 +159,7 @@ async def test_zeroconf_unsupported_model(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
hostname="example.local.",
name="Brother Printer",
properties={"product": "MFC-8660DN"},
@ -184,7 +184,7 @@ async def test_zeroconf_device_exists_abort(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
hostname="example.local.", name="Brother Printer"
),
)
@ -201,7 +201,9 @@ async def test_zeroconf_no_probe_existing_device(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(hostname="localhost", name="Brother Printer"),
data=zeroconf.ZeroconfServiceInfo(
hostname="localhost", name="Brother Printer"
),
)
await hass.async_block_till_done()
@ -220,7 +222,7 @@ async def test_zeroconf_confirm_create_entry(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
hostname="example.local.", name="Brother Printer"
),
)

View file

@ -120,7 +120,7 @@ async def test_api_password_abort(hass):
@pytest.mark.parametrize(
"source, data, unique_id",
[
(SOURCE_ZEROCONF, zeroconf.HaServiceInfo(host=HOST), MAC),
(SOURCE_ZEROCONF, zeroconf.ZeroconfServiceInfo(host=HOST), MAC),
],
)
async def test_discovery_zeroconf(

View file

@ -2,7 +2,7 @@
from homeassistant.components import zeroconf
DISCOVERY_INFO = zeroconf.HaServiceInfo(
DISCOVERY_INFO = zeroconf.ZeroconfServiceInfo(
host="192.168.0.1",
port=14791,
hostname="test.local.",
@ -19,6 +19,8 @@ DISCOVERY_INFO = zeroconf.HaServiceInfo(
},
)
DISCOVERY_INFO_WRONG_DEVOLO_DEVICE = zeroconf.HaServiceInfo(properties={"MT": "2700"})
DISCOVERY_INFO_WRONG_DEVOLO_DEVICE = zeroconf.ZeroconfServiceInfo(
properties={"MT": "2700"}
)
DISCOVERY_INFO_WRONG_DEVICE = zeroconf.HaServiceInfo(properties={"Features": ""})
DISCOVERY_INFO_WRONG_DEVICE = zeroconf.ZeroconfServiceInfo(properties={"Features": ""})

View file

@ -16,7 +16,7 @@ CONNECTED_STATIONS = {
],
}
DISCOVERY_INFO = zeroconf.HaServiceInfo(
DISCOVERY_INFO = zeroconf.ZeroconfServiceInfo(
host=IP,
port=14791,
hostname="test.local.",
@ -36,7 +36,7 @@ DISCOVERY_INFO = zeroconf.HaServiceInfo(
},
)
DISCOVERY_INFO_WRONG_DEVICE = zeroconf.HaServiceInfo(properties={"MT": "2600"})
DISCOVERY_INFO_WRONG_DEVICE = zeroconf.ZeroconfServiceInfo(properties={"MT": "2600"})
NEIGHBOR_ACCESS_POINTS = {
"neighbor_aps": [

View file

@ -82,7 +82,7 @@ async def test_form_zeroconf_wrong_oui(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
properties={"macaddress": "notdoorbirdoui"},
host="192.168.1.8",
name="Doorstation - abc123._axis-video._tcp.local.",
@ -98,7 +98,7 @@ async def test_form_zeroconf_link_local_ignored(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
properties={"macaddress": "1CCAE3DOORBIRD"},
host="169.254.103.61",
name="Doorstation - abc123._axis-video._tcp.local.",
@ -121,7 +121,7 @@ async def test_form_zeroconf_correct_oui(hass):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
properties={"macaddress": "1CCAE3DOORBIRD"},
name="Doorstation - abc123._axis-video._tcp.local.",
host="192.168.1.5",
@ -180,7 +180,7 @@ async def test_form_zeroconf_correct_oui_wrong_device(hass, doorbell_state_side_
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
properties={"macaddress": "1CCAE3DOORBIRD"},
name="Doorstation - abc123._axis-video._tcp.local.",
host="192.168.1.5",

View file

@ -158,7 +158,7 @@ async def test_zeroconf(hass: HomeAssistant) -> None:
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
properties={"serialnum": "1234"},
host="1.1.1.1",
),
@ -254,7 +254,7 @@ async def test_zeroconf_serial_already_exists(hass: HomeAssistant) -> None:
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
properties={"serialnum": "1234"},
host="1.1.1.1",
),
@ -289,7 +289,7 @@ async def test_zeroconf_host_already_exists(hass: HomeAssistant) -> None:
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf.HaServiceInfo(
data=zeroconf.ZeroconfServiceInfo(
properties={"serialnum": "1234"},
host="1.1.1.1",
),

View file

@ -18,7 +18,7 @@ from .const import MOCK_HOST, MOCK_PORT
from tests.common import MockConfigEntry
MOCK_ZEROCONF_DATA = zeroconf.HaServiceInfo(
MOCK_ZEROCONF_DATA = zeroconf.ZeroconfServiceInfo(
host="192.168.0.254",
port=80,
hostname="Freebox-Server.local.",

View file

@ -5,7 +5,7 @@ from unittest.mock import MagicMock, patch
from aiolookin import Climate, Device, Remote
from homeassistant.components.zeroconf import HaServiceInfo
from homeassistant.components.zeroconf import ZeroconfServiceInfo
DEVICE_ID = "98F33163"
MODULE = "homeassistant.components.lookin"
@ -17,7 +17,7 @@ DEFAULT_ENTRY_TITLE = DEVICE_NAME
ZC_NAME = f"LOOKin_{DEVICE_ID}"
ZC_TYPE = "_lookin._tcp."
ZEROCONF_DATA: HaServiceInfo = {
ZEROCONF_DATA: ZeroconfServiceInfo = {
"host": IP_ADDRESS,
"hostname": f"{ZC_NAME.lower()}.local.",
"port": 80,